2014-05-09 36 views
3

我想使用先前检测到的ORB特征位置来提取图像中的ORB描述符,使用先前确定的位置,从而绕过检测器。Python中的opencv2 ORB数据结构的深层副本

我似乎无法得到检测到的功能的深层拷贝,然后传回来生成新的描述符。

  1. 使用原始数据不变f1关键点来生成描述符的im_y形象工程
  2. 运行检测两次,以确定重复显然不工作,而是一个黑客攻击的一位,我希望做一些处理在原始特征点上。
  3. 我的MacPorts通过OS X上运行的Python 2.7.6,2.4.8 opencv的,10.8.5

代码:

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> 

回答

4

显然,deepcopy的不工作的关键点。由于功能F1仅仅是一个关键点的列表,你可以手动复制的关键点的列表:

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) 

我希望这将有助于;-)

克里斯托夫