Simply stands that the cv2.findContours() method didn't found any contours in the given image, so it is always suggested to do a sanity checking before accessing the contour, as:if len(contours) > 0: # Processing here.else: print "Sorry No contour Found."错误 2ValueError: too many values to unpack这个错误是由于 _,contours,_ = cv2.findContours 引起的,因为 cv2.findContours 只返回 2 个值,轮廓和层次,所以很明显当您尝试从 cv2.findContours 返回的 2 个元素元组中解压缩 3 个值,它会引发上述错误.This error is raised due to _,contours,_ = cv2.findContours, since the cv2.findContours returns only 2 values, contours and hierarchy, So obviously when you try to unpack 3 values from 2 element tuple returned by the cv2.findContours, it would raise the above mentioned error.同样 cv2.findContours 改变了输入 mat,所以建议将 cv2.findContours 调用为:Also the cv2.findContours changes the input mat in place, so it is suggested to call the cv2.findContours as:contours, hierarchy = cv2.findContours(imgThresholded.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)if len(contours) > 0: # Processing here.else: print "Sorry No contour Found." 这篇关于在 Python 中使用 findContours 和 OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-29 18:27