diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-11 15:35:53 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-11 15:40:37 +0100 |
commit | 98edf8f8da40b7a16af6bf135f47edb1a7e5f04c (patch) | |
tree | 7858ea9d20692fc51ca9757b1e03857b64939412 | |
parent | 47bc9e57ad55128ae0a5bf206f3931a3aa4f5dc1 (diff) |
video/opencv: fix exposure reset
-rw-r--r-- | video-opencv/impl-camera.cpp | 49 | ||||
-rw-r--r-- | video-opencv/impl.hpp | 4 |
2 files changed, 33 insertions, 20 deletions
diff --git a/video-opencv/impl-camera.cpp b/video-opencv/impl-camera.cpp index 5c7f736d..c18c35ba 100644 --- a/video-opencv/impl-camera.cpp +++ b/video-opencv/impl-camera.cpp @@ -31,27 +31,31 @@ bool cam::is_open() return !!cap; } -void cam::set_exposure(bool write) +void cam::set_exposure(exposure_preset e) { - auto e = *s.exposure; - if (e != exposure) - switch (e) - { - case exposure_preset::near: cap->set(cv::CAP_PROP_EXPOSURE, -6); qDebug() << "near"; break; - case exposure_preset::medium: cap->set(cv::CAP_PROP_EXPOSURE, -5); qDebug() << "medium"; break; - case exposure_preset::far: cap->set(cv::CAP_PROP_EXPOSURE, -4); qDebug() << "far"; break; - default: break; - } + switch (e) + { + using enum exposure_preset; + case near: cap->set(cv::CAP_PROP_EXPOSURE, -6); qDebug() << "near"; break; + case medium: cap->set(cv::CAP_PROP_EXPOSURE, -5); qDebug() << "medium"; break; + case far: cap->set(cv::CAP_PROP_EXPOSURE, -4); qDebug() << "far"; break; + default: break; + } - if (s.exposure != exposure_preset::ignored) + switch (e) { + using enum exposure_preset; + default: + break; + case near: + case medium: + case far: { constexpr struct { int prop, value; } props[] = { { cv::CAP_PROP_AUTO_EXPOSURE, 0 }, { cv::CAP_PROP_BRIGHTNESS, 0 }, { cv::CAP_PROP_SHARPNESS, 3 }, - { cv::CAP_PROP_AUTO_EXPOSURE, 0 }, { cv::CAP_PROP_BRIGHTNESS, 0 }, { cv::CAP_PROP_SHARPNESS, 3 }, { cv::CAP_PROP_CONTRAST, 32 }, @@ -65,9 +69,7 @@ void cam::set_exposure(bool write) for (const auto [prop, value] : props) cap->set(prop, value); } - - if (write) - exposure = e; + } } bool cam::start(info& args) @@ -86,7 +88,7 @@ bool cam::start(info& args) if (args.use_mjpeg) cap->set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G')); - set_exposure(false); + set_exposure(*s.exposure); if (!cap->isOpened()) goto fail; @@ -106,6 +108,19 @@ bool cam::get_frame_() if (!is_open()) return false; + auto e = *s.exposure; + if (e != exposure) + { + writes = 2; + exposure = e; + set_exposure(e); + } + else if (writes > 0) + { + writes--; + set_exposure(e); + } + for (unsigned i = 0; i < 10; i++) { if (cap->read(mat)) @@ -124,8 +139,6 @@ bool cam::get_frame_() portable::sleep(50); } - set_exposure(true); - return false; } diff --git a/video-opencv/impl.hpp b/video-opencv/impl.hpp index 8e61989e..8de82640 100644 --- a/video-opencv/impl.hpp +++ b/video-opencv/impl.hpp @@ -44,7 +44,7 @@ static constexpr int video_capture_backend = bool is_open() override; std::tuple<const frame&, bool> get_frame() override; bool show_dialog() override; - void set_exposure(bool write); + void set_exposure(exposure_preset e); bool get_frame_(); @@ -53,7 +53,7 @@ static constexpr int video_capture_backend = std::optional<cv::VideoCapture> cap; cv::Mat mat; frame frame_; - int idx = -1; + int idx = -1, writes = 0; exposure_preset exposure = exposure_preset::ignored; }; |