Question

I would like to use the previously detected ORB feature locations in an image to extract ORB descriptors in an other image, using the earlier ascertained locations, thus bypassing the detector.

I just can't seem to get a deepcopy of the detected features to process and later pass back to generate new descriptors.

  1. Using the original untouched f1 keypoints to generate descriptors for the im_y image works
  2. Running the detector twice to ascertain a duplicate obviously does work, but is a bit of a hack and I would like to do some processing on the original feature points.
  3. I'm running Python 2.7.6, Opencv 2.4.8 via macports on OS X, 10.8.5

code:

from matplotlib import pyplot as plt
import copy as cp
import cv2

im_x = cv2.imread('stinkbug1.png', 0)
im_y = cv2.imread('stinkbug2.png', 0)

orb = cv2.ORB()

# Keypoint detection in first image
f1 = orb.detect(im_x, None)
f1, d1 = orb.compute(im_x, f1)

# Make a copy of the orginal key points
f2 = cp.deepcopy(f1)

# Magic processing here

# Get descriptors from second y image using the detected points from the x image
f2, d2 = orb.compute(im_y, f2)

# f2 and d2 are now an empty list and a <NoneType>
Was it helpful?

Solution

Apparently, deepcopy is not working on KeyPoint. As the features f1 is just a list of KeyPoint, you can copy manually the list of keypoints:

def features_deepcopy (f):
    return [cv2.KeyPoint(x = k.pt[0], y = k.pt[1], 
            _size = k.size, _angle = k.angle, 
            _response = k.response, _octave = k.octave, 
            _class_id = k.class_id) for k in f]

f2 = features_deepcopy(f1)

I hope this will help ;-)

Christophe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top