本文介绍了在OpenCV + Python中使用knnMatch时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Python + OpenCV匹配两张图片.我已经使用SURF从它们两个中提取关键点和描述符.现在,我需要匹配这些描述符,因此,我决定使用Flann Matcher.
I want to match two pictures using Python+OpenCV. I have used SURF to extract keypoints and descriptors from both of them. Now, I need to match these descriptors and for this reason I decided to use Flann Matcher.
flann_params = dict(algorithm = FLANN_INDEX_KDTREE,trees = 4)
matcher = cv2.FlannBasedMatcher(flann_params, {})
但是当我尝试将knnMatch与描述符(desc1,desc2)一起使用时,openCV会引发异常.
But when I try to use knnMatch with descriptors (desc1, desc2), openCV throws an exception.
raw_matches=matcher.knnMatch(np.asarray(desc1),np.asarray(desc2), 2)
例外情况如下:
raw_matches=matcher.knnMatch(np.asarray(desc1),np.asarray(desc2), 2) #2
cv2.error: /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_graphics_opencv/opencv/work/OpenCV-2.4.2/modules/flann/src/miniflann.cpp:299: error: (-210) type=6
in function buildIndex_
如何正确使用knnMatch?是虫子吗?
How I could use knnMatch correctly? Is it a Bug?
推荐答案
我使用函数np.asarray()使用正确的数据类型解决了此问题
I solved this problem using the correct data type with the function np.asarray()
raw_matches=matcher.knnMatch(np.asarray(desc1,np.float32),np.asarray(desc2,np.float32), 2) #2
这篇关于在OpenCV + Python中使用knnMatch时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!