使用OpenCV检测小圆圈(图像质量差) [英] Detecting small circles with OpenCV (bad image quality)

查看:140
本文介绍了使用OpenCV检测小圆圈(图像质量差)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检测在图片中央可以看到的四个点: 这个被转换为png,我实际上使用的是ppm格式(从相机的原始输出转换后).可以在此处

I'm trying to detect the four dots you can see in the center of this picture: This one is converted to png, I actually use a ppm format (after conversion from raw output from the camera). The actual processed image is available here

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

I'm new to opencv and therefore have a huge problem detecting those dots. Here's my so far best result:

如您所见,我已经检测到3个点,但除此之外,图片中的许多其他东西也被识别为圆圈.

As you can see, I've detected 3 of the dots, but aside from that also lots of other things in the picture are recognized as circles.

这是代码:

    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);

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

Do you have any idea how to help that? I would be most grateful. I think it's quite easy for a human eye to spot the dots, so I hope I can detect them using a computer.

推荐答案

您应该看看基于我正在开发的应用程序,我得到了:

With the application I am developing based on it, I got:

您基本上可以使这种方法适应您的情况,并使其更加有效: 5." (根据轮廓的形状(大小,面积,凸度...来验证或使轮廓无效.").在您的情况下,由于您没有圆簇,因此可能更加严格.您可以只需映射几乎完美圈子的对象.此外,您知道您的圈子有相同的大小/相对强度...

You could basically adapt this method to you case and make it much more efficient: "5." ("validate or invalidate contours on the grant of their shape (size, area, convexity..."). In your case could be much more stringent since you do not have clusters of circles. You could just map objects that are almost perfect circles. In addition, you know that your circles have the same size/relative intensity...

如果不清楚,请告诉我

祝你好运

这篇关于使用OpenCV检测小圆圈(图像质量差)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆