Harsh Dethe
Published © CC BY-NC-SA

Colour Detection Using OpenCV & Python

Learn how to detect and track a particular colour using Python and OpenCV.

IntermediateProtip1 hour26,245
Colour Detection Using OpenCV & Python

Things used in this project

Hardware components

Web-cam
×1

Software apps and online services

Python 2.7
OpenCV
OpenCV

Story

Read more

Code

Code snippet #9

Plain text
#Tracking Colour (Yellow) 

(_,contours,hierarchy)=cv2.findContours(yellow,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
        
     for pic, contour in enumerate(contours):
              area = cv2.contourArea(contour)
              if(area>300):
                   x,y,w,h = cv2.boundingRect(contour)     
                        img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),3)

Code snippet #11

Plain text
cv2.imshow("Color Tracking",img)
if cv2.waitKey(10) & 0xFF == 27:
                cap.release()
                cv2.destroyAllWindows()
                break

Credits

Harsh Dethe

Harsh Dethe

30 projects • 68 followers
Electronics hobbyist, AI Enthusiast. I like to play with technology.

Comments