cv2 3.0.0 cv2.FlannBasedMatcher:flann.knnMatch抛出cv2错误 [英] cv2 3.0.0 cv2.FlannBasedMatcher: flann.knnMatch is throwing cv2 error

查看:369
本文介绍了cv2 3.0.0 cv2.FlannBasedMatcher:flann.knnMatch抛出cv2错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按照 http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_feature2d/py_matcher/py_matcher.html

由于我使用的是OpenCV 3.0.0,因此我不得不调整有关SIFT检测器初始化的代码.其余部分不做任何更改

Since I am using OpenCV 3.0.0, I had to adjust the code regarding the initialization of the SIFT detector. The rest is taken without changes

def calculateMatch(self):
    # Initiate SIFT detector
    sift = cv2.xfeatures2d.SIFT_create()

    # find the keypoints and descriptors with SIFT
    (kp1, desc1) = sift.detectAndCompute(self.image1,None)
    (kp2, desc2) = sift.detectAndCompute(self.image2,None)

    # FLANN parameters
    FLANN_INDEX_KDTREE = 0

    index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
    search_params = dict(checks=50)   # or pass empty dictionary

    flann = cv2.FlannBasedMatcher(index_params,search_params)
    matches = flann.knnMatch(desc1,desc2,k=2)

运行代码时,我收到以下消息:

When I run the code, I get the following message:

cv2.error: cv2.cpp:161: error: (-215) The data should normally be NULL! in function allocate

该行中的

matches = flann.knnMatch(desc1,desc2,k=2)        

另外一条评论: 如果我使用蛮力匹配器,则一切正常:

One more comment: If I use brute force matcher, everything works fine:

bf = cv2.BFMatcher()
matches = bf.knnMatch(desc1, desc2, k=2)

推荐答案

我在计算机上遇到了同样的问题. 因此,我使用Ubuntu 14.04制作了一个新的虚拟机并进行了测试.

I got same problem on my computer. so, I maked a new virtual-machine with Ubuntu 14.04 and tested.

我不知道为什么....但是,我用OpenCV 3.0.0-rc1解决了这个问题.

I don't know why.... but, I got this problem solved with OpenCV 3.0.0-rc1.

如果您使用的是OpenCV3.0.0,请尝试其他版本的OpenCV3

If you are using OpenCV3.0.0, then try another release of OpenCV3

对于安装,我指的是下一页. http://rodrigoberriel.com/2014/10/installing-opencv-3-0-0-on-ubuntu-14-04/ 在此页面上,Opencv的版本为Alpha.如下面的示例所示.

For installation , I was referring to the following page. http://rodrigoberriel.com/2014/10/installing-opencv-3-0-0-on-ubuntu-14-04/ On this page, Opencv's version is alpha. To read as in the example below.

wget https://github.com/Itseez/opencv/archive/3.0.0-rc1.zip -O opencv-3.0.0-rc1.zip

这篇关于cv2 3.0.0 cv2.FlannBasedMatcher:flann.knnMatch抛出cv2错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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