From db41f531ab84aa447f4cbd0f134dc97bed373a49 Mon Sep 17 00:00:00 2001 From: ZwX1616 Date: Tue, 19 Mar 2024 21:13:54 -0700 Subject: [PATCH] box defs --- system/camerad/cameras/camera_common.cc | 6 +++--- system/camerad/cameras/camera_common.h | 2 +- system/camerad/cameras/camera_qcom2.cc | 7 ++++--- system/camerad/sensors/ar0231.cc | 9 +++++++++ system/camerad/sensors/os04c10.cc | 9 +++++++++ system/camerad/sensors/ox03c10.cc | 9 +++++++++ system/camerad/sensors/sensor.h | 3 +++ 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/system/camerad/cameras/camera_common.cc b/system/camerad/cameras/camera_common.cc index ab9d9529a5..187d3e8aea 100644 --- a/system/camerad/cameras/camera_common.cc +++ b/system/camerad/cameras/camera_common.cc @@ -269,14 +269,14 @@ static void publish_thumbnail(PubMaster *pm, const CameraBuf *b) { pm->send("thumbnail", msg); } -float set_exposure_target(const CameraBuf *b, int x_start, int x_end, int x_skip, int y_start, int y_end, int y_skip) { +float set_exposure_target(const CameraBuf *b, int x_start, int x_len, int x_skip, int y_start, int y_len, int y_skip) { int lum_med; uint32_t lum_binning[256] = {0}; const uint8_t *pix_ptr = b->cur_yuv_buf->y; unsigned int lum_total = 0; - for (int y = y_start; y < y_end; y += y_skip) { - for (int x = x_start; x < x_end; x += x_skip) { + for (int y = y_start; y < y_start + y_len; y += y_skip) { + for (int x = x_start; x < x_start + x_len; x += x_skip) { uint8_t lum = pix_ptr[(y * b->rgb_width) + x]; lum_binning[lum]++; lum_total += 1; diff --git a/system/camerad/cameras/camera_common.h b/system/camerad/cameras/camera_common.h index f98691ef00..2bdc4f8b17 100644 --- a/system/camerad/cameras/camera_common.h +++ b/system/camerad/cameras/camera_common.h @@ -75,7 +75,7 @@ typedef void (*process_thread_cb)(MultiCameraState *s, CameraState *c, int cnt); void fill_frame_data(cereal::FrameData::Builder &framed, const FrameMetadata &frame_data, CameraState *c); kj::Array get_raw_frame_image(const CameraBuf *b); -float set_exposure_target(const CameraBuf *b, int x_start, int x_end, int x_skip, int y_start, int y_end, int y_skip); +float set_exposure_target(const CameraBuf *b, int x_start, int x_len, int x_skip, int y_start, int y_len, int y_skip); std::thread start_process_thread(MultiCameraState *cameras, CameraState *cs, process_thread_cb callback); void cameras_init(VisionIpcServer *v, MultiCameraState *s, cl_device_id device_id, cl_context ctx); diff --git a/system/camerad/cameras/camera_qcom2.cc b/system/camerad/cameras/camera_qcom2.cc index 3191b821ac..37d8809427 100644 --- a/system/camerad/cameras/camera_qcom2.cc +++ b/system/camerad/cameras/camera_qcom2.cc @@ -902,7 +902,8 @@ void CameraState::set_camera_exposure(float grey_frac) { } static void process_driver_camera(MultiCameraState *s, CameraState *c, int cnt) { - c->set_camera_exposure(set_exposure_target(&c->buf, 96, 1832, 2, 242, 1148, 4)); + const auto ae_xywh = c->ci->driver_ae_xywh; + c->set_camera_exposure(set_exposure_target(&c->buf, ae_xywh[0], ae_xywh[2], 2, ae_xywh[1], ae_xywh[3], 4)); MessageBuilder msg; auto framed = msg.initEvent().initDriverCameraState(); @@ -927,9 +928,9 @@ void process_road_camera(MultiCameraState *s, CameraState *c, int cnt) { c->ci->processRegisters(c, framed); s->pm->send(c == &s->road_cam ? "roadCameraState" : "wideRoadCameraState", msg); - const auto [x, y, w, h] = (c == &s->wide_road_cam) ? std::tuple(96, 250, 1734, 524) : std::tuple(96, 160, 1734, 986); + const auto ae_xywh = (c == &s->wide_road_cam) ? c->ci->wide_ae_xywh : c->ci->road_ae_xywh; const int skip = 2; - c->set_camera_exposure(set_exposure_target(b, x, x + w, skip, y, y + h, skip)); + c->set_camera_exposure(set_exposure_target(b, ae_xywh[0], ae_xywh[2], skip, ae_xywh[1], ae_xywh[3], skip)); } void cameras_run(MultiCameraState *s) { diff --git a/system/camerad/sensors/ar0231.cc b/system/camerad/sensors/ar0231.cc index 5c4934fb61..3c257624aa 100644 --- a/system/camerad/sensors/ar0231.cc +++ b/system/camerad/sensors/ar0231.cc @@ -17,6 +17,10 @@ const float sensor_analog_gains_AR0231[] = { 5.0 / 4.0, 6.0 / 4.0, 6.0 / 3.0, 7.0 / 3.0, // 8, 9, 10, 11 7.0 / 2.0, 8.0 / 2.0, 8.0 / 1.0}; // 12, 13, 14, 15 = bypass +const int ar0231_road_ae_xywh[] = {96, 160, 1734, 986}; +const int ar0231_wide_ae_xywh[] = {96, 250, 1734, 524}; +const int ar0231_driver_ae_xywh[] = {96, 242, 1736, 906}; + std::map> ar0231_build_register_lut(CameraState *c, uint8_t *data) { // This function builds a lookup table from register address, to a pair of indices in the // buffer where to read this address. The buffer contains padding bytes, @@ -116,6 +120,11 @@ AR0231::AR0231() { min_ev = exposure_time_min * sensor_analog_gains[analog_gain_min_idx]; max_ev = exposure_time_max * dc_gain_factor * sensor_analog_gains[analog_gain_max_idx]; target_grey_factor = 1.0; + for (int i = 0; i < 4; i++) { + road_ae_xywh[i] = ar0231_road_ae_xywh[i]; + wide_ae_xywh[i] = ar0231_wide_ae_xywh[i]; + driver_ae_xywh[i] = ar0231_driver_ae_xywh[i]; + } } void AR0231::processRegisters(CameraState *c, cereal::FrameData::Builder &framed) const { diff --git a/system/camerad/sensors/os04c10.cc b/system/camerad/sensors/os04c10.cc index a13eb303a2..c51ed12a1b 100644 --- a/system/camerad/sensors/os04c10.cc +++ b/system/camerad/sensors/os04c10.cc @@ -16,6 +16,10 @@ const uint32_t os04c10_analog_gains_reg[] = { 0x2E0, 0x300, 0x320, 0x340, 0x380, 0x3C0, 0x400, 0x440, 0x480, 0x4C0, 0x500, 0x540, 0x580, 0x5C0, 0x600, 0x640, 0x680, 0x6C0, 0x700, 0x740, 0x780, 0x7C0}; +const int os04c10_road_ae_xywh[] = {44, 50, 2600, 1470}; +const int os04c10_wide_ae_xywh[] = {44, 194, 2600, 838}; +const int os04c10_driver_ae_xywh[] = {44, 180, 2600, 1340}; + } // namespace OS04C10::OS04C10() { @@ -56,6 +60,11 @@ OS04C10::OS04C10() { min_ev = (exposure_time_min) * sensor_analog_gains[analog_gain_min_idx]; max_ev = exposure_time_max * dc_gain_factor * sensor_analog_gains[analog_gain_max_idx]; target_grey_factor = 0.01; + for (int i = 0; i < 4; i++) { + road_ae_xywh[i] = os04c10_road_ae_xywh[i]; + wide_ae_xywh[i] = os04c10_wide_ae_xywh[i]; + driver_ae_xywh[i] = os04c10_driver_ae_xywh[i]; + } } std::vector OS04C10::getExposureRegisters(int exposure_time, int new_exp_g, bool dc_gain_enabled) const { diff --git a/system/camerad/sensors/ox03c10.cc b/system/camerad/sensors/ox03c10.cc index c74274872f..83e3ecb60a 100644 --- a/system/camerad/sensors/ox03c10.cc +++ b/system/camerad/sensors/ox03c10.cc @@ -16,6 +16,10 @@ const uint32_t ox03c10_analog_gains_reg[] = { 0x5C0, 0x600, 0x640, 0x680, 0x700, 0x780, 0x800, 0x880, 0x900, 0x980, 0xA00, 0xA80, 0xB00, 0xB80, 0xC00, 0xC80, 0xD00, 0xD80, 0xE00, 0xE80, 0xF00, 0xF80}; +const int ox03c10_road_ae_xywh[] = {96, 160, 1734, 986}; +const int ox03c10_wide_ae_xywh[] = {96, 250, 1734, 524}; +const int ox03c10_driver_ae_xywh[] = {96, 242, 1736, 906}; + const uint32_t VS_TIME_MIN_OX03C10 = 1; const uint32_t VS_TIME_MAX_OX03C10 = 34; // vs < 35 @@ -57,6 +61,11 @@ OX03C10::OX03C10() { min_ev = (exposure_time_min + VS_TIME_MIN_OX03C10) * sensor_analog_gains[analog_gain_min_idx]; max_ev = exposure_time_max * dc_gain_factor * sensor_analog_gains[analog_gain_max_idx]; target_grey_factor = 0.01; + for (int i = 0; i < 4; i++) { + road_ae_xywh[i] = ox03c10_road_ae_xywh[i]; + wide_ae_xywh[i] = ox03c10_wide_ae_xywh[i]; + driver_ae_xywh[i] = ox03c10_driver_ae_xywh[i]; + } } std::vector OX03C10::getExposureRegisters(int exposure_time, int new_exp_g, bool dc_gain_enabled) const { diff --git a/system/camerad/sensors/sensor.h b/system/camerad/sensors/sensor.h index d97fd32a9c..2d20f4086f 100644 --- a/system/camerad/sensors/sensor.h +++ b/system/camerad/sensors/sensor.h @@ -48,6 +48,9 @@ public: float target_grey_factor; float min_ev; float max_ev; + int road_ae_xywh[4]; + int wide_ae_xywh[4]; + int driver_ae_xywh[4]; bool data_word; uint32_t probe_reg_addr;