这是使用OpenCV的我的一个图像处理项目的源图像。我试图检测图像中的孔但不知何故无法做到。我尝试了Hough Circle算法,但仍未正确检测到孔洞。它可能适用于此图片,但可能不适用于其他图片。
/// Convert it to gray
cvtColor( src, src_gray, CV_BGR2GRAY );
/// Reduce the noise so we avoid false circle detection
GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );
vector<Vec3f> circles;
/// Apply the Hough Transform to find the circles
HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/10, 20, 10, 0, 100 );
/// Draw the circles detected
for( size_t i = 0; i < circles.size(); i++ )
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
putText(src, to_string(i), center, 1, 1, Scalar(0,255,0));
circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
}