cv2.findContours()出现错误ValueError: not enough values to unpack (expected 3, got 2)

cv2.findContours()出现错误ValueError: not enough values to unpack (expected 3, got 2)

cv2.findContours()出现错误ValueError: not enough values to unpack (expected 3, got 2)_第1张图片
出现错误原因:如果用的是cv 4.0版本,findContours返回的是两个参数,旧版的返回的则是三个参数

解决方法:移除第一个参数赋值

将image, cnts, hierarchy = cv2.findContours(diff.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

改为 cnts, hierarchy = cv2.findContours(diff.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

参考:https://stackoverflow.com/questions/54275633/valueerror-while-using-cv2-findcontours-in-python-not-enough-values-to-unp

你可能感兴趣的:(cv2.findContours()出现错误ValueError: not enough values to unpack (expected 3, got 2))