Python中的OpenCV 2.4 estimateAffine3D

Python中的OpenCV 2.4 estimateAffine3D,opencv,python-2.7,numpy,Opencv,Python 2.7,Numpy,我尝试使用cv2.estimateAffine3D方法,但没有成功。以下是我的代码示例: 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]

我尝试使用cv2.estimateAffine3D方法,但没有成功。以下是我的代码示例:

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)
当我尝试运行这个示例时,我得到了与另一篇文章相同的错误

我正在使用OpenCV 2.4.3和Python 2.7.3


请帮帮我

这是一个已知的bug,已在
2.4.4
中修复

如果只需要刚性(旋转+平移)对齐,以下是标准方法:

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])) 

这是一个已知的bug,已在
2.4.4
中修复

如果只需要刚性(旋转+平移)对齐,以下是标准方法:

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]))