How to get extra information of blobs with SimpleBlobDetector?

后端 未结 3 902
[愿得一人]
[愿得一人] 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:05

    //Access SimpleBlobDetector datas for video
    
    #include "opencv2/imgproc/imgproc.hpp" // 
    #include "opencv2/highgui/highgui.hpp"
    
        #include 
        #include 
        #include 
        #include 
        #include 
        #include 
        #include 
    
    #include "opencv2/objdetect/objdetect.hpp"
    #include "opencv2/features2d/features2d.hpp"
    
    
    using namespace cv;
    using namespace std;
    
    
    int main(int argc, char *argv[])
    {
    
    
        const char* fileName ="C:/Users/DAGLI/Desktop/videos/new/m3.avi";  
        VideoCapture cap(fileName); //
        if(!cap.isOpened()) //
        {
            cout << "Couldn't open Video  " << fileName << "\n"; 
            return -1; 
        }
        for(;;)  // videonun frameleri icin sonsuz dongu
        {
            Mat frame,labelImg; 
            cap >> frame; 
            if(frame.empty()) break;  
            //imshow("main",frame);  
    
            Mat frame_gray;
            cvtColor(frame,frame_gray,CV_RGB2GRAY);
    
    
            //////////////////////////////////////////////////////////////////////////
            // convert binary_image
            Mat binaryx;
            threshold(frame_gray,binaryx,120,255,CV_THRESH_BINARY);
    
    
            Mat src, gray, thresh, binary;
            Mat out;
            vector keyPoints;
    
            SimpleBlobDetector::Params params;
            params.minThreshold = 120;
            params.maxThreshold = 255;
            params.thresholdStep = 100;
    
            params.minArea = 20; 
            params.minConvexity = 0.3;
            params.minInertiaRatio = 0.01;
    
            params.maxArea = 1000;
            params.maxConvexity = 10;
    
            params.filterByColor = false;
            params.filterByCircularity = false;
    
    
    
            src = binaryx.clone();
    
            SimpleBlobDetector blobDetector( params );
            blobDetector.create("SimpleBlob");
    
    
    
            blobDetector.detect( src, keyPoints );
            drawKeypoints( src, keyPoints, out, CV_RGB(255,0,0), DrawMatchesFlags::DEFAULT);
    
    
            cv::Mat blobImg;    
            cv::drawKeypoints(frame, keyPoints, blobImg);
            cv::imshow("Blobs", blobImg);
    
            for(int i=0; i

提交回复
热议问题