9

I have a n:2 Matrix with points(x,y) found from dots in a rectangular calibration pattern. I like to sort these points row by row. I have sorted these points with lexsort but the distortion from the camera is too big so that y-coordinates will be overlap.

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

enter image description here

Is there a way to sort this with help of a delaunay pattern going a long the rows?

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

enter image description here

4

1 回答 1

2

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

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 中获得水平边缘,这是一个 2d 数组[[p_{0},p_{1}], ..., [p_{n}, p_{n+1}]],其中 p_i 是coordinates数组的索引。

于 2012-12-20T11:51:24.010 回答