OpenCV多标记检测? [英] OpenCV Multiple marker detection?

查看:262
本文介绍了OpenCV多标记检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直致力于在场景中检测基准标记。我的基准标记的示例在这里:
http:/ /tinypic.com/view.php?pic=4r6k3q&s=8#.VNgsgzVVK1F

I've been working on detecting fiducial markers in scenes. An example of my fiducial marker is here: http://tinypic.com/view.php?pic=4r6k3q&s=8#.VNgsgzVVK1F

我已经能够检测到一个单一的基准标记场景很好。在场景中检测多个基准标记的方法是什么?执行特征检测,提取,然后匹配是伟大的找到一个匹配,但它似乎是错误的方法检测多个匹配,因为很难确定哪些功能属于哪个标记?

I have been able to detect a single fiducial marker in a scene very well. What is the methodology for detecting multiple fiducial markers in a scene? Doing feature detection, extraction, and then matching is great for finding a single match, but it seems to be the wrong method for detecting multiple matches since it would be difficult to determine which features belong to which marker?

基准标记将是相同的,并且不会在场景中的已知位置。

The fiducial markers would be the same, and would not be in a known location in the scene.

更新:

下面是一些示例代码。我尝试使用 x 个关键点数匹配第一个基准标记,然后使用剩余的关键点与第二个标记匹配。然而,这是不健壮的。有人有任何建议吗?

Below is some sample code. I was trying to match the first fiducial marker with x number of keypoints, and then use the remaining keypoints to match the second marker. However, this is not robust at all. Does anybody have any suggestions?

OrbFeatureDetector detector;
vector<KeyPoint> keypoints1, keypoints2; 

detector.detect(im1, keypoints1);
detector.detect(im2, keypoints2);

Mat display_im1, display_im2;
drawKeypoints(im1, keypoints1, display_im1, Scalar(0,0,255));
drawKeypoints(im2, keypoints2, display_im2, Scalar(0,0,255));

SiftDescriptorExtractor extractor;

Mat descriptors1, descriptors2;

extractor.compute( im1, keypoints1, descriptors1 );
extractor.compute( im2, keypoints2, descriptors2 );

BFMatcher matcher;
vector< DMatch > matches1, matches2;
matcher.match( descriptors1, descriptors2, matches1 );
sort (matches1.begin(), matches1.end());
matches2 = matches;
int numElementsToSave = 50;

matches1.erase(matches1.begin()+numElementsToSave,matches1.end());
matches2.erase(matches2.begin(),matches2.begin()+numElementsToSave);

Mat match_im1, match_im2;
drawMatches( im1, keypoints1, im2, keypoints2,
    matches1, match_im1, Scalar::all(-1), Scalar::all(-1),
    vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

drawMatches( im1, keypoints1, im2, keypoints2,
    matches2, match_im2, Scalar::all(-1), Scalar::all(-1),
    vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );


推荐答案

我开发了一个半自动算法来检测多个标记(我的标记是白色的绿色表面上,然后我限制我的搜索区域约束从图像使用 findContours 方法(利息点)但是你可以使用 matchShape / code> opencv函数来消除坏的轮廓。
这里是我为此做的代码的一部分。

I developed a semi-automatic algorithm to detect multiple markers (interest points) from image using findContours method on a binary image (my markers are white on a green surface then I limit my search to area constraint as I know how big is each marker in each frame. of course this got some false positives but it was good enough. I couldn't see the picture in your post as tinypic is blocked here for some reason. But you can use the matchShape opencv function to eliminate the bad contours. here is the part of code I made for this.

Mat tempFrame;
cvtColor(BallFrame, tempFrame, COLOR_BGR2GRAY);
GaussianBlur(tempFrame, tempFrame, Size(15, 15), 2, 2); // remove noise
Mat imBw;
threshold(tempFrame, imBw, 220, 255, THRESH_BINARY); // High threshold to get better results
std::vector<std::vector<Point> > contours;
std::vector<Vec4i> hierarchy;
findContours(imBw, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
Point2f center;
float radius = 0.0;
for (int i = 0; i < contours.size(); i++)
{
    double area = contourArea(contours[i]);
if (area > 1 && area < 4000) {
        minEnclosingCircle(contours[i], center, radius);
        if (radius < 50) // eliminate wide narrow contours
        {
            // You can use `matchShape` here to match your marker shape
        }
    }

}

我希望这将有助于

这篇关于OpenCV多标记检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆