From acd04e5f59df8bf6f360ea9691621299d990105e Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 27 Jun 2022 14:43:35 +0200 Subject: [PATCH] cleanup zoom --- selfdrive/ui/qt/onroad.cc | 6 +----- selfdrive/ui/qt/widgets/cameraview.cc | 7 ++----- selfdrive/ui/qt/widgets/cameraview.h | 8 ++++++-- selfdrive/ui/ui.h | 2 -- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 9a9d152676265e..ecd6d61471cf8b 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -412,11 +412,7 @@ void NvgWindow::updateFrameMat() { s->fb_w = w; s->fb_h = h; - auto intrinsic_matrix = s->wide_camera ? ecam_intrinsic_matrix : fcam_intrinsic_matrix; - float zoom = ZOOM / intrinsic_matrix.v[0]; - if (s->wide_camera) { - zoom *= 0.5; - } + // Apply transformation such that video pixel coordinates match video // 1) Put (0, 0) in the middle of the video // 2) Apply same scaling as video diff --git a/selfdrive/ui/qt/widgets/cameraview.cc b/selfdrive/ui/qt/widgets/cameraview.cc index b8c00bd8e43416..a80672f2c36992 100644 --- a/selfdrive/ui/qt/widgets/cameraview.cc +++ b/selfdrive/ui/qt/widgets/cameraview.cc @@ -187,11 +187,8 @@ void CameraViewWidget::updateFrameMat() { if (stream_type == VISION_STREAM_DRIVER) { frame_mat = get_driver_view_transform(w, h, stream_width, stream_height); } else { - auto intrinsic_matrix = stream_type == VISION_STREAM_WIDE_ROAD ? ecam_intrinsic_matrix : fcam_intrinsic_matrix; - float zoom = ZOOM / intrinsic_matrix.v[0]; - if (stream_type == VISION_STREAM_WIDE_ROAD) { - zoom *= 0.5; - } + intrinsic_matrix = (stream_type == VISION_STREAM_WIDE_ROAD) ? ecam_intrinsic_matrix : fcam_intrinsic_matrix; + zoom = (stream_type == VISION_STREAM_WIDE_ROAD) ? 2.5 : 1.1; // Project point at "infinity" to compute x and y offsets // to ensure this ends up in the middle of the screen diff --git a/selfdrive/ui/qt/widgets/cameraview.h b/selfdrive/ui/qt/widgets/cameraview.h index 6e51e6e38a3385..cc11ec2c277d0e 100644 --- a/selfdrive/ui/qt/widgets/cameraview.h +++ b/selfdrive/ui/qt/widgets/cameraview.h @@ -66,11 +66,15 @@ class CameraViewWidget : public QOpenGLWidget, protected QOpenGLFunctions { int stream_width = 0; int stream_height = 0; int stream_stride = 0; + std::atomic stream_type; + QThread *vipc_thread = nullptr; + + // Calibration float x_offset = 0; float y_offset = 0; + float zoom = 1.0; mat3 calibration = DEFAULT_CALIBRATION; - std::atomic stream_type; - QThread *vipc_thread = nullptr; + mat3 intrinsic_matrix = fcam_intrinsic_matrix; std::deque> frames; uint32_t draw_frame_id = 0; diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 08b92ebe485a7a..7364b81a40833b 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -22,8 +22,6 @@ const int footer_h = 280; const int UI_FREQ = 20; // Hz typedef cereal::CarControl::HUDControl::AudibleAlert AudibleAlert; -// TODO: choose based on frame input size -const float ZOOM = 2912.8; const mat3 DEFAULT_CALIBRATION = {{ 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0 }}; struct Alert {