concepts.gui.opencv.point_picker.CV2PointPicker#
- class CV2PointPicker[source]#
Bases:
object
A simple point picker using OpenCV.
Example
import cv2 import numpy as np from concepts.gui.opencv.point_picker import CV2PointPicker color_image = np.zeros((480, 640, 3), dtype=np.uint8) depth_image = np.zeros((480, 640), dtype=np.uint16) picker = CV2PointPicker() points = picker.run(color_image, depth_image)
The order of the points corresponds to the order in which they were clicked. To remove a point, click on it again. The current checking radius is 10 pixels.
Methods
imshow
(color_image, depth_image[, window_name])Helper function to visualize the registered points on the color and depth images.
register_point
(event, x, y, flag, param)Register a point based on the click by the user.
run
(color_image[, depth_image, ...])Run the point picker.
- __new__(**kwargs)#
- imshow(color_image, depth_image, window_name=None)[source]#
Helper function to visualize the registered points on the color and depth images.
- register_point(event, x, y, flag, param)[source]#
Register a point based on the click by the user. See OpenCV documentation for
cv2.setMouseCallback()
for more details.- Parameters:
event – the event type.
x – the x-coordinate of the click.
y – the y-coordinate of the click.
flag – the flag.
param – the parameter.
- run(color_image, depth_image=None, file_dirname='visualization', file_prefix='', save=False, window_name=None)[source]#
Run the point picker.
To pick a point, click on the image.
To remove a point, click on it again.
Press ‘c’ to print the registered points, and save it to a file if save is True.
Press ‘esc’ or ‘q’ to exit. The function will return the registered points.
If save is True, the visualization and the points will be saved to the specified directory: {file_dirname}/{file_prefix}_visualization.png and {file_dirname}/{file_prefix}_points.pkl.
- Parameters:
color_image (ndarray) – the color image.
depth_image (ndarray | None) – the depth image. Defaults to None. If specified, it will be shown side by side with the color image.
file_dirname (str) – the directory to save the visualization and the points. Defaults to ‘visualization’.
file_prefix (str) – the prefix for the file names. Defaults to ‘’.
save (bool) – whether to save the visualization and the points. Defaults to False.
window_name (str | None) – the name of the window. Defaults to None, in which case the name of the class is used.
- Returns:
list of registered points.
- Return type: