diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ac08e07c8..c25a3d4b5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1711,13 +1711,16 @@ status(" Build with moment combine:" ENABLE_MOMENTS_COMBINE_MATRICES THEN "y # ===================== Optional 3rd parties ===================== status("") status(" OpenCV: ") -status(" Version:" USE_OPENCV THEN "${OpenCV_VERSION}" ELSE "n/a") +status(" Version:" USE_OPENCV THEN "${OpenCV_VERSION}" ELSE "n/a") if(USE_OPENCV) vp_list_replace_string(OpenCV_LIB_COMPONENTS OpenCV_LIB_COMPONENTS_FILTERED "^opencv_+" "") status(" Modules:" "${OpenCV_LIB_COMPONENTS_FILTERED}") status(" OpenCV dir:" "${OpenCV_DIR}") endif() status("") +status(" YARP: ") +status(" Version:" USE_YARP THEN "${YARP_VERSION_SHORT}" ELSE "n/a") +status("") status(" Mathematics: ") status(" Blas/Lapack:" (USE_LAPACK OR WITH_LAPACK) THEN "yes" ELSE "no") status(" \\- Use MKL:" USE_MKL THEN "yes" ELSE "no") diff --git a/ChangeLog.txt b/ChangeLog.txt index df585eecb7..926f81569c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -75,6 +75,7 @@ ViSP 3.x.x (Version in development) . [#1337] The pose of the automatic datageneration pipeline from blenderproc seems wrong . [#1341] SVD computation fails with Lapack when m < n . [#1370] encountered compilation errors while building the ViSP library + . [#1424] Unable to detect Yarp 3.9.0 ---------------------------------------------- ViSP 3.6.0 (released September 22, 2023) - Contributors: diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index c43a4b9f78..69db0c63a3 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -161,7 +161,24 @@ if(USE_OPENCV) endif(USE_OPENCV) if(USE_YARP) - list(APPEND opt_incs ${YARP_INCLUDE_DIRS}) + foreach(lib_ ${YARP_LIBRARIES}) + get_target_property(imported_libs_ ${lib_} INTERFACE_LINK_LIBRARIES) + if(imported_libs_) + list(APPEND YARP_LIBS ${lib_}) + list(APPEND YARP_IMPORTED_LIBS ${imported_libs_}) + else() + list(APPEND YARP_LIBS ${lib_}) + endif() + + get_target_property(imported_incs_ ${lib_} INTERFACE_INCLUDE_DIRECTORIES) + if(imported_incs_) + list(APPEND YARP_IMPORTED_INCLUDE_DIRS ${imported_incs_}) + endif() + endforeach() + vp_list_unique(YARP_IMPORTED_LIBS) + vp_list_unique(YARP_IMPORTED_INCLUDE_DIRS) + + list(APPEND opt_incs ${YARP_IMPORTED_INCLUDE_DIRS}) # Work around to add Yarp libraries and also third party libraries requested by Yarp list(REVERSE YARP_LIBRARIES) # to start with YARP_init, that depends on YARP_dev, YARP_sig and YARP_OS @@ -182,21 +199,8 @@ if(USE_YARP) else() list(APPEND opt_libs ${YARP_LIB}) # Append full absolute library path and name endif() - # Get 3rd party libraries requested by Yarp - get_target_property(YARP_LINK_LIBS_ ${lib} "IMPORTED_LINK_INTERFACE_LIBRARIES_${CONFIGURATION}") - list(APPEND YARP_LINK_LIBS ${YARP_LINK_LIBS_}) endforeach() endforeach() - - # Remove Yarp libraries since they were added previously with full absolute library path and name - if(YARP_LINK_LIBS) - foreach(lib ${YARP_LIBRARIES}) - list(REMOVE_ITEM YARP_LINK_LIBS ${lib}) - endforeach() - endif() - # Add 3rd party libraries requested by Yarp - list(APPEND opt_libs ${YARP_LINK_LIBS}) - add_definitions(${YARP_DEFINES}) endif(USE_YARP) # Math: eigen3, gsl, mkl, openblas, atlas, netlib, OpenCV diff --git a/modules/core/src/image/vpImageConvert_yarp.cpp b/modules/core/src/image/vpImageConvert_yarp.cpp index 030abf62e7..f8374b6d24 100644 --- a/modules/core/src/image/vpImageConvert_yarp.cpp +++ b/modules/core/src/image/vpImageConvert_yarp.cpp @@ -29,8 +29,7 @@ * * Description: * Convert image types. - * -*****************************************************************************/ + */ /*! \file vpImageConvert_yarp.cpp @@ -40,6 +39,8 @@ #ifdef VISP_HAVE_YARP +#include + BEGIN_VISP_NAMESPACE /*! Convert a vpImage\ to a yarp::sig::ImageOf\ @@ -65,7 +66,7 @@ BEGIN_VISP_NAMESPACE int main() { #if defined(VISP_HAVE_YARP) - vpImage I; // A mocochrome image + vpImage I; // A monochrome image // Read an image on a disk vpImageIo::read(I, "image.pgm"); @@ -83,7 +84,11 @@ void vpImageConvert::convert(const vpImage &src, yarp::sig::Image { if (copyData) { dest->resize(src.getWidth(), src.getHeight()); - memcpy(dest->getRawImage(), src.bitmap, src.getHeight() * src.getWidth()); + for (unsigned int i = 0; i < src.getHeight(); ++i) { + for (unsigned int j = 0; j < src.getWidth(); ++j) { + dest->pixel(j, i) = src[i][j]; + } + } } else { dest->setExternal(src.bitmap, static_cast(src.getCols()), static_cast(src.getRows())); @@ -136,11 +141,11 @@ void vpImageConvert::convert(const yarp::sig::ImageOf *src bool copyData) { dest.resize(src->height(), src->width()); - if (copyData) { - memcpy(dest.bitmap, src->getRawImage(), src->height() * src->width() * sizeof(yarp::sig::PixelMono)); - } - else { - dest.bitmap = src->getRawImage(); + (void)(copyData); + for (unsigned int i = 0; i < dest.getHeight(); ++i) { + for (unsigned int j = 0; j < dest.getWidth(); ++j) { + dest[i][j] = src->pixel(j, i); + } } } @@ -238,10 +243,14 @@ void vpImageConvert::convert(const vpImage &src, yarp::sig::ImageOf *src, vpImage &dest, bool copyData) { dest.resize(src->height(), src->width()); - if (copyData) - memcpy(dest.bitmap, src->getRawImage(), src->height() * src->width() * sizeof(yarp::sig::PixelRgba)); - else { - dest.bitmap = static_cast(src->getRawImage()); + (void)(copyData); + for (unsigned int i = 0; i < dest.getHeight(); ++i) { + for (unsigned int j = 0; j < dest.getWidth(); ++j) { + dest[i][j].R = src->pixel(j, i).r; + dest[i][j].G = src->pixel(j, i).g; + dest[i][j].B = src->pixel(j, i).b; + dest[i][j].A = src->pixel(j, i).a; + } } } diff --git a/modules/core/test/image-with-dataset/testConversion.cpp b/modules/core/test/image-with-dataset/testConversion.cpp index 0805138ddd..da3f0cc0c6 100644 --- a/modules/core/test/image-with-dataset/testConversion.cpp +++ b/modules/core/test/image-with-dataset/testConversion.cpp @@ -54,6 +54,15 @@ #include #endif +/*! + \example testConversion.cpp + + \brief Manipulation of image conversions. +*/ +#if defined(VISP_HAVE_YARP) +#include +#endif + #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif @@ -657,9 +666,170 @@ int main(int argc, const char **argv) std::cout << " Resulting image saved in: " << filename << std::endl; vpImageIo::write(I_bgr2gray_flip_crop_no_continuous_sse, filename); #endif - std::cout << "Test succeed" << std::endl; + std::cout << " Test succeed" << std::endl; + } + +#if defined(VISP_HAVE_YARP) + ///////////////////////// + // Convert a ViSP to Yarp uchar image + //////////////////////// + std::cout << "** Test ViSP to Yarp image conversion by copy" << std::endl; + { + bool convert_by_copy = true; + filename = vpIoTools::createFilePath(ipath, "Klimt/Klimt.pgm"); + std::cout << " Reading the gray image with ViSP: " << filename << std::endl; + vpImage I; + // Read an image on a disk + vpImageIo::read(I, filename); + + yarp::sig::ImageOf< yarp::sig::PixelMono > *Iyarp = new yarp::sig::ImageOf(); + // Convert the vpImage\ to a yarp::sig::ImageOf\ + vpImageConvert::convert(I, Iyarp, convert_by_copy); + // Write the image + filename = vpIoTools::createFilePath(opath, "Klimt_yarp_copy.pgm"); + std::cout << " Converted Yarp image saved in: " << filename << std::endl; + yarp::sig::file::write(*Iyarp, filename, yarp::sig::file::FORMAT_PGM); + + std::cout << " Reading the gray image with Yarp: " << filename << std::endl; + yarp::sig::ImageOf< yarp::sig::PixelMono > *IIyarp = new yarp::sig::ImageOf(); + yarp::sig::file::read(*IIyarp, filename, yarp::sig::file::FORMAT_PGM); + vpImage II; + vpImageConvert::convert(IIyarp, II, convert_by_copy); + filename = vpIoTools::createFilePath(opath, "Klimt_yarp_copy_visp.pgm"); + std::cout << " Converted image in ViSP saved in: " << filename << std::endl; + vpImageIo::write(II, filename); + if (I != II) { + std::cout << " Yarp gray conversion test failed" << std::endl; + return EXIT_FAILURE; + } + std::cout << std::endl; + } + { + bool convert_by_copy = true; + filename = vpIoTools::createFilePath(ipath, "Klimt/Klimt.ppm"); + std::cout << " Reading the color image with ViSP: " << filename << std::endl; + vpImage I; + // Read an image on a disk + vpImageIo::read(I, filename); + + yarp::sig::ImageOf< yarp::sig::PixelRgba > *Iyarp = new yarp::sig::ImageOf(); + // Convert the vpImage\ to a yarp::sig::ImageOf\ + vpImageConvert::convert(I, Iyarp, convert_by_copy); + // Write the image + filename = vpIoTools::createFilePath(opath, "Klimt_yarp_copy.ppm"); + std::cout << " Converted image saved in: " << filename << std::endl; + yarp::sig::file::write(*Iyarp, filename, yarp::sig::file::FORMAT_PPM); + + std::cout << " Reading the color image with Yarp: " << filename << std::endl; + yarp::sig::ImageOf< yarp::sig::PixelRgba > *IIyarp = new yarp::sig::ImageOf(); + yarp::sig::file::read(*IIyarp, filename, yarp::sig::file::FORMAT_PPM); + vpImage II; + vpImageConvert::convert(IIyarp, II, convert_by_copy); + filename = vpIoTools::createFilePath(opath, "Klimt_yarp_copy_visp.ppm"); + std::cout << " Converted image in ViSP saved in: " << filename << std::endl; + vpImageIo::write(II, filename); + if (I != II) { + std::cout << " Yarp color conversion test failed" << std::endl; + return EXIT_FAILURE; + } + std::cout << std::endl; } + std::cout << "** Test ViSP to Yarp image conversion without copy" << std::endl; + { + bool convert_by_copy = false; + filename = vpIoTools::createFilePath(ipath, "Klimt/Klimt.pgm"); + std::cout << " Reading the gray image with ViSP: " << filename << std::endl; + vpImage I; + // Read an image on a disk + vpImageIo::read(I, filename); + + yarp::sig::ImageOf< yarp::sig::PixelMono > *Iyarp = new yarp::sig::ImageOf(); + // Convert the vpImage\ to a yarp::sig::ImageOf\ + vpImageConvert::convert(I, Iyarp, convert_by_copy); + // Write the image + filename = vpIoTools::createFilePath(opath, "Klimt_yarp_without_copy.pgm"); + std::cout << " Converted Yarp image saved in: " << filename << std::endl; + yarp::sig::file::write(*Iyarp, filename, yarp::sig::file::FORMAT_PGM); + + std::cout << " Reading the gray image with Yarp: " << filename << std::endl; + yarp::sig::ImageOf< yarp::sig::PixelMono > *IIyarp = new yarp::sig::ImageOf(); + yarp::sig::file::read(*IIyarp, filename, yarp::sig::file::FORMAT_PGM); + vpImage II; + vpImageConvert::convert(IIyarp, II, convert_by_copy); + filename = vpIoTools::createFilePath(opath, "Klimt_yarp_without_copy_visp.pgm"); + std::cout << " Converted image in ViSP saved in: " << filename << std::endl; + vpImageIo::write(II, filename); + if (I != II) { + std::cout << " Yarp gray conversion test failed" << std::endl; + return EXIT_FAILURE; + } + else { + std::cout << " Yarp gray conversion test succeed" << std::endl; + } + std::cout << std::endl; + } + { + bool convert_by_copy = false; + filename = vpIoTools::createFilePath(ipath, "Klimt/Klimt.ppm"); + std::cout << " Reading the color image with ViSP: " << filename << std::endl; + vpImage I; + // Read an image on a disk + vpImageIo::read(I, filename); + + yarp::sig::ImageOf< yarp::sig::PixelRgba > *Iyarp = new yarp::sig::ImageOf(); + // Convert the vpImage\ to a yarp::sig::ImageOf\ + vpImageConvert::convert(I, Iyarp, convert_by_copy); + // Write the image + filename = vpIoTools::createFilePath(opath, "Klimt_yarp_without_copy.ppm"); + std::cout << " Converted image saved in: " << filename << std::endl; + yarp::sig::file::write(*Iyarp, filename, yarp::sig::file::FORMAT_PPM); + + std::cout << " Reading the color image with Yarp: " << filename << std::endl; + yarp::sig::ImageOf< yarp::sig::PixelRgba > *IIyarp = new yarp::sig::ImageOf(); + yarp::sig::file::read(*IIyarp, filename, yarp::sig::file::FORMAT_PPM); + vpImage II; + vpImageConvert::convert(IIyarp, II, convert_by_copy); + filename = vpIoTools::createFilePath(opath, "Klimt_yarp_without_copy_visp.ppm"); + std::cout << " Converted image in ViSP saved in: " << filename << std::endl; + vpImageIo::write(II, filename); + if (I != II) { + std::cout << " Yarp RGBa color conversion test failed" << std::endl; + return EXIT_FAILURE; + } + else { + std::cout << " Yarp RGBa color conversion test succeed" << std::endl; + } + + yarp::sig::ImageOf< yarp::sig::PixelRgb > *IIIyarp = new yarp::sig::ImageOf(); + // Convert the vpImage\ to a yarp::sig::ImageOf\ + vpImageConvert::convert(I, IIIyarp); + // Write the image + filename = vpIoTools::createFilePath(opath, "Klimt_yarp_without_copy_rgb.ppm"); + std::cout << " Converted RGB image saved in: " << filename << std::endl; + yarp::sig::file::write(*Iyarp, filename, yarp::sig::file::FORMAT_PPM); + + std::cout << " Reading the RGB color image with Yarp: " << filename << std::endl; + yarp::sig::file::read(*IIIyarp, filename, yarp::sig::file::FORMAT_PPM); + vpImage III; + vpImageConvert::convert(IIIyarp, III); + filename = vpIoTools::createFilePath(opath, "Klimt_yarp_without_copy_visp_rgb.ppm"); + std::cout << " Converted RGB image in ViSP saved in: " << filename << std::endl; + vpImageIo::write(II, filename); + if (I != III) { + std::cout << " Yarp RGB color conversion test failed" << std::endl; + return EXIT_FAILURE; + } + else { + std::cout << " Yarp RGB color conversion test succeed" << std::endl; + } + + std::cout << std::endl; + } +#endif + + std::cout << "** All the tests succeed" << std::endl; + return EXIT_SUCCESS; } catch (const vpException &e) {