2014-05-09 38 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) 

我希望這將有助於;-)

克里斯托夫