feat(v2): add fall event regression engine

This commit is contained in:
ila
2026-07-22 16:18:16 +08:00
parent 258fa49259
commit 1298369054
22 changed files with 1214 additions and 92 deletions
+6 -35
View File
@@ -1,43 +1,14 @@
package spike
import "fmt"
import "silverpose/v2/internal/pose"
// LetterboxBGRToNCHW converts one packed BGR frame into the RGB, CHW,
// float32 tensor expected by the locked 640-pixel YOLO pose ONNX model.
//
// It intentionally uses nearest-neighbour scaling for this Spike. T-303
// must replace or validate this preprocessing against the V1 implementation
// before it becomes the V2 production preprocessing path.
// T-303 aligned the implementation with the fixed-shape Ultralytics
// letterbox used by the V1/ONNX baseline. New V2 code should import the pose
// package directly to retain the returned coordinate transform.
func LetterboxBGRToNCHW(frame []byte, width, height, target int) ([]float32, error) {
if width <= 0 || height <= 0 || target <= 0 {
return nil, fmt.Errorf("frame width, height and target must be positive")
}
if len(frame) != width*height*3 {
return nil, fmt.Errorf("BGR frame length = %d, want %d", len(frame), width*height*3)
}
scaleWidth := target
scaleHeight := height * target / width
if scaleHeight > target {
scaleHeight = target
scaleWidth = width * target / height
}
padX := (target - scaleWidth) / 2
padY := (target - scaleHeight) / 2
plane := target * target
input := make([]float32, 3*plane)
for y := 0; y < scaleHeight; y++ {
sourceY := y * height / scaleHeight
for x := 0; x < scaleWidth; x++ {
sourceX := x * width / scaleWidth
source := (sourceY*width + sourceX) * 3
destination := (padY+y)*target + padX + x
input[destination] = float32(frame[source+2]) / 255.0
input[plane+destination] = float32(frame[source+1]) / 255.0
input[2*plane+destination] = float32(frame[source]) / 255.0
}
}
return input, nil
input, _, err := pose.PreprocessBGR(frame, width, height, target)
return input, err
}