From 5751650af3e6d71629fad4ff2643544171cff147 Mon Sep 17 00:00:00 2001 From: boltgolt Date: Thu, 28 Jun 2018 14:36:47 +0200 Subject: [PATCH] Added config option to set height and width of frame from #40 --- src/cli/test.py | 7 +++++++ src/compare.py | 10 +++++++++- src/config.ini | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/cli/test.py b/src/cli/test.py index ca34470..6321d98 100644 --- a/src/cli/test.py +++ b/src/cli/test.py @@ -24,6 +24,13 @@ video_capture = cv2.VideoCapture(int(config.get("video", "device_id"))) if config.get("video", "force_mjpeg") == "true": video_capture.set(cv2.CAP_PROP_FOURCC, 1196444237) +# Set the frame width and height if requested +if int(config.get("video", "frame_width")) != -1: + video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, int(config.get("video", "frame_width"))) + +if int(config.get("video", "frame_height")) != -1: + video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, int(config.get("video", "frame_height"))) + # 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 e248983..03d89dc 100644 --- a/src/compare.py +++ b/src/compare.py @@ -62,8 +62,16 @@ video_capture = cv2.VideoCapture(int(config.get("video", "device_id"))) # Force MJPEG decoding if true if config.get("video", "force_mjpeg") == "true": + # Set a magic number, will enable MJPEG but is badly documentated video_capture.set(cv2.CAP_PROP_FOURCC, 1196444237) +# Set the frame width and height if requested +if int(config.get("video", "frame_width")) != -1: + video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, int(config.get("video", "frame_width"))) + +if int(config.get("video", "frame_height")) != -1: + video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, int(config.get("video", "frame_height"))) + # Capture a single frame so the camera becomes active # This will let the camera adjust its light levels while we're importing for faster scanning video_capture.read() @@ -164,5 +172,5 @@ while True: print("Winning model: " + str(match_index) + " (\"" + models[match_index]["label"] + "\")") - # End peacegully + # End peacefully stop(0) diff --git a/src/config.ini b/src/config.ini index dfdd304..ef65786 100644 --- a/src/config.ini +++ b/src/config.ini @@ -38,6 +38,12 @@ max_height = 320 # YUYV raw frame deconding force_mjpeg = false +# Set the camera input profile to this width and height +# The largest profile will be used if set to -1 +# Automatically ignored if not a valid profile +frame_width = -1 +frame_height = -1 + # Because of flashing IR emitters, some frames can be completely unlit # Skip the frame if the lowest 1/8 of the histogram is above this percentage # of the total