Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

your contours list seems to be empty, so contours[0] is invalid.

please check like:

if len(contours) > 0:
     # process contours

your contours list seems to be empty, so contours[0] is invalid.

please check like:

 if len(contours) > 0:
     # process contours
   rc = cv2.minAreaRect(contours[0])
        box = cv2.boxPoints(rc)
        for p in box: 
            pt = (p[0],p[1])
            cv2.circle(ret,pt,5,(200,0,0),2)

    #Display the resulting frame
    cv2.imshow('frame',bin) #shows the frame to screen
    if cv2.waitKey(1) & 0xFF == ord('q'): #if 'q' key is pressed, end feed
         break

but the main reason, you're not finding any contours is: your "lower" values for inRange() are larger than the "upper" ones (it should be the opposite), so already your binary img is all black only. it's probably a good idea, to visualize it, by putting an cv2.imshow("bin",bin) after the inRange() operation.