【发布时间】:2017-10-04 05:20:18
【问题描述】:
我有一个带点的二进制图像,我使用 OpenCV 的 goodFeaturesToTrack 获得,如 Image1 所示。
我想在其上放置一个 4*25 点的网格,例如 Image2 上显示的 on(并非所有点都在图像上可见,但它是一个常规的 4*25 点矩形)。
我的 4*25 点模型网格参数化为: 1 - 左上角的位置 2 - 矩形与地平线的倾角 下面的代码展示了一个构建这样一个模型的函数。
这个问题似乎接近棋盘角问题。
我想知道如何将我的模型点云拟合到输入图像并获取云的位置和角度。 我可以轻松测量两个图像之间的距离(输入图像和模型网格),但我想避免检查图像上的每个像素和角度以找到该距离的最小值。
def ModelGrid(pos, angle, shape):
# Initialization of output image of size shape
table = np.zeros(shape)
# Parameters
size_pan = [32, 20]# Pixels
nb_corners= [4, 25]
index = np.ndarray([nb_corners[0], nb_corners[1], 2],dtype=np.dtype('int16'))
angle = angle*np.pi/180
# Creation of the table
for i in range(nb_corners[0]):
for j in range(nb_corners[1]):
index[i,j,0] = pos[0] + j*int(size_pan[1]*np.sin(angle)) + i*int(size_pan[0]*np.cos(angle))
index[i,j,1] = pos[1] + j*int(size_pan[1]*np.cos(angle)) - i*int(size_pan[0]*np.sin(angle))
if 0 < index[i,j,0] < table.shape[0]:
if 0 < index[i,j,1] < table.shape[1]:
table[index[i,j,0], index[i,j,1]] = 1
return table
【问题讨论】:
标签: python opencv image-processing optimization model-fitting