我正在购买python
_, threshold = cv2.threshold(gray_roi, 3, 255, cv2.THRESH_BINARY_INV)
_, contours, _ = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key=lambda x: cv2.contourArea(x), reverse=True)
Traceback (most recent call last):
File "/Users/hissain/PycharmProjects/hello/hello.py", line 17, in <module>
_, contours, _ = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
ValueError: not enough values to unpack (expected 3, got 2)
怎么解决呢?
根据cv2.findContours
文档,该函数仅返回2个值。您尝试打开包装3。
_
从第二行中删除第一行(不需要的值)以匹配文档中的签名。
_, threshold = cv2.threshold(gray_roi, 3, 255, cv2.THRESH_BINARY_INV)
contours, _ = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key=lambda x: cv2.contourArea(x), reverse=True)
一般来说,当您收到以下Python错误消息时:
ValueError:没有足够的值可解包(预期x得到y)
搜索您尝试解包y
元素的位置,然后尝试通过解包x
元素对其进行修复。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句