From 69398a3d1502fb1e785e0207e78c6d84dcc81cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6ssler?= Date: Wed, 5 Feb 2020 14:12:04 +0000 Subject: [PATCH] video_stream: implement auto focus --- cfg/VideoStream.cfg | 2 ++ src/video_stream.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/cfg/VideoStream.cfg b/cfg/VideoStream.cfg index b92b7e9..e2fcc1d 100755 --- a/cfg/VideoStream.cfg +++ b/cfg/VideoStream.cfg @@ -29,6 +29,8 @@ gen.add("hue", double_t, LEVEL.RUNNING, "Target hue", 0.5, 0.0, 1.0) gen.add("saturation", double_t, LEVEL.RUNNING, "Target saturation", 0.64, 0.0, 1.0) gen.add("auto_exposure", bool_t, LEVEL.RUNNING, "Target auto exposure", True) gen.add("exposure", double_t, LEVEL.RUNNING, "Target exposure", 0.5, 0.0, 1.0) +gen.add("auto_focus", bool_t, LEVEL.RUNNING, "Target auto focus", True) +gen.add("focus", double_t, LEVEL.RUNNING, "Target focus", 0.5, 0.0, 1.0) gen.add("loop_videofile", bool_t, LEVEL.RUNNING, "Loop videofile", False) gen.add("reopen_on_read_failure", bool_t, LEVEL.RUNNING, "Re-open camera device on read failure", False) gen.add("output_encoding", str_t, LEVEL.NORMAL, "Output encoding", "bgr8") diff --git a/src/video_stream.cpp b/src/video_stream.cpp index 053663a..777ad8a 100644 --- a/src/video_stream.cpp +++ b/src/video_stream.cpp @@ -287,6 +287,14 @@ virtual void subscribe() { cap->set(cv::CAP_PROP_HUE, latest_config.hue); cap->set(cv::CAP_PROP_SATURATION, latest_config.saturation); + if (latest_config.auto_focus) { + cap->set(cv::CAP_PROP_AUTOFOCUS, 1); + latest_config.exposure = 0.5; + } else { + cap->set(cv::CAP_PROP_AUTOFOCUS, 0); + cap->set(cv::CAP_PROP_FOCUS, latest_config.focus); + } + if (latest_config.auto_exposure) { cap->set(cv::CAP_PROP_AUTO_EXPOSURE, 0.75); latest_config.exposure = 0.5;