Ask Your Question

soboh's profile - activity

2016-12-11 22:42:43 -0600 received badge  Notable Question (source)
2016-09-01 19:04:20 -0600 received badge  Popular Question (source)
2015-11-22 00:38:47 -0600 asked a question Regarding the error message "The data should normally be NULL"

I have compiled OpenCV 3.0.0 for python on Windows.
When I tried to run the code bellow I got this error message: "The data should normally be NULL!"

import numpy as np
import cv2

img1 = cv2.imread('C:\\Users\\soboh\\Documents\\pcb.jpg',0)          # queryImage
img2 = cv2.imread('C:\\Users\\soboh\\Documents\\pcb.jpg',0) # trainImage

sift = cv2.xfeatures2d.SURF_create()

kp1, des1 = sift.detectAndCompute(img1,None)
kp2, des2 = sift.detectAndCompute(img2,None)


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(des1,des2,k=2)

The error happens when calling the function flann.knnMatch(). The full error message is:
"cv2.error: cv2.cpp:161: error: (-215) The data should normally be NULL! in function allocate"

So I have opened the file cv2.cpp and looked at line 161 and found these lines of code:
"
if( data != 0 )
{
CV_Error(Error::StsAssert, "The data should normally be NULL!");
// probably this is safe to do in such extreme case
return stdAllocator->allocate(dims0, sizes, type, data, step, flags, usageFlags);
}
"
so I have put the line that starts with "CV_Error" in a comment and compiled again the OpenCV and tried to run the same code and everything worked fine, but I am not sure that what I did is ok!!! Any help?