gpt4 book ai didi

python - 有序坐标

转载 作者:行者123 更新时间:2023-12-02 17:11:47 25 4
gpt4 key购买 nike

我有一个二维无序坐标列表:

[[ 95 146]
[118 146]
[ 95 169]
[ 95 123]
[ 72 146]
[118 169]
[118 123]
[141 146]
[ 95 100]
[ 72 123]
[ 95 192]
[ 72 169]
[141 169]
[118 100]
[141 123]
[ 72 100]
[ 95 77]
[118 192]
[ 49 146]
[ 48 169]]
Diplay coordinates
如何找到每个点的对应行和列?我的观点不是很完美,可能存在很小的轮换。我正在查看Opencv findCirclesGrid代码,但没有找到排序算法。
编辑:@armatita解决方案使用一组数据,但是当坐标旋转7°时
data = array([[ 95, 146],[72,143],[92,169],[98,123],[75,120],[69,166],[49,140],[89,192],[115,172],[46,163],[52,117],[66,189],[112,194],[121,126],[123,103],[101,100],[78,97],[141,152],[86,215],[138,175]])

def find(arr,threshold):
rmin = sys.maxint
for i in range(len(arr)):
for j in range(i+1,len(arr)):
diff = abs( arr[i] - arr[j] )
if diff > threshold and diff < rmin:
rmin = diff
return rmin

threshold = 10
space = np.array([ find(data[:,0],threshold), find(data[:,1],threshold) ], dtype=np.float32)
print "space=",space
first = np.min(data,axis=0)

order = np.around( ( data - first ) / space )

plt.scatter(data[:,1], data[:,0],c=range(len(data)),cmap="ocean")
for pt in zip(order,data):
c, rc = ( pt[1], pt[0] )
plt.text( c[1], c[0]+5, "[%d,%d]" % (rc[1],rc[0]),color='black')
plt.show()
enter image description here
问题来自空间计算

最佳答案

通过将它们放入伪规则网格中:

    c = [[ 95, 146],[118, 146],[ 95, 169],[ 95, 123],[ 72, 146],[118, 169],
[118, 123],[141, 146],[ 95, 100],[ 72 ,123] ,[ 95 ,192],[ 72 ,169]
,[141 ,169],[118 ,100],[141 ,123],[ 72 ,100],[ 95 , 77],[118 ,192]
,[ 49 ,146],[ 48 ,169]]

nodesx = 100
sizex = 20
sizey = 20
firstx = 70
firsty = 40

new,xt,yt = [],[],[]
for i in c:
xo = int((i[0]-firstx)/sizex)
yo = int((i[1]-firsty)/sizey)
new.append(nodesx*yo+xo)
xt.append(i[0])
yt.append(i[1])

sortedc = [x for (y,x) in sorted(zip(new,c))]

import matplotlib.pyplot as plt
plt.scatter(xt,yt)
for i in range(len(sortedc)):
plt.text(sortedc[i][0],sortedc[i][1],str(i))
plt.show()

,这将导致此情况(请告诉您是否不了解逻辑):

sorted 2D coordinates

关于python - 有序坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36065021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com