opencv — открытый CV C ++ connectedComponentsWithStats и SimpleBlobDetector

Я хочу найти область множества капель, которые я нашел с simpleblobdetector, и я знаю, что способ сделать это заключается в использовании connectedComponentsWithStats. Я не совсем уверен, как использовать эту функцию; Может ли кто-нибудь дать мне пример или ссылку на него?

Вот мой код до сих пор:

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/opencv.hpp>
#include <vector>

#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::vector;
using namespace cv;

using std::string;

int main() {
string filename = "Grassland2.jpg";
Mat im = imread(filename, IMREAD_GRAYSCALE);
if (!im.data) {
cout << "File not found" << endl;
return -1;
}
Mat labelled;
int total_pixels = im.rows*im.cols;
int blob_area = -1;
SimpleBlobDetector::Params params;
params.minThreshold = 10;
params.maxThreshold = 200;

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

// 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;
// Set up detector with params
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);
//Is this correct? Also, where do I find the centroids?
connectedComponentsWithStats(im, labelled, CC_STAT_AREA, centroids, 8, CV_32S)
//I want to find out the area and set it to blob_area
blob_area = CC_STAT_AREA;
// Show blobs
imshow("keypoints", im_with_keypoints);
waitKey(0);
return 0;
}

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector