【发布时间】:2016-09-21 15:09:51
【问题描述】:
我尝试使用 Moravec 检测。当我尝试运行此代码时,出现一些错误:
diff = diff - image.getpixel((x, y))
TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'
我该如何解决?任何帮助将不胜感激。代码是:
def moravec(image, threshold = 100):
"""Moravec's corner detection for each pixel of the image."""
corners = []
xy_shifts = [(1, 0), (1, 1), (0, 1), (-1, 1)]
for y in range(1, image.size[1]-1):
for x in range(1, image.size[0]-1):
# Look for local maxima in min(E) above threshold:
E = 100000
for shift in xy_shifts:
diff = image.getpixel((x + shift[0], y + shift[1]))
diff = diff - image.getpixel((x, y))
diff = diff * diff
if diff < E:
E = diff
if E > threshold:
corners.append((x, y))
return corners
if __name__ == "__main__":
threshold = 100
image = Image.open('all.jpg')
corners = moravec(image, threshold)
draw_corners(image, corners)
image.save('low2.png')
【问题讨论】:
-
你不能直接从另一个元组中减去一个元组。查看替代方案here。
标签: python python-imaging-library