question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: too many values to unpack in cv2.findContours

See original GitHub issue

For whatever reason, cv2.findContours on line 211 returns three arguments instead of the expected 2. From playing with it, I found that by eliminating the first value would solve the problem. I am not knowledgeable about cv2 so if this is something obvious someone please say so. (MacOS, cv2 ‘3.2.0’). Here is the fix that worked for me. result = cv2.findContours(edges.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) contours, hierarchy = result if len(result) == 2 else result[1:3]

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:4
  • Comments:13

github_iconTop GitHub Comments

42reactions
ossiachcommented, Aug 14, 2017

Adding a third value in front of the other two also solved the problem for me. For example: _, contours, hierarchy = cv2.findContours(edges.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

Apparently findContours got changed some time ago: https://stackoverflow.com/questions/25504964/opencv-python-valueerror-too-many-values-to-unpack

6reactions
bharath5673commented, Jan 17, 2019

EASY FIX 😉

( _ , cnts , _ ) = cv2.findContours(threshFrame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) ValueError: not enough values to unpack (expected 3, got 2)

try this

( cnts , _ )

python is right. you cannot unpack 3 values from the turple and place them in a turple of two ###

happy coding 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

cv2.findContours - ValueError: too many values to unpack
I got the answer from the OpenCV Stack Exchange site. Answer. THE ANSWER: I bet you are using the current OpenCV's master branch:...
Read more >
Python: ValueError: too many values to unpack
I'm writing an opencv program and I found a script on another stackoverflow question: Computer Vision Masking A Human Hand.
Read more >
too many values to unpack (expected 2), when you use "cv2 ...
ValueError : too many values to unpack (expected 2), when you use "cv2.findContours". check this tip! before (error) contours, _ = cv2.
Read more >
Solved: ValueError: too many values to unpack (expected 2)
ValueError : too many values to unpack (expected 2) this error occured when executing below program # USAGE # python distance_to_camera.py ...
Read more >
cv2.findContours 返回错误:too many values to unpack ...
今天在使用cv2.findContours报错:too many values to unpack (expected 2)返回是两个数值啊,但是,不同cv2版本的cv2.findContours返回值不一样, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found