首页 文章

OpenCV分组白色像素

提问于
浏览
7

我已经完成了艰苦的工作,将我的MacBook上的iSight摄像头转换为红外摄像头,转换它,设置阈值等等 . 现在有一个看起来像这样的图像:

alt text

我现在的问题是;我需要通过分组白色像素来了解我的图像上有多少斑点 . 我不想使用 cvBlob / cvBlobsLib ,我宁愿只使用OpenCV中已有的内容 .

我可以通过检查(阈值)触摸白色像素来循环像素并对它们进行分组,但我猜测从OpenCV可能有一种非常简单的方法吗?

我'm guessing I can' t使用 cvFindContours ,因为这将检索一个大数组中的所有白色像素,而不是将它们分成"groups" . 谁能推荐? (注意这些不是圆圈,只是从小红外LED发出的光)

提前谢谢了!
tommed

2 回答

  • 8

    循环通过图像寻找白色像素 . 当你遇到一个时,你使用 cvFloodFill 将该像素作为种子 . 然后增加每个区域的填充值,以便每个区域具有不同的颜色 . 这称为标签 .

  • 4

    是的,你可以用 cvFindContours() 来做 . 它返回指向找到的第一个序列的指针 . 使用该指针,您可以遍历找到的所有序列 .

    // your image converted to grayscale
        IplImage* grayImg = LoadImage(...);
    
        // image for drawing contours onto
        IplImage* colorImg = cvCreateImage(cvGetSize(grayImg), 8, 3);
    
        // memory where cvFindContours() can find memory in which to record the contours
        CvMemStorage* memStorage = cvCreateMemStorage(0);
    
        // find the contours on image *grayImg*
        CvSeq* contours = 0;
        cvFindContours(grayImg, memStorage, &contours);
    
        // traverse through and draw contours
        for(CvSeq* c = contours; c != NULL; c = c->h_next) 
        {
             cvCvtColor( grayImg, colorImg, CV_GRAY2BGR );
             cvDrawContours(
                            colorImg,
                            c,
                            CVX_RED,
                            CVX_BLUE,
                            0, // Try different values of max_level, and see what happens
                            2,
                            8
             );
        }
    

    除了这个方法,我建议你看看 cvBlobscvBlobsLib . 后者作为官方blob检测库集成在OpenCV 2.0中 .

相关问题