Skip to main content
The robotic arm system uses OpenCV to capture images for object detection. The CameraManager class handles all camera operations including initialization, configuration, and image capture.

CameraManager Class

The camera system is implemented in arm_system/perception/vision/camera/main.py:5.
class CameraManager:
    def __init__(self, camera_index: int = 0, width: int = 1280, height: int = 720):
        self.cap = cv2.VideoCapture(camera_index)
        self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
        self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)

Camera Configuration

The camera is configured with the following default settings:
  • Resolution: 1280x720 pixels
  • Camera Index: 0 (default system camera)
  • Backend: OpenCV VideoCapture

Resolution Settings

The camera resolution is set using OpenCV properties (arm_system/perception/vision/camera/main.py:8):
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

Image Capture Process

The capture_image() method handles the complete image capture workflow (arm_system/perception/vision/camera/main.py:11):
def capture_image(self):
    # Flush camera buffer by grabbing 5 frames
    for _ in range(5):
        self.cap.grab()
    
    # Capture actual frame
    ret, frame = self.cap.read()
    if not ret:
        return None
    
    # Generate filename with timestamp
    current_dir = os.path.dirname(os.path.abspath(__file__))
    timestamp = time.strftime("%Y%m%d-%H%M%S")
    filename = f"{current_dir}/objects_images/{timestamp}.png"
    
    # Create directory if needed
    os.makedirs(os.path.dirname(filename), exist_ok=True)
    
    # Save image
    cv2.imwrite(filename, frame)
    return filename

Buffer Flushing

The camera flushes 5 frames before capturing to ensure the most recent frame is captured (arm_system/perception/vision/camera/main.py:12):
for _ in range(5):
    self.cap.grab()

Storage Location

Captured images are stored in the objects_images/ directory relative to the camera module:
  • Directory: arm_system/perception/vision/camera/objects_images/
  • Filename Format: YYYYMMDD-HHMMSS.png
  • Example: 20260307-143022.png
The directory is automatically created if it doesn’t exist (arm_system/perception/vision/camera/main.py:23).

Integration with System

The camera is initialized in the CommunicationManager class (arm_system/communication/serial_manager.py:49):
self.camera = CameraManager(camera_index=camera_index)
When an object is detected during scanning, the camera captures an image for YOLO inference (arm_system/communication/serial_manager.py:178):
def _handle_object_detection(self, data: dict):
    # Capture image
    img_path = self.camera.capture_image()
    if not img_path:
        log.error("camera could not be captured")
        return
    
    # Process with YOLO
    image, yolo_result = self.object_detect_model.read_image_path(img_path, draw_results=True, save_drawn_img=True)

Cleanup

The camera is automatically released when the CameraManager object is destroyed (arm_system/perception/vision/camera/main.py:28):
def __del__(self):
    self.cap.release()

Build docs developers (and LLMs) love