2
(_,contours,hierarchy)=cv2.findContours(yellow, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
ValueError: not enough values to unpack (expected 3, got 2)

The code here throws an error saying that I am missing the third value but it already has three values

yellow = 1.  
cv2.RETR_TREE = 2.  
cv2.CHAIN_APROX_SIMPLE = 3.  

and I don't know what to do.

I define yellow as

yellow = cv2.inRange(hsv, yellow_lower, yellow_upper)

and both yellow_lower and yellow_upper are defined...

Can anybody help? Thanks in advance

Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40
  • [How to use `cv2.findContours` in different OpenCV versions?](https://stackoverflow.com/questions/48291581/how-to-use-cv2-findcontours-in-different-opencv-versions/48292371#48292371) – Kinght 金 Apr 17 '19 at 04:44

1 Answers1

0

You believed three values would be returned (with 1st one discarded):

_, contours, hierarchy = cv2.findContours(yellow, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

The diagnostic is telling you that just two are being returned. So, accept both of them:

contours, hierarchy = cv2.findContours(yellow, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

You appear to be using a downrev cv2 library, with major version number 2. In 3.x the signature was changed to prepend an image as 3rd return value.

J_H
  • 17,926
  • 4
  • 24
  • 44
  • I yet haven't tried doing it because I moved on a new computer and I have other problems in the code... I'll see if it works after I finish with this. – Leonardo Poljak Apr 17 '19 at 16:25