mcap2img 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. mcap2img-0.1.0/MANIFEST.in +2 -0
  2. mcap2img-0.1.0/PKG-INFO +460 -0
  3. mcap2img-0.1.0/README.md +429 -0
  4. mcap2img-0.1.0/mcap2img/__init__.py +3 -0
  5. mcap2img-0.1.0/mcap2img/__main__.py +4 -0
  6. mcap2img-0.1.0/mcap2img/cli.py +246 -0
  7. mcap2img-0.1.0/mcap2img/overlay.py +100 -0
  8. mcap2img-0.1.0/mcap2img/pb/CameraCalibration_pb2.py +26 -0
  9. mcap2img-0.1.0/mcap2img/pb/CompressedImage_pb2.py +26 -0
  10. mcap2img-0.1.0/mcap2img/pb/Pose_pb2.py +28 -0
  11. mcap2img-0.1.0/mcap2img/pb/Quaternion_pb2.py +26 -0
  12. mcap2img-0.1.0/mcap2img/pb/RobotInfo_pb2.py +31 -0
  13. mcap2img-0.1.0/mcap2img/pb/Vector3_pb2.py +26 -0
  14. mcap2img-0.1.0/mcap2img/pb/__init__.py +1 -0
  15. mcap2img-0.1.0/mcap2img/pb/proto/CameraCalibration.proto +12 -0
  16. mcap2img-0.1.0/mcap2img/pb/proto/CompressedImage.proto +7 -0
  17. mcap2img-0.1.0/mcap2img/pb/proto/Pose.proto +10 -0
  18. mcap2img-0.1.0/mcap2img/pb/proto/Quaternion.proto +9 -0
  19. mcap2img-0.1.0/mcap2img/pb/proto/RobotInfo.proto +20 -0
  20. mcap2img-0.1.0/mcap2img/pb/proto/Vector3.proto +8 -0
  21. mcap2img-0.1.0/mcap2img/progress.py +41 -0
  22. mcap2img-0.1.0/mcap2img/projection.py +293 -0
  23. mcap2img-0.1.0/mcap2img/proto_utils.py +11 -0
  24. mcap2img-0.1.0/mcap2img/reader.py +227 -0
  25. mcap2img-0.1.0/mcap2img/timestamp_index.py +47 -0
  26. mcap2img-0.1.0/mcap2img.egg-info/PKG-INFO +460 -0
  27. mcap2img-0.1.0/mcap2img.egg-info/SOURCES.txt +35 -0
  28. mcap2img-0.1.0/mcap2img.egg-info/dependency_links.txt +1 -0
  29. mcap2img-0.1.0/mcap2img.egg-info/entry_points.txt +2 -0
  30. mcap2img-0.1.0/mcap2img.egg-info/requires.txt +11 -0
  31. mcap2img-0.1.0/mcap2img.egg-info/top_level.txt +1 -0
  32. mcap2img-0.1.0/pyproject.toml +52 -0
  33. mcap2img-0.1.0/setup.cfg +4 -0
  34. mcap2img-0.1.0/tests/test_cli.py +61 -0
  35. mcap2img-0.1.0/tests/test_progress.py +18 -0
  36. mcap2img-0.1.0/tests/test_projection.py +120 -0
  37. mcap2img-0.1.0/tests/test_timestamp_index.py +30 -0
@@ -0,0 +1,2 @@
1
+ include README.md
2
+ recursive-include mcap2img/pb/proto *.proto
@@ -0,0 +1,460 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcap2img
3
+ Version: 0.1.0
4
+ Summary: Export MCAP camera frames to PNG with robot coordinate axis overlays
5
+ Author: Genrobota
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://gitee.com/mimidegongkai/mcap2img
8
+ Project-URL: Repository, https://gitee.com/mimidegongkai/mcap2img.git
9
+ Keywords: mcap,robotics,camera,opencv,export
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
19
+ Requires-Python: <3.14,>=3.10
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: mcap>=1.1.1
22
+ Requires-Dist: av>=12.0.0
23
+ Requires-Dist: numpy>=1.24.0
24
+ Requires-Dist: opencv-python>=4.8.0
25
+ Requires-Dist: protobuf==4.25.1
26
+ Requires-Dist: scipy>=1.10.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0; extra == "dev"
29
+ Requires-Dist: build>=1.0; extra == "dev"
30
+ Requires-Dist: twine>=5.0; extra == "dev"
31
+
32
+ # mcap2img
33
+
34
+ 读取本地 MCAP 文件,将 `/robot0/sensor/camera2/compressed` 的每帧解码为 PNG,并在图像上叠加 `/robot1/sim/robot_info` 与 `/robot2/sim/robot_info` 的坐标轴投影。
35
+
36
+ 投影算法与 [web-matrix-monitor](../web-matrix-monitor/src/components/monitor/layout2d/robotAxesVideoOverlay.js) 保持一致。
37
+
38
+ ---
39
+
40
+ ## 安装
41
+
42
+ ### 方式一:pip 安装(推荐)
43
+
44
+ 从 Gitee 仓库安装最新版:
45
+
46
+ ```bash
47
+ pip install git+https://gitee.com/mimidegongkai/mcap2img.git
48
+ ```
49
+
50
+ 安装完成后可直接使用 `mcap2img` 命令:
51
+
52
+ ```bash
53
+ mcap2img --input /path/to/bag.mcap --output ./output
54
+ mcap2img --input /path/to/mcap_dir --output ./output
55
+ ```
56
+
57
+ 也支持模块方式运行:
58
+
59
+ ```bash
60
+ python -m mcap2img --input /path/to/bag.mcap --output ./output
61
+ ```
62
+
63
+ ### 方式二:本地源码开发安装
64
+
65
+ 克隆仓库后,在项目根目录执行:
66
+
67
+ ```bash
68
+ cd mcap2img
69
+ python3.12 -m venv .venv
70
+ source .venv/bin/activate # Windows: .\.venv\Scripts\Activate.ps1
71
+ pip install --upgrade pip
72
+ pip install -e ".[dev]"
73
+ ```
74
+
75
+ ### 方式三:打包分发
76
+
77
+ 维护者可将项目打包为 wheel / sdist,供他人离线安装:
78
+
79
+ ```bash
80
+ pip install build
81
+ python -m build
82
+ pip install dist/mcap2img-0.1.0-py3-none-any.whl
83
+ ```
84
+
85
+ ---
86
+
87
+ ## 环境要求
88
+
89
+ | 项 | 要求 |
90
+ |---|---|
91
+ | Python | **3.10 ~ 3.12**(推荐 **3.12**,已在 3.12.3 验证) |
92
+ | 系统 | macOS / Linux / Windows |
93
+ | 磁盘 | 输出为 PNG,默认仅导出 camera2(约千帧量级) |
94
+
95
+ > **注意**:Python 3.14 与 protobuf 存在兼容问题,暂不建议使用。请用 `python3.12` 创建虚拟环境。
96
+
97
+ ---
98
+
99
+ ## 一、本地开发环境(可选)
100
+
101
+ 若已用 `pip install -e ".[dev]"` 安装,可跳过本节。否则进入项目目录手动创建虚拟环境:
102
+
103
+ ```bash
104
+ cd /path/to/mcap2img
105
+ ```
106
+
107
+ ### macOS / Linux
108
+
109
+ ```bash
110
+ # 推荐指定 3.12
111
+ python3.12 -m venv .venv
112
+
113
+ # 激活虚拟环境
114
+ source .venv/bin/activate
115
+
116
+ # 确认当前 Python 版本
117
+ python --version
118
+ # 应显示 Python 3.12.x
119
+
120
+ # 安装项目及开发依赖
121
+ pip install --upgrade pip
122
+ pip install -e ".[dev]"
123
+ ```
124
+
125
+ ### Windows (PowerShell)
126
+
127
+ ```powershell
128
+ cd C:\path\to\mcap2img
129
+
130
+ py -3.12 -m venv .venv
131
+ .\.venv\Scripts\Activate.ps1
132
+
133
+ python --version
134
+ pip install --upgrade pip
135
+ pip install -e ".[dev]"
136
+ ```
137
+
138
+ ### Windows (CMD)
139
+
140
+ ```cmd
141
+ cd C:\path\to\mcap2img
142
+
143
+ py -3.12 -m venv .venv
144
+ .venv\Scripts\activate.bat
145
+
146
+ pip install --upgrade pip
147
+ pip install -e ".[dev]"
148
+ ```
149
+
150
+ 激活成功后,终端提示符前会出现 `(.venv)`。
151
+
152
+ ---
153
+
154
+ ## 二、运行
155
+
156
+ ### 基本用法(单个 MCAP)
157
+
158
+ 将 MCAP 文件放到 `input/` 目录(或任意路径),然后执行:
159
+
160
+ ```bash
161
+ # 确保虚拟环境已激活
162
+ source .venv/bin/activate # macOS/Linux
163
+ # 或 .\.venv\Scripts\Activate.ps1 # Windows
164
+
165
+ python -m mcap2img \
166
+ --input input/425cb3d4fde94dd6ac03ad9030657a6a-with_gt.mcap \
167
+ --output output
168
+
169
+ # 或使用命令行入口
170
+ mcap2img \
171
+ --input input/425cb3d4fde94dd6ac03ad9030657a6a-with_gt.mcap \
172
+ --output output
173
+ ```
174
+
175
+ ### 批量处理(input 目录下多个 MCAP)
176
+
177
+ 将多个 `.mcap` 文件放入同一目录(例如 `input/`),指定该目录即可批量导出。每个 MCAP 会在 `output/` 下按文件名(不含扩展名)创建子目录:
178
+
179
+ ```bash
180
+ python -m mcap2img \
181
+ --input input \
182
+ --output output
183
+ ```
184
+
185
+ 例如 `input/a.mcap` 与 `input/b-with_gt.mcap` 会分别输出到:
186
+
187
+ ```
188
+ output/a/camera2/
189
+ output/b-with_gt/camera2/
190
+ ```
191
+
192
+ ### 不激活虚拟环境,直接调用
193
+
194
+ ```bash
195
+ # macOS/Linux
196
+ .venv/bin/python -m mcap2img \
197
+ --input input/your_bag.mcap \
198
+ --output output
199
+
200
+ # Windows
201
+ .venv\Scripts\python.exe -m mcap2img ^
202
+ --input input\your_bag.mcap ^
203
+ --output output
204
+ ```
205
+
206
+ ### 常用示例
207
+
208
+ **导出多路相机(例如 camera0 与 camera2):**
209
+
210
+ ```bash
211
+ python -m mcap2img \
212
+ --input input/your_bag.mcap \
213
+ --output output \
214
+ --cameras 0,2
215
+ ```
216
+
217
+ **指定叠加的机器人:**
218
+
219
+ ```bash
220
+ python -m mcap2img \
221
+ --input input/your_bag.mcap \
222
+ --output output \
223
+ --overlay-robots robot1,robot2
224
+ ```
225
+
226
+ **开启详细日志:**
227
+
228
+ ```bash
229
+ python -m mcap2img \
230
+ --input input/your_bag.mcap \
231
+ --output output \
232
+ -v
233
+ ```
234
+
235
+ ---
236
+
237
+ ## 三、运行时的进度输出
238
+
239
+ 任务较大时,终端会分两个阶段打印百分比进度:
240
+
241
+ ```
242
+ INFO: Scanning input/your_bag.mcap ...
243
+ INFO: Scanning MCAP: 503/50236 (1%)
244
+ INFO: Scanning MCAP: 10048/50236 (20%)
245
+ ...
246
+ INFO: camera2: 1329 frames
247
+ INFO: Exporting 1329 frames across 1 cameras ...
248
+ INFO: Exporting PNG: 80/7983 (1%)
249
+ INFO: Exporting PNG: 1596/7983 (20%)
250
+ ...
251
+ INFO: Done: saved=7983 overlay_drawn=7500 overlay_skipped=483 missing_calib=0
252
+ ```
253
+
254
+ - **Scanning MCAP**:读取并解码 MCAP 中的消息
255
+ - **Exporting PNG**:写入 PNG 并绘制坐标轴叠加
256
+
257
+ ---
258
+
259
+ ## 四、输出目录结构
260
+
261
+ **单个 MCAP:**
262
+
263
+ ```
264
+ output/
265
+ camera2/
266
+ 1778813410223851000.png # 文件名为 MCAP log_time(纳秒)
267
+ 1778813410323851000.png
268
+ ...
269
+ ```
270
+
271
+ **批量处理(`--input input/`):**
272
+
273
+ ```
274
+ output/
275
+ 425cb3d4fde94dd6ac03ad9030657a6a-with_gt/
276
+ camera2/
277
+ 1778813410223851000.png
278
+ ...
279
+ another_bag/
280
+ camera2/
281
+ ...
282
+ ```
283
+
284
+ 时间戳与 web-matrix-monitor 播放时间轴一致(使用 MCAP `log_time`,非 `header.timestamp`)。
285
+
286
+ ---
287
+
288
+ ## 五、命令行参数
289
+
290
+ | 参数 | 默认值 | 说明 |
291
+ |------|--------|------|
292
+ | `--input` | 必填 | 本地 `.mcap` 文件路径,或包含多个 `.mcap` 的目录(批量处理) |
293
+ | `--output` | `./output` | PNG 输出目录 |
294
+ | `--cameras` | `2` | 要导出的相机编号,逗号分隔 |
295
+ | `--overlay-robots` | `robot1,robot2` | 绘制坐标轴的机器人 id |
296
+ | `-v`, `--verbose` | 关闭 | 输出 DEBUG 级别日志 |
297
+
298
+ ---
299
+
300
+ ## 六、退出虚拟环境
301
+
302
+ ```bash
303
+ deactivate
304
+ ```
305
+
306
+ ---
307
+
308
+ ## 七、运行测试
309
+
310
+ ```bash
311
+ source .venv/bin/activate
312
+ pip install pytest
313
+ python -m pytest tests/ -v
314
+ ```
315
+
316
+ ---
317
+
318
+ ## 八、发布与 CI
319
+
320
+ ### 本地一键发布(推荐)
321
+
322
+ 只需配置一次本地文件(**不会提交到 git**):
323
+
324
+ ```bash
325
+ cp release.local.env.example release.local.env
326
+ # 编辑 release.local.env,填入 TWINE_PASSWORD
327
+ ```
328
+
329
+ 之后每次发布:
330
+
331
+ ```bash
332
+ chmod +x scripts/publish.sh # 首次
333
+
334
+ ./scripts/publish.sh # 发布当前版本
335
+ ./scripts/publish.sh 0.1.1 # 改版本号并发布
336
+ ./scripts/publish.sh --dry-run # 只测试+打包,不上传
337
+ ```
338
+
339
+ 可选:在 `release.local.env` 里设置 `AUTO_GIT_TAG=1`,上传成功后会自动 commit、打 tag 并 push。
340
+
341
+ ### 手动分步发布
342
+
343
+ ```bash
344
+ # 1. 更新版本号
345
+ ./scripts/bump_version.sh 0.1.1
346
+
347
+ # 2. 构建并校验(自动使用 .venv 若存在)
348
+ ./scripts/release.sh
349
+
350
+ # 3. 上传到 PyPI(需先配置 token)
351
+ export TWINE_USERNAME=__token__
352
+ export TWINE_PASSWORD=pypi-xxxxxxxx
353
+ ./scripts/release.sh --upload
354
+
355
+ # 或先上传到 TestPyPI 验证
356
+ ./scripts/release.sh --testpypi
357
+ ```
358
+
359
+ ### GitHub Actions
360
+
361
+ 仓库已包含:
362
+
363
+ | 工作流 | 触发条件 | 作用 |
364
+ |--------|----------|------|
365
+ | `.github/workflows/ci.yml` | push / PR 到 `master`/`main` | Python 3.10–3.12 测试 + 打包 |
366
+ | `.github/workflows/publish.yml` | 推送 tag `v*` | 测试通过后发布到 PyPI |
367
+
368
+ **GitHub 配置:**
369
+
370
+ 1. 在 [PyPI](https://pypi.org/) 创建 API Token
371
+ 2. 仓库 Settings → Secrets → `PYPI_API_TOKEN`
372
+ 3. (可选)Settings → Environments → 创建 `pypi` 环境并保护发布
373
+
374
+ **发布流程:**
375
+
376
+ ```bash
377
+ ./scripts/bump_version.sh 0.1.1
378
+ git add mcap2img/__init__.py
379
+ git commit -m "release: v0.1.1"
380
+ git tag v0.1.1
381
+ git push origin master --tags
382
+ ```
383
+
384
+ ### Gitee Go 流水线
385
+
386
+ 仓库已包含:
387
+
388
+ | 流水线 | 文件 | 触发条件 |
389
+ |--------|------|----------|
390
+ | CI | `.gitee/pipelines/master.yml` | push / PR 到 `master`/`main` |
391
+ | 发布 | `.gitee/pipelines/release.yml` | 推送 tag `v*` |
392
+
393
+ **Gitee 配置:**
394
+
395
+ 1. 仓库 → **Gitee Go** → 启用流水线
396
+ 2. 导入 `.gitee/pipelines/` 下的 YAML,或同步后自动识别
397
+ 3. 流水线 **环境变量 / 凭证** 中添加:
398
+ - `TWINE_USERNAME` = `__token__`
399
+ - `TWINE_PASSWORD` = PyPI API Token
400
+
401
+ 推送 tag 后自动构建并上传 PyPI;CI 流水线会在 `dist/` 保留构建产物。
402
+
403
+ ---
404
+
405
+ ## 九、常见问题
406
+
407
+ ### `pip install` 失败 / 找不到 python3.12
408
+
409
+ ```bash
410
+ # macOS (Homebrew)
411
+ brew install python@3.12
412
+
413
+ # Ubuntu/Debian
414
+ sudo apt install python3.12 python3.12-venv
415
+ ```
416
+
417
+ ### `ModuleNotFoundError: No module named 'mcap2img'`
418
+
419
+ 确保在 `mcap2img/` 项目根目录下运行,且使用 `python -m mcap2img`(不要直接 `python mcap2img/cli.py`)。
420
+
421
+ ### 导出很慢
422
+
423
+ 默认仅导出 camera2,扫描 + 导出通常比 6 路全量快很多。如需其他相机,使用 `--cameras` 指定。
424
+
425
+ ### 图像无坐标轴叠加
426
+
427
+ 可能原因:该帧缺少 `camera_info` 或 `robot_info`。程序仍会保存原图,并在最终统计中显示 `overlay_skipped` / `missing_calib` 数量。
428
+
429
+ ### 重新导出前清理旧输出
430
+
431
+ ```bash
432
+ rm -rf output/*
433
+ ```
434
+
435
+ ---
436
+
437
+ ## 项目结构
438
+
439
+ ```
440
+ mcap2img/
441
+ ├── pyproject.toml # pip 包配置
442
+ ├── MANIFEST.in # 打包额外文件
443
+ ├── scripts/
444
+ │ ├── release.sh # 本地构建/发布脚本
445
+ │ └── bump_version.sh # 版本号更新脚本
446
+ ├── .github/workflows/ # GitHub Actions CI / 发布
447
+ ├── .gitee/pipelines/ # Gitee Go CI / 发布
448
+ ├── input/ # 放置待处理的 MCAP(已 gitignore)
449
+ ├── output/ # 导出结果(已 gitignore)
450
+ ├── .venv/ # 虚拟环境(已 gitignore)
451
+ ├── mcap2img/
452
+ │ ├── cli.py # 命令行入口
453
+ │ ├── reader.py # MCAP 读取与解码
454
+ │ ├── projection.py # 坐标轴投影
455
+ │ ├── overlay.py # OpenCV 绘制
456
+ │ └── progress.py # 进度百分比
457
+ ├── tests/
458
+ ├── requirements.txt # 开发说明(依赖见 pyproject.toml)
459
+ └── README.md
460
+ ```