解决:ValueError: not enough values to unpack (expected 3, got 2)

错误原因: cv2.findContours的opencv旧版本返回3个值:
im2, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE),
新版本返回2个值:
contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)。
原代码:_,contours, hierarchy = cv2.findContours(img_gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
改为: contours, hierarchy = cv2.findContours(img_gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
 

你可能感兴趣的:(解决:ValueError: not enough values to unpack (expected 3, got 2))