当使用OpenCV时,我想找到一个用实时图像指向地面的激光指示器。现在,出于测试目的,我使用静止图像来测试OpenCV算法。目前,我成功地在多个testimages中找到了激光器。这是我的问题。当试图找到x和y坐标时,我得到一些非常奇怪的结果。 simpleblobdetector可以找到大约18 * e ^个关键点。奇怪,因为图像只有640X480像素的分辨率。我的代码和一些输出发布在下面。有谁知道为什么我会得到这么多关键点以及如何修复它,以便我可以提取坐标?
// Read image
Mat im = imread(argv[1], IMREAD_COLOR);
cout << im.cols << " " << im.rows << endl;
Mat filtered;
inRange(im, Scalar(0, 0, 0), Scalar(255, 255, 216), filtered);
imshow("Filtered image", filtered);
// Simpleblobdetector parameters.
SimpleBlobDetector::Params params;
params.filterByArea = true;
params.filterByCircularity = false;
params.filterByColor = false;
params.filterByConvexity = false;
params.filterByInertia = false;
params.minArea = 50;
params.maxArea = 100;
// Set up the detector with default parameters.
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
// Detect blobs.
std::vector<KeyPoint> keypoints;
detector->detect(filtered, keypoints);
cout << "There are " << keypoints.size() << " BLOBs found." << endl;
// 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);
// De locatie van de keypoints weergeven in de console.
for (int i = 0; i < keypoints.size(); i++)
{
cout << "The X-cooridnate is: " << keypoints.at(i).pt.x << endl;
cout << "The Y-coordinate is: " << keypoints.at(i).pt.y << endl;
}
// Show blobs
imshow("keypoints", im_with_keypoints);
waitKey(0);
return 0;