python报错The truth value of an array with more than one element is ambiguous.
投影法做字符切割的一段程序,像素比较的时候会报错是为什么
def projection_line(array_vals, minimun_val, minimun_range):
start_i = None
end_i = None
line_ranges = []
'''
for index, item in enumerate(list1):
print index, item
'''
for i, val in enumerate(array_vals):
# 黑色像素起点
if val > minimun_val and start_i is None:
start_i = i
# 黑色像素区间
elif val > minimun_val and start_i is not None:
pass
# 黑色像素终点
elif val < minimun_val and start_i is not None:
# 黑色像素的长度
if i - start_i >= minimun_range:
end_i = i
#print(end_i - start_i)
# 记录此段黑色像素起始点
line_ranges.append((start_i, end_i))
start_i = None
end_i = None
# 白色像素区域
elif val < minimun_val and start_i is None:
pass
else:
raise ValueError("cannot parse this case...")
return line_ranges
报错信息:if val > minimun_val and start_i is None:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()