我想使用带有 C++ 的 OpenCV 查找此图像中的圆圈/结节总数。
我为此编写了以下代码:
src = imread("src.bmp"); //src is source image
cvtColor(src, src_gray, CV_BGR2GRAY); // Gray scale convert
Mat bw = src_gray > 128;
imshow("Gray Scaled Source",src_gray);
Canny(src_gray, canny_output, thresh, thresh * 2, 3); /// Detect edges using canny
/// Find contours
findContours(canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
/// Draw contours
drawing = Mat::zeros(canny_output.size(), CV_8UC3);
cout<<contours.size(); // total no of contours
通过这段代码,我的答案是:117
但正确答案是:62