【发布时间】:2023-03-09 19:56:02
【问题描述】:
我已经尽可能地简化了这个,但仍然得到错误,所以我认为这是一个 OpenCV 错误......但试图确认我没有先做一些愚蠢的事情。
我有这张图片:
哪个 SimpleBlobDetector 被检测为
如您所见,有两个小斑点被正确检测到,但主要的大斑点在 x 方向偏移了大约 20 个像素,在 y 方向偏移了 10 个像素。我做错了什么?
显示此错误的示例应用程序:
#include "opencv2/opencv.hpp"
using namespace cv;
int main()
{
cv::Mat im = imread("blob_error.png", cv::IMREAD_GRAYSCALE);
// Set up SimpleBlobDetector parameters.
cv::SimpleBlobDetector::Params params{};
// Filter by color
params.filterByColor = true;
params.blobColor = 255;
// Change grayscale search thresholds - since the input is a pre-binary-thresholded image, just use some values in the middle of the gray range
// Note that simpleblobfinder does multiple passes at each threshold, exclusively, so the below is equivalent to a single pass at 128
// The docs say the min is inclusive and the max is exclusive, but setting (128,129) yields zero detections
params.minThreshold = 127;
params.maxThreshold = 129;
params.thresholdStep = 1;
// Consider very-close blobs to be the same blob
params.minDistBetweenBlobs = 5;
// Filter by Area. Always want to filter out tiny noise blobs
params.filterByArea = true;
params.minArea = 10; // Minimum size just to ignore noise
params.maxArea = static_cast<float>(im.size().width * im.size().height) * 0.9f ; // Let's say maximum size is 90% of the visible area.
// Filter by Circularity (skipping)
params.filterByCircularity = false;
params.minCircularity = 0.1;
params.maxCircularity = 1;
// Filter by Convexity (skipping)
params.filterByConvexity = false;
params.minConvexity = 0;//.67;
// Filter by Inertia (skipping)
params.filterByInertia = false;
params.minInertiaRatio = 0;//0.30;
// Perform the detection
cv::Ptr<cv::SimpleBlobDetector> detector = cv::SimpleBlobDetector::create(params);
std::vector<cv::KeyPoint> keypoints;
detector->detect( im, keypoints );
cv::Mat im_with_keypoints;
drawKeypoints(im, keypoints, im_with_keypoints, cv::Scalar(0, 0, 255), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
imshow("keypoints", im_with_keypoints);
imwrite("blob_error_detected.png", im_with_keypoints);
cvWaitKey(0);
return 0;
}
我正在使用 OpenCV 3.4.2
编辑 -- 这是没有中心圆的图像:
这里是检测结果(没有圆形过滤)
【问题讨论】:
-
我建议使用 findcontour 来更好地控制您想要实现的目标。
-
我实际上使用了一系列检测机制,包括轮廓——但我担心这个奇怪的结果以及它为什么会给出偏移量。我想确保我没有遗漏任何东西,如果没有,请计划将其提交给 opencv 错误跟踪器。
-
我不认为这是一个错误。请检查我的答案。
标签: c++ opencv computer-vision