Files

40 lines
1.2 KiB
Go

package pose
import "testing"
func TestPreprocessBGRUsesUltralyticsPaddingAndRGBCHW(t *testing.T) {
// A 2x1 BGR frame letterboxes into a 4x4 tensor with one row of 114-gray
// padding above and below. The rightmost source pixel is pure blue in BGR.
frame := []byte{0, 0, 0, 255, 0, 0}
input, transform, err := PreprocessBGR(frame, 2, 1, 4)
if err != nil {
t.Fatalf("PreprocessBGR returned an error: %v", err)
}
if transform.ResizedWidth != 4 || transform.ResizedHeight != 2 || transform.PadTop != 1 {
t.Fatalf("unexpected transform: %+v", transform)
}
const plane = 16
padding := float32(114.0 / 255.0)
if got := input[2*plane+0]; got != padding {
t.Fatalf("top padding blue = %v, want %v", got, padding)
}
if got := input[0*plane+1*4+3]; got != 0 {
t.Fatalf("red channel = %v, want 0", got)
}
if got := input[1*plane+1*4+3]; got != 0 {
t.Fatalf("green channel = %v, want 0", got)
}
if got := input[2*plane+1*4+3]; got != 1 {
t.Fatalf("blue channel = %v, want 1", got)
}
}
func TestPreprocessBGRRejectsTruncatedFrame(t *testing.T) {
_, _, err := PreprocessBGR([]byte{0}, 2, 1, 4)
if err == nil {
t.Fatal("PreprocessBGR accepted a truncated BGR frame")
}
}