gpt4 book ai didi

python - 这是我在 python 中的边界填充 pgm bt 它只填充了边界的一半

转载 作者:太空宇宙 更新时间:2023-11-03 22:52:30 25 4
gpt4 key购买 nike

这是我在 python 中的边界填充 pgm bt 它只填充了边界的一半

def is_equal(a, b):
_equal = a[0]==b[0] and a[1]==b[1] and a[2]==b[2]
return _equal

def boundary_fill(src, x, y, fill_color, boundary_color):
print "x , y ", x, y
try:
color_at_xy = src[y, x]
except IndexError:
return
if not is_equal(color_at_xy,fill_color) and not is_equal(color_at_xy,boundary_color):
src[y, x] = fill_color
#boundary_fill(src, x + 1, y, fill_color, boundary_color)
boundary_fill(src, x - 1, y, fill_color, boundary_color)
boundary_fill(src, x, y + 1, fill_color, boundary_color)
boundary_fill(src, x, y - 1, fill_color, boundary_color)

评论被删除时---

File "as.py", line 5, in is_equal
_equal = a[0]==b[0] and a[1]==b[1] and a[2]==b[2]
RuntimeError: maximum recursion depth exceeded in cmp

---出现这个错误请帮我解决这个问题提前致谢

最佳答案

import cv2  
import numpy as np
import sys

def is_equal(a, b):
_equal = a[0]==b[0] and a[1]==b[1] and a[2]==b[2]
return _equal
sys.setrecursionlimit(10000)
def boundary_fill(src, x, y, fill_color, boundary_color):
print "x , y ", x, y
try:
color_at_xy = src[y, x]
except IndexError:
return
if not is_equal(color_at_xy,fill_color) and not is_equal(color_at_xy,boundary_color):
src[y, x] = fill_color
boundary_fill(src, x + 1, y, fill_color, boundary_color)
boundary_fill(src, x - 1, y, fill_color, boundary_color)
boundary_fill(src, x, y - 1, fill_color, boundary_color)
boundary_fill(src, x, y + 1, fill_color, boundary_color)
boundary_fill(src, x + 1, y - 1, fill_color, boundary_color)
boundary_fill(src, x + 1, y + 1, fill_color, boundary_color)
boundary_fill(src, x - 1, y - 1, fill_color, boundary_color)
boundary_fill(src, x - 1, y + 1, fill_color, boundary_color)

关于python - 这是我在 python 中的边界填充 pgm bt 它只填充了边界的一半,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36376885/

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