ArmSoM
← All stories

Fixing Shifted RKNN Bounding Boxes After Letterboxing

On an ArmSoM Sige5 detector, boxes can drift vertically even when the model identifies the correct objects. Letterboxing introduces an offset that must be removed before mapping a prediction back onto the original frame. Save the actual scale and padding applied to each frame.

ArmSoM Sige5 single-board computer product photo

ArmSoM Sige5 single-board computer · ArmSoM

Invert the transform explicitly

For example, a 1280 by 720 image scaled to fit a 640 by 640 tensor becomes 640 by 360. With centered padding, 140 pixels sit above the content. A predicted y coordinate of 240 in tensor pixels corresponds to (240 − 140) / 0.5 = 200 in source pixels. Convert normalized outputs into tensor pixels first if the model uses normalized coordinates.

Stage

Vertical coordinate in the example

Source height

720 px

Resized image in tensor

360 px tall with 140 px above

Reported box edge

240 px from the tensor top

Original box edge

(240 − 140) ÷ 0.5 = 200 px

Add a corner case whose box touches the padded area. After the reverse transform, clip to the original frame bounds and check that the stored box still has a positive width and height.

Draw test boxes near each corner as well as the center. If the center looks correct but corner errors increase, check scale and coordinate convention. Use the recorded integer padding when the preprocessing library rounds an odd number of pixels.

What if the boxes line up only in the middle?

Use three detections in a saved frame, one near each side and one near the center. Compare the signed horizontal and vertical errors in source pixels. A nearly constant error suggests a missing offset, such as padding. An error that grows with distance from the origin suggests an incorrect scale. If boxes match on the saved source image but drift on the physical screen, investigate an additional crop or display transform in the preview.

Save the source frame, the resized tensor preview and the final annotated frame as a set. A later change to the camera aspect ratio can then be tested without having to reconstruct the original pipeline.

Reference material

ArmSoM Sige5 hardware documentation

Rockchip RKNN-Toolkit2 and model conversion resources

Related ArmSoM guide

RK3576 yolo deployment RKNN

Explore ArmSoM Sige5