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
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)
cv2.ORB_create()
will do the job I think
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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With