From 25dcb1d0ceba86ab894b9e68fcbf94d722ac86a1 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 13 Mar 2024 16:44:36 +0100 Subject: [PATCH] Fix build on centos 7.2 ci that has OpenCV 2.4.5 --- modules/core/include/visp3/core/vpImage.h | 2 +- .../core/include/visp3/core/vpImageConvert.h | 2 +- .../perfColorConversion.cpp | 2 +- .../image-with-dataset/perfGaussianFilter.cpp | 2 +- .../image-with-dataset/perfImageResize.cpp | 2 +- .../image-with-dataset/testConversion.cpp | 2 +- .../gui/include/visp3/gui/vpDisplayOpenCV.h | 7 +++ modules/gui/src/display/vpDisplayOpenCV.cpp | 48 ++++++++----------- tutorial/image/tutorial-image-converter.cpp | 2 +- 9 files changed, 34 insertions(+), 35 deletions(-) diff --git a/modules/core/include/visp3/core/vpImage.h b/modules/core/include/visp3/core/vpImage.h index 3687de81e9..4f6ed7c048 100644 --- a/modules/core/include/visp3/core/vpImage.h +++ b/modules/core/include/visp3/core/vpImage.h @@ -845,7 +845,7 @@ vpImage::vpImage(const vpImage &I) { resize(I.getHeight(), I.getWidth()); if (bitmap) { - memcpy(static_cast(bitmap), static_cast(I.bitmap), I.npixels * sizeof(Type)); + memcpy(static_cast(bitmap), static_cast(I.bitmap), I.npixels * sizeof(Type)); } } diff --git a/modules/core/include/visp3/core/vpImageConvert.h b/modules/core/include/visp3/core/vpImageConvert.h index 1e566d531a..6d48456f6b 100644 --- a/modules/core/include/visp3/core/vpImageConvert.h +++ b/modules/core/include/visp3/core/vpImageConvert.h @@ -49,7 +49,7 @@ #include #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) -#include +#include #include #endif diff --git a/modules/core/test/image-with-dataset/perfColorConversion.cpp b/modules/core/test/image-with-dataset/perfColorConversion.cpp index 03d24abf5b..e6df803d23 100644 --- a/modules/core/test/image-with-dataset/perfColorConversion.cpp +++ b/modules/core/test/image-with-dataset/perfColorConversion.cpp @@ -47,7 +47,7 @@ #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC) #include -#include +#include #endif static std::string ipath = vpIoTools::getViSPImagesDataPath(); diff --git a/modules/core/test/image-with-dataset/perfGaussianFilter.cpp b/modules/core/test/image-with-dataset/perfGaussianFilter.cpp index 62adcee3c9..e557cf30ce 100644 --- a/modules/core/test/image-with-dataset/perfGaussianFilter.cpp +++ b/modules/core/test/image-with-dataset/perfGaussianFilter.cpp @@ -47,7 +47,7 @@ #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC) #include -#include +#include #endif static const std::string ipath = vpIoTools::getViSPImagesDataPath(); diff --git a/modules/core/test/image-with-dataset/perfImageResize.cpp b/modules/core/test/image-with-dataset/perfImageResize.cpp index 69cd7d90ca..98fb426a42 100644 --- a/modules/core/test/image-with-dataset/perfImageResize.cpp +++ b/modules/core/test/image-with-dataset/perfImageResize.cpp @@ -48,7 +48,7 @@ #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC) #include -#include +#include #endif static const std::string ipath = vpIoTools::getViSPImagesDataPath(); diff --git a/modules/core/test/image-with-dataset/testConversion.cpp b/modules/core/test/image-with-dataset/testConversion.cpp index c164315390..5386640292 100644 --- a/modules/core/test/image-with-dataset/testConversion.cpp +++ b/modules/core/test/image-with-dataset/testConversion.cpp @@ -47,7 +47,7 @@ #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC) #include -#include +#include #endif /*! diff --git a/modules/gui/include/visp3/gui/vpDisplayOpenCV.h b/modules/gui/include/visp3/gui/vpDisplayOpenCV.h index ca9ce797d9..693a9672d2 100644 --- a/modules/gui/include/visp3/gui/vpDisplayOpenCV.h +++ b/modules/gui/include/visp3/gui/vpDisplayOpenCV.h @@ -135,11 +135,18 @@ class VISP_EXPORT vpDisplayOpenCV : public vpDisplay { private: +#if (VISP_HAVE_OPENCV_VERSION < 0x020408) + IplImage *m_background; + CvScalar *col; + CvScalar cvcolor; + CvFont *font; +#else cv::Mat m_background; cv::Scalar *col; cv::Scalar cvcolor; int font; float fontScale; +#endif static std::vector m_listTitles; static unsigned int m_nbWindows; int fontHeight; diff --git a/modules/gui/src/display/vpDisplayOpenCV.cpp b/modules/gui/src/display/vpDisplayOpenCV.cpp index a31918ab57..0ba15d1e68 100644 --- a/modules/gui/src/display/vpDisplayOpenCV.cpp +++ b/modules/gui/src/display/vpDisplayOpenCV.cpp @@ -778,7 +778,7 @@ void vpDisplayOpenCV::displayImageROI(const vpImage &I, const vpI \warning Display has to be initialized. - \warning suppres the overlay drawing + \warning suppress the overlay drawing \param I : Image to display. @@ -1142,7 +1142,7 @@ void vpDisplayOpenCV::displayText(const vpImagePoint &ip, const std::string &tex if (m_displayHasBeenInitialized) { if (color.id < vpColor::id_unknown) { #if VISP_HAVE_OPENCV_VERSION < 0x020408 - cvPutText(m_background, text, + cvPutText(m_background, text.c_str(), cvPoint(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)), font, col[color.id]); #else @@ -1154,7 +1154,7 @@ void vpDisplayOpenCV::displayText(const vpImagePoint &ip, const std::string &tex else { cvcolor = CV_RGB(color.R, color.G, color.B); #if VISP_HAVE_OPENCV_VERSION < 0x020408 - cvPutText(m_background, text, + cvPutText(m_background, text.c_str(), cvPoint(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)), font, cvcolor); #else @@ -1209,11 +1209,10 @@ void vpDisplayOpenCV::displayCircle(const vpImagePoint ¢er, unsigned int rad #else int filled = CV_FILLED; #endif - double opacity = static_cast(color.A) / 255.0; #if VISP_HAVE_OPENCV_VERSION < 0x020408 - overlay([x, y, r, cv_color, filled](cv::Mat image) { cvCircle(image, cvPoint(x, y), r, cv_color, filled); }, - opacity); + cvCircle(m_background, cvPoint(x, y), r, cv_color, filled); #else + double opacity = static_cast(color.A) / 255.0; overlay([x, y, r, cv_color, filled](cv::Mat image) { cv::circle(image, cv::Point(x, y), r, cv_color, filled); }, opacity); #endif @@ -1426,15 +1425,12 @@ void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, unsigned int #else int filled = CV_FILLED; #endif - double opacity = static_cast(color.A) / 255.0; #if VISP_HAVE_OPENCV_VERSION < 0x020408 - overlay([left, top, right, bottom, cv_color, filled]( - cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); }, - opacity); + cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); #else - overlay( - [left, top, right, bottom, cv_color, filled](cv::Mat image) { - cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled); + double opacity = static_cast(color.A) / 255.0; + overlay([left, top, right, bottom, cv_color, filled](cv::Mat image) { + cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled); }, opacity); #endif @@ -1488,15 +1484,12 @@ void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, const vpImag #else int filled = CV_FILLED; #endif - double opacity = static_cast(color.A) / 255.0; #if VISP_HAVE_OPENCV_VERSION < 0x020408 - overlay([left, top, right, bottom, cv_color, filled]( - cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); }, - opacity); + cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); #else - overlay( - [left, top, right, bottom, cv_color, filled](cv::Mat image) { - cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled); + double opacity = static_cast(color.A) / 255.0; + overlay([left, top, right, bottom, cv_color, filled](cv::Mat image) { + cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled); }, opacity); #endif @@ -1549,15 +1542,12 @@ void vpDisplayOpenCV::displayRectangle(const vpRect &rectangle, const vpColor &c #else int filled = CV_FILLED; #endif - double opacity = static_cast(color.A) / 255.0; #if VISP_HAVE_OPENCV_VERSION < 0x020408 - overlay([left, top, right, bottom, cv_color, filled]( - cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); }, - opacity); + cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); #else - overlay( - [left, top, right, bottom, cv_color, filled](cv::Mat image) { - cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled); + double opacity = static_cast(color.A) / 255.0; + overlay([left, top, right, bottom, cv_color, filled](cv::Mat image) { + cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled); }, opacity); #endif @@ -2147,6 +2137,7 @@ unsigned int vpDisplayOpenCV::getScreenHeight() return height; } +#if VISP_HAVE_OPENCV_VERSION >= 0x020408 /*! * Initialize display overlay layer for transparency. * \param overlay_function : Overlay function @@ -2161,7 +2152,7 @@ void vpDisplayOpenCV::overlay(std::function overlay_function, d overlay = m_background.clone(); } else { - // Shallow copy + // Shallow copy overlay = m_background; } @@ -2172,6 +2163,7 @@ void vpDisplayOpenCV::overlay(std::function overlay_function, d cv::addWeighted(overlay, opacity, m_background, 1.0 - opacity, 0.0, m_background); } } +#endif #elif !defined(VISP_BUILD_SHARED_LIBS) // Work around to avoid warning: libvisp_core.a(vpDisplayOpenCV.cpp.o) has no symbols diff --git a/tutorial/image/tutorial-image-converter.cpp b/tutorial/image/tutorial-image-converter.cpp index 15c96d7037..59e5a9bf9d 100644 --- a/tutorial/image/tutorial-image-converter.cpp +++ b/tutorial/image/tutorial-image-converter.cpp @@ -4,7 +4,7 @@ #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGCODECS) && defined(HAVE_OPENCV_IMGPROC) #include -#include +#include #endif int main()