2015-12-08 52 views
0

我对simpleBlobDetector的代码有问题。我可以构建并运行所有代码,但程序检测到的斑点只是像素左右的大小。我已经尝试更改param.minArea和maxArea,但它不起作用。所以我要求你们帮忙。顺便说一下,我使用的图像已经是灰度图,所以它不是因为我的阈值命令,它不起作用。手前谢谢!使用simpleBlobDetector进行对象检测,但它不起作用

Martin。

#include <opencv/cv.h> 
#include <opencv/highgui.h> 
#include <opencv2/opencv.hpp> 

using namespace std; 
using namespace cv; 

int main(){ 
Mat src; 
Mat dst; 


src = imread("C:\\Users\\martin\\Desktop\\ThermalImage2.png", CV_LOAD_IMAGE_GRAYSCALE); //Load an image from directory path 

if (! src.data){ 
    cout << "Could not open or find the image" << endl ; // Look for invalid input 
    return -1; 
    } 


else{ 

double thresh = 130; // Threshold 
double maxValue = 255; // Value assigned to the pixel if it is over 'thresh' 

threshold(src, dst, thresh, maxValue, THRESH_BINARY); // threshold the picture src and call it dst 

namedWindow("thresholdedPicture", WINDOW_AUTOSIZE); // Create a window 

imshow("thresholdedPicture", dst); // display thresholded picture in the window 

} 

SimpleBlobDetector::Params params; // Set parameters for the object detection 

params.minDistBetweenBlobs = 10; //Minimum distance between blobs 

params.filterByColor = true; 
params.blobColor = 255; 

params.filterByArea = true; // filter by area of the blob 
params.minArea = 1 ;// Minimum area of the blob 
params.maxArea = 100000; // Maximum area of the blob 



vector<KeyPoint> keypoints; 


cv::SimpleBlobDetector detector(params); // Set up the blob detector with the parameters (params) 

detector.detect(dst, keypoints); // Input thresholded picture for detection of the blobs 

Mat dst_blob_dect; // New array to store the picture with the blobs detected 


drawKeypoints(dst, keypoints, dst_blob_dect, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS); //Drawing a red line around the detected objects 



namedWindow("keypoints", WINDOW_AUTOSIZE); // Create a window 

imshow("keypoints", dst_blob_dect); // Show the picture with the blobs detected in the window "keypoints" 


waitKey(0); // Press any key and the main function returns 0 

return 0;} 
+0

你能后的形象呢? –

回答

0

试试这个,并使用params.minDistBetweenBlobs的不同值。

#include "stdafx.h" 
#include <opencv/cv.h> 
#include <opencv/highgui.h> 
#include <opencv2/opencv.hpp> 
#include <stdio.h> 

using namespace std; 
using namespace cv; 

int main(){ 
    Mat src; 
    Mat dst; 

    src = imread("C:\\Users\\sanche8x\\Pictures\\gather.png", CV_LOAD_IMAGE_GRAYSCALE); //Load an image from directory path 

    if (! src.data){ 
     cout << "Could not open or find the image" << endl ; // Look for invalid input 
     return -1; 
    } 
    else{ 
     double thresh = 130; // Threshold 
     double maxValue = 255; // Value assigned to the pixel if it is over 'thresh'  
     threshold(src, dst, thresh, maxValue, THRESH_BINARY); // threshold the picture src and call it dst 
     namedWindow("thresholdedPicture", WINDOW_AUTOSIZE); // Create a window 
     imshow("thresholdedPicture", dst); // display thresholded picture in the window 
    } 

    SimpleBlobDetector::Params params; // Set parameters for the object detection 
    params.minDistBetweenBlobs = 10; //Minimum distance between blobs 
    params.filterByColor = true; 
    params.blobColor = 255; 
    params.filterByCircularity = false; 
    params.filterByConvexity = false; 
    params.filterByInertia = false; 

    params.filterByArea = true; // filter by area of the blob 
    params.minArea = 1 ;// Minimum area of the blob 
    params.maxArea = 100000; // Maximum area of the blob 

    vector<KeyPoint> keypoints; 

    cv::SimpleBlobDetector detector(params); // Set up the blob detector with the parameters (params) 
    detector.detect(dst, keypoints); // Input thresholded picture for detection of the blobs 
    Mat dst_blob_dect; // New array to store the picture with the blobs detected  
    drawKeypoints(dst, keypoints, dst_blob_dect, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS); //Drawing a red line around the detected objects 

    namedWindow("keypoints", WINDOW_AUTOSIZE); // Create a window 

    imshow("keypoints", dst_blob_dect); // Show the picture with the blobs detected in the window "keypoints" 


    waitKey(0); // Press any key and the main function returns 0 

    return 0; 

}