SimpleBlobDetector异常

时间:2018-02-08 11:54:08

标签: c++ opencv exception blobs

我正在尝试编写用于Blob检测的代码,我在这里遵循教程 https://www.learnopencv.com/blob-detection-using-opencv-python-c/ 我刚刚复制并粘贴了代码

Mat im = imread("blob.jpg", IMREAD_GRAYSCALE);

// Set up the detector with default parameters.
SimpleBlobDetector detector;

// Detect blobs.
std::vector<KeyPoint> keypoints;
detector.detect(im, keypoints);

// Draw detected blobs as red circles.
// DrawMatchesFlags::DRAW_RICH_KEYPOINTS flag ensures the size of the circle corresponds to the size of blob
Mat im_with_keypoints;
drawKeypoints(im, keypoints, im_with_keypoints, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

// Show blobs
imshow("keypoints", im_with_keypoints);

当我运行它时,我收到错误

drawKeypoints(im, keypoints, im_with_keypoints, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

说“未处理的异常”,:Microsoft C ++:cv :: Exception

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

在没有编码的情况下完成本教程后,我已经意识到在本文开头发布的代码没有指定探测器的参数。指定它们后,程序现在正常工作。这是完整的代码:

#include "opencv2\opencv.hpp"

using namespace cv;

``int main() {
//LOAD THE IMAGE
Mat im = imread("../data/blob.jpg", IMREAD_GRAYSCALE);

// Setup SimpleBlobDetector parameters.
SimpleBlobDetector::Params params;

// Change thresholds
params.minThreshold = 10;
params.maxThreshold = 200;

// Filter by Area.
params.filterByArea = true;
params.minArea = 1500;

// Filter by Circularity
params.filterByCircularity = true;
params.minCircularity = 0.1;

// Filter by Convexity
params.filterByConvexity = true;
params.minConvexity = 0.87;

// Filter by Inertia
params.filterByInertia = true;
params.minInertiaRatio = 0.01;


// Storage for blobs
vector<KeyPoint> keypoints;
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);

// Detect blobs
detector->detect(im, keypoints);

// Draw detected blobs as red circles.
// DrawMatchesFlags::DRAW_RICH_KEYPOINTS flag ensures
// the size of the circle corresponds to the size of blob

Mat im_with_keypoints;
drawKeypoints(im, keypoints, im_with_keypoints, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

// Show blobs
imshow("keypoints", im_with_keypoints);
waitKey(0);
return 0;
}