Best way to count number of “White Blobs” in a Thresholded IplImage in OpenCV 2.3.0

强颜欢笑 提交于 2019-12-13 02:52:37

问题


I need to count the number of white blobs in a Thresholded image. I'm counting small squares on a marker. But due to the poor image quality of the webcam, these squares don't appear as squares. This is why I decided to use Blob detection. This is for an Augmented reality application. Is my decision right?

Camera placed near the marker

Camera placed far from the marker


回答1:


What about the cvFindContours function? It's been a while since I use it but I think you can then iterate in the CvSeq of found contours and work with them the way you like.

I know it's an old thread but maybe it can help you!




回答2:


How about using the cvBlobsLib. This detects connected regions which you should easily be able to count, and obtain further information such as their size.




回答3:


I have used findContours function. Here is the piece of code:

    std::vector<std::vector<cv::Point> > contours;      

    cv::findContours(m, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
    for( unsigned int i = 0; i < contours.size(); i++ )
    { 
        if( contours[i].size() < 3  ) // at least a triangular area?
            continue;

        double area = cv::contourArea(Mat(contours[i]) );
        if ( (area > min * min) && ( area < max * max ) )
        {
           //... use or count blob


来源:https://stackoverflow.com/questions/8259655/best-way-to-count-number-of-white-blobs-in-a-thresholded-iplimage-in-opencv-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!