Я пытаюсь написать код для обнаружения 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;
}
Других решений пока нет …