Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
741 views
in Technique[技术] by (71.8m points)

python - cv2 3.0.0 cv2.FlannBasedMatcher: flann.knnMatch is throwing cv2 error

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Comment out line 162 in cv2.cpp in ..opencvmodulespythonsrc2

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...