OpenCV绘制不匹配点 [英] OpenCV draw non-matching points
问题描述
我遵循了 OpenCV功能检测和说明教程,并在OpenCV中使用SIFT和其他算法在2张图像之间找到匹配的特征点.据我了解,这些算法可以找到2张图像之间的相似区域.但是我对识别不同或不相似的区域感兴趣.
如何在两个图像上绘制所有非匹配特征点?此外,我是否可以在这些不匹配点周围绘制边界以显示两幅图像中哪些区域不同?
I have followed OpenCV Feature Detection and Description tutorial and used SIFT and other algorithms in OpenCV to find matching feature points between 2 images. From what i understood, these algorithms can find the similar regions between 2 images. But i am interested in identifying the different or dis-similar regions.
How can i draw all the NON-MATCHING feature points on both the images? Further more, can i draw boundaries around these non-matching points to be able to show which regions in the 2 images are different?
我正在Windows 7上使用Python代码,并从最新的OpenCV源代码构建.
I am using Python code on Windows 7 and build from latest OpenCV source.
推荐答案
- 在两个图像上绘制所有非匹配"特征点:
This task is pretty straight forward once you know the structure of the Matcher objects resulting from the match of two descriptors (matches = bf.match(des1,des2)
). The two Matcher objects' properties relevant to this problem are the following:
- DMatch.trainIdx :火车描述符中的描述符索引(或火车图像中的关键点)
- DMatch.queryIdx :查询描述符中描述符的索引(或查询图像中的关键点)
- DMatch.trainIdx: Index of the descriptor (or keypoint from the train image) in train descriptors
- DMatch.queryIdx: Index of the descriptor (or keypoint from the query image) in query descriptors
然后,知道了这些信息,就像@uzair_syed所说的那样,这只是一个简单的列表操作任务.
Then, knowing this information and as @uzair_syed said, this is just a simple list operations task.
- 在不匹配点周围绘制边界:
要实现这一目标,我会做这样的事情:
To achieve this, I would do something like this:
- 为每个不匹配的点创建一个带有白色像素的黑色蒙版
- 根据不匹配点簇的密度,使用大内核(即15 x 15像素)扩张遮罩.
- 侵蚀具有相同内核大小的蒙版.
- 最后,在蒙版上应用
findContours
函数以获取不匹配点的边界.
- Create a black mask with a white pixel for each non-matching points
- Depending on the density of the non-matching point's cluster, dilate the mask with a big kernel (i.e. 15 x 15 px).
- Erode the mask with the same kernel's size.
- Finally, apply the
findContours
function on the mask to get the boundaries of the non-matching points.
有关更多信息,您可以查看此问题及其答案.
For more information, you can have a look at this question and its answer.
希望它能使您走上正确的轨道!
Hope it gets you on the right track!
这篇关于OpenCV绘制不匹配点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!