Image / video labeling backend for the MoonbitLabeler app: 21 async ops over @fs/@json for folder browsing, image IO, label IO, class management, and VOC/YOLO export. Originally driven through Proton IPC; the 21 op handlers themselves are pure async MoonBit functions and can be wired into any IPC layer (HTTP, WASM, custom bridge).
┌─ menubar (File / Annotate / View / Settings / Tools) ───────────────┐
│ ┌─ sidebar ───────────┐ ┌─ canvas stage (image or video frame) ──┐ │
│ │ 文件列表 │ │ [ toolbar with mode buttons + class ] │ │
│ │ ▣ 1800003_0.jpg ✓ │ │ ┌────────────────────────────────────┐ │ │
│ │ ▣ 1800007_0.jpg │ │ │ │ │ │
│ │ ▣ 1800008_0.jpg │ │ │ canvas + SVG overlay │ │ │
│ │ ▣ 1800018_0.jpg │ │ │ │ │ │
│ │ ... │ │ └────────────────────────────────────┘ │ │
│ │ ── 类别 ────────── │ │ [ timeline (video mode only) ] │ │
│ │ 1 knife_blade 1332 │ └────────────────────────────────────────┘ │
│ │ 2 scissors 1117 │ ┌─ statusbar (path / index / hints) ┐ │
│ └─────────────────────┘ └─────────────────────────────────────┘ │
└────────────────────────────────────────────────────────────────────┘| Layer | Choice | Why |
|---|---|---|
| Backend | MoonBit 0.4.43 + async runtime | Native AOT compile, no GC pauses in the hot path |
| UI shell | Proton 0.1.12 + CEF 147 | Self-contained portable exe, no Electron |
| Image codec | vendored buildliming/moonbit_image (MIT) | Faster than mizchi/image for our workload |
| Frontend | Vanilla JS + Vite | No framework lock-in, fast cold reload |
| IPC | MoonBit @proton_command JSON ops | Type-safe request/response structs |
.
├── app/
│ └── main.mbt # @proton.config(...).extension().run_or_abort()
├── extensions/
│ ├── labeler/ # 21 IPC ops + the image/label/VOC/YOLO pipeline
│ │ ├── labeler.mbt # ~3,400 lines
│ │ ├── moon.pkg
│ │ └── write_probe.mbt # (deprecated ops, kept for test)
│ └── image/ # vendored buildliming/moonbit_image (14 .mbt files)
├── frontend/
│ ├── dist/ # Vite build output (inlined into the exe)
│ ├── index.html
│ └── src/
│ ├── main.js # state + IPC + UI orchestration (~1,800 lines)
│ ├── canvas.js # Canvas 2D rendering + hit testing
│ ├── image-loader.js # file:// / IPC fallback / lazy thumbs
│ ├── label.js # shared IPC wrappers for parse/serialize
│ ├── video.js # video mode controller (fetches, timeline, frame save)
│ ├── webkit-pickers.js # <input type="file"> folder/file pickers
│ ├── lazy-images.js # IntersectionObserver sidebar thumbs
│ ├── log.js # per-stage timing instrumentation
│ └── style.css # all CSS in one place
├── data/ # local sample dataset (Image@CARS.Part.01)
├── docs/VIDEO_LABELING.md
├── moon.mod # deps: moonbitlang/x@0.4.43
├── moon.proton # window 1280x800, entry=frontend/dist/index.html
└── README.mbt.md # generated Proton README (do not edit)Image@CARS.Part.01/1800007_0.jpg
Label@CARS.Part.01/1800007_0.json{
"img_name": "1800007_0.jpg",
"infos": [
{
"id": "obj_a1b2c3",
"shape": "rect",
"type": "knife_blade",
"points": [[287, 111], [303, 180]]
}
],
"bindings": [
{ "id": "b_d3e4f5", "from": "obj_a1b2c3", "to": "obj_…", "type": "same_group" }
],
"frames": [] // omitted when empty (image mode)
}moon fmt
moon check --target native --diagnostic-limit 80
proton_cli package app # full build -> target/proton-dist/moonbit-labeler/
proton_cli dev # hot-reload dev mode| Key | Action |
|---|---|
| 1 - 9 | Select class 1 - 9 (only classes with a non-empty count, see sidebar) |
| V | Select / move mode |
| R | Rectangle mode |
| P | Polygon mode |
| K | Keypoint mode |
| B | Binding mode |
| Ctrl /Z / Y | Undo / Redo |
| Delete | Delete selected annotation |
| Ctrl /S | Save current label |
| Ctrl /+ / Ctrl /- / Ctrl /0 | Zoom in / out / actual size |
| ← / → / W / S | Previous / next image (or video frame in video mode) |
| Op | Direction | Purpose |
|---|---|---|
| list_images | frontend → backend | List image files in a folder |
| read_image / read_thumb | frontend → backend | Read image bytes (base64), with optional resize for thumbs |
| decode_image / resize_image | frontend → backend | Backend-side image decode / resize (vendored buildliming/moonbit_image) |
| read_text / write_text | frontend → backend | Read / write a UTF-8 text file |
| read_label / write_label | frontend → backend | Read / write the on-disk label JSON for a given image path |
| scan_classes / save_classes / load_classes / load_classes_from_file | frontend → backend | Manage the curated class list (TXT or JSON, by file path or by Image/Label dir scan) |
| parse_label / serialize_label | frontend → backend | Round-trip a label JSON through the shared normalizer (handles legacy + modern schema) |
| list_videos / read_video_info / read_video_frame | frontend → backend | Video enumeration + per-frame decode (via ffprobe / ffmpeg) |
| export_voc_folder / export_yolo_folder | frontend → backend | Batch export the current Image/Label folder to Pascal VOC XML or YOLO TXT |
Install
Download zipImage / video labeling backend for the MoonbitLabeler app: 21 async ops over @fs/@json for folder browsing, image IO, label IO, class management, and VOC/YOLO export. Originally driven through Proton IPC; the 21 op handlers themselves are pure async MoonBit functions and can be wired into any IPC layer (HTTP, WASM, custom bridge).