Home > Blockchain >  Contours tuple must have length 2 or 3, otherwise OpenCV changed their cv2.findContours return signa
Contours tuple must have length 2 or 3, otherwise OpenCV changed their cv2.findContours return signa

Time:03-10

cnts,_ = cv2.findContours(cv.rectangle(img3.copy(), (0,200) , (5000, 1150), (255,0,0), 2) ,cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(rgb_img, cnts, -1, (0,255,0), 2)


conts = imutils.grab_contours(cnts)
c = max(conts, key=cv2.contourArea)

I'm trying to find the contours of two irregular edges in between the image. Else the rectangular actual edge of the image is being detected as contour max area. So i thought of using a rectangular area where I want it to exactly detect the edges.

CodePudding user response:

You are using imutils.grab_contours wrong.

If you do the destructuring yourself, with (cnts, *_) = cv.findContours(...), then you don't need imutils at all.

If you want to use imutils anyway, you need to pass it the entire tuple (2-tuple or 3-tuple) returned by cv.findContours, like so: cnts = imutils.grab_contours(cv.findContours(...))

  • Related