问题
I want to use a flann-based matcher in Python as described in http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_feature2d/py_matcher/py_matcher.html
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
in the line:
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)
回答1:
I got same problem on my computer. so, I maked a new virtual-machine with Ubuntu 14.04 and tested.
I don't know why.... but, I got this problem solved with OpenCV 3.0.0-rc1.
If you are using OpenCV3.0.0, then try another release of OpenCV3
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
回答2:
Comment out line 162 in cv2.cpp in ..\opencv\modules\python\src2
CV_Error(Error::StsAssert, "The data should normally be NULL!")
Recompile and SIFT should work just fine.
Source: http://answers.opencv.org/question/76952/regarding-the-error-message-the-data-should-normally-be-null/
回答3:
A fix has been merged into the master branch of OpenCV, and I've confirmed that it works. Unfortunately there hasn't been a new release yet so you'll have to use the nightly build, but I found it relatively easy in Ubuntu. Adrian Rosebrock has a great post on how to install OpenCV 3 from source for Ubuntu and for OSX. If you follow Adrian's guide and simply leave out the step where he checks out the 3.0.0 tag, you should remain on master and get the latest build which includes the fix.
回答4:
If you're on a Mac and using python3, this did it for me instead of building it from github:
brew install opencv3 --with-python3 --with-contrib
and
export PYTHONPATH=$PYTHONPATH:/usr/local/Cellar/opencv3/3.0.0/lib/python3.4/site-packages
replace python3.4 with your version.
Seems like there's some general problem with the function allocate(). I also had the same problem with BackgroundSubtractorMOG2, beside the FLANN matcher. This fixed both.
来源:https://stackoverflow.com/questions/32931856/cv2-3-0-0-cv2-flannbasedmatcher-flann-knnmatch-is-throwing-cv2-error