opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
76.49k stars 55.64k forks source link

OpenCV3 python calls to FlannBasedMatcher::knnMatch fail with error #5667

Closed Algomorph closed 8 years ago

Algomorph commented 8 years ago

The following code returns an error.

    sift = x2d.SIFT_create(1000)
    features_l, des_l = sift.detectAndCompute(im_l, None)
    features_r, des_r = sift.detectAndCompute(im_r, None)

    FLANN_INDEX_KDTREE = 1
    index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5)
    search_params = dict(checks=50)
    flann = cv2.FlannBasedMatcher(index_params,search_params)

The error returned:

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

I tried this with Python 2.7. FLANN_INDEX_KDTREE is set to 1 unlike here, since in modules/flann/include/opencv2/flann/defines.h I found it set to 1 on line 84.

niyazpk commented 6 years ago

Even after setting: cv2.ocl.setUseOpenCL(False) I am getting the same error, for ORB as well as SIFT.

python: 3.6.2 opencv 3.1.0

benjimin commented 6 years ago

@niyazpk could you try testing the latest opencv release? (Currently 3.3 as of a month ago.)

niyazpk commented 6 years ago

I was not able to make OpenCV 3.3 work with my conda ENV. Some issues with Openblas etc.

So I tried my code on a new docker image with OpenCV 3.3. It worked fine. Thanks!

lavinachitara commented 6 years ago

Yeah, earlier I was also facing the same issue but after installing opencv contrib it is working without any error pip install opencv-contrib-python

Motherboard commented 6 years ago

@lavinachitara This solved it for me as well.

shubham9008 commented 6 years ago

@lavinachitara that was awwsome...