Files
silver_pose/v2/internal/spike/preprocess_test.go
T

39 lines
1.1 KiB
Go

package spike
import "testing"
func TestLetterboxBGRToNCHWPlacesPixelInScaledImage(t *testing.T) {
// One bright BGR pixel in a 2:1 frame should be resized into the centred
// 640x320 image area. The remaining top/bottom area must stay black.
frame := []byte{0, 0, 0, 255, 0, 0}
input, err := LetterboxBGRToNCHW(frame, 2, 1, 640)
if err != nil {
t.Fatalf("LetterboxBGRToNCHW returned an error: %v", err)
}
const plane = 640 * 640
if got := len(input); got != 3*plane {
t.Fatalf("input length = %d, want %d", got, 3*plane)
}
if got := input[2*plane+159*640+320]; got != 0 {
t.Fatalf("top padding blue channel = %v, want 0", got)
}
if got := input[0*plane+320*640+320]; got != 0 {
t.Fatalf("red channel = %v, want 0", got)
}
if got := input[1*plane+320*640+320]; got != 0 {
t.Fatalf("green channel = %v, want 0", got)
}
if got := input[2*plane+320*640+320]; got != 1 {
t.Fatalf("blue channel = %v, want 1", got)
}
}
func TestLetterboxBGRToNCHWRejectsIncorrectFrameSize(t *testing.T) {
_, err := LetterboxBGRToNCHW([]byte{0}, 2, 1, 640)
if err == nil {
t.Fatal("LetterboxBGRToNCHW accepted a truncated BGR frame")
}
}