【发布时间】:2020-03-15 09:41:58
【问题描述】:
我正在尝试获取诸如水敏感卡上水滴所占面积之类的信息,我必须在其中提取面积、滴数,并确定最大水滴和最小水滴。
示例图片:
到目前为止,我所做的是检测潮湿区域,但我很难检测到水滴并测量它们的大小和数量。
按照下面的代码,
如果有人可以提供帮助,我将不胜感激!
src = cv::imread("/Users/gustavovisentini/Documents/Developer/Desktop/OpenCV-Teste3.3.1/binary_image.png");
cout << "Loading Image...\n\n";
cvtColor( src, src_gray, COLOR_BGR2GRAY );
blur( src_gray, src_gray, Size(3,3) );
Mat canny_output;
Canny( src_gray, canny_output, thresh, thresh*2 );
vector<vector<Point>> contours;
findContours( src_gray, contours, RETR_TREE, CHAIN_APPROX_SIMPLE );
vector<vector<Point> > contours_poly( contours.size() );
vector<Rect> boundRect( contours.size() );
vector<Point2f>centers( contours.size() );
vector<float>radius( contours.size() );
for( size_t i = 0; i < contours.size(); i++ )
{
approxPolyDP( contours[i], contours_poly[i], 3, true );
boundRect[i] = boundingRect( contours_poly[i] );
minEnclosingCircle( contours_poly[i], centers[i], radius[i] );
}
Mat drawing = src.clone();
for( size_t i = 0; i< contours.size(); i++ )
{
Scalar color = Scalar( rng.uniform(0, 256), rng.uniform(0,256), rng.uniform(0,256) );
drawContours( drawing, contours_poly, (int)i, color );
rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2 );
circle( drawing, centers[i], (int)radius[i], color, 2 );
}
stringstream temp;
temp << "Total: " << contours.size() << " - " << thresh << " - " << contours[1][1];
cv::putText(drawing, temp.str(), cv::Point(10,40), FONT_HERSHEY_PLAIN, 0.7, CV_RGB(255, 0, 0));
imshow( "Contours", drawing );
【问题讨论】:
-
除非我们能重现这个问题,否则我们可能无能为力。这些类型的编码问题通常需要大量的设置和时间来理解确切的问题。
标签: c++ image opencv image-processing