Python中opencv2 ORB数据结构的深层副本

时间:2014-05-09 09:35:14

标签: python opencv image-processing orb

我想在图像中使用先前检测到的ORB特征位置,使用较早确定的位置提取其他图像中的ORB描述符,从而绕过检测器。

我似乎无法对检测到的要处理的功能进行深层检查,然后再传回以生成新的描述符。

  1. 使用原始未触及的f1关键点生成im_y图像的描述符
  2. 运行检测器两次以确定重复显然确实有效,但有点黑客,我想对原始特征点进行一些处理。
  3. 我在OS X上通过macports运行Python 2.7.6,Opencv 2.4.8,10.8.5
  4. 代码:

    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>
    

1 个答案:

答案 0 :(得分:4)

显然,deepcopy不适用于KeyPoint。由于功能f1只是KeyPoint的列表,因此您可以手动复制关键点列表:

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)

我希望这会有所帮助; - )

克里斯托弗