How to label every blob?

Hi i need help with my project. i have this beans that detected by using a simpleblobdetector fuction.

I detected several blob and i want to know if the beans is a “good beans” or “bad beans”. I qdebug the result but i dont know which blob is the result showing.

Is it possible to label every blob like “blob 1, blob 2,” So i know this result belong to which blob.

Here below is my code for detecting the blob

    // Storage for blobs
       vector<KeyPoint> keypoints;

  // Set up detector with params
    Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);

    // Detect blobs
    detector->detect( frameBrightness, keypoints);


            Mat im_with_keypoints ;
            cv::Scalar mean;
                   drawKeypoints( frameBrightness, keypoints, im_with_keypoints, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );
                   size_t i;
                   Point Coordinate;

                    for( i = 0; i < keypoints.size(); i++ )
                    {
                        Coordinate =    keypoints[i].pt ;
                    Rect r(Coordinate.x-(keypoints[i].size /2), Coordinate.y-(keypoints[i].size/2), keypoints[i].size, keypoints[i].size) ;
                    Mat roi(im_with_keypoints, r);

                    mean = cv::mean(roi);

                    if (mean[0]>= 15 && mean[0]<= 87){

                        if(mean[1]>=70 && mean[1]<= 135){


                            if(mean[2]>=79 && mean [2] <= 148){

                                result = "Good Beans";
                            }
                            else{
                                result = "Bad Beans";
                            }
                        }
                        else{
                                result = "Bad Beans";
                        }
                    }
                    else {
                        result = "Bad Beans";
                    }

                    qDebug() << result ;
                    }

well you already have an indexed vector of center keypoints, now what ? …

if it’s about visualization, have a look at putText, you could just draw numbers next to the blob circles

btw, you probably need 2 seperate images, one for drawing, and one for measuring.
at least do not sample from the image you’ve drawn stuff into, right ?

2 Likes

ahh okay so i need to differentiate between putText,drawkeypoints and detect ? and btw sorry i still dont understand how to draw different numbers on every blob circles

kindly look at tutorials ()i won’t write your program)

okayy will do thanks for your help :blush: