Skip to content

Commit

Permalink
Add short support with vpImageConvert::convert(const cv::Mat &src, vp…
Browse files Browse the repository at this point in the history
…Image<float> &dest, bool flip) function. This allows using the OpenCV backend with Canny detection.
  • Loading branch information
s-trinh committed Oct 21, 2024
1 parent a65eebc commit c892bf6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions modules/core/src/image/vpImageConvert_opencv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ void vpImageConvert::convert(const cv::Mat &src, vpImage<unsigned char> &dest, b
}

/*!
* Converts cv::Mat CV_32FC1 format to ViSP vpImage<float>.
* Converts cv::Mat CV_32FC1 / CV_16SC1 format to ViSP vpImage<float>.
*
* \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.
*/
Expand All @@ -296,7 +296,7 @@ void vpImageConvert::convert(const cv::Mat &src, vpImage<float> &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) {

Check warning on line 299 in modules/core/src/image/vpImageConvert_opencv.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageConvert_opencv.cpp#L299

Added line #L299 was not covered by tests
for (unsigned int j = 0; j < destCols; ++j) {
if (flip) {
dest[dest.getRows() - i - 1][j] = src.at<float>(static_cast<int>(i), static_cast<int>(j));
Expand All @@ -305,6 +305,19 @@ void vpImageConvert::convert(const cv::Mat &src, vpImage<float> &dest, bool flip
dest[i][j] = src.at<float>(static_cast<int>(i), static_cast<int>(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<short>(static_cast<int>(i), static_cast<int>(j));

Check warning on line 314 in modules/core/src/image/vpImageConvert_opencv.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageConvert_opencv.cpp#L310-L314

Added lines #L310 - L314 were not covered by tests
}
else {
dest[i][j] = src.at<short>(static_cast<int>(i), static_cast<int>(j));

Check warning on line 317 in modules/core/src/image/vpImageConvert_opencv.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageConvert_opencv.cpp#L317

Added line #L317 was not covered by tests
}
}
}
}
else {
throw vpException(vpException::badValue, "cv::Mat type is not supported!");
Expand Down

0 comments on commit c892bf6

Please sign in to comment.