Tuesday 23 July 2019

face det

import cv2

faceCascade = cv2.CascadeClassifier('D:\\opencv\\OpenCV Final Softwares\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_default.xml')

# grab the reference to the webcam
vs = cv2.VideoCapture(0)

# keep looping
while True:
# grab the current frame
ret, frame = vs.read()
 
# if we are viewing a video and we did not grab a frame,
# then we have reached the end of the video
if frame is None:
break

faces = faceCascade.detectMultiScale(frame)

for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255,0,0), 2)

# show the frame to our screen
cv2.imshow("Video", frame)
key = cv2.waitKey(1) & 0xFF

# if the 'q' key is pressed, stop the loop
if key == ord("q"):
break

# close all windows
cv2.destroyAllWindows()

No comments:

Post a Comment