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.
f1
keypoints to generate descriptors for the im_y
image workscode:
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>
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