gpt4 book ai didi

python - 类型错误 : unsupported operand type(s) for -: 'tuple' and 'tuple'

转载 作者:太空宇宙 更新时间:2023-11-04 10:12:38 24 4
gpt4 key购买 nike

<分区>

我尝试使用 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')

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