Welcome to MicroROS V2 Robot Car repository
7. 3D Object Recognition
3D Object Recognition
1. Experiment Objective
Use MediaPipe Objectron to detect 3D objects (shoe, chair, cup, camera) in real time and draw 3D bounding boxes and coordinate axes.
2. Experiment Principle
1. Key Terms
| Keyword | Description |
|---|---|
| MediaPipe Objectron | A 3D object detection model that outputs both the object's 3D bounding box and pose without requiring a depth camera |
| 3D bounding box | The 3D bounding box of the object, composed of 9 vertices (8 corners + 1 center), projected onto the 2D image for drawing |
| Coordinate axes | RGB three-color axes (red=X, green=Y, blue=Z) indicating the object's spatial orientation |
| Four model types | Supports four pretrained models — shoe, chair, cup and camera — switchable at runtime |
2. Technical Architecture
Terminal 1: start agent + camera + joint modelsTerminal 2: start 3D object recognition
3. Experiment Steps
1. Hardware Preparation
| Hardware | Requirement |
|---|---|
| PTZ version | ✅ Supported |
| No-PTZ version | ✅ Supported |
| Required peripherals | ESP32 camera, and one of the four supported objects (shoe/chair/cup/camera) |
2. Start the agent + camera + joint models (Terminal 1)
xxxxxxxxxxros2 launch microros_v2_bringup car_base.launch.py
3. Start 3D object recognition (Terminal 2)
xxxxxxxxxxros2 launch microros_v2_mediapipe_pkg objectron.launch.py4. Observed Results
- Press
Fto switch among the four object types to detect - Place one of the four objects in the camera's field of view and the object is enclosed by a 3D bounding box
- The RGB three-color axes indicate the object's spatial orientation (red=X, green=Y, blue=Z)

5. Code Walkthrough
Source code paths:
- Launch:
~/microros_ws/src/microros_v2_mediapipe_pkg/launch/objectron.launch.py- Node:
~/microros_ws/src/microros_v2_mediapipe_pkg/microros_v2_mediapipe_pkg/Objectron.py
1. Core Node Analysis
x# Source file: ~/microros_ws/src/microros_v2_mediapipe_pkg/microros_v2_mediapipe_pkg/Objectron.pyclass Objectron(Node): def __init__(self): super().__init__("objectron_node") self.declare_parameter("static_image_mode", False) self.declare_parameter("max_objects", 1) self.declare_parameter("detection_con", 0.3) self.declare_parameter("process_every_n", 3) self.declare_parameter("object_name", "Shoe") self.mp_objectron = mp.solutions.objectron object_model = getattr(self.mp_objectron.ObjectModel, object_name) self.objectron = self.mp_objectron.Objectron( static_image_mode=False, max_num_objects=1, min_detection_confidence=0.3, min_tracking_confidence=0.3, model_name=object_model) def image_callback(self, msg): frame = self.bridge.imgmsg_to_cv2(msg, 'bgr8') results = self.objectron.process(cv.cvtColor(frame, cv.COLOR_BGR2RGB)) if results.detected_objects: for obj in results.detected_objects: self.mp_draw.draw_landmarks(frame, obj.landmarks_2d, self.mp_objectron.BOX_CONNECTIONS) self.mp_draw.draw_axis(frame, self.camera_matrix, self.dist_coeffs, obj.rotation, obj.translation) cv.imshow(self.window_name, frame)Key logic:
getattr(self.mp_objectron.ObjectModel, object_name): dynamically fetches the enum value from one of the four model namesprocess_every_n=3: processes one frame out of every 3 to reduce computational loadmin_detection_confidence=0.3: the default threshold is lower than for Hands/Pose because 3D object detection is more difficultdraw_axis: draws the RGB three-color axes; requires camera intrinsics (loaded fromcamera.yaml)- Objectron tends to SIGSEGV under the Ubuntu VM's SVGA3D/EGL stack, so the startup script sets
LIBGL_ALWAYS_SOFTWARE=1to force software rendering
2. Key Parameters
Parameter definition files:
- Launch:
~/microros_ws/src/microros_v2_mediapipe_pkg/launch/objectron.launch.py- Node:
~/microros_ws/src/microros_v2_mediapipe_pkg/microros_v2_mediapipe_pkg/Objectron.py
| Parameter | Type | Default | Description |
|---|---|---|---|
object_name | string | Shoe | Detection model: Shoe / Chair / Cup / Camera |
max_objects | int | 1 | Maximum number of objects to detect |
detection_con | float | 0.3 | Detection confidence threshold |
process_every_n | int | 3 | Process once every N frames (to reduce load) |
3. Node Description
| Node | Function |
|---|---|
objectron_node | MediaPipe Objectron 3D detection + bounding box / coordinate axis visualization |
6. Frequently Asked Questions
| Issue | Cause | Solution |
|---|---|---|
| Object not detected | The object is not within the current model's supported scope | Switch object_name to the matching model |
| Display freezes in the VM | SVGA3D/EGL graphics stack compatibility issue | The script already sets the software rendering environment variable |