From 0c4992ffaf51e281a7c11e2dfd66aa71de85fec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Aceda=C5=84ski?= Date: Mon, 11 Mar 2019 00:21:54 +0100 Subject: [PATCH] Manual exposure support for OpenCV --- src/cli/test.py | 11 +++++++++++ src/compare.py | 11 +++++++++++ src/config.ini | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/src/cli/test.py b/src/cli/test.py index c3cbebb..346e465 100644 --- a/src/cli/test.py +++ b/src/cli/test.py @@ -37,6 +37,17 @@ if fw != -1: if fh != -1: video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, fh) +# Disable autoexposure +exposure = config.getint("video", "exposure", fallback=-1) +if exposure != -1: + # For a strange reason on some cameras (e.g. Lenoxo X1E) + # setting manual exposure works only after a couple frames + # are captured. + for i in range(6): + video_capture.grab() + video_capture.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1.0) # 1 = Manual + video_capture.set(cv2.CAP_PROP_EXPOSURE, 167.0) + # Let the user know what's up print(""" Opening a window with a test feed diff --git a/src/compare.py b/src/compare.py index 3f472b8..97d1027 100644 --- a/src/compare.py +++ b/src/compare.py @@ -144,6 +144,17 @@ if fh != -1: # This will let the camera adjust its light levels while we're importing for faster scanning video_capture.grab() +# Disable autoexposure +exposure = config.getint("video", "exposure", fallback=-1) +if exposure != -1: + # For a strange reason on some cameras (e.g. Lenoxo X1E) + # setting manual exposure works only after a couple frames + # are captured. + for i in range(5): + video_capture.grab() + video_capture.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1.0) # 1 = Manual + video_capture.set(cv2.CAP_PROP_EXPOSURE, 167.0) + # Note the time it took to open the camera timings["ic"] = time.time() - timings["ic"] diff --git a/src/config.ini b/src/config.ini index 34d5685..c306410 100644 --- a/src/config.ini +++ b/src/config.ini @@ -70,6 +70,11 @@ device_format = v4l2 # OPENCV only. force_mjpeg = false +# Specify exposure value explicitly. This disables autoexposure. +# Use qv4l2 to determine an appropriate value. +# OPENCV only. +exposure = -1 + [debug] # Show a short but detailed diagnostic report in console end_report = false