ValueError: too many values to unpack in cv2.findContours
See original GitHub issueFor 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:
- Created 6 years ago
- Reactions:4
- Comments:13
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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 😉