We can also detect eyes and faces using OpenCV Python that which wee are going to learn in this tutorial.To achieve this we are using a trained model for eyes and face
For Detecting the eyes and faces on the webcam using Python you have to get the Haarcascade packages
haarcascade_frontalface_default.xml:
For detecting the faces using OpenCV we have to use this XML file.
haarcascade_eye.xml:
For detecting the Eyes using OpenCV we have to use this XML file.
You can get the XML files by click here.
Note:
We have to place the XML files in the same folder where our Python file will be or else you have to give the file destination whereever we are using.
Step 1:
import cv2 import matplotlib.pyplot as plt import numpy as np
we have to import the OpenCV , Matplotlib,NumPy for detection of eyes and face
step 2:
cap=cv2.VideoCapture(0)
Giving permission for webcam to capture the Video.
step 3:
face_cascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml') eye_cascade=cv2.CascadeClassifier("haarcascade_eye.xml")
Assigning the XML files using CascadeClassifier.
Submitted by Yerra Vijay Sai (vijaysai)
Download packets of source code on Coders Packet
Comments