1 | initial version |
actually, getting the lower/upper bounds right is the hardest thing here, then it needs a few more steps:
# binarized image:
bin = cv2.inRange(hsv, lower,upper)
# contours:
im2, contours,hierarchy = cv2.findContours(bin,2,1) # without 'im2' for opencv2.4 !!
if len(contours)>0:
cnt = contours[0]
(x,y,w,h) = cv2.boundingRect(cnt)
cv2.rectangle(img, (x,y), (x+w,y+h), (255,0,0), 1)