robokudo.utils.cv_helper

Attributes

Functions

crop_image(image, xy, wh)

crop_image_roi(image, roi)

convert_ros_to_cv_image(ros_image)

Convert a ros image to a CV image.

convert_cv_to_ros_image(cv_image)

Convert a CV image to a ROS image.

get_scaled_color_image_for_depth_image(...)

If the color2depth ratio is not 1,1, we will usually scale the color image to the same size

get_scale_coordinates(→ tuple)

get_hsv_for_rgb_color(→ numpy.typing.NDArray)

get_hsv_for_bgr_color(→ numpy.typing.NDArray)

draw_rectangle_around_center(→ numpy.typing.NDArray)

param binary_image:

a uint8 dtyped image

clamp_bounding_rect(→ cv2.boundingRect)

sanity_checks_bounding_rects(bounding_rect, ...)

Check basic rules of a boundingRect to reject bad ones. Might happen if projections are done on objects

adjust_roi(image, roi, offset)

Adjusts the ROI by a given offset while respecting image boundaries,

adjust_image_roi(image, image_roi, offset)

Adjusts the ImageROI's ROI by a given offset while respecting image boundaries,

adjust_mask(mask, offset[, fill_value])

Adjusts the mask by a given offset. When expanding, the new areas are filled

Module Contents

robokudo.utils.cv_helper.LOGGER = None
robokudo.utils.cv_helper.crop_image(image, xy: tuple, wh: tuple)
robokudo.utils.cv_helper.crop_image_roi(image, roi: robokudo.types.cv.ImageROI)
robokudo.utils.cv_helper.convert_ros_to_cv_image(ros_image)

Convert a ros image to a CV image.

robokudo.utils.cv_helper.convert_cv_to_ros_image(cv_image)

Convert a CV image to a ROS image.

robokudo.utils.cv_helper.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.

Parameters:
  • cas – The robokudo.cas.CAS where the COLOR2DEPTH_RATIO is stored.

  • color_image – The color image to be adjusted

Returns:

A resized copy of the color image if a resize necessary. Otherwise, the unchanged color_image

is returned.

robokudo.utils.cv_helper.get_scale_coordinates(color2depth_ratio: tuple, coordinates: tuple) tuple
robokudo.utils.cv_helper.get_hsv_for_rgb_color(rgb: tuple) numpy.typing.NDArray
robokudo.utils.cv_helper.get_hsv_for_bgr_color(bgr: tuple) numpy.typing.NDArray
robokudo.utils.cv_helper.draw_rectangle_around_center(binary_image: numpy.typing.NDArray, x: int, y: int, width: int, height: int, value=255) numpy.typing.NDArray
Parameters:
  • binary_image – a uint8 dtyped image

  • x – target coordinate x for center point

  • y – target coordinate y for center point

  • width – width of the rectangle

  • height – height of the rectangle

  • value – Numerical value that shall be written to the rectangular area. Default=255

robokudo.utils.cv_helper.clamp_bounding_rect(bounding_rect: cv2.boundingRect, image_width: int, image_height: int) cv2.boundingRect
robokudo.utils.cv_helper.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.

Parameters:
  • bounding_rect

  • image_width

  • image_height

Returns:

True if rules have been passed, False otherwise

robokudo.utils.cv_helper.adjust_roi(image, roi, offset)

Adjusts the ROI by a given offset while respecting image boundaries, keeping the same center point.

Parameters:
  • image – The image (OpenCV format).

  • roi – A tuple (x, y, width, height) representing the bounding box.

  • offset – The amount by which to grow or shrink the ROI (can be negative).

Returns:

A tuple (new_x, new_y, new_width, new_height) representing the adjusted ROI.

robokudo.utils.cv_helper.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.

Parameters:
  • image – The image this ROI is relative to. Necessary to respect the boundaries properly.

  • image_roi – An object of type ImageROI.

  • offset – The amount by which to grow or shrink the ROI (can be negative).

Returns:

None. The ImageROI’s ROI is adjusted in place.

robokudo.utils.cv_helper.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.

Parameters:
  • mask – The mask corresponding to the ROI (same dimensions as the ROI).

  • offset – The amount by which to grow or shrink the mask (can be negative).

  • fill_value – The value to fill new areas when expanding the mask.

Returns:

The adjusted mask.