From c892bf60a8ebeed2f933ebc0231bd0ce63e24318 Mon Sep 17 00:00:00 2001 From: Souriya Trinh Date: Mon, 21 Oct 2024 21:59:17 +0200 Subject: [PATCH] Add short support with vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip) function. This allows using the OpenCV backend with Canny detection. --- .../core/src/image/vpImageConvert_opencv.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/core/src/image/vpImageConvert_opencv.cpp b/modules/core/src/image/vpImageConvert_opencv.cpp index 12b7eda56f..b3b380674e 100644 --- a/modules/core/src/image/vpImageConvert_opencv.cpp +++ b/modules/core/src/image/vpImageConvert_opencv.cpp @@ -283,9 +283,9 @@ void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, b } /*! - * Converts cv::Mat CV_32FC1 format to ViSP vpImage. + * Converts cv::Mat CV_32FC1 / CV_16SC1 format to ViSP vpImage. * - * \param[in] src : OpenCV image in CV_32FC1 format. + * \param[in] src : OpenCV image in CV_32FC1 / CV_16SC1 format. * \param[out] dest : ViSP image in float format. * \param[in] flip : When true during conversion flip image vertically. */ @@ -296,7 +296,7 @@ void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip unsigned int destCols = dest.getCols(); if (src.type() == CV_32FC1) { - for (unsigned int i = 0; i < destRows; ++i) + for (unsigned int i = 0; i < destRows; ++i) { for (unsigned int j = 0; j < destCols; ++j) { if (flip) { dest[dest.getRows() - i - 1][j] = src.at(static_cast(i), static_cast(j)); @@ -305,6 +305,19 @@ void vpImageConvert::convert(const cv::Mat &src, vpImage &dest, bool flip dest[i][j] = src.at(static_cast(i), static_cast(j)); } } + } + } + else if (src.type() == CV_16SC1) { + for (unsigned int i = 0; i < destRows; ++i) { + for (unsigned int j = 0; j < destCols; ++j) { + if (flip) { + dest[dest.getRows() - i - 1][j] = src.at(static_cast(i), static_cast(j)); + } + else { + dest[i][j] = src.at(static_cast(i), static_cast(j)); + } + } + } } else { throw vpException(vpException::badValue, "cv::Mat type is not supported!");