dmonitoringmodeld: fix black padding not black after libyuv.I420Scale (#22971)

* true black

* set black once

* move def

* add commnet

* Update selfdrive/modeld/models/dmonitoring.cc

* Update selfdrive/modeld/models/dmonitoring.cc

* Update selfdrive/modeld/models/dmonitoring.cc

* Update selfdrive/modeld/models/dmonitoring.cc

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
pull/22987/head
ZwX1616 3 years ago committed by GitHub
parent 148c739ec7
commit 80940b9844
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      selfdrive/modeld/models/dmonitoring.cc

@ -13,11 +13,30 @@
#define MODEL_HEIGHT 640
#define FULL_W 852 // should get these numbers from camerad
template <class T>
static inline T *get_buffer(std::vector<T> &buf, const size_t size) {
if (buf.size() < size) buf.resize(size);
return buf.data();
}
static inline void init_yuv_buf(std::vector<uint8_t> &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 <class T>
static inline T *get_buffer(std::vector<T> &buf, const size_t size) {
if (buf.size() < size) buf.resize(size);
return buf.data();
}
static inline auto get_yuv_buf(std::vector<uint8_t> &buf, const int width, int height) {
uint8_t *y = get_buffer(buf, width * height * 3 / 2);
uint8_t *u = y + width * height;

Loading…
Cancel
Save