Vision APIο
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, kernel_shape=(5, 5), kernel_type=KernelType.ELLIPSE)ο
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
- Parameters:
contour (OpenCV Contour)
- Returns:
Barycenter X, Barycenter Y
- Return type:
int, int
- 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:
float
- image_functions.biggest_contour_finder()ο
- image_functions.biggest_contours_finder(nb_contours_max=3)ο
Function to find the biggest contour in an binary image
- Parameters:
img (numpy.array) β Binary Image
nb_contours_max (int) β maximal number of contours which will be returned
- Returns:
biggest contours found
- Return type:
list[OpenCV Contour]
- 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
- Parameters:
img (numpy.array) β Image
cx (int) β Barycenter X
cy (int) β Barycenter Y
color (list[uint8, utin8, uint8]) β (R, G, B) colors of the marker
marker_size (int) β size of the marker
thickness (int) β thickness of the marker
- Returns:
Image with drawing
- Return type:
numpy.array
- 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:
img (numpy.array) β Image
cx (int) β Barycenter X
cy (int) β Barycenter Y
angle β angle to display
color (list[uint8, utin8, uint8]) β (R, G, B) colors of the marker
arrow_length (int) β length of the arrow marker
thickness (int) β thickness of the arrow marker
- 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
- image_functions.relative_pos_from_pixels(x_pixels, y_pixels)ο
Transform a pixels position to a relative position
- Parameters:
img (numpy.array) β Image where the object is detected
x_pixels (int) β coordinate X
y_pixels (int) β coordinate Y
- Returns:
X relative, Y relative
- Return type:
float, float
Showο
- image_functions.show_img_and_check_close(img)ο
Display an image and check whether the user want to close
- Parameters:
window_name (str) β windowβs name
img (numpy.array) β Image
- Returns:
boolean indicating if the user wanted to leave
- Return type:
bool
- image_functions.show_img(img, wait_ms=1)ο
Display an image during a certain time
- Parameters:
window_name (str) β windowβs name
img (numpy.array) β Image
wait_ms (int) β Wait time in milliseconds
- Returns:
value of the key pressed during the display
- Return type:
int
- image_functions.show_img_and_wait_close(img)ο
Display an image and wait that the user close it
- Parameters:
window_name (str) β windowβs name
img (numpy.array) β Image
- Returns:
None
- Return type:
None
Image Editingο
- image_functions.compress_image(quality=90)ο
Compress OpenCV image
- Parameters:
img (numpy.array) β OpenCV Image
quality (int) β integer between 1 - 100. The higher it is, the less information will be lost, but the heavier the compressed image will be
- Returns:
status & string representing compressed image
- Return type:
bool, str
- 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
- Parameters:
img (numpy.array) β Image
text (str) β text string
write_on_top (bool) β if you write the text on top
- Returns:
img with text written on it
- Return type:
numpy.array
- image_functions.undistort_image(mtx, dist)ο
Use camera intrinsics to undistort raw image
- Parameters:
img (numpy.array) β Raw Image
mtx (list[list[float]]) β Camera Intrinsics matrix
dist (list[list[float]]) β Distortion Coefficient
- Returns:
Undistorted image
- Return type:
numpy.array
- 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
- Parameters:
img (numpy.array) β OpenCV Image
width (int) β Target Width
height (int) β Target Height
inter (long) β OpenCV interpolation flag
- Returns:
resized image
- Return type:
numpy.array
- image_functions.concat_imgs(axis=1)ο
Concat multiple images along 1 axis
- Parameters:
tuple_imgs (tuple[numpy.array]) β tuple of images
axis (int) β 0 means vertically and 1 means horizontally
- Returns:
Concat image
- Return type:
numpy.array
Enums Image Processingο
Enums are used to pass specific parameters to functions.
List of enums:
- class pyniryo.vision.enums.ColorHSV(*values)ο
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)ο
- class pyniryo.vision.enums.ColorHSVPrime(*values)ο
MIN HSV, MAX HSV, Invert Hue (bool)
- BLUE = ([90, 70, 100], [115, 255, 255], False)ο
- RED = ([15, 70, 100], [170, 255, 255], True)ο
- GREEN = ([40, 70, 100], [85, 255, 255], False)ο
- ANY = ([0, 70, 140], [179, 255, 255], False)ο
- class pyniryo.vision.enums.ObjectType(*values)ο
- SQUARE = 4ο
- TRIANGLE = 3ο
- CIRCLE = -1ο
- ANY = 0ο