Recognizing Objects Based on Color and Size using OpenCV
This file shows how to use the openCV library to recognize the largest object of a particular color within the cameras view.
Masking and Image Preparation
Identifying and using Contours
if len(contours) != 0:
# draw in blue the contours that were founded
cv2.drawContours(output, contours, -1, 255, 3)
# find the biggest countour (c) by the area
c = max(contours, key = cv2.contourArea)
x,y,w,h = cv2.boundingRect(c)
cx = x + (w/2)
cy = y + (h/2)
# draw the biggest contour (c) in green
cv2.rectangle(output,(x,y),(x+w,y+h),(0,255,0),2)Example Image

Last updated
Was this helpful?
