<分区>
使用 opencv
,我正在检测轮廓并选择其中的一些:
CNTS = []
_, contours, _ = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
if some_condition(c):
CNTS.append(c)
然后我遍历轮廓列表的 2 个子集 {c1, c2},并删除其中的一些:
TMP = CNTS[:] # copy it, to avoid deleting element from a list while looping on it!
for c1, c2 in itertools.combinations(TMP, 2):
if dist(c1, c2) < 100 # custom function to evaluate distance between 2 contours
if c1 in CNTS: # it might have been already removed
CNTS.remove(c1)
CNTS.remove(c1)
行出现问题:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
如何从 opencv
轮廓列表中正确删除轮廓?
注意:其实大部分时间都有效,但有时,经过几次迭代后,我会出现这个错误。可能是因为轮廓是一个点列表,然后测试“点列表”是否是另一个列表的成员是不明确的?
更一般地说,在 Python 中,在测试点列表(= 2 个元素列表的列表!)本身是否是另一个列表的成员时,是否存在一些模棱两可的情况?