Tyler Canine
Tyler Canine

Reputation: 31

Python OpenCV: ValueError: too many values to unpack

I am trying to get through an OpenCV tutorial and I am using the provided source code. I run into this error:

File "C:\xxx\xxxxxxx\Desktop\basic-motion-detection\motion_detector.py", line 61, in cv2.CHAIN_APPROX_SIMPLE) ValueError: too many values to unpack.

Here is the code:

# on thresholded image
thresh = cv2.dilate(thresh, None, iterations=3)
(cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
    cv2.CHAIN_APPROX_SIMPLE)`

Upvotes: 1

Views: 6324

Answers (1)

roccolocko
roccolocko

Reputation: 594

The problem is that you are using cv2 version 3, and not version 2, the code is for version 2. To Solve your problem only change this line

(cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
    cv2.CHAIN_APPROX_SIMPLE)

for this:

(_, cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
    cv2.CHAIN_APPROX_SIMPLE)

Upvotes: 3

Related Questions