Python findContours and contourArea

asked 2017-05-09 07:34:25 -0500

Rocketmagnet gravatar image

I'm writing a motion triggered camera system on a Raspberry Pi, using Python and OpenCV 3.

The following command seems to work:

cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

because sometimes I can draw those contours using:

cv2.drawContours(frame0, c, -1, (0,255,0), 3)

But it only works reliably if I enclose the drawContours statement in a try except structure. Furthermore, when I try this:

area = if cv2.contourArea(c)

It never works, and always throws an exception.

  • Am I doing something wrong?
  • Is there some way to detect if a contour returned by findContours is a valid one, and won't cause exceptions to be thrown?
edit retag flag offensive close merge delete


findContours returns a vector of contours, drawContours also expects a vector (not a single contour),

can you take another look at the tutorials ?

also please try to show the complete code, the isonlated lines are meaningless without context

berak gravatar imageberak ( 2017-05-09 07:57:09 -0500 )edit