Python:绘制sift点返回图片上的点

2024-09-30 20:34:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用sift实现以及“用Python编程计算机视觉”中的代码。你知道吗

在中使用plotMatches函数时视觉.py(相当于书中的plot_matches()函数),一些绘制的点甚至不在图像上: Output of the results

如您所见,大多数点都不在图像上。你知道吗

这可能是我必须更改plotMatches()函数的结果:

        for i, m in enumerate(matchscores):
            if i > 0:
                 lab.plot([locs1[i][1], locs2[i][1] + cols1],
                 [locs1[i][0], locs2[i][0]], 'c')

原始代码:

        for i, m in enumerate(matchscores):
            if i > 0:
                lab.plot([locs1[i][1], locs2[m][1] + cols1],
                [locs1[i][0], locs2[m][0]], 'c')

将引发以下错误:

    Traceback (most recent call last):
    File "/home/peter-brown/AI/Markus/ImageRecognition.py", line 37,     in <module>
     sch.plotMatches(image, image2, l1, l2, matches, show_below=False)
     File "/home/peter-brown/AI/Markus/vision.py", line 199, in    plotMatches
     lab.plot([locs1[i][1], locs2[m][1] + cols1],
     IndexError: index 1 is out of bounds for axis 0 with size 1

通过更改代码中使用的任何“m”,程序可以工作,但输出不正确。你知道吗

为什么输出与图像不对应,如何更改plotMatches函数以使其工作?你知道吗


Tags: 函数代码inpy图像forplotlab
1条回答
网友
1楼 · 发布于 2024-09-30 20:34:09

matplotlib中,翻转xy坐标。从你的图像上看,你似乎把所有的x坐标解释为y坐标,反之亦然。从您的函数来看,这是一个简单的更改:

for i, m in enumerate(matchscores):
        if i > 0:
             lab.plot([locs1[i][0], locs2[i][0] + cols1],
             [locs1[i][1], locs2[i][1]], 'c')

相关问题 更多 >