gpt4 book ai didi

c - 使用 OpenCV 检测小圆圈(图像质量差)

转载 作者:太空狗 更新时间:2023-10-29 15:04:33 26 4
gpt4 key购买 nike

我正在尝试检测您可以在这张图片的中心看到的四个点: enter image description here这个转换成png,我实际上使用的是ppm格式(从相机的原始输出转换后)。实际处理后的图片有here

我是 opencv 的新手,因此在检测这些点时遇到了很大的问题。这是我迄今为止最好的结果: enter image description here

如您所见,我检测到了其中的 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);

您知道如何提供帮助吗?我将不胜感激。我认为人眼很容易发现这些点,所以我希望我能用计算机检测它们。

最佳答案

你应该看看this post .

有了我基于它开发的应用程序,我得到了:

enter image description here

您基本上可以根据自己的情况调整此方法并使其更加高效: “5。” (“根据其形状(大小、面积、凸度...)验证或使轮廓无效”)。在您的情况下可能会更加严格,因为您没有圆圈。您可以只需映射几乎 perfect circles 的对象。此外,您知道您的圆圈具有相同的大小/相对强度...

有什么不明白的可以告诉我,

祝你好运

关于c - 使用 OpenCV 检测小圆圈(图像质量差),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11816245/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com