Example #1
0
def process_frame_for_line(frame, image_format="PIL", process_image_width=320):
    cv2 = import_opencv()
    cv_frame = ImageFunctions.convert(frame, format="OpenCV")

    from imutils import resize

    resized_frame = resize(cv_frame, width=process_image_width)
    hsv_lower, hsv_upper = calculate_blue_limits()
    image_mask = color_mask(resized_frame, hsv_lower, hsv_upper)
    line_contour = find_largest_contour(image_mask)

    centroid = None
    scaled_image_centroid = None
    rectangle_dimensions = None
    angle = None
    if line_contour is not None:
        # find centroid of contour
        scaled_image_centroid = find_centroid(line_contour)
        centroid = center_reposition(scaled_image_centroid, resized_frame)
        bounding_rectangle = cv2.boundingRect(line_contour)
        rectangle_dimensions = bounding_rectangle[2:5]
        angle = get_object_target_lock_control_angle(centroid, resized_frame)

    robot_view_img = robot_view(resized_frame, image_mask, line_contour,
                                scaled_image_centroid)

    if image_format.lower() != "opencv":
        robot_view_img = ImageFunctions.convert(robot_view_img, format="PIL")

    return DotDict({
        "line_center": centroid,
        "robot_view": robot_view_img,
        "rectangle_dimensions": rectangle_dimensions,
        "angle": angle,
    })
 def __import_libs(self):
     global cv2, dlib, imutils, face_utils
     if cv2 is None:
         cv2 = import_opencv()
     if dlib is None:
         dlib = import_dlib()
     if face_utils is None:
         face_utils = import_face_utils()
     if imutils is None:
         imutils = import_imutils()
    def __init__(self, callback_on_motion, moving_object_minimum_area):
        self.cv2 = import_opencv()

        self.__motion_detect_previous_frame = None
        self.__motion_detect_threshold = moving_object_minimum_area**2
        self.__motion_detect_callback = callback_on_motion
        self.__event_executor = ThreadPoolExecutor()

        callback_signature = signature(callback_on_motion)
        self.callback_has_argument = len(callback_signature.parameters) > 0
Example #4
0
def robot_view(frame, image_mask, line_contour, centroid):
    cv2 = import_opencv()
    masked_image = cv2.bitwise_and(frame, frame, mask=image_mask)

    # draw contour lines on robot view
    if line_contour is not None:
        cv2.drawContours(masked_image, [line_contour], 0, (100, 60, 240), 2)
        draw_contour_bound(masked_image, line_contour)

    if centroid:
        cv2.drawMarker(
            masked_image,
            (centroid[0], centroid[1]),
            (100, 60, 240),
            markerType=cv2.MARKER_CROSS,
            markerSize=20,
            thickness=4,
            line_type=cv2.FILLED,
        )
    return masked_image
def import_libs():
    global cv2, face_utils
    if cv2 is None:
        cv2 = import_opencv()
    if face_utils is None:
        face_utils = import_face_utils()
Example #6
0
def draw_contour_bound(image, contour):
    cv2 = import_opencv()
    x, y, w, h = cv2.boundingRect(contour)
    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
Example #7
0
def import_libs():
    global cv2, imutils
    if cv2 is None:
        cv2 = import_opencv()
    if imutils is None:
        imutils = import_imutils()