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

今天又又又遇到问题了,问题如下:
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)
问题就解决啦~

你可能感兴趣的:(python)