首页 > 解决方案 > 标准化 Python 中的点,以便与原点的 RMS 距离为 sqrt2

问题描述

我想实现 DLT 算法,我有 6 个对象点 (X,Y,Z,1).T 和 6 个图像点 (u,v,1).T ,它们是对象点到图像平面的投影.

因此,在实施 DLT 之前,我必须对数据进行规范化。

更具体地说,我发现我必须执行以下操作:应该对 2D 图像点进行归一化,以便它们的质心位于原点,并且它们与原点的均方根距离为 sqrt(2)

知道如何在 python 中做到这一点吗?

标签: pythonnormalizationpointsnormalize

解决方案


为两张图像取 6 个图像点,一张是原始的,另一张是扭曲的,然后:

x1 = np.array([202,202,500,523,530,522])
y1 = np.array([459,473,403,403,405,434])
x2 = np.array([283,285,526,544,552,550])
y2 = np.array([482,494,371,367,365,392])
img1 = np.column_stack((x1,y1))
img2= np.column_stack((x2,y2))`

def normalise(img):
    '''
    input:img = image points that we want to normalize
    return:Tr = Transformation that normalises the points
    normalised_points = Points normalise by Tr
    '''
    s = np.sqrt(2)/((1/25)*np.sum((np.sqrt(abs(img - np.mean(img,axis=0))**2))))
    m = np.mean(img,0)
    normalised_points = np.zeros((25,3))
    Tr = np.array([[s, 0, m[0]], [0, s, m[1]], [0, 0, 1]])
    for i in range(img.shape[0]):
        normalised_points[i][0] = s*img[i][0] + m[0]
        normalised_points[i][1] = s*img[i][1] + m[1]
        normalised_points[i][2] = 1
    return Tr, normalised_points

Tr1,normalised_X = normalise(img1)

参考


推荐阅读