Ask Your Question
0

3.0.0-Python cv2 module cannot find SIFT/SURF/ORB

asked 2014-12-30 22:04:04 -0600

zrinker gravatar image

The OpenCV-3.0.0-Python tutorial just told us we can just use 'cv2.ORB()' to create the ORB detector like this:

import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('simple.jpg',0)
# Initiate STAR detector
orb = cv2.ORB()

However, the Python interpreter reported error: 'module' object has no attribute 'ORB'
I used 'help(cv2)' to explore the module and found no module or functions like SIFT/SURF/ORB.
Somebody said the SIFT/SURF/ORB may be moved to xfeatures2d in opencv-contrib since 3.0.0. So I built opencv-contrib and used help(cv2.xfeatures2d) but found nothing but 2 functions: SIFT_craete() and SURF_create().

I just ran the codes in tutorial but came up with a lot of trouble and I am going to be crazy.
Thanks for any help!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-12-31 02:47:45 -0600

berak gravatar image

updated 2014-12-31 02:49:43 -0600

opencv's api is changing rapidly, and that tutorial might need an update.

you already have found cv2.xfeatures2d.SURF_create(), and it's similar with ORB,MSER,AKAZE, or GFTTDetector, there is a _create() method for all of them, which gives you an instance:

>>> orb = cv2.ORB_create()
>>> help(orb)
...
 |  Methods inherited from Feature2D:
 |
 |  compute(...)
 |      compute(image, keypoints[, descriptors]) -> keypoints, descriptors
 |
 |  defaultNorm(...)
 |      defaultNorm() -> retval
 |
 |  descriptorSize(...)
 |      descriptorSize() -> retval
 |
 |  descriptorType(...)
 |      descriptorType() -> retval
 |
 |  detect(...)
 |      detect(image[, mask]) -> keypoints
 |
 |  detectAndCompute(...)
 |      detectAndCompute(image, mask[, descriptors[, useProvidedKeypoints]]) -> keypoints, descriptors
 |
 |  empty(...)
 |      empty() -> retval
...

or SIFT:

>>> img = cv2.imread('simple.jpg',0)
>>> sift = cv2.xfeatures2d.SIFT_create()
>>> sift.detect(img)
edit flag offensive delete link more
-1

answered 2019-02-07 05:55:45 -0600

Install opencv-contrib-python version 3.4.2.16, as the SIFT & SURF are removed from the main python library due to patent issues.

sudo pip3 install opencv-contrib-python==3.4.2.16

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-12-30 21:54:03 -0600

Seen: 18,899 times

Last updated: Dec 31 '14