Skip to content

Commit

Permalink
Compute the threshold on the gradient image instead of the equalized …
Browse files Browse the repository at this point in the history
…histogram version of the gradient with OpenCV
  • Loading branch information
rlagneau committed Oct 11, 2023
1 parent 0f30862 commit d916053
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions modules/core/src/image/vpImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,6 @@ float vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p
cv::addWeighted(sobelxabs, 1, sobelyabs, 1, 0, sobel);
sobel.convertTo(sobel, CV_8U);

Check warning on line 639 in modules/core/src/image/vpImageFilter.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageFilter.cpp#L636-L639

Added lines #L636 - L639 were not covered by tests

// Equalize the histogram
cv::Mat equalized;
cv::equalizeHist(sobel, equalized);

// Compute the upper threshold from the equalized histogram
cv::Mat hist;
const float range[] = { 0.f, 256.f }; // The upper boundary is exclusive
Expand All @@ -651,7 +647,7 @@ float vpImageFilter::computeCannyThreshold(const cv::Mat &cv_I, const cv::Mat *p
int histSize[] = { bins };

Check warning on line 647 in modules/core/src/image/vpImageFilter.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageFilter.cpp#L647

Added line #L647 was not covered by tests
bool uniform = true;
bool accumulate = false; // Clear the histogram at the beginning of calcHist if false, does not clear it otherwise
cv::calcHist(&equalized, 1, channels, cv::Mat(), hist, dims, histSize, ranges, uniform, accumulate);
cv::calcHist(&sobel, 1, channels, cv::Mat(), hist, dims, histSize, ranges, uniform, accumulate);

Check warning on line 650 in modules/core/src/image/vpImageFilter.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageFilter.cpp#L650

Added line #L650 was not covered by tests
float accu = 0;
float t = (float)(upperThresholdRatio * w * h);
float bon = 0;
Expand Down Expand Up @@ -922,7 +918,7 @@ void vpImageFilter::canny(const vpImage<unsigned char> &Isrc, vpImage<unsigned c
vpImageConvert::convert(Isrc, img_cvmat);
if (cannyFilteringSteps == CANNY_GBLUR_SOBEL_FILTERING) {
cv::Mat cv_I_blur;
cv::GaussianBlur(img_cvmat, cv_I_blur, cv::Size((int)gaussianFilterSize, (int)gaussianFilterSize), 0, 0);
cv::GaussianBlur(img_cvmat, cv_I_blur, cv::Size((int)gaussianFilterSize, (int)gaussianFilterSize), gaussianStdev, 0);
cv::Sobel(cv_I_blur, cv_dx, CV_16S, 1, 0, apertureSobel);
cv::Sobel(cv_I_blur, cv_dy, CV_16S, 0, 1, apertureSobel);
}

Check warning on line 924 in modules/core/src/image/vpImageFilter.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageFilter.cpp#L917-L924

Added lines #L917 - L924 were not covered by tests
Expand Down

0 comments on commit d916053

Please sign in to comment.