docs/curation_pipeline.md: add BGR-vs-RGB channel-order gotcha
Browse files- docs/curation_pipeline.md +35 -0
docs/curation_pipeline.md
CHANGED
|
@@ -312,6 +312,41 @@ PY
|
|
| 312 |
|
| 313 |
---
|
| 314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
## Failure-mode reference table
|
| 316 |
|
| 317 |
| Mode | Detector | Threshold | Where logged |
|
|
|
|
| 312 |
|
| 313 |
---
|
| 314 |
|
| 315 |
+
## Channel-order gotcha (read before adding any new visualiser)
|
| 316 |
+
|
| 317 |
+
The three video streams use **different byte orders** inside the H5 files. Get
|
| 318 |
+
this wrong and your previews come out with R/B swapped:
|
| 319 |
+
|
| 320 |
+
| Stream | H5 byte order | Why |
|
| 321 |
+
|---|---|---|
|
| 322 |
+
| `realsense/cam{0,1,2}/color` | **BGR** | `pyrealsense2` enabled with `rs.format.bgr8` in `camera_stream/realsense_stream.py` |
|
| 323 |
+
| `gelsight/{left,right}/frames` | **RGB** | Converted in `camera_stream/usb_video_stream.py` (`cv2.cvtColor(BGR2RGB)`) before writing |
|
| 324 |
+
| `view` in `processed/.../*.pt` | **BGR** | Carved out of cam0 by `twm.contact_index` with no further conversion |
|
| 325 |
+
| `tactile_{left,right}` in `.pt` | **RGB** | Carved out of gelsight frames, same as above |
|
| 326 |
+
|
| 327 |
+
Rules of thumb:
|
| 328 |
+
|
| 329 |
+
- `cv2.imshow` and `cv2.VideoWriter` expect BGR — RealSense streams + the
|
| 330 |
+
recording UI are end-to-end consistent (and incidentally hide the fact
|
| 331 |
+
that the GelSight thumbnails in `twm.visualize` are technically rendered
|
| 332 |
+
with their R/B swapped).
|
| 333 |
+
- `PIL.Image.fromarray` and the GIF encoder interpret bytes as RGB. Anything
|
| 334 |
+
PIL-bound (gallery previews, dataloader sample GIFs) must convert
|
| 335 |
+
RealSense BGR → RGB once. The cheapest way is `arr[..., ::-1]`.
|
| 336 |
+
- When reusing `twm.data_collection.make_preview` as the panel builder for a
|
| 337 |
+
GIF, feed the H5 streams in **as-is** so the panel matches the live viewer
|
| 338 |
+
pixel-for-pixel, then `cv2.cvtColor(panel, cv2.COLOR_BGR2RGB)` once at the
|
| 339 |
+
end before saving with PIL.
|
| 340 |
+
|
| 341 |
+
If you're writing a new visualiser:
|
| 342 |
+
|
| 343 |
+
```python
|
| 344 |
+
import cv2, h5py, hdf5plugin # noqa: F401
|
| 345 |
+
with h5py.File(path, "r") as f:
|
| 346 |
+
cam_rgb = f["realsense/cam0/color"][i][..., ::-1].copy() # BGR → RGB
|
| 347 |
+
gs_rgb = f["gelsight/left/frames"][i] # already RGB
|
| 348 |
+
```
|
| 349 |
+
|
| 350 |
## Failure-mode reference table
|
| 351 |
|
| 352 |
| Mode | Detector | Threshold | Where logged |
|