【问题标题】:usage of findContours causes ValueError: not enough values to unpack (expected 3, got 2) [duplicate]使用 findContours 会导致 ValueError: not enough values to unpack (expected 3, got 2) [重复]
【发布时间】:2022-01-27 15:38:25
【问题描述】:

我正在使用 RaspberryPi 3 我正在尝试运行This 代码 显示以下错误

Waiting for video to adjust... Done. 
 Waiting for motion. 
Waiting for video to adjust... Done. 
 Waiting for motion.  
Traceback (most recent call last): 
        File "/home/pi/Tracking-Turret/turret.py", line 418, in <module> t.motion_detection(show_video=True) 
        File "/home/pi/Tracking-Turret/turret.py", line 273, in motion_detection VideoUtils.find_motion(self.__move_axis, show_video=show_video) 
        File "/home/pi/Tracking-Turret/turret.py", line 134, in find_motion c = VideoUtils.get_best_contour(thresh.copy(), 5000) 
        File "/home/pi/Tracking-Turret/turret.py", line 158, in get_best_contour im, contours, hierarchy = cv2.findContours(imgmask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) 
        ValueError: not enough values to unpack (expected 3, got 2)

【问题讨论】:

  • 我认为,cv2.findContours 函数的返回是一个具有 2 个值的元组,例如 (a, b)。但您的代码需要 3 个值 (im, contours, hierarchy)。所以你需要检查一下,你想得到什么。
  • 不正确。它从未返回 (x,y) 值。

标签: python opencv opencv-contour motion-detection


【解决方案1】:

这是版本更改。在 OpenCV 4.4 之前,findCounters 确实返回了三件事。较新的版本返回 2:contourshierarchy

https://docs.opencv.org/4.4.0/d3/dc0/group__imgproc__shape.html#gadf1ad6a0b82947fa1fe3c3d497f260e0

【讨论】:

  • 问题重复。如果您有新见解(行为取决于版本),请将其添加到其他问题中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-10-10
  • 1970-01-01
  • 2019-06-07
  • 2020-10-26
  • 2022-01-08
  • 2017-12-23
相关资源
最近更新 更多