Functions documentation
This file presents the different functions and Enums Image Processing available for image processing.
These functions are divided in subsections:
Pure image processing are used to deal with the thresholding, contours detection, ..
Workspaces wise section contains functions to extract workspace and deal with the relative position in the workspace
The section Show allows to display images
Image Editing contains lot of function which can compress images, add text to image, …
Pure image processing
- image_functions.threshold_hsv(list_min_hsv, list_max_hsv, reverse_hue=False, use_s_prime=False)
Take BGR image (OpenCV imread result) and return thresholded image according to values on HSV (Hue, Saturation, Value) Pixel will worth 1 if a pixel has a value between min_v and max_v for all channels
- Parameters
img (numpy.array) – image BGR if rgb_space = False
list_min_hsv (list[int]) – list corresponding to [min_value_H,min_value_S,min_value_V]
list_max_hsv (list[int]) – list corresponding to [max_value_H,max_value_S,max_value_V]
use_s_prime (bool) – True if you want to use S channel as S’ = S x V else classic
reverse_hue (bool) – Useful for Red color cause it is at both extremum
- Returns
threshold image
- Return type
numpy.array
- image_functions.debug_threshold_color(color_hsv)
Return masked image to see the effect of color threshold
- Parameters
img (numpy.array) – OpenCV image
color_hsv (ColorHSV) – Color used for debug
- Returns
Masked image
- Return type
numpy.array
- image_functions.morphological_transformations(morpho_type=<MorphoType.CLOSE: 3>, kernel_shape=(5, 5), kernel_type=<KernelType.ELLIPSE: 2>)
Take black & white image and apply morphological transformation
- Parameters
im_thresh (numpy.array) – Black & White Image
morpho_type (MorphoType) – CLOSE/OPEN/ERODE/DILATE => See on OpenCV/Google if you do not know these words
kernel_shape (tuple[float]) – tuple corresponding to the size of the kernel
kernel_type (KernelType) – RECT/ELLIPSE/CROSS => see on OpenCV
- Returns
image after processing
- Return type
numpy.array
- image_functions.get_contour_barycenter()
Return barycenter of an OpenCV Contour
- image_functions.get_contour_angle()
Return orientation of a contour according to the smallest side in order to be well oriented for gripper
- Parameters
contour (OpenCV Contour) – contour
- Returns
Angle in radians
- Return type
- image_functions.biggest_contour_finder()
- image_functions.biggest_contours_finder(nb_contours_max=3)
Function to find the biggest contour in an binary image
- image_functions.draw_contours(contours)
Draw a list of contour on an image and return the drawing image
- Parameters
img (numpy.array) – Image
contours (list[OpenCV Contour]) – contours list
- Returns
Image with drawing
- Return type
numpy.array
- image_functions.draw_barycenter(cx, cy, color=(255, 0, 255), marker_size=10, thickness=2)
Draw a barycenter marker on an image and return the drawing image
- image_functions.draw_angle(cx, cy, angle, color=(0, 0, 255), arrow_length=30, thickness=2)
Draw an arrow that represents the orientation of an object on an image and return the drawing image
- Parameters
- Returns
Image with drawing
- Return type
numpy.array
Workspaces wise
- image_functions.extract_img_workspace(workspace_ratio=1.0)
Extract working area from an image thanks to 4 Niryo’s markers
- Parameters
img (numpy.array) – OpenCV image which contain 4 Niryo’s markers
workspace_ratio (float) – Ratio between the width and the height of the area represented by the markers
- Returns
extracted and warped working area image
- Return type
numpy.array
- image_functions.debug_markers(workspace_ratio=1.0)
Display detected markers on an image
- Parameters
img (numpy.array) – OpenCV image which contain Niryo’s markers
workspace_ratio (float) – Ratio between the width and the height of the area represented by the markers
- Returns
(status, annotated image)
- Return type
numpy.array
Show
- image_functions.show_img_and_check_close(img)
Display an image and check whether the user want to close
- image_functions.show_img(img, wait_ms=1)
Display an image during a certain time
Image Editing
- image_functions.compress_image(quality=90)
Compress OpenCV image
- image_functions.uncompress_image()
Take a compressed img and return an OpenCV image
- Parameters
compressed_image (str) – compressed image
- Returns
OpenCV image
- Return type
numpy.array
- image_functions.add_annotation_to_image(text, write_on_top=True)
Add Annotation to an image
- image_functions.undistort_image(mtx, dist)
Use camera intrinsics to undistort raw image
- image_functions.resize_img(width=None, height=None, inter=3)
Resize an image. The user should precise only width or height if he wants to keep image’s ratio
Enums Image Processing
Enums are used to pass specific parameters to functions.
List of enums:
- class ColorHSV(value)[source]
MIN HSV, MAX HSV, Invert Hue (bool)
- BLUE = ([90, 50, 85], [125, 255, 255], False)
- RED = ([15, 80, 75], [170, 255, 255], True)
- GREEN = ([40, 60, 75], [85, 255, 255], False)
- ANY = ([0, 50, 100], [179, 255, 255], False)