gpt4 book ai didi

c++ - FindCirclesGrid c++11 不起作用,尽管检测器找到了所有点

转载 作者:行者123 更新时间:2023-12-02 10:36:36 25 4
gpt4 key购买 nike

中的网格

image

未找到,尽管 simpleBlobDetector检测每个 blob。

我使用以下代码,图像作为输入图像:

    vector<Point2f> pointBuf;
Size gridSize(4, 11);

cv::SimpleBlobDetector::Params params;
params.maxArea = (image.rows * image.cols) / (gridSize.height * gridSize.width * 1.5);
params.minArea = 70;
params.minConvexity = 0.85;
params.minThreshold = 80;
params.maxThreshold = 230;
params.thresholdStep = 20;
params.minInertiaRatio = 0.05;

auto detector = cv::SimpleBlobDetector::create(params);
vector<KeyPoint> keypoints;
detector->detect(image, keypoints);

Mat debugImage = Mat::zeros(image.size(), CV_8U);
for (auto keypoint : keypoints) {
drawKeypoints(debugImage, keypoints, debugImage, 255);
}
imwrite("./debug/" + "debugImage.png", image);
imwrite("./debug/" + "debugImage2.png", debugImage);

findCirclesGrid(image, gridSize, pointBuf, cv::CALIB_CB_ASYMMETRIC_GRID, detector);

该代码适用于其他图像。那么为什么代码在这个图像上不起作用呢?

最佳答案

您的代码没有问题并且工作正常。您分享的关于过滤器参数的图像的唯一问题params.maxArea此限制不会让程序检测到您的网格。这是我尝试的代码和结果:

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

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{

Mat image = imread("/your/image/directory/blob.jpg");

vector<Point2f> pointBuf;
Size gridSize(4, 11);

cv::SimpleBlobDetector::Params params;
params.maxArea = 10000;
params.minArea = 70;
params.minConvexity = 0.85;
params.minThreshold = 80;
params.maxThreshold = 230;
params.thresholdStep = 20;
params.minInertiaRatio = 0.05;

auto detector = cv::SimpleBlobDetector::create(params);
vector<KeyPoint> keypoints;
detector->detect(image, keypoints);

Mat debugImage = Mat::zeros(image.size(), CV_8U);
for (auto keypoint : keypoints) {
drawKeypoints(debugImage, keypoints, debugImage, 255);
}

findCirclesGrid(image, gridSize, pointBuf, cv::CALIB_CB_ASYMMETRIC_GRID, detector);

imshow("Result",debugImage);
imshow("Before",image);

waitKey(0);
return 0;

}

结果:

enter image description here

注:您可以查看 this documentation了解有关参数的更多信息。

关于c++ - FindCirclesGrid c++11 不起作用,尽管检测器找到了所有点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60000857/

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