Functions Documentation
Important
Section not finished yet !
This file presents the different functions and Enums available for image processing
These functions are divided in subsections:
Pure Image Processing are used to deal to do 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
- biggest_contours_finder(img, nb_contours_max=3)[source]
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]
- debug_threshold_color(img, color_hsv)[source]
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
- draw_contours(img, contours)[source]
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
- get_contour_angle(contour)[source]
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
- get_contour_barycenter(contour)[source]
Return barycenter of an OpenCV Contour
- Parameters:
contour (OpenCV Contour)
- Returns:
Barycenter X, Barycenter Y
- Return type:
int, int
- morphological_transformations(im_thresh, morpho_type=MorphoType.CLOSE, kernel_shape=(5, 5), kernel_type=KernelType.ELLIPSE)[source]
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
- threshold_hsv(img, list_min_hsv, list_max_hsv, reverse_hue=False, use_s_prime=False)[source]
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
Workspaces wise
- debug_markers(img, workspace_ratio=1.0)[source]
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
- extract_img_workspace(img, workspace_ratio=1.0)[source]
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
Show
- show_img(window_name, img, wait_ms=1)[source]
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 Editing
- add_annotation_to_image(img, text, write_on_top=True)[source]
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
- compress_image(img, quality=90)[source]
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
- concat_imgs(tuple_imgs, axis=1)[source]
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
- resize_img(img, width=None, height=None, inter=3)[source]
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
Enums Image Processing
Enums are used to pass specific parameters to functions.
List of enums:
- class ColorHSV(*values)[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)