【问题标题】:sort 2d calibration pattern points with numpy用 numpy 对 2d 校准模式点进行排序
【发布时间】:2012-12-05 19:59:24
【问题描述】:

我有一个 n:2 矩阵,其中点 (x,y) 从矩形校准图案中的点中找到。 我喜欢逐行对这些点进行排序。 我已经用 lexsort 对这些点进行了排序,但是相机的失真太大,以至于 y 坐标会重叠。

imageloading...
blobs=imageprocessing....
coordinates=np.array([blob.centroid() for blob in blobs])
nd=np.lexsort((coordinates[:,0],coordinates[:,1]))
coordinates=coordinates[ind]

有没有办法在 delaunay 模式的帮助下进行排序?

import matplotlib.tri as tri 
x=coordinates[:,0] y=coordinates[:,1]
triang = tri.Triangulation(x, y)

【问题讨论】:

  • 你能指望 x 坐标不重叠吗?您可以颠倒排序顺序,然后转置结果矩阵。这将使生活变得更加轻松。 Delaunay 三角剖分对小的重叠可能更稳健,但如果失真太大,也会破坏矩形模式。
  • 为什么要对它们进行排序?校准的重点是您可以“只是”在算法中放置大量点。校准后,您可以恢复图像,并且点将完全在线。

标签: python sorting numpy matplotlib delaunay


【解决方案1】:

使用三角测量确实很有趣,并且可以用于您的应用程序:

import numpy as np
import matplotlib.tri as tri
import matplotlib.pyplot as plt
import random

# create fake data
x,y = np.meshgrid(np.arange(10), np.arange(10))
x = x.flatten()
y = y.flatten()
coordinates = np.column_stack([x,y])+0.04 * np.random.rand(len(x), 2)
np.random.shuffle(coordinates)
x=coordinates[:,0]
y=coordinates[:,1]

# perform triangulation
triang=tri.Triangulation(x,y)
f = plt.figure(0)
ax = plt.axes()
tri.triplot(ax,triang)

# find horizontal edges
f = plt.figure(1)
e_start = coordinates[triang.edges[:,0]]
e_end = coordinates[triang.edges[:,1]]
e_diff = e_end - e_start
e_x = e_diff[:,0]
e_y = e_diff[:,1]

e_len = np.sqrt(e_x**2+e_y**2)
alpha = 180*np.arcsin(e_y/e_len)/np.pi

hist, bins, patches = plt.hist(alpha, bins=20)

# in the histogram, we find that the 'horizontal' lines
# have an alpha < 10.

ind_horizontal = (-10<alpha) & (alpha < 10)
edges_horizontal = triang.edges[ind_horizontal]
plt.show()

因此,您会在 edges_horizo​​ntal 中获得水平边缘,这是一个二维数组 [[p_{0},p_{1}], ..., [p_{n}, p_{n+1}]],其中 p_i 是 coordinates 数组的索引。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-18
    • 2011-02-11
    • 1970-01-01
    • 2019-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多