示例#1
0
    def run(self, args):
        if (args.use_svm):
            settings.USE_SVM = True
            print('use svm')
        else:
            settings.USE_SVM = False
            print('use distance')
        plc = PLCControl()
        face_recognition = Recognition()
        video_capture = VideoProcessor(
            self.camera.get_url(), output_queue=frame_queue)
        video_capture.start_processing()
        while True:
            # Capture frame-by-frame
            frame = video_capture.get_latest_frame()
            if frame is None:
                continue

            faces = face_recognition.identify(frame)
            legal = False
            for f in faces:
                recognition_result_processor.put_result(f.result)
                #recognition_result_processor.send_email(f.result)
                if (f.result.result == settings.LEGAL):
                    legal = True

            if len(faces) > 0:
                recognition_result_processor.push_result()

            if legal:
                plc.open_door()

            self.add_overlays(frame, faces)
            if args.debug:
                cv2.imshow('Video', frame)
                if cv2.waitKey(1) & 0xFF == ord('q'):
                    break

        # When everything is done, release the capture
        video_capture.stop_processing()
        video_capture.cleanup()
        cv2.destroyAllWindows()
def main(args):
    video_capture = VideoProcessor(
        'rtsp://{username}:{password}@{ip}/cam/realmonitor?channel=1&subtype=0'
        .format(username=settings.USERNAME,
                password=settings.PASSWORD,
                ip=settings.IP),
        output_queue=frame_queue)

    detection = Detection()
    num = 0
    count = 0
    path = 'faces'
    if not os.path.exists(path):
        os.mkdir(path)
    path = path + '/' + args.id
    if not os.path.exists(path):
        os.mkdir(path)
    print('capture faces for : ', str(args.id))
    video_capture.start_processing()
    while True:
        frame = video_capture.get_latest_frame()
        if frame is None:
            continue

        faces = detection.find_faces(frame)
        for face in faces:
            filename = path + '/' + str(num) + '.jpg'
            if num % 2 == 0:
                cv2.imwrite(filename, face.face_image_raw)
                count = count + 1

        add_overlays(frame, faces, count)
        num = num + 1
        cv2.imshow('face capture', frame)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    print('capture faces num: ', str(num))