Python programming blog

Sunday, April 25, 2021

Real time Color detection project using python

Step 1: Installing libraries

1.pip install Opencv-Python

2.pip install colorthief

 

Step 2: Importing libraries

import cv2
from colorthief import ColorThief 

 

Step 3: Capture screen

camera=cv2.VideoCapture(0)

  

Step 4: Loop & reading webcam

while True:
    _,image=camera.read()
    cv2.imshow('image',image)

 

Step 5: Assign a key to take capture

if cv2.waitKey(1)& 0xFF==ord('s'):
        cv2.imwrite('test1.jpg',image)

camera.release()
cv2.destroyAllWindows() 


Step 6:Function for detecting colors

def ss():
    colorthief=ColorThief('test1.jpg')
    colors=colorthief.get_palette(color_count=2)
    print(colors)
ss() 

 

Full code: Color detector project 

Buy me a coffee...!💓
 

 

No comments:

Post a Comment