diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-01 18:21:29 +0000 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-01 18:21:29 +0000 |
commit | f10845076e6430aef6c0b58b26050552dafe20ad (patch) | |
tree | 6b1b6b8759413b11b57bf1074cfde17f8fae5cba | |
parent | 34cd32f3f10d4c0b56077cc07bfe36bb959de810 (diff) |
video/opencv: workaround win11 trackhat camera bug
-rw-r--r-- | video-opencv/impl-camera.cpp | 30 | ||||
-rw-r--r-- | video-opencv/impl.hpp | 2 |
2 files changed, 21 insertions, 11 deletions
diff --git a/video-opencv/impl-camera.cpp b/video-opencv/impl-camera.cpp index 60a713d1..b11c5cd5 100644 --- a/video-opencv/impl-camera.cpp +++ b/video-opencv/impl-camera.cpp @@ -31,7 +31,7 @@ bool cam::is_open() return !!cap; } -void cam::set_exposure() +void cam::set_exposure(bool write) { auto e = *s.exposure_preset; if (e != exposure) @@ -41,7 +41,22 @@ void cam::set_exposure() case exposure_preset::far: cap->set(cv::CAP_PROP_EXPOSURE, -4); qDebug() << "far"; break; default: break; } - exposure = e; + + if (s.exposure_preset != exposure_preset::ignored) + { + constexpr struct { + int prop, value; + } props[] = { + { cv::CAP_PROP_AUTO_EXPOSURE, 0 }, + { cv::CAP_PROP_BRIGHTNESS, 0 }, + { cv::CAP_PROP_SHARPNESS, 3 }, + }; + for (const auto [prop, value] : props) + cap->set(prop, value); + } + + if (write) + exposure = e; } bool cam::start(info& args) @@ -60,12 +75,7 @@ bool cam::start(info& args) if (args.use_mjpeg) cap->set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G')); - if (s.exposure_preset != exposure_preset::ignored) - { - cap->set(cv::CAP_PROP_AUTO_EXPOSURE, 0); - //cap->set(cv::CAP_PROP_SHARPNESS, 0); - } - set_exposure(); + set_exposure(false); if (!cap->isOpened()) goto fail; @@ -85,8 +95,6 @@ bool cam::get_frame_() if (!is_open()) return false; - set_exposure(); - for (unsigned i = 0; i < 10; i++) { if (cap->read(mat)) @@ -105,6 +113,8 @@ 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 c142e2a5..8e61989e 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(); + void set_exposure(bool write); bool get_frame_(); |