我有一张照片,我详细说明我的程序以获取坐标列表。
在图像中表示有一个矩阵。 在一个理想的测试中,我只得到矩阵每个方格的十六个中心点。 但在实际测试中,我会得到很多噪点。
我想使用算法从坐标列表中推断出来,该坐标由最能代表矩阵的16个坐标组成。
矩阵可以具有任何纵横比(在一个范围之间)并且可以导致稍微旋转。 但总是一个4x4矩阵。 矩阵并不总是出现在图像中,但不是问题,我只需要最佳匹配。 当然,创始点总是超过16(或我跳过)
成立点的例子:
渴望结果的例子:
如果有人可以建议我这样做的首选方法会很棒。
我正在考虑点之间的欧氏距离。
For each point in the list:
1. calculate the euclidean distance (D) with the others
2. filter that points that D * 3 > image.widht (or height)
3. see if it have at least 2 point at the same (more or less) distance,
if not skip
4. if yes put the point in a list and for each same-distance founded points: go to 2nd step.
如果我在列表中有16个点,那么这可能是一个矩阵。
有什么更好的建议吗?
谢谢
答案 0 :(得分:2)
这是我想到的算法:
for each pair of points (p1, p2):
let d be the distance vector (x and y) between them
if d.x > (image.width-p1.x)/3 or d.y > (image.height-p1.y)/3:
continue
let d_t be d turned 90 degrees (d.y, -d.x)
for i from 0 to 3:
for j from 0 to 3:
if there is no point at p1 + i*d + j*d_t:
continue outer loop
if you get here, you have a 4*4 grid
要将运行时间减半(平均),您可以考虑p1右侧的p2。
答案 1 :(得分:0)
根据您要使用的处理能力,并假设“小旋转”意味着很少,您可以尝试以下方法: 1)仅获取点的X坐标,搜索大小为4的簇。
2)对于每个群集,如果还有两个距离为2 * d和3 * d,则查看距离为d的左侧每个群集。
3)如果是,则比较每个聚类的y坐标,看它们是否大致相等。
根据数据,您可以在第二步之前执行第三步并使用它来修剪您考虑的选项,从而获得更好的性能。