Ask Your Question
0

Code from the tutorial doesn't work

asked 2019-01-08 07:33:54 -0600

updated 2019-01-08 07:36:29 -0600

berak gravatar image

.

import numpy as np
import cv2

im = cv2.imread('test.jpg')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

When executing this code, I get an error: ValueError: too many values to unpack (expected 2) .

Is there a mistake in tutorial or am I doing something wrong?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2019-01-08 07:38:19 -0600

berak gravatar image

updated 2019-01-08 07:39:49 -0600

you're using the wrong tutorial for your opencv version.for latest, have a look here , for 3.4 or older here

opencv4 does no more return the image from there, so there are only 2 return values now, while older versions had 3 return values there.

edit flag offensive delete link more
2

answered 2019-01-08 09:04:18 -0600

supra56 gravatar image

ValueError: too many values to unpack (expected 2) meaning you need another varaible.

 ret, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-01-08 07:33:54 -0600

Seen: 594 times

Last updated: Jan 08 '19