Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Yarp cmake detection and usage (Closes #1424) #1425

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 18 additions & 14 deletions modules/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
35 changes: 22 additions & 13 deletions modules/core/src/image/vpImageConvert_yarp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
*
* Description:
* Convert image types.
*
*****************************************************************************/
*/

/*!
\file vpImageConvert_yarp.cpp
Expand All @@ -40,6 +39,8 @@

#ifdef VISP_HAVE_YARP

#include <visp3/core/vpImageConvert.h>

BEGIN_VISP_NAMESPACE
/*!
Convert a vpImage\<unsigned char\> to a yarp::sig::ImageOf\<yarp::sig::PixelMono\>
Expand All @@ -65,7 +66,7 @@ BEGIN_VISP_NAMESPACE
int main()
{
#if defined(VISP_HAVE_YARP)
vpImage<unsigned char> I; // A mocochrome image
vpImage<unsigned char> I; // A monochrome image
// Read an image on a disk
vpImageIo::read(I, "image.pgm");

Expand All @@ -83,7 +84,11 @@ void vpImageConvert::convert(const vpImage<unsigned char> &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<int>(src.getCols()), static_cast<int>(src.getRows()));
Expand Down Expand Up @@ -136,11 +141,11 @@ void vpImageConvert::convert(const yarp::sig::ImageOf<yarp::sig::PixelMono> *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);
}
}
}

Expand Down Expand Up @@ -238,10 +243,14 @@ void vpImageConvert::convert(const vpImage<vpRGBa> &src, yarp::sig::ImageOf<yarp
void vpImageConvert::convert(const yarp::sig::ImageOf<yarp::sig::PixelRgba> *src, vpImage<vpRGBa> &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<vpRGBa *>(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;
}
}
}

Expand Down
172 changes: 171 additions & 1 deletion modules/core/test/image-with-dataset/testConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
#include <opencv2/imgproc/imgproc.hpp>
#endif

/*!
\example testConversion.cpp

\brief Manipulation of image conversions.
*/
#if defined(VISP_HAVE_YARP)
#include <yarp/sig/ImageFile.h>
#endif

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
Expand Down Expand Up @@ -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<unsigned char> I;
// Read an image on a disk
vpImageIo::read(I, filename);

yarp::sig::ImageOf< yarp::sig::PixelMono > *Iyarp = new yarp::sig::ImageOf<yarp::sig::PixelMono >();
// Convert the vpImage\<unsigned char\> to a yarp::sig::ImageOf\<yarp::sig::PixelMono\>
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::PixelMono >();
yarp::sig::file::read(*IIyarp, filename, yarp::sig::file::FORMAT_PGM);
vpImage<unsigned char> 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<vpRGBa> I;
// Read an image on a disk
vpImageIo::read(I, filename);

yarp::sig::ImageOf< yarp::sig::PixelRgba > *Iyarp = new yarp::sig::ImageOf<yarp::sig::PixelRgba >();
// Convert the vpImage\<vpRGBa\> to a yarp::sig::ImageOf\<yarp::sig::PixelRgba\>
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::PixelRgba >();
yarp::sig::file::read(*IIyarp, filename, yarp::sig::file::FORMAT_PPM);
vpImage<vpRGBa> 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<unsigned char> I;
// Read an image on a disk
vpImageIo::read(I, filename);

yarp::sig::ImageOf< yarp::sig::PixelMono > *Iyarp = new yarp::sig::ImageOf<yarp::sig::PixelMono >();
// Convert the vpImage\<unsigned char\> to a yarp::sig::ImageOf\<yarp::sig::PixelMono\>
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::PixelMono >();
yarp::sig::file::read(*IIyarp, filename, yarp::sig::file::FORMAT_PGM);
vpImage<unsigned char> 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<vpRGBa> I;
// Read an image on a disk
vpImageIo::read(I, filename);

yarp::sig::ImageOf< yarp::sig::PixelRgba > *Iyarp = new yarp::sig::ImageOf<yarp::sig::PixelRgba >();
// Convert the vpImage\<vpRGBa\> to a yarp::sig::ImageOf\<yarp::sig::PixelRgba\>
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::PixelRgba >();
yarp::sig::file::read(*IIyarp, filename, yarp::sig::file::FORMAT_PPM);
vpImage<vpRGBa> 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<yarp::sig::PixelRgb >();
// Convert the vpImage\<vpRGBa\> to a yarp::sig::ImageOf\<yarp::sig::PixelRgb\>
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<vpRGBa> 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) {
Expand Down
Loading