Friday , June 18 2021
Home / Computer Vision / Face Detection From Webcam in Python Using OpenCV

Face Detection From Webcam in Python Using OpenCV

14 Face Detection from Webcam

Face Detection From Webcam in Python Using OpenCV

The objective of the program given is to detect object of interest(face) in real time and to keep tracking of the same object.This is a simple example of how to detect face in Python. You can try to use training samples of any other object of your choice to be detected by training the classifier on required objects.

In [2]:
import cv2
face_cascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
capture=cv2.VideoCapture(0)

while True:
    ret,frame=capture.read()
    gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray,scaleFactor=1.1,minNeighbors=5)
    for x,y,w,h in faces:
        frame=cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),3)
    cv2.imshow('Color',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
capture.release()
cv2.destroyAllWindows()

About Machine Learning

Check Also

Access Camera Using OpenCV with Python

11 Open Webcam Access Camera Using OpenCV with Python¶ first, we Import libraries OpenCV. Then …

Leave a Reply

Your email address will not be published. Required fields are marked *