コード例 #1
0
def main():
    # Capture RTMP video stream
    port = 'Input the port number here'
    host = 'Input the SDK endpoint'
    password = '******'
    cert_path = 'Input the certificate path'

    chrys = chrysalis.Connect(host=host,
                              port=port,
                              password=password,
                              ssl_ca_cert=cert_path)

    while True:
        # Read the frame
        chrysframe = chrys.VideoLatestImage()
        if chrysframe is not None:
            frame = chrysframe.data
            cv2.imshow('Video From server', frame)
            # if the 'ESC' key is pressed, stop the loop
            if cv2.waitKey(1) & 0xFF == 27:
                break

    cv2.destroyAllWindows()
コード例 #2
0
def validate_param(param_name):
    """
    Validating OS environment variables

    """
    if param_name not in os.environ:
        raise ValueError("missing environment variable " + param_name)
    return os.environ[param_name]


if __name__ == "__main__":
    port = validate_param('chrys_port')
    host = validate_param('chrys_host')
    password = validate_param('chrys_password')
    cert_path = validate_param('chrys_cert')

    chrys = chrysalis.Connect(host=host,
                              port=port,
                              password=password,
                              ssl_ca_cert=cert_path)

    while True:
        img = chrys.VideoLatestImage()
        if img is not None:
            frame = img.data
            frame = add_face_markers(frame)

            cv2.imshow("facemarkers", frame)
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
コード例 #3
0
def main():
    # Capture RTMP video stream
    port = validate_param('chrys_port')
    host = validate_param('chrys_host')
    password = validate_param('chrys_password')
    cert_path = validate_param('chrys_cert')

    chrys = chrysalis.Connect(host=host,
                              port=port,
                              password=password,
                              ssl_ca_cert=cert_path)

    # Load the front face detector cascade
    face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
    while True:
        # Read the frame
        chrysframe = chrys.VideoLatestImage()

        if chrysframe is not None:
            frame = chrysframe.data

            # copy to store face region and cropped forehead region
            frameFullFace = frame.copy()
            frameForehead = frame.copy()
            frame_copy = frame.copy()

            # Convert to grayscale
            gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            # Detect the faces
            faces = face_cascade.detectMultiScale(gray, 1.1, 4)

            # use for display
            displayFrame = frame.copy()
            x = 0
            y = 0
            w = 0
            h = 0
            # Draw the rectangle around the face
            for (x, y, w, h) in faces:
                frameFullFace = frame[y:y + h, x:x + w]
                cv2.rectangle(displayFrame, (x, y), (x + w, y + h),
                              (255, 0, 0), 2)
                # Draw a rectangle around the foread region
                newx = int(x + w / 4)
                newy = int(y + h / 4)
                newx_w = newx + int(w / 2)
                newy_h = newy + int(h / 2)
                frameForehead = frame[newy:newy_h, newx:newx_w]
                cv2.rectangle(displayFrame, (newx, newy), (newx_w, newy_h),
                              (0, 255, 0), 2)

            # Display the input with Face detection
            cv2.imshow('Face detection', displayFrame)

            # find sking regions in the frame
            skin_mask = find_skin(frame, frameForehead)

            # Black out the region so as to minimize the search region for the hand
            skin_mask[y:y + h, x:x + w] = 0

            # segment out the hand region
            hand = segment(skin_mask)

            # First check if we were able to actually detect a hand
            if hand is not None:

                # unpack
                thresholded, hand_segment = hand
                # Draw contours around hand segment
                cv2.drawContours(frame_copy, [hand_segment], -1, (255, 0, 0),
                                 1)
                # Count the fingers
                fingers = count_fingers(thresholded, hand_segment)
                # Display count
                if fingers <= 10:
                    cv2.putText(frame_copy, str(fingers), (70, 45),
                                cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)

                # display the thresholded image, if required for reference
                # cv2.imshow("Thesholded", thresholded)

            # Display the frame with segmented hand
            cv2.imshow("Finger Count", frame_copy)

            # if the 'ESC' key is pressed, stop the loop
            if cv2.waitKey(1) & 0xFF == 27:
                break

    # close any open windows
    cv2.destroyAllWindows()