Note: for the definitions of actions, services, and messages mentioned below, please refer to the
b-it-bots/mas_perception_msgs repository.
Port of bounding box creation for point clouds from C++. Provide the following API methods:
get_pose: returnsgeometry_msgs/PoseStampedof the bounding box.get_ros_message: returnsmas_perception_msgs/BoundingBox.msgversion of the bounding box.
Common interface in C++ and Python for rectangle regions in RGB images. Several visualization and utility methods are built around this class.
Common place for all the perception related constants.
Abstract class for image classification.
- An extension of this class needs to implement the following functions:
classify: receive a list ofsensor_msgs/Imageas argument, returns a list of corresponding classes.
- Any extension of this class can be used by the
RecognizeImageServiceclass for classifying images.
An example implementation of ImageClassifier which return random classes for each image message.
Used by mdr_perceive_plane_action for testing.
An implementation of ImageClassifier which uses the Keras framework to classify images.
Abstract class for detecting things in images.
- Any extension needs to implement methods:
load_model: load detection model using keyword arguments given to the constructor. These arguments are specified in themodel_kwargs_filepassed into the class constructor. An example of this file isimage_detector_test_kwargs.yml._detect: perform detection on a list ofsensor_msgs/Imageobjects using the detection model.
- Extension of this class can be used with
SingleImageDetectionHandler, which is used inPlaneDetectionActionServerand the test scriptimage_detection_testfor detecting in images.
Simple detection model which generates random bounding boxes and is meant to be an usage example for ImageDetectorBase
together with class_annotation_example.yml and
image_detector_test_kwargs.yml.
Used by SceneDetectionActionServer and in image_detection_test to detect
objects in a single image message at a time and publish detection results on a desired topic.
An instance of ImageDetectorBase that runs a PyTorch object detection model.
A wrapper for a mas_perception_msgs/RecognizeImage.srv service which uses ImageClassifier instances to
classify images.
Interact with an mas_perception_msgs/RecognizeImage.srv service to get image classification results. An example
can be found in the script image_recognition_server, which uses the
RecognizeImageService class above.
- Interact with a
mas_perception_msgs/DetectScene.actionaction server to get a list of planes containing objects. - Perform common preprocessing steps on the objects (i.e. create bounding box, transform to desired frame,...).
- Detection action is triggered by method
start_detect_objects. A callback param can be passed in to be executed at the end of the method. - The list of planes and objects can be accessed through property
plane_list. - An example usage is written in the
DetectObjectsstate, defined in fileaction_states.pyof themdr_perceive_plane_actionpackage.
Serialize and deserialize ROS messages for interaction with C++ code.
An abstract class which creates an actionlib.SimpleActionServer object to handle object detection action goals using
action specifications in mas_perception_msgs/DetectScene.action. An extension of this class needs to implement:
_initialize: initialization procedures before starting the action servers (i.e. loading models)._execute_cb: perform object detection and respond to the action client.
Uses SingleImageDetectionHandler and ImageDetectorBase for detecting objects in an image extracted from a sensor_msgs/PointCloud2 message.
An extension of SceneDetectionActionServer which uses SingleImageDetectionHandler and ImageDetectorBase for detecting
from an image extracted from a sensor_msgs/PointCloud2 message, while also fitting planes in the clouds.
get_classes_in_data_dir: Returns a dictionary mapping from indices to classes as names of top level directories. This directory structure
data
├── class_1
└── class_2
should return
{0: 'class_1', 1: 'class_2'}
when called on data.
process_image_message: Convertssensor_msgs/Imageto CV image, then resizes and/or runs a preprocessing function if specified.case_insensitive_glob:globfiles ignoring case.cloud_msg_to_cv_image: extract a CV image as andarrayobject from asensor_msgs/PointCloud2message.cloud_msg_to_image_msg: extract asensor_msgs/Imagemessage from asensor_msgs/PointCloud2message.crop_organized_cloud_msg: use aBoundingBox2Dobject to crop asensor_msgs/PointCloud2message.crop_cloud_to_xyz: use aBoundingBox2Dobject to extract an array of(x, y, z)coordinates from asensor_msgs/PointCloud2message.transform_point_cloud: transform asensor_msgs/PointCloud2cloud using a transformation matrix, calling the PCL function in C++ code.PlaneSegmenter: Python wrapper of C++ classPlaneSegmenterROS(see C++ documentation) for fitting planes insensor_msgs/PointCloud2messages.
draw_labeled_boxes: draw boxes on a CV image (ndarray) usingBoundingBox2Dobjects.draw_labeled_boxes_img_msg: same with above but forsensor_msgs/Imagemessages.fit_box_to_image: adjust aBoundingBox2Dobject to fit an image size.crop_image: crop a CV image (ndarray) using aBoundingBox2Dobject.bgr_dict_from_classes: generate colors from a list of class names.
import numpy as np
from sensor_msgs.msg import PointCloud2
from mas_perception_libs.utils import cloud_msg_to_cv_image
from mas_perception_libs import BoundingBox2D
### An example of extracting (x, y, z) coordinates from a PointCloud2 message and estimate pose
cloud_msg = PointCloud2() # example cloud message
# extract CV image
cv_image = cloud_msg_to_image_msg(cloud_msg)
# detect regions in image to get a bounding box
def favorite_detect_func(cv_image):
return BoundingBox2D(box_geometry=(10, 15, 20, 30)) # (x, y, width, height)
box = favorite_detect_func(cv_image)
# crop cloud for coordinates and estimate pose
cropped_coord = crop_cloud_to_xyz(cloud_msg, box)
mean_pose = np.nanmean(np.reshape(cropped_coord, (-1, 3)), axis=0)