我正在尝试检测您可以在这张图片的中心看到的四个点: 这个被转换为 png,我实际上使用的是 ppm 格式(从相机的原始输出转换后)。实际处理的图像可在此处获得
我是opencv的新手,因此在检测这些点时遇到了很大的问题。这是我迄今为止最好的结果:
如您所见,我检测到了 3 个点,但除此之外,图片中的许多其他东西也被识别为圆圈。
这是代码:
IplImage* img;
if((img = cvLoadImage( "photos/img-000012.ppm", 1)) == 0 )
{
perror("cvLoadImage");
return 1;
}
cvNamedWindow( "Image view", 1 );
cvShowImage( "Image view", img );
// cvWaitKey(0);
IplImage* gray = cvCreateImage( cvGetSize(img), 8, 1 ); // allocate a 1 channel byte image
CvMemStorage* storage = cvCreateMemStorage(0);
cvCvtColor( img, gray, CV_BGR2GRAY );
cvShowImage( "Image view", gray );
// cvWaitKey(0);
cvSmooth( gray, gray, CV_GAUSSIAN, 3, 3, 0, 0 );
cvShowImage( "Image view", gray );
cvWaitKey(0);
CvSeq* circles = cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT,
4, // inverse ratio of the accumulator resolution
1, // minimum distance between circle centres
100, // higher threshold value for Canny
20, // accumulator threshold for the circle centers; smaller->more false circles
1, // minimum radius
10 ); // maximum radius
printf("circles == %d\n", circles->total);
int i;
for (i = 0; i < circles->total; i++) {
float *p = (float*)cvGetSeqElem(circles, i);
CvPoint center = cvPoint(cvRound(p[0]),cvRound(p[1]));
CvScalar val = cvGet2D(gray, center.y, center.x);
if (val.val[0] < 1) continue;
printf("%d %d %d\n", cvRound(p[0]),cvRound(p[1]), cvRound(p[2]));
cvCircle(img, center, cvRound(p[2]), CV_RGB(0,255,0), 1, CV_AA, 0);
}
cvShowImage( "Image view", img );
cvWaitKey(0);
你知道如何帮助吗?我将不胜感激。我认为人眼很容易发现这些点,所以我希望我可以使用计算机检测它们。