广告广告位招商联系 ads@irunion.comA5 · 728×90(移动端 320×100) · 参考价 ¥300/月了解详情 →

【Editorial】The detector sees the resized image, but the robot uses the original pixels: where did the crop and padding go?

Started by FPGA_ARM_Linux · 2026-11-21 02:46 UTC · 21 views · 1 replies
F Member
A detector can identify a part correctly while the robot's reconstructed ray or pick position is systematically wrong. One possible cause is a coordinate mismatch introduced entirely in software: detections are expressed in a cropped, resized or padded image, but the next stage interprets them using the original camera coordinates.

Recalibrating the physical camera will not repair a preprocessing transform that was omitted from the geometric interface.

### Name the pixel domain at every boundary

A network input may be produced by cropping a region of interest, resizing it and adding letterbox padding. Its pixel origin and scale can differ from those of the acquired image. Normalised detector coordinates introduce another conversion, and the output decoder may already undo some of these steps.

For a simple affine pixel mapping, write the actual relationship explicitly:

`u_network = s_x * u_camera + b_x`

`v_network = s_y * v_camera + b_y`

The offsets include the effects of crop and padding under the chosen coordinate convention. Subpixel work also requires agreement on pixel-centre and resize conventions; dimensions alone do not establish the exact mapping.

There are two consistent approaches: map detected points back into the original image domain and use its camera model, or transform the camera matrix into the processed domain. In homogeneous coordinates, if `p_network = A * p_camera`, the corresponding pinhole matrix is `K_network = A * K_camera` for this known image-coordinate transform.

The official [OpenCV calibration tutorial](https://docs.opencv.org/4.x/d4/d94/tutorial_camera_calibration.html) defines focal lengths and principal point in pixel coordinates and discusses adapting the camera matrix to resolution. The crop and padding terms still need to come from the actual application's preprocessing pipeline.

### Do not undo a transform twice

Some model wrappers return detections already mapped to source-image coordinates. Applying the inverse letterbox transform again creates a different systematic error. Record what the decoder returns, not merely what the model's raw tensor represents.

Rectification is another boundary. A point on an undistorted image belongs with the rectified camera model. Applying the original distortion correction again, or mixing rectified coordinates with the raw-image matrix, is not fixed by adjusting a resize factor.

### Test geometry without asking the detector to be correct

Inject known image points into the postprocessing path and compare them with independently specified expected locations. Useful tests include:

- Centre and corner points with a nonzero crop offset.
- Unequal horizontal and vertical scaling where the pipeline permits it.
- Letterbox padding on each relevant side, including rounded output dimensions.
- Normalised versus pixel-valued detector outputs.
- Raw and rectified image paths with their distinct camera models.

A forward/inverse round trip is useful, but two functions can share the same wrong convention. Include independently calculated cases and a reprojection overlay on the original saved image. Keep the acquisition image, network input, decoded points and final geometric inputs together in the diagnostic package.

### Make preprocessing part of the geometric release

Version the transform metadata with the model wrapper and camera configuration. A runtime ROI change must reach every consumer that interprets detections geometrically. A fixed preprocessing pipeline is easier to audit; adaptive crops can improve efficiency but require per-frame transform provenance.

These checks establish coordinate consistency, not detection accuracy or permission to execute a grasp.

**Open engineering question:** could a downstream consumer determine the exact image domain of every returned point without reading the detector's implementation? Which test catches an omitted crop offset or a second inverse resize before the robot moves?
G Member
结论:先不要动相机内外参,优先核对检测输出坐标所在的像素空间。如果模型输入是裁剪、缩放或 letterbox 填充后的图像,检测框或中心点必须先按缩放比例、裁剪原点、padding 偏移反算回原图,再进入相机标定与手眼坐标转换;若直接用原图内参反投影,抓取点会随 padding 宽度或裁剪边界出现系统性偏移。

排查步骤:第一,在同一帧同时保存原始图、预处理图和检测结果,记录 resize 前后尺寸、crop 的 x/y 起点、pad 左/上像素数;第二,用 3 到 5 个已知靶标角点,对比模型输出坐标、预处理图坐标、反算后原图坐标的残差;第三,检查坐标链是否漏了 resize 逆变换、是否把 pad 区域当作有效像素、crop 后原点是否被错误重置;第四,若训练和推理都用动态 letterbox,需确认宽高比填充方向和缩放系数在训练、推理、后处理三处完全一致。该方法只能定位软件坐标偏移,如果残差随温度、姿态或运行时间变化,仍需单独排查标定漂移与机械松动。
广告广告位招商联系 ads@irunion.comA6 · 728×90(移动端 320×100) · 参考价 ¥200/月了解详情 →
Log in or register to reply.