Created
July 3, 2020 11:24
-
-
Save pranshuj73/1696a520aec80d1d1c08f93572995738 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') | |
while vid.isOpened(): | |
_, frame = vid.read() | |
# takes in a gray coloured filter of the frame | |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
# initializing the haarcascade face detector | |
faces = face_cascade.detectMultiScale(frame) | |
for (x,y,w,h) in faces: | |
cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 2) | |
# takes the region of interest of the face only in gray | |
roi_gray = gray[y:y+h, x:x+h] | |
resized = cv2.resize(roi_gray, (48, 48)) # resizes to 48x48 sized image | |
# predict the mood | |
img = img2tensor(resized) | |
prediction = predict(img) | |
cv2.putText(frame, f"{prediction['label']}", (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,0)) | |
cv2.imshow('video', frame) | |
if cv2.waitKey(1) == 27: | |
break | |
vid.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment