python - 标准化 Python 中的点,以便与原点的 RMS 距离为 sqrt2
问题描述
我想实现 DLT 算法,我有 6 个对象点 (X,Y,Z,1).T 和 6 个图像点 (u,v,1).T ,它们是对象点到图像平面的投影.
因此,在实施 DLT 之前,我必须对数据进行规范化。
更具体地说,我发现我必须执行以下操作:应该对 2D 图像点进行归一化,以便它们的质心位于原点,并且它们与原点的均方根距离为 sqrt(2)
知道如何在 python 中做到这一点吗?
解决方案
为两张图像取 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)
推荐阅读
- computer-vision - SIFT 实现返回整个图像的单个向量
- acumatica - 如何使用 PXSelect 获取用户定义的字段?(又名 ext 字段)
- postgresql - PostgreSQL - 不是过程中的已知变量
- reactjs - React:无法访问存储在渲染函数内部状态中的数组的属性
- python-3.x - '没有唯一模式;发现 %d 个同样常见的值' % len(table) statistics.StatisticsError: no unique mode; 找到 2 个同样常见的值
- arm - quartus 模拟器和 fpga 中的时钟周期时间可以不同吗?
- sql - SQL 查询以获取 12 列的一行中非 Null 出现的次数
- python - Keras 返回二进制结果
- swift - CarPlay MPContentItem
- yii2 - 如何在 yii2 中关闭 boostrap 对话框?