Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV ORB descriptor: TypeError: Incorrect type of self (must be 'Feature2D' or its derivative)

I followed this simple OpenCV Feature Matching example exactly:

import cv2

img = cv2.imread('box.png',0) # queryImage
orb = cv2.ORB()               # Initiate ORB detector

# find the keypoints and descriptors with ORB
kp1, des1 = orb.detectAndCompute(img, None)

and have been getting the following error:

TypeError: Incorrect type of self (must be 'Feature2D' or its derivative)

I'm using OpenCV 3.3.1

like image 925
Sam Avatar asked Apr 22 '18 22:04

Sam


3 Answers

This is a OpenCV version compatibility issue. Just use cv2.ORB_create() instead of cv2.ORB().

The code should look like:

import cv2

img = cv2.imread('box.png',0) # queryImage
orb = cv2.ORB_create()        # Initiate SIFT detector

# find the keypoints and descriptors with SIFT
kp1, des1 = orb.detectAndCompute(img, None)
like image 199
Sam Avatar answered Oct 20 '22 02:10

Sam


cv2.ORB_create() will do the job I think

like image 40
sameer maurya Avatar answered Oct 20 '22 02:10

sameer maurya


Note the python structures change "frequently" (in internet history years anyway). It's a good idea to pay attention to version.

Go here to find the right link: https://docs.opencv.org/

3.1.1 --> 3.1.0 --> https://docs.opencv.org/3.1.0/ ( OpenCV-Python Tutorials --> https://docs.opencv.org/3.1.0/d6/d00/tutorial_py_root.html ) ... not as pretty as that (old) readthedocs site, but more accurate. :)

like image 3
Kaolin Fire Avatar answered Oct 20 '22 02:10

Kaolin Fire