Go to the documentation of this file.00001 import cv2
00002
00003 from scripts import face_detector
00004
00005
00006 def run():
00007 capture = cv2.VideoCapture(0)
00008 finder = face_detector.FaceDetector()
00009 while True:
00010 ret, frame = capture.read()
00011
00012 input_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
00013
00014 faces, keypoints = finder.find_faces(input_image)
00015
00016 for (face, points) in zip(faces, keypoints):
00017 x1 = int(face[0])
00018 y1 = int(face[1])
00019 x2 = int(face[2])
00020 y2 = int(face[3])
00021 c = (0, 255, 0)
00022
00023 cv2.rectangle(frame, (x1, y1), (x2, y2), c, 3)
00024 nose_x = int(points[2])
00025 nose_y = int(points[7])
00026 left_eye_x = int(points[1])
00027 left_eye_y = int(points[6])
00028 right_eye_x = int(points[0])
00029 right_eye_y = int(points[5])
00030 left_mouth_x = int(points[4])
00031 left_mouth_y = int(points[9])
00032 right_mouth_x = int(points[3])
00033 right_mouth_y = int(points[8])
00034
00035 cv2.circle(frame, (nose_x, nose_y), 3, c, thickness=1)
00036 cv2.circle(frame, (left_eye_x, left_eye_y), 3, c, thickness=1)
00037 cv2.circle(frame, (right_eye_x, right_eye_y), 3, c, thickness=1)
00038 cv2.circle(frame, (left_mouth_x, left_mouth_y), 3, c, thickness=1)
00039 cv2.circle(frame, (right_mouth_x, right_mouth_y), 3, c, thickness=1)
00040
00041 cv2.imshow('frame', frame)
00042
00043 if cv2.waitKey(1) & 0xFF == ord('q'):
00044 break
00045 capture.release()
00046 cv2.destroyAllWindows()
00047
00048 run()
00049