OpenCV python#39;s API: FlannBasedMatcher(OpenCV python的API:FlannBasedMatcher)
问题描述
我正在尝试重写此处中描述的代码.使用 Opencv 的 python API.
I am trying to rewrite the code described here. using the python API for Opencv.
代码的第 3 步有这几行:
The step 3 of the code has this lines:
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_object, descriptors_scene, matches );
我在 OpenCV 参考 中反复查看,但没有发现与 python 中的 FlannBasedMatcher 或其他对象相关的内容哪个可以完成这项工作.
I have looked over and over in the OpenCV reference but found nothing related to a FlannBasedMatcher in python or some other object which can do the work.
有什么想法吗?
注意:我使用 OpenCV 2.3.1 和 Python 2.6
NOTE: I am usign OpenCV 2.3.1 and Python 2.6
推荐答案
查看python2文件夹下OpenCV 2.3.1提供的示例,我发现了一个基于flann的匹配函数的实现,它不依赖于FlanBasedMatcher对象.
Looking in the examples provided by OpenCV 2.3.1 under the python2 folder, I found an implementation of a flann based match function which doesn't rely on the FlanBasedMatcher object.
代码如下:
FLANN_INDEX_KDTREE = 1 # bug: flann enums are missing
flann_params = dict(algorithm = FLANN_INDEX_KDTREE,
trees = 4)
def match_flann(desc1, desc2, r_threshold = 0.6):
flann = cv2.flann_Index(desc2, flann_params)
idx2, dist = flann.knnSearch(desc1, 2, params = {}) # bug: need to provide empty dict
mask = dist[:,0] / dist[:,1] < r_threshold
idx1 = np.arange(len(desc1))
pairs = np.int32( zip(idx1, idx2[:,0]) )
return pairs[mask]
这篇关于OpenCV python的API:FlannBasedMatcher的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:OpenCV python的API:FlannBasedMatcher
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
