2013-04-12 73 views
1

我試圖使用方法cv2.estimateAffine3D但沒有成功。這裏是我的代碼示例:OpenCV 2.4在Python中估計Affine3D

import numpy as np 
import cv2 

shape = (1, 4, 3) 
source = np.zeros(shape, np.float32) 

# [x, y, z] 
source[0][0] = [857, 120, 854] 
source[0][1] = [254, 120, 855] 
source[0][2] = [256, 120, 255] 
source[0][3] = [858, 120, 255] 
target = source * 10 

retval, M, inliers = cv2.estimateAffine3D(source, target) 

當我嘗試運行此示例中,我得到了同樣的錯誤,因爲這等崗位here

我使用的是OpenCV 2.4.3和Python 2.7.3

請幫幫我!

回答

1

這是一個已知的bug,在2.4.4中已修復。

http://code.opencv.org/issues/2375

如果你只需要剛性的(旋轉+翻譯)對齊,這裏的標準方法:

def get_rigid(src, dst): # Assumes both or Nx3 matrices 
    src_mean = src.mean(0) 
    dst_mean = dst.mean(0) 
    # Compute covariance 
    H = reduce(lambda s, (a,b) : s + np.outer(a, b), zip(src - src_mean, dst - dst_mean), np.zeros((3,3))) 
    u, s, v = np.linalg.svd(H) 
    R = v.T.dot(u.T) # Rotation 
    T = - R.dot(src_mean) + dst_mean # Translation 
    return np.hstack((R, T[:, np.newaxis]))