1

Can someone tell me whats going wrong here?

line 11, in <module>
    im2, contours, hierarchy = cv2.findContours(thresh, 1, 2)
ValueError: not enough values to unpack (expected 3, got 2)

code:

import cv2 as cv
import cv2

filename = "C:\\Users\\Tony\\Pictures\\img807.tif"
img = cv.imread(filename, 0)
ret, thresh = cv.threshold(img, 127, 255, 0)
im2, contours, hierarchy = cv2.findContours(thresh, 1, 2)
cnt = contours[0]
M = cv.moments(cnt)
print(M)
exit()
Tony
  • 8,681
  • 7
  • 36
  • 55

1 Answers1

0

cv2.findContours return two values (contours and hierarchy) not three.

So it solve the error replace by:

contours, hierarchy = = cv2.findContours(thresh, 1, 2)
Nidal Barada
  • 373
  • 2
  • 14