-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
31 lines (24 loc) · 933 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import cv2
import numpy as np
from model import Facial_Pose_Net_model
faceCas = cv2.CascadeClassifier('detector_architectures\haarcascade_frontalface_default.xml')
model = Facial_Pose_Net_model('model_new_latest.json', 'model_weights_LATEST.h5')
cap = cv2.VideoCapture(0)
while True:
ret, fr = cap.read()
#gray_fr = cv2.cvtColor(fr, cv2.COLOR_BGR2GRAY)
faces = faceCas.detectMultiScale(fr, 1.3, 5)
for (x, y, w, h) in faces:
fc = fr[y:y+h, x:x+w]
roi = cv2.resize(fc, (96,96))
pred = model.predict_points(roi[np.newaxis, :, :])
pred= pred.astype('uint8').reshape(-1,2)
for i in range(15,60):
cv2.circle(roi,(pred[i,0], pred[i,1]), 2, (255,0,0), 1)
cv2.rectangle(fr,(x,y),(x+w,y+h),(255,0,0),1)
cv2.imshow('FKPD',roi)
cv2.imshow('org',fr)
if cv2.waitKey(50) & 0xFF==27:
break
cap.release()
cv2.destroyAllWindows()