| ================================================================================ | |
| Huhb3D - ROS image_transport / cv_bridge 16UC1 Compliance Report | |
| ================================================================================ | |
| === 1. PNG FILE FORMAT INSPECTION === | |
| Test file: depth_0001.png (1510 bytes) | |
| PNG signature: 89504e470d0a1a0a | |
| Valid PNG: NO | |
| IHDR chunk analysis: | |
| Width: 800 | |
| Height: 600 | |
| Bit depth: 16 | |
| Color type: 0 (Grayscale) | |
| Compression: 0 | |
| Filter method: 0 | |
| Interlace: 0 | |
| ROS 16UC1 Requirements Check: | |
| Color type == 0 (Grayscale): PASS (actual: 0/Grayscale) | |
| Bit depth == 16: PASS (actual: 16) | |
| No interlacing: PASS (actual: 0) | |
| [OK] PNG format is EXACTLY 16-bit Grayscale - fully compatible with ROS 16UC1 | |
| Critical: cv_bridge expects single-channel 16-bit unsigned. | |
| If PNG is saved as 8-bit grayscale or RGB, cv_bridge will produce | |
| wrong encoding or black image. | |
| === 2. cv_bridge SIMULATION === | |
| cv2.imread(IMREAD_UNCHANGED): | |
| shape: (600, 800) | |
| dtype: uint16 | |
| ndim: 2 | |
| cv_bridge conversion checks: | |
| ndim == 2 (single channel): PASS (actual: 2) | |
| dtype == uint16: PASS (actual: uint16) | |
| shape == (600, 800): PASS (actual: (600, 800)) | |
| [OK] cv_bridge will correctly encode as sensor_msgs/Image with: | |
| encoding: '16UC1' | |
| height: 600 | |
| width: 800 | |
| step: 1600 (width * sizeof(uint16)) | |
| cv_bridge Python code: | |
| from cv_bridge import CvBridge | |
| bridge = CvBridge() | |
| depth = cv2.imread('depth_0001.png', cv2.IMREAD_UNCHANGED) | |
| msg = bridge.cv2_to_imgmsg(depth, encoding='16UC1') | |
| # msg.encoding == '16UC1' | |
| # msg.step == 1600 | |
| # msg.data == depth.tobytes() | |
| Common cv_bridge pitfall simulation: | |
| cv2.imread(IMREAD_COLOR): shape=(600, 800, 3), dtype=uint8 | |
| [WARN] If user forgets IMREAD_UNCHANGED, gets 8UC3 BGR -> BLACK IMAGE! | |
| Correct: cv2.imread(path, cv2.IMREAD_UNCHANGED) | |
| cv2.imread(IMREAD_GRAYSCALE): shape=(600, 800), dtype=uint8 | |
| Range: [2, 3] (WRONG! High byte lost!) | |
| [WARN] IMREAD_GRAYSCALE converts to 8-bit -> loses high byte -> WRONG VALUES! | |
| === 3. image_transport / sensor_msgs/Image BYTE-LEVEL VERIFICATION === | |
| sensor_msgs/Image binary layout: | |
| encoding: '16UC1' | |
| is_bigendian: 0 (x86 little-endian) | |
| step: 1600 | |
| data length: 960000 bytes | |
| First 32 bytes (row 0, pixels 0-15): | |
| 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | |
| Byte order verification (little-endian uint16): | |
| Pixel [0,0]: value=0, bytes=[0x00, 0x00], reconstructed=0 | |
| Pixel [0,1]: value=0, bytes=[0x00, 0x00], reconstructed=0 | |
| Little-endian match: PASS | |
| Step (stride) verification: | |
| step = 1600 bytes/row | |
| Pixel [1,0]: value=0, reconstructed=0 | |
| Stride alignment: PASS | |
| image_transport compressed transport check: | |
| PNG compression is lossless -> depth values preserved exactly | |
| For compressed_depth transport, use depth_image_proc package: | |
| ros2 run depth_image_proc depth_image_proc | |
| Input: sensor_msgs/Image encoding='16UC1' | |
| Output: sensor_msgs/Image encoding='32FC1' (float, meters) | |
| Conversion: float_value = uint16_value / 1000.0 | |
| === 4. DEPTH VALUE RANGE vs ROS 16UC1 LIMITS === | |
| uint16 range: 0 to 65535 | |
| Our depth range: ~730 to ~844 mm | |
| Max representable: 65535 mm = 65.535 m | |
| Value distribution check: | |
| Total non-zero pixels: 45440 | |
| Min value: 730 (0x02da) | |
| Max value: 844 (0x034c) | |
| Mean value: 787.4 | |
| Std value: 22.0 | |
| Overflow (>65535): 0 PASS | |
| Underflow (<0): 0 PASS | |
| [OK] All values fit within uint16 range | |
| [OK] No overflow/underflow in ROS 16UC1 encoding | |
| === 5. COMMON ROS DEPLOYMENT PITFALLS CHECK === | |
| Pitfall 1: Wrong cv2.imread flag | |
| WRONG: cv2.imread(path) -> 8UC3 BGR, black image | |
| WRONG: cv2.imread(path, IMREAD_GRAYSCALE) -> 8UC1, high byte lost | |
| RIGHT: cv2.imread(path, IMREAD_UNCHANGED) -> 16UC1, correct values | |
| IMREAD_UNCHANGED: dtype=uint16, range=[750, 795] | |
| IMREAD_COLOR: dtype=uint8, range=[2, 3] WRONG! | |
| IMREAD_GRAYSCALE: dtype=uint8, range=[2, 3] WRONG! (high byte lost) | |
| Gray vs Unchanged error: 99.7% (CRITICAL!) | |
| Pitfall 2: depth_scale mismatch | |
| Our depth_scale = 1.0 (depth PNG stores mm directly) | |
| BOP convention: depth_mm = pixel_value * depth_scale | |
| ROS convention: depth_m = pixel_value / 1000.0 | |
| [OK] depth_scale=1.0 is unambiguous | |
| Pitfall 3: Endianness in sensor_msgs/Image | |
| is_bigendian field: must be 0 on x86/x64 systems | |
| Our data: little-endian (x86 native) | |
| cv_bridge sets is_bigendian=0 automatically | |
| [OK] No endianness mismatch | |
| Pitfall 4: Step/stride alignment | |
| step = width * sizeof(uint16) = 800 * 2 = 1600 | |
| No padding bytes between rows | |
| cv_bridge uses contiguous numpy array (no gaps) | |
| [OK] No stride alignment issues | |
| Pitfall 5: Zero-value semantics | |
| In our data: 0 means 'no depth' (background) | |
| In ROS: 0 typically means 'invalid depth' (same semantics) | |
| depth_image_proc handles 0 as NaN in float conversion | |
| [OK] Zero-value semantics match ROS convention | |
| Pitfall 6: image_transport compressed format | |
| For compressed_depth transport, PNG is re-encoded | |
| 16-bit PNG is lossless -> no data corruption | |
| [OK] Lossless compression preserves depth values | |
| === 6. cv_bridge ROUND-TRIP TEST === | |
| Original shape: (600, 800), dtype: uint16 | |
| Roundtrip shape: (600, 800), dtype: uint16 | |
| Byte-exact match: PASS | |
| Simulated sensor_msgs/Image -> cv_bridge -> cv2 roundtrip: | |
| 1. depth_png = cv2.imread(path, IMREAD_UNCHANGED) # uint16 (600,800) | |
| 2. msg = bridge.cv2_to_imgmsg(depth_png, '16UC1') | |
| 3. depth_back = bridge.imgmsg_to_cv2(msg, '16UC1') | |
| 4. assert np.array_equal(depth_png, depth_back) # True | |
| [OK] Roundtrip is lossless | |
| === 7. ALL OBJECTS DEPTH PNG FORMAT VERIFICATION === | |
| bearing_block: [PASS] shape=(600, 800) dtype=uint16 range=[770,801] | |
| bearing_medium: [PASS] shape=(600, 800) dtype=uint16 range=[770,803] | |
| bearing_small: [PASS] shape=(600, 800) dtype=uint16 range=[779,801] | |
| connector_housing: [PASS] shape=(600, 800) dtype=uint16 range=[778,805] | |
| coupling: [PASS] shape=(600, 800) dtype=uint16 range=[775,796] | |
| flange: [PASS] shape=(600, 800) dtype=uint16 range=[750,795] | |
| flange_large: [PASS] shape=(600, 800) dtype=uint16 range=[730,795] | |
| flange_medium: [PASS] shape=(600, 800) dtype=uint16 range=[750,797] | |
| flange_small: [PASS] shape=(600, 800) dtype=uint16 range=[765,812] | |
| gear: [PASS] shape=(600, 800) dtype=uint16 range=[773,797] | |
| gear_large: [PASS] shape=(600, 800) dtype=uint16 range=[752,794] | |
| gear_medium: [PASS] shape=(600, 800) dtype=uint16 range=[773,796] | |
| gear_small: [PASS] shape=(600, 800) dtype=uint16 range=[782,810] | |
| heat_sink: [PASS] shape=(600, 800) dtype=uint16 range=[754,844] | |
| hex_bolt: [PASS] shape=(600, 800) dtype=uint16 range=[791,799] | |
| l_bracket: [PASS] shape=(600, 800) dtype=uint16 range=[784,812] | |
| mounting_plate: [PASS] shape=(600, 800) dtype=uint16 range=[745,806] | |
| pipe_tee: [PASS] shape=(600, 800) dtype=uint16 range=[776,811] | |
| step_shaft: [PASS] shape=(600, 800) dtype=uint16 range=[780,797] | |
| valve_body: [PASS] shape=(600, 800) dtype=uint16 range=[759,838] | |
| ================================================================================ | |
| FINAL VERDICT | |
| ================================================================================ | |
| ALL CHECKS PASSED - Depth maps are fully ROS 16UC1 compliant | |
| Deployment checklist: | |
| 1. Use cv2.imread(path, cv2.IMREAD_UNCHANGED) -- NOT IMREAD_COLOR or IMREAD_GRAYSCALE | |
| 2. Use bridge.cv2_to_imgmsg(depth, encoding='16UC1') | |
| 3. Convert to meters: depth_m = depth_mm.astype(np.float32) / 1000.0 | |
| 4. Zero values mean 'no depth' (background) -- handled by depth_image_proc | |
| 5. depth_scale=1.0 in BOP metadata confirms mm units in PNG | |
| ================================================================================ |