gpt4 book ai didi

c++ - SimpleBlobDetector 异常

转载 作者:行者123 更新时间:2023-11-28 04:48:36 32 4
gpt4 key购买 nike

我正在尝试编写用于 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

我该如何解决这个问题?

最佳答案

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

#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;
}

关于c++ - SimpleBlobDetector 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48684878/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com