New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError: too many values to unpack in cv2.findContours #5
Comments
Adding a third value in front of the other two also solved the problem for me. Apparently findContours got changed some time ago: |
Yes above solution worked for me too. |
ValueError: too many values to unpack jasonlfunk/ocr-text-extraction#5 (comment)
conts,h=cv2.findContours(maskFinal.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) sir please tell me where I'm wrong |
Just initialize with one more variable in front of other two on L.H.S.For example:- I've used _(Underscore) here.You can give any name or simply use it as underscore only. |
Is it safe to say that find Contours needs three variables to store the returned value? |
Ofcourse it is.Don't worry, it is safe to say this. |
(cnts, _) = cv2.findContours(closed.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) Not able to understand. Please help me. giving error too many values to unpack. |
Use like this:- |
Because you cannot unpack 3 values from the tuple and place them in a tuple of two,which you are doing. |
What is the third value, though? According to the docs, only two should be returned. https://docs.opencv.org/2.4/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#findcontours Edit: I am using opencv3, cannot find the docs for |
EASY FIX ;) ( _ , cnts , _ ) = cv2.findContours(threshFrame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) try this
python is right. happy coding ;) |
@bharath5673 this works ,thank u |
I'm getting the same error unable to resolve it. in extract_bv(image) ValueError: not enough values to unpack (expected 3, got 2) |
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]
The text was updated successfully, but these errors were encountered: