opencv中的SimpleBlobDetector没有检测到任何内容

时间:2016-04-10 03:47:03

标签: c++ opencv blob

我使用OpenCV 3.1使用SimpleBlobDetector进行一些blob检测,但我没有运气,也没有教程能够解决这个问题。我的环境是x64上的XCode。

我开始使用此图片: enter image description here

然后我把它变成了灰度: enter image description here

最后我将其转换为二进制图像并对此进行blob检测: enter image description here

我已经包含了" iostream"和" opencv2 / opencv.hpp"。

using namespace cv;
using namespace std;

Mat img_rgb;
Mat img_gray;
Mat img_keypoints;    
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create();

vector<KeyPoint> keypoints;

img_rgb = imread("summertriangle.jpg");

//Convert to greyscale
cvtColor(img_rgb, img_gray, CV_RGB2GRAY);

imshow("Grey Scale", img_gray);

// Start by creating the matrix that will allocate the new image
Mat img_bw(img_gray.size(), img_gray.type());

// Apply threshhold to convert into binary image and save to new matrix
threshold(img_gray, img_bw, 100, 255, THRESH_BINARY);

// Extract cordinates of blobs at their centroids, save to keypoints variable.
detector->detect(img_bw, keypoints);
cout << "The size of keypoints vector is: " << keypoints.size();

关键点矢量始终为空。我没有尝试过任何作品。

1 个答案:

答案 0 :(得分:9)

所以我解决了这个问题,没有阅读文档上的细则。感谢戴在Params的负责人,让我仔细看看文档。

Default values of parameters are tuned to extract dark circular blobs.

我必须在创建SimpleBlobDetector对象时执行此操作:

SimpleBlobDetector::Params params;

params.filterByArea = true;
params.minArea = 1;
params.maxArea = 1000;
params.filterByColor = true;
params.blobColor = 255;

Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);

这样做了。