예제 #1
0
 def get_detected_faces(self, bounding_boxes, points):
     detected_faces = []
     # the number of boxes indicates the number of faces detected
     for i in range(len(bounding_boxes)):
         bbox = bounding_boxes[i][:4]
         score = bounding_boxes[i][4:]
         detected_face = Face()
         detected_face.face_rectangle = bbox.tolist()
         landmarks = []
         for p in range(len(points)):
             landmarks.append(float(points[p][i]))
         detected_face.face_landmarks = landmarks
         detected_face.confidence = score[0]
         detected_faces.append(detected_face)
     return detected_faces
예제 #2
0
def get_frames(user_id):
    """Video streaming generator function."""
    video = cv2.VideoCapture(0)
    while True:
        rval, frame = video.read()
        if not rval:
            load_faces()
            break
        else:
            new_frame = frame[:, :, ::-1]
            locations, face_encodings = get_face(new_frame)
            print(locations)
            f = pickle.dumps(face_encodings)
            if face_encodings is not None:
                face = Face(user_id, f)
                db.session.add(face)
                db.session.commit()
                top, right, bottom, left = locations
                cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255),
                              2)
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' +
               cv2.imencode('.jpg', frame)[1].tostring() + b'\r\n')