Reputation: 136
I'm using the sift implementation along with code found in the "Programming Computer Vision with Python".
While using the plotMatches function in vision.py (equivalent to the plot_matches() function to the book), some of the points plotted aren't even on the image:
As you can see, most of the points aren't on either of the image.
This may be the result of a change I had to make to my plotMatches() function:
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')
The original code:
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')
Would throw the following error:
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
By changing any 'm' used in the code, the program would work, but it would output incorrectly.
Why does the output not correspond to the image, and how can i change the plotMatches function to work?
Upvotes: 1
Views: 96
Reputation: 2471
In matplotlib
, the x
and y
coordinates are flipped. From your image it looks like you are interpreting all x
coordinates as y
coordinates and vice-versa. From your function, this is a simple change:
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')
Upvotes: 1