robokudo.utils.cv_helper ======================== .. py:module:: robokudo.utils.cv_helper Attributes ---------- .. autoapisummary:: robokudo.utils.cv_helper.LOGGER Functions --------- .. autoapisummary:: robokudo.utils.cv_helper.crop_image robokudo.utils.cv_helper.crop_image_roi robokudo.utils.cv_helper.convert_ros_to_cv_image robokudo.utils.cv_helper.convert_cv_to_ros_image robokudo.utils.cv_helper.get_scaled_color_image_for_depth_image robokudo.utils.cv_helper.get_scale_coordinates robokudo.utils.cv_helper.get_hsv_for_rgb_color robokudo.utils.cv_helper.get_hsv_for_bgr_color robokudo.utils.cv_helper.draw_rectangle_around_center robokudo.utils.cv_helper.clamp_bounding_rect robokudo.utils.cv_helper.sanity_checks_bounding_rects robokudo.utils.cv_helper.adjust_roi robokudo.utils.cv_helper.adjust_image_roi robokudo.utils.cv_helper.adjust_mask Module Contents --------------- .. py:data:: LOGGER :value: None .. py:function:: crop_image(image, xy: tuple, wh: tuple) .. py:function:: crop_image_roi(image, roi: robokudo.types.cv.ImageROI) .. py:function:: convert_ros_to_cv_image(ros_image) Convert a ros image to a CV image. .. py:function:: convert_cv_to_ros_image(cv_image) Convert a CV image to a ROS image. .. py:function:: get_scaled_color_image_for_depth_image(cas: robokudo.cas.CAS, color_image: numpy.typing.NDArray) -> numpy.typing.NDArray If the color2depth ratio is not 1,1, we will usually scale the color image to the same size the depth image has. This method will get check if a conversion is required and will return the correct size. This is usually called before o3d.geometry.RGBDImage.create_from_color_and_depth is called, so that depth and color image match. :param cas: The robokudo.cas.CAS where the COLOR2DEPTH_RATIO is stored. :param color_image: The color image to be adjusted :return: A resized copy of the color image if a resize necessary. Otherwise, the unchanged color_image is returned. .. py:function:: get_scale_coordinates(color2depth_ratio: tuple, coordinates: tuple) -> tuple .. py:function:: get_hsv_for_rgb_color(rgb: tuple) -> numpy.typing.NDArray .. py:function:: get_hsv_for_bgr_color(bgr: tuple) -> numpy.typing.NDArray .. py:function:: draw_rectangle_around_center(binary_image: numpy.typing.NDArray, x: int, y: int, width: int, height: int, value=255) -> numpy.typing.NDArray :param binary_image: a uint8 dtyped image :param x: target coordinate x for center point :param y: target coordinate y for center point :param width: width of the rectangle :param height: height of the rectangle :param value: Numerical value that shall be written to the rectangular area. Default=255 .. py:function:: clamp_bounding_rect(bounding_rect: cv2.boundingRect, image_width: int, image_height: int) -> cv2.boundingRect .. py:function:: sanity_checks_bounding_rects(bounding_rect: cv2.boundingRect, image_width: int, image_height: int) Check basic rules of a boundingRect to reject bad ones. Might happen if projections are done on objects that are out-of-view etc. :param bounding_rect: :param image_width: :param image_height: :return: True if rules have been passed, False otherwise .. py:function:: adjust_roi(image, roi, offset) Adjusts the ROI by a given offset while respecting image boundaries, keeping the same center point. :param image: The image (OpenCV format). :param roi: A tuple (x, y, width, height) representing the bounding box. :param offset: The amount by which to grow or shrink the ROI (can be negative). :return: A tuple (new_x, new_y, new_width, new_height) representing the adjusted ROI. .. py:function:: adjust_image_roi(image, image_roi, offset) Adjusts the ImageROI's ROI by a given offset while respecting image boundaries, keeping the same center point. This method uses the adjust_roi function. :param image: The image this ROI is relative to. Necessary to respect the boundaries properly. :param image_roi: An object of type ImageROI. :param offset: The amount by which to grow or shrink the ROI (can be negative). :return: None. The ImageROI's ROI is adjusted in place. .. py:function:: adjust_mask(mask, offset, fill_value=0) Adjusts the mask by a given offset. When expanding, the new areas are filled with the specified fill value. :param mask: The mask corresponding to the ROI (same dimensions as the ROI). :param offset: The amount by which to grow or shrink the mask (can be negative). :param fill_value: The value to fill new areas when expanding the mask. :return: The adjusted mask.