Пример #1
0
def test_webcam():
    camera = Camera.Subsystem(type="WEB",
                              name=None,
                              camera_path=None,
                              storage_path=None)
    camera.initialize()
    frame = camera.capture_image()

    while True:
        cv2.imshow("Frame", frame)
        key = cv2.waitKey(1) & 0xFF

        # if the `q` key was pressed, break from the loop
        if key == ord("q"):
            break

    cv2.destroyAllWindows()
    camera.shutdown()
Пример #2
0
                ["Core", "PreProcessing", "face_detector", "deploy.prototxt"])

            weightsPath = os.path.sep.join([
                "Core", "PreProcessing", "face_detector",
                "res10_300x300_ssd_iter_140000.caffemodel"
            ])

            faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)

            predictor_path = "Core/FacialFeatureDetection/shape_predictor_68_face_landmarks.dat"
            mouth_xml = "Core/FacialFeatureDetection/cascade-files/haarcascade_mcs_mouth.xml"
            nose_xml = "Core/FacialFeatureDetection/cascade-files/haarcascade_mcs_nose.xml"

            camera = Camera.Subsystem(
                type=options.
                camera,  # "IP" for ip camera, "WEB" for web camera
                name=None,
                camera_path=None,
                storage_path=None)
            preprocessor = PreProcessor.Subsystem(frame=None)
            face_detection = FaceDetection.Subsystem(frame=None,
                                                     height=None,
                                                     width=None,
                                                     blob=None,
                                                     faceNet=None)
            mask_detection = MaskDetection.SubSystem()
            facial_feat_detection = FacialFeatureDetection.Subsystem(
                detector=None,
                predictor=None,
                mouthCascade=None,
                noseCascade=None)
            mask_eval = MaskEvaluate.Subsystem(noseflag=None,
Пример #3
0
def main():
    prototxtPath = os.path.sep.join(
        ["..", "PreProcessing", "face_detector", "deploy.prototxt"])

    weightsPath = os.path.sep.join([
        "..", "PreProcessing", "face_detector",
        "res10_300x300_ssd_iter_140000.caffemodel"
    ])

    faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)

    camera = Camera.Subsystem(type=None,
                              name=None,
                              camera_path=None,
                              storage_path=None)

    preprocessor = PreProcessor.Subsystem(frame=None)

    face_detection = FaceDetection.Subsystem(frame=None,
                                             height=None,
                                             width=None,
                                             blob=None,
                                             faceNet=None)

    postprocessor = PostProcessing.SubSystem()

    camera.initialize()
    preprocessor.initialize()
    face_detection.initialize(faceNet)
    postprocessor.initialize()

    while True:
        frame = camera.capture_image()

        # Face Detection Module
        face_detection.setFrame(frame)
        faces, locations = face_detection.runFaceDetect()

        # Pre Process Module
        prepared = []
        if len(faces) > 0:
            for face in faces:
                preprocessor.setFrame(face)
                modified = preprocessor.prepareFace()
                cv2.imshow("modified", modified)
                prepared.append(modified)

        # Drawing box around face location
        for box in locations:
            # will make a box around face not mask area because these are Kenneth's coordinates
            (startX, startY, endX, endY) = box

            # Post-Processing Module
            #       1) will always yield green box because mask > noMask; probability = 100% mask
            #       2) switch tuple to (0, 1) if testing mask < noMask (red box); probability = 100% no mask
            #       3) to test probability reading, play with different numbers in tuple
            #          ie. (0.38, 0.62) -> probability = 62% no mask
            postprocessing = PostProcessing.SubSystem()
            output_frame = postprocessing.prepareOutputFrame(
                frame, (0, 1), startX, startY, endX, endY)

        cv2.imshow("Frame", frame)
        key = cv2.waitKey(1) & 0xFF

        # if the `q` key was pressed, break from the loop
        if key == ord("q"):
            break

    cv2.destroyAllWindows()
    camera.shutdown()
Пример #4
0
def main():
    prototxtPath = os.path.sep.join(["..",
                                     "PreProcessing",
                                     "face_detector",
                                     "deploy.prototxt"])

    weightsPath = os.path.sep.join(["..",
                                    "PreProcessing",
                                    "face_detector",
                                    "res10_300x300_ssd_iter_140000.caffemodel"])

    faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)

    camera = Camera.Subsystem(
        type=None,
        name=None,
        camera_path=None,
        storage_path=None
    )

    preprocessor = PreProcessor.Subsystem(
        frame=None
    )

    face_detection = FaceDetection.Subsystem(
        frame=None,
        height=None,
        width=None,
        blob=None,
        faceNet=None
    )

    camera.initialize()
    preprocessor.initialize()
    face_detection.initialize(faceNet)

    while True:
        frame = camera.capture_image()

        # Face Detection Module
        face_detection.setFrame(frame)
        faces, locations = face_detection.runFaceDetect()

        # Pre Process Module
        prepared = []
        if len(faces) > 0:
            for face in faces:
                preprocessor.setFrame(face)
                modified = preprocessor.prepareFace()
                cv2.imshow("modified", modified)
                prepared.append(modified)



        # Drawing box around face location
        for box in locations:
            (startX, startY, endX, endY) = box

            color = (0, 255, 0)  # GREEN outline
            cv2.rectangle(frame, (startX, startY), (endX, endY), color, 2)

        cv2.imshow("Frame", frame)
        key = cv2.waitKey(1) & 0xFF

        # if the `q` key was pressed, break from the loop
        if key == ord("q"):
            break

    cv2.destroyAllWindows()
    camera.shutdown()
Пример #5
0
def main():
    prototxtPath = os.path.sep.join(
        ["..", "PreProcessing", "face_detector", "deploy.prototxt"])

    weightsPath = os.path.sep.join([
        "..", "PreProcessing", "face_detector",
        "res10_300x300_ssd_iter_140000.caffemodel"
    ])

    faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)

    predictor_path = "shape_predictor_68_face_landmarks.dat"
    mouth_xml = "cascade-files/haarcascade_mcs_mouth.xml"
    nose_xml = "cascade-files/haarcascade_mcs_nose.xml"

    camera = Camera.Subsystem(type="WEB",
                              name=None,
                              camera_path=None,
                              storage_path=None)

    preprocessor = PreProcessor.Subsystem(frame=None)

    face_detection = FaceDetection.Subsystem(frame=None,
                                             height=None,
                                             width=None,
                                             blob=None,
                                             faceNet=None)

    facial_feat_detection = FacialFeatureDetection.Subsystem(detector=None,
                                                             predictor=None,
                                                             mouthCascade=None,
                                                             noseCascade=None)

    camera.initialize()
    preprocessor.initialize()
    face_detection.initialize(faceNet)
    facial_feat_detection.initialize(predictor_path, mouth_xml, nose_xml)

    while True:
        frame = camera.capture_image()

        # Face Detection Module
        # face_detection.setFrame(frame)
        # faces, locations = face_detection.runFaceDetect()

        # Pre Process Module
        # prepared = []
        # if len(faces) > 0:
        #     for face in faces:
        #         preprocessor.setFrame(face)
        #         modified = preprocessor.prepareFace()
        #         cv2.imshow("modified", modified)
        #         prepared.append(modified)

        # Facial Feature Module
        gray = preprocessor.cvtToGRAY(frame)
        shape = facial_feat_detection.detect_facial_landmarks(gray)
        mouth_rects = facial_feat_detection.cascade_detect(gray, "mouth")
        nose_rects = facial_feat_detection.cascade_detect(gray, "nose")

        # Draw facial feature dots
        if len(shape) > 0:
            for (x, y) in shape:
                cv2.circle(frame, (x, y), 1, (0, 0, 255), -1)

        # Draw nose and mouth using haar cascade
        if len(nose_rects) > 0:
            for (startX, startY, endX, endY) in nose_rects:
                cv2.rectangle(frame, (startX, startY), (endX, endY),
                              (0, 255, 0), 1)

        if len(mouth_rects) > 0:
            for (startX, startY, endX, endY) in mouth_rects:
                cv2.rectangle(frame, (startX, startY), (endX, endY),
                              (0, 255, 0), 1)

        # Drawing box around face location
        # for box in locations:
        #     (startX, startY, endX, endY) = box
        #
        #     color = (0, 255, 0)  # GREEN outline
        #     cv2.rectangle(frame, (startX, startY), (endX, endY), color, 2)

        cv2.imshow("Frame", frame)
        key = cv2.waitKey(1) & 0xFF

        # if the `q` key was pressed, break from the loop
        if key == ord("q"):
            break

    cv2.destroyAllWindows()
    camera.shutdown()