c++ - opencv 中的 SimpleBlobDetector 没有检测到任何东西

标签 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();

关键点 vector 始终为空。我尝试过的任何东西都不起作用。

最佳答案

所以我解决了这个问题,没有阅读文档上的细则。感谢 Dai 对参数的提醒,让我更仔细地查看了文档。

调整参数的默认值以提取黑色圆形 Blob 。

我在创建 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);

做到了。

关于c++ - opencv 中的 SimpleBlobDetector 没有检测到任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36525539/

相关文章:

c++ - 我可以使用 memcpy 写入多个相邻的标准布局子对象吗?

java - java中的OpenCV Mat对象序列化

java - 使用 jni 将位图从 android 相机传递到 C++

java - JDBC 4 的 java.sql.Clob.free() 方法和向后兼容性

javascript - 在 DOM 中插入文件输入作为 img

c# - DataGridView 中的 BLOB 数据到简单字符串?

c++ - Visual C++ 中的数组大小

C++ 如何管理依赖项(例如使用来自 github 的库)

c++ - 使用 OpenCV header 编译 C++ 文件时没有此类文件或目录错误

python - 如何确保使用OpenCV读取和处理所有帧