2012-12-18 5 views
9

私は、長方形キャリブレーションパターンのドットからポイント(x、y)を持つn:2マトリックスを持っています。 私は行ごとにこれらのポイントを並べ替えるのが好きです。 これらの点をlexsortでソートしましたが、カメラからの歪みが大きすぎてy座標が重なり合わないようになっています。ソート2dキャリブレーションパターンポイントnumpy with

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

行の長行くドロネーパターンの助けを借りてこれをソートする方法はありますか?三角測量を使用し

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

enter image description here

+0

重複していないx座標をカウントできますか?並べ替え順を逆にして、結果の行列を転置することができます。それは命をはるかに簡単にするでしょう。 Delaunayの三角測量は、小さなオーバーラップに対してより堅牢ですが、歪みが大きすぎると、矩形パターンも分解されます。 – Jaime

+0

なぜソートしたいですか?校正のポイントは、アルゴリズムに多数のポイントを置くことができるということです。キャリブレーション後、画像を復元することができ、ポイントはライン上に正確に表示されます。 – RobAu

答えて

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のインデックスです。