# hebutmas/mas_vision architecture

> Architecture diagram of the GitHub repository hebutmas/mas_vision, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hebutmas/mas_vision
- Repository: https://github.com/hebutmas/mas_vision

## Overview

rm_vision is a C++17 RoboMaster aiming-vision framework for headless Linux. The infantry workflow reads gimbal state and camera frames, selects armor or energy-mechanism detection from the incoming mode, then publishes detection and timing data for remote debugging; the excerpt does not show a target-command output stage. A separate calibration app captures checkerboard samples, computes and verifies camera calibration, and reports results. The README also documents USB-camera support and remote Rerun visualization. Some detector internals and runtime links are unsampled, so uncertain links are omitted or dashed.

Main entry points: [`apps/infantry/main.cpp`](https://github.com/hebutmas/mas_vision/blob/master/apps/infantry/main.cpp) (Infantry app), [`apps/calibration/main.cpp`](https://github.com/hebutmas/mas_vision/blob/master/apps/calibration/main.cpp) (Calibration app), [`apps/infantry/main_debug.cpp`](https://github.com/hebutmas/mas_vision/blob/master/apps/infantry/main_debug.cpp) (Infantry debug), [`hardware/hikcamera/hikcamera.cpp`](https://github.com/hebutmas/mas_vision/blob/master/hardware/hikcamera/hikcamera.cpp) (Hik camera)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Applications"]
  node_infantry["Infantry app<br/>[main.cpp]"]
  node_calibration_app["Calibration app<br/>[main.cpp]"]
end

subgraph group_hardware["Hardware I/O"]
  node_hik_camera["Hik camera<br/>[hikcamera.cpp]"]
  node_usb_camera["USB camera<br/>[usbcamera.cpp]"]
  node_serial["Serial link<br/>[serialport.cpp]"]
end

subgraph group_vision["Vision modules"]
  node_armor_aim["Armor aiming<br/>[auto_armor.cpp]"]
  node_armor_detector["Armor detector<br/>[detector.cpp]"]
  node_armor_model["Armor model<br/>[shenzhen_model.cpp]"]
  node_buff_vision["Buff detection<br/>[auto_buff.cpp]"]
  node_buff_detector["Buff detector<br/>[detector.cpp]"]
  node_buff_refiner["Buff refiner<br/>[refiner.cpp]"]
end

subgraph group_debug["Remote debugging"]
  node_armor_viz["Armor visualization<br/>[visualize.cpp]"]
  node_buff_viz["Buff visualization<br/>[visualize.cpp]"]
  node_infantry_debug["Infantry debug<br/>[main_debug.cpp]"]
  node_debug_sink["Rerun sink<br/>[debug.hpp]"]
  node_video_encoder["Video encoder<br/>[video_encoder.cpp]"]
end

subgraph group_core["Shared tools"]
  node_calibration["Calibration logic<br/>[calibration.cpp]"]
  node_config["YAML config<br/>[config.hpp]"]
  node_frame_slot["Latest-frame slot<br/>[latest_frame.hpp]"]
  node_time["Shared timebase<br/>[time.hpp]"]
  node_exit_flag["Exit handling<br/>[exiter.hpp]"]
end

node_viewer(("Rerun Viewer"))

node_infantry -->|"reads state"| node_serial
node_infantry -->|"reads frames"| node_hik_camera
node_infantry -->|"runs armor"| node_armor_aim
node_infantry -->|"runs buff"| node_buff_vision
node_armor_detector -->|"uses model"| node_armor_model
node_armor_aim -.->|"dispatches detection"| node_armor_detector
node_buff_vision -.->|"dispatches detection"| node_buff_detector
node_buff_detector -.->|"refines detections"| node_buff_refiner
node_hik_camera -->|"publishes frames"| node_frame_slot
node_usb_camera -->|"publishes frames"| node_frame_slot
node_serial -->|"publishes state"| node_frame_slot
node_calibration_app -->|"captures images"| node_hik_camera
node_calibration_app -->|"captures images"| node_usb_camera
node_calibration_app -->|"calibrates camera"| node_calibration
node_infantry -->|"pushes results"| node_infantry_debug
node_infantry_debug -->|"visualizes armor"| node_armor_viz
node_infantry_debug -->|"visualizes buff"| node_buff_viz
node_infantry_debug -->|"encodes video"| node_video_encoder
node_infantry_debug -.->|"streams debug"| node_debug_sink
node_calibration_app -->|"reports progress"| node_debug_sink
node_debug_sink -->|"streams telemetry"| node_viewer
node_calibration_app -->|"loads settings"| node_config
node_infantry -->|"loads settings"| node_config
node_infantry -->|"checks shutdown"| node_exit_flag

click node_infantry "https://github.com/hebutmas/mas_vision/blob/master/apps/infantry/main.cpp"
click node_calibration_app "https://github.com/hebutmas/mas_vision/blob/master/apps/calibration/main.cpp"
click node_hik_camera "https://github.com/hebutmas/mas_vision/blob/master/hardware/hikcamera/hikcamera.cpp"
click node_usb_camera "https://github.com/hebutmas/mas_vision/blob/master/hardware/usbcamera/usbcamera.cpp"
click node_serial "https://github.com/hebutmas/mas_vision/blob/master/hardware/serialport/serialport.cpp"
click node_armor_aim "https://github.com/hebutmas/mas_vision/blob/master/modules/auto_armor/auto_armor.cpp"
click node_armor_detector "https://github.com/hebutmas/mas_vision/blob/master/modules/auto_armor/detection/detector.cpp"
click node_armor_model "https://github.com/hebutmas/mas_vision/blob/master/modules/auto_armor/models/shenzhen_model.cpp"
click node_buff_vision "https://github.com/hebutmas/mas_vision/blob/master/modules/auto_buff/auto_buff.cpp"
click node_buff_detector "https://github.com/hebutmas/mas_vision/blob/master/modules/auto_buff/detection/detector.cpp"
click node_buff_refiner "https://github.com/hebutmas/mas_vision/blob/master/modules/auto_buff/detection/refiner.cpp"
click node_armor_viz "https://github.com/hebutmas/mas_vision/blob/master/modules/auto_armor/debug/visualize.cpp"
click node_buff_viz "https://github.com/hebutmas/mas_vision/blob/master/modules/auto_buff/debug/visualize.cpp"
click node_infantry_debug "https://github.com/hebutmas/mas_vision/blob/master/apps/infantry/main_debug.cpp"
click node_debug_sink "https://github.com/hebutmas/mas_vision/blob/master/tools/debug/debug.hpp"
click node_video_encoder "https://github.com/hebutmas/mas_vision/blob/master/tools/debug/video/video_encoder.cpp"
click node_calibration "https://github.com/hebutmas/mas_vision/blob/master/tools/calibration/calibration.cpp"
click node_config "https://github.com/hebutmas/mas_vision/blob/master/tools/config/config.hpp"
click node_frame_slot "https://github.com/hebutmas/mas_vision/blob/master/tools/latest_frame/latest_frame.hpp"
click node_time "https://github.com/hebutmas/mas_vision/blob/master/tools/time/time.hpp"
click node_exit_flag "https://github.com/hebutmas/mas_vision/blob/master/tools/exiter/exiter.hpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_infantry,node_calibration_app,node_viewer toneBlue
class node_hik_camera,node_usb_camera,node_serial toneAmber
class node_armor_aim,node_armor_detector,node_armor_model,node_buff_vision,node_buff_detector,node_buff_refiner toneMint
class node_armor_viz,node_buff_viz,node_infantry_debug,node_debug_sink,node_video_encoder toneRose
class node_calibration,node_config,node_frame_slot,node_time,node_exit_flag toneIndigo
```

## Components

### Applications

- [Infantry app](https://github.com/hebutmas/mas_vision/blob/master/apps/infantry/main.cpp): `apps/infantry/main.cpp`
- [Calibration app](https://github.com/hebutmas/mas_vision/blob/master/apps/calibration/main.cpp): `apps/calibration/main.cpp`

### Hardware I/O

- [Hik camera](https://github.com/hebutmas/mas_vision/blob/master/hardware/hikcamera/hikcamera.cpp): `hardware/hikcamera/hikcamera.cpp`
- [USB camera](https://github.com/hebutmas/mas_vision/blob/master/hardware/usbcamera/usbcamera.cpp): `hardware/usbcamera/usbcamera.cpp`
- [Serial link](https://github.com/hebutmas/mas_vision/blob/master/hardware/serialport/serialport.cpp): `hardware/serialport/serialport.cpp`

### Vision modules

- [Armor aiming](https://github.com/hebutmas/mas_vision/blob/master/modules/auto_armor/auto_armor.cpp): `modules/auto_armor/auto_armor.cpp`
- [Armor detector](https://github.com/hebutmas/mas_vision/blob/master/modules/auto_armor/detection/detector.cpp): `modules/auto_armor/detection/detector.cpp`
- [Armor model](https://github.com/hebutmas/mas_vision/blob/master/modules/auto_armor/models/shenzhen_model.cpp): `modules/auto_armor/models/shenzhen_model.cpp`
- [Buff detection](https://github.com/hebutmas/mas_vision/blob/master/modules/auto_buff/auto_buff.cpp): `modules/auto_buff/auto_buff.cpp`
- [Buff detector](https://github.com/hebutmas/mas_vision/blob/master/modules/auto_buff/detection/detector.cpp): `modules/auto_buff/detection/detector.cpp`
- [Buff refiner](https://github.com/hebutmas/mas_vision/blob/master/modules/auto_buff/detection/refiner.cpp): `modules/auto_buff/detection/refiner.cpp`

### Remote debugging

- [Armor visualization](https://github.com/hebutmas/mas_vision/blob/master/modules/auto_armor/debug/visualize.cpp): `modules/auto_armor/debug/visualize.cpp`
- [Buff visualization](https://github.com/hebutmas/mas_vision/blob/master/modules/auto_buff/debug/visualize.cpp): `modules/auto_buff/debug/visualize.cpp`
- [Infantry debug](https://github.com/hebutmas/mas_vision/blob/master/apps/infantry/main_debug.cpp): `apps/infantry/main_debug.cpp`
- [Rerun sink](https://github.com/hebutmas/mas_vision/blob/master/tools/debug/debug.hpp): `tools/debug/debug.hpp`
- [Video encoder](https://github.com/hebutmas/mas_vision/blob/master/tools/debug/video/video_encoder.cpp): `tools/debug/video/video_encoder.cpp`

### Shared tools

- [Calibration logic](https://github.com/hebutmas/mas_vision/blob/master/tools/calibration/calibration.cpp): `tools/calibration/calibration.cpp`
- [YAML config](https://github.com/hebutmas/mas_vision/blob/master/tools/config/config.hpp): `tools/config/config.hpp`
- [Latest-frame slot](https://github.com/hebutmas/mas_vision/blob/master/tools/latest_frame/latest_frame.hpp): `tools/latest_frame/latest_frame.hpp`
- [Shared timebase](https://github.com/hebutmas/mas_vision/blob/master/tools/time/time.hpp): `tools/time/time.hpp`
- [Exit handling](https://github.com/hebutmas/mas_vision/blob/master/tools/exiter/exiter.hpp): `tools/exiter/exiter.hpp`

### Other components

- **Rerun Viewer**

## Connections

- Infantry app → Serial link: reads state (evidence: `apps/infantry/main.cpp`)
- Infantry app → Hik camera: reads frames (evidence: `apps/infantry/main.cpp`)
- Infantry app → Armor aiming: runs armor (evidence: `apps/infantry/main.cpp`)
- Infantry app → Buff detection: runs buff (evidence: `apps/infantry/main.cpp`)
- Armor detector → Armor model: uses model (evidence: `modules/auto_armor/detection/detector.cpp`)
- Armor aiming → Armor detector: dispatches detection
- Buff detection → Buff detector: dispatches detection
- Buff detector → Buff refiner: refines detections
- Hik camera → Latest-frame slot: publishes frames
- USB camera → Latest-frame slot: publishes frames
- Serial link → Latest-frame slot: publishes state
- Calibration app → Hik camera: captures images (evidence: `apps/calibration/main.cpp`)
- Calibration app → USB camera: captures images (evidence: `apps/calibration/main.cpp`)
- Calibration app → Calibration logic: calibrates camera (evidence: `apps/calibration/main.cpp`)
- Infantry app → Infantry debug: pushes results (evidence: `apps/infantry/main.cpp`)
- Infantry debug → Armor visualization: visualizes armor (evidence: `apps/infantry/main_debug.cpp`)
- Infantry debug → Buff visualization: visualizes buff (evidence: `apps/infantry/main_debug.cpp`)
- Infantry debug → Video encoder: encodes video (evidence: `apps/infantry/main_debug.cpp`)
- Infantry debug → Rerun sink: streams debug
- Calibration app → Rerun sink: reports progress (evidence: `apps/calibration/main.cpp`)
- Rerun sink → Rerun Viewer: streams telemetry (evidence: `tools/debug/debug.hpp`)
- Calibration app → YAML config: loads settings (evidence: `apps/calibration/main.cpp`)
- Infantry app → YAML config: loads settings (evidence: `apps/infantry/main.cpp`)
- Infantry app → Exit handling: checks shutdown (evidence: `apps/infantry/main.cpp`)
