欢迎进入黄工小课堂
1.0 固定阈值
halcon算子(threshold)
Mat image = imread(currentDir + "/image/1.png");
Mat image_gray;
cvtColor(image, image_gray, COLOR_RGB2GRAY);
Mat outimage, outimage1, outimage3;
threshold(image_gray,outimage,25,255, THRESH_BINARY);
threshold(image_gray, outimage1, 80, 255, THRESH_BINARY_INV);
bitwise_and(outimage, outimage1, outimage3);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(outimage3, contours, hierarchy, RETR_LIST, CHAIN_APPROX_NONE);
for (int i=0; i<contours.size();i++)
{
float area = contourArea(contours[i]);
if (area>350)
{
drawContours(image, contours,i, Scalar(0,0,255),2,8);
}
}