Skip to content

Commit

Permalink
[FIX] Fix Canny auto threshold
Browse files Browse the repository at this point in the history
Ensure that lower ratio < upper ratio
  • Loading branch information
LAGNEAU Romain committed Oct 30, 2024
1 parent cc3881e commit 6adf6a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion modules/core/include/visp3/core/vpImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ class VISP_EXPORT vpImageFilter
throw(vpException(vpException::fatalError, errMsg.str()));
}

Check warning on line 352 in modules/core/include/visp3/core/vpImageFilter.h

View check run for this annotation

Codecov / codecov/patch

modules/core/include/visp3/core/vpImageFilter.h#L348-L352

Added lines #L348 - L352 were not covered by tests

if (lowerThresholdRatio >= upperThresholdRatio) {
std::stringstream errMsg;
errMsg << "Lower ratio (" << lowerThresholdRatio << ") should be lower than the upper ratio (" << upperThresholdRatio << ")";
throw(vpException(vpException::fatalError, errMsg.str()));
}

Check warning on line 358 in modules/core/include/visp3/core/vpImageFilter.h

View check run for this annotation

Codecov / codecov/patch

modules/core/include/visp3/core/vpImageFilter.h#L354-L358

Added lines #L354 - L358 were not covered by tests

vpImage<unsigned char> dI(h, w);
vpImage<OutType> dIx(h, w), dIy(h, w);
if ((p_dIx != nullptr) && (p_dIy != nullptr)) {
Expand Down Expand Up @@ -1509,6 +1515,6 @@ class VISP_EXPORT vpImageFilter
}
#endif

};
};
END_VISP_NAMESPACE
#endif
6 changes: 6 additions & 0 deletions modules/core/src/image/vpImageFilter_canny.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ float vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p
throw(vpException(vpException::fatalError, errMsg.str()));
}

Check warning on line 216 in modules/core/src/image/vpImageFilter_canny.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageFilter_canny.cpp#L212-L216

Added lines #L212 - L216 were not covered by tests

if (lowerThresholdRatio >= upperThresholdRatio) {
std::stringstream errMsg;
errMsg << "Lower ratio (" << lowerThresholdRatio << ") should be lower than the upper ratio (" << upperThresholdRatio << ")";
throw(vpException(vpException::fatalError, errMsg.str()));
}

Check warning on line 222 in modules/core/src/image/vpImageFilter_canny.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageFilter_canny.cpp#L218-L222

Added lines #L218 - L222 were not covered by tests

double w = cv_I.cols;
double h = cv_I.rows;
int bins = 256;
Expand Down

0 comments on commit 6adf6a0

Please sign in to comment.