1# cv2.rectangle(img, pt1, pt2, color, thickness, lineType, shift)
2cv2.rectangle(img, (x1, y1), (x2, y2), (255,0,0), 2)
3
4"""
5x1,y1 ------
6| |
7| |
8| |
9--------x2,y2
10"""
1## drawing b.box for given coutour
2
3
4contours, _ = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
5for c in contours:
6 rect = cv2.boundingRect(c)
7 if rect[2] < 100 or rect[3] < 100: continue
8 print cv2.contourArea(c)
9 x,y,w,h = rect
10 cv2.rectangle(im,(x,y),(x+w,y+h),(0,255,0),2)
11 cv2.putText(im,'Moth Detected',(x+w+10,y+h),0,0.3,(0,255,0))
12cv2.imshow("Show",im)
13cv2.waitKey()
14cv2.destroyAllWindows()
15