This Article is written by Prattay Chakrabarty
Requirement-
- python 3.6
- numpy module
- opencv module
Step----
step1-- open command prompt
1.pip install numpy
then
2.pip install opencv-python
Code---
#developed by Prattay Chakrabarty
import cv2
import numpy as np
face_cascade = cv2.CascadeClassifier(
'haar_cascade_files/haarcascade_frontalface_default.xml')
if face_cascade.empty():
raise IOError('Unable to load the face cascade classifier xml file')
cap = cv2.VideoCapture(0)
scaling_factor = 0.5
while True:
_, frame = cap.read()
frame = cv2.resize(frame, None,
fx=scaling_factor, fy=scaling_factor,
interpolation=cv2.INTER_AREA)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
face_rects = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in face_rects:
cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 3)
cv2.imshow('Free Python Face Detector By Bongcode.com', frame)
c = cv2.waitKey(1)
if c == 27:
break
cap.release()
cv2.destroyAllWindows()
#you can get the code in the project folder
Run The Code---
You Have to download the folder from the link-- Click Here
then open the face_detector.py file .
and run the file.
Thanks Everyone :)
Any Question or Doubt You Can Ask .
Comments
Post a Comment