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

Woj*_*tek 5 c opencv computer-vision feature-detection

我正试图检测你在这张照片中央可以看到的四个点: 在此输入图像描述 这个转换为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);
Run Code Online (Sandbox Code Playgroud)

你知道如何帮助吗?我将非常感激.我认为人眼很容易发现这些点,所以我希望我能用电​​脑检测它们.

Que*_*ann 4

你应该看看这篇文章

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

在此输入图像描述

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

如果有什么不清楚的地方请告诉我

祝你好运,