gpt4 book ai didi

c++ - 如何使用 Blob Detector

转载 作者:行者123 更新时间:2023-11-28 01:56:13 26 4
gpt4 key购买 nike

我正在尝试使用 OpenCV 3 中的 SimpleBlobDetector 来检测热图像中的热 Blob ,例如人。任何简单的代码或示例将不胜感激。

我试过了`

#include <opencv2/core/core.hpp>

#include <opencv2/highgui/highgui.hpp>

#include <iostream>

#include "opencv2\features2d.hpp"

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
if (argc != 2)
{
cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
return 0;
}

Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE); // Read the file

if (!image.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return 0;
}



// Set up the detector with default parameters.
//SimpleBlobDetector detector;
// Setup SimpleBlobDetector parameters.
SimpleBlobDetector::Params params;

// Change thresholds
params.minThreshold = 50;
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;

// Detect blobs.
std::vector<KeyPoint> keypoints;
cv::Ptr<cv::SimpleBlobDetector> detector = cv::SimpleBlobDetector::create(params);
//detector->detect(img, keypoints);
detector->detect(image, keypoints);
//params.detect(image, 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(image, keypoints, im_with_keypoints, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

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

//namedWindow("Display window", WINDOW_AUTOSIZE);// Create a window for display.
//imshow("Display window", image); // Show our image inside it.

//waitKey(0); // Wait for a keystroke in the window
//return 0;

}` 但它只是返回未更改的灰色图像。

最佳答案

要使用 OpenCV 检测 Blob ,您需要:

  1. 实例化一个 SimpleBlobDetector 类型
  2. 声明一个KeyPoints类型的 vector
  3. 调用 SimpleBlobDetector::detect()

这里有一个很棒的在线教程(我从那里截取了代码):https://www.learnopencv.com/blob-detection-using-opencv-python-c/

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

SimpleBlobDetector detector;

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

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

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

您还可以调整参数以选择具有特定属性的 Blob ,这些都在教程中列出。我建议玩一玩,感受一下它是如何运作的。

关于c++ - 如何使用 Blob Detector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41116049/

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