From 8b20908fe30bb004ebbb6913d6e371f02505e3b3 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 1/2] 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 ed9b908..7617063 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 88ff61e..b8a160a 100644 --- a/src/video_stream.cpp +++ b/src/video_stream.cpp @@ -293,6 +293,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.focus = 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; From 190498a2d0af1964e6f5df638823d657136841a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6ssler?= Date: Mon, 10 May 2021 12:02:15 +0200 Subject: [PATCH 2/2] README: add documentation for auto_focus param --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7998e1a..8d9c49c 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ You can use any input that OpenCV on your system accepts, e.g.: Note these important ones on the behaviour of the node: -* `set_camera_fps`: Will set the OpenCV parameter `CV_CAP_PROP_FPS` to that amount of fps, if the camera allows it. +* `set_camera_fps`: Will set the OpenCV parameter `CV_CAP_PROP_FPS` to that amount of fps, if the camera allows it. Does nothing on video streams or video files. * `buffer_queue_size`: Will set the size of the buffer of images read from the capturing device. We read @@ -70,9 +70,9 @@ So if you want the very latest image published from a camera, set `buffer_queue_ If you want to publish all images (don't drop any and you don't mind some possible delay from real time), set `buffer_queue_size` big enough for your case (1000?), `set_camera_fps` and `fps` to whatever FPS it has. - + The rest of the parameters explained, even though they are pretty self explanatory: - + * `camera_name`: node name and ros graph name. All topics will hang from this e.g.: /camera_name/. * `video_stream_provider`: A number for the /dev/videoX device, e.g.: 0 for /dev/video0. A string for a path for a video file, e.g.: /home/user/Videos/myvideo.avi or a url of a video stream e.g.: rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov and http://10.68.0.6/mjpg/video.mjpg. @@ -84,6 +84,7 @@ If you want to publish all images (don't drop any and you don't mind some possib * `width` and `height`: force a width and height to the capturing device (if it allows), 0 means no forcing. * `start_frame`: if the provider is a video file, set the start frame of video. * `stop_frame`: if the provider is a video file, set the stop frame of video. `-1` means the end of the video. Also setting `stop_frame = start_frame + 1` can publish a single frame with a certain rate. + * `auto_focus`: enable/disable auto focus on capture devices that support auto focus, disable auto focus if you want to use the device tag tracking # Extras @@ -100,4 +101,3 @@ And you'll see an output like: Correctly opened resource, starting to show feed. With an OpenCV image show window showing the stream (which should close when pressing ESC, or Control+C the shell). -