0

I am trying to compute descriptors given a set of Keypoint that i have computed with cv2.KeyPoint ! But when i try to call sift.compute() like this, just to see if it works:

sift= cv2.SIFT()
sift.compute(img, Keypoint)

I get the following error that i can't manage to understand: <method 'compute' of 'cv2.Feature2D' objects> returned NULL without setting an error

I am using Opencv 4.4

user13369031
  • 55
  • 3
  • 7
  • 1
    it's a redending question, you just have to search, there are plenty of posts on that https://stackoverflow.com/a/64525431/12848103 – RashidLadj_Winux Nov 07 '20 at 12:23

2 Answers2

0

If you look at the documentation

You should declare SIFT as:

sift = cv.SIFT_create()

Therefore the correct code will be:

sift = cv.SIFT_create()
kp, des = sift.detectAndCompute(gray,None)

Update

If you have already calculated the key-points (kp) then draw it on the current image:

img=cv.drawKeypoints(gray,kp,img)
cv.imwrite('sift_keypoints.jpg',img)
Ahmet
  • 7,527
  • 3
  • 23
  • 47
0

you can use the method that you like: methode 1:

img = cv2.imread('../input/data-for-knn/data/train/airplane/0000.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)
sift = cv2.SIFT_create()
kp = sift.detect(gray,None)
desc = sift.compute(gray,kp)

methode 2:

des = sift.detectAndCompute(gray,None)