diff --git a/selfdrive/modeld/models/dmonitoring.cc b/selfdrive/modeld/models/dmonitoring.cc index 719a9d8a07..9d87e320af 100644 --- a/selfdrive/modeld/models/dmonitoring.cc +++ b/selfdrive/modeld/models/dmonitoring.cc @@ -13,11 +13,30 @@ #define MODEL_HEIGHT 640 #define FULL_W 852 // should get these numbers from camerad +template +static inline T *get_buffer(std::vector &buf, const size_t size) { + if (buf.size() < size) buf.resize(size); + return buf.data(); +} + +static inline void init_yuv_buf(std::vector &buf, const int width, int height) { + uint8_t *y = get_buffer(buf, width * height * 3 / 2); + uint8_t *u = y + width * height; + uint8_t *v = u + (width / 2) * (height / 2); + + // needed on comma two to make the padded border black + // equivalent to RGB(0,0,0) in YUV space + memset(y, 16, width * height); + memset(u, 128, (width / 2) * (height / 2)); + memset(v, 128, (width / 2) * (height / 2)); +} + void dmonitoring_init(DMonitoringModelState* s) { s->is_rhd = Params().getBool("IsRHD"); for (int x = 0; x < std::size(s->tensor); ++x) { s->tensor[x] = (x - 128.f) * 0.0078125f; } + init_yuv_buf(s->resized_buf, MODEL_WIDTH, MODEL_HEIGHT); #ifdef USE_ONNX_MODEL s->m = new ONNXModel("../../models/dmonitoring_model.onnx", &s->output[0], OUTPUT_SIZE, USE_DSP_RUNTIME); @@ -26,12 +45,6 @@ void dmonitoring_init(DMonitoringModelState* s) { #endif } -template -static inline T *get_buffer(std::vector &buf, const size_t size) { - if (buf.size() < size) buf.resize(size); - return buf.data(); -} - static inline auto get_yuv_buf(std::vector &buf, const int width, int height) { uint8_t *y = get_buffer(buf, width * height * 3 / 2); uint8_t *u = y + width * height;