How to get extra information of blobs with SimpleBlobDetector?

后端 未结 3 904
[愿得一人]
[愿得一人] 2021-02-06 19:15

@robot_sherrick answered me this question, this is a follow-up question for his answer.

cv::SimpleBlobDetector in Opencv 2.4 looks very exciting but I am no

3条回答
  •  误落风尘
    2021-02-06 20:01

    So the code should look something like this:

    cv::Mat inputImg = imread(image_file_name, CV_LOAD_IMAGE_COLOR);   // Read a file
    cv::SimpleBlobDetector::Params params; 
    params.minDistBetweenBlobs = 10.0;  // minimum 10 pixels between blobs
    params.filterByArea = true;         // filter my blobs by area of blob
    params.minArea = 20.0;              // min 20 pixels squared
    params.maxArea = 500.0;             // max 500 pixels squared
    SimpleBlobDetector myBlobDetector(params);
    std::vector myBlobs;
    myBlobDetector.detect(inputImg, myBlobs);
    

    If you then want to have these keypoints highlighted on your image:

    cv::Mat blobImg;    
    cv::drawKeypoints(inputImg, myBlobs, blobImg);
    cv::imshow("Blobs", blobImg);
    

    To access the info in the keypoints, you then just access each element like so:

    for(std::vector::iterator blobIterator = myBlobs.begin(); blobIterator != myBlobs.end(); blobIterator++){
       std::cout << "size of blob is: " << blobIterator->size << std::endl;
       std::cout << "point is at: " << blobIterator->pt.x << " " << blobIterator->pt.y << std::endl;
    } 
    

    Note: this has not been compiled and may have typos.

提交回复
热议问题