pythonimageopencvorb

OpenCV can't find ORB


In my previous question I learned that I had to install opencv-contrib in order to use OpenCV Python with external modules such as SIFT. In my project, however, I want to use ORB or something similar. cv2.ORB() does not work, nor does cv2.xfeatures2d.ORB_create() or any other agglutination of commands.

As SO knows, OpenCV has rather poor documentation for its Python API.

How do I use ORB to match features in OpenCV Python?

MWE:

#!/usr/bin/python2.7
import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('smallburger.jpg',0)

# Initiate STAR detector
orb = cv2.ORB()

# find the keypoints with ORB
kp = orb.detect(img,None)

# compute the descriptors with ORB
kp, des = orb.compute(img, kp)

# draw only keypoints location,not size and orientation
img2 = cv2.drawKeypoints(img,kp,color=(0,255,0), flags=0)
plt.imshow(img2),plt.show()

CLI output:

Traceback (most recent call last):
  File "./mwe.py", line 9, in <module>
    orb = cv2.ORB()
AttributeError: 'module' object has no attribute 'ORB'

Solution

  • Silly OpenCV. It's just cv2.ORB_create().