use ConfigParser.get*() functions; move config reading out of maincycle; drop unused import
This commit is contained in:
parent
b4ecafe61c
commit
5b6ca8525c
1 changed files with 14 additions and 10 deletions
|
|
@ -12,7 +12,6 @@ import cv2
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import math
|
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
# Read config from disk
|
# Read config from disk
|
||||||
|
|
@ -61,16 +60,18 @@ timings.append(time.time())
|
||||||
video_capture = cv2.VideoCapture(config.get("video", "device_path"))
|
video_capture = cv2.VideoCapture(config.get("video", "device_path"))
|
||||||
|
|
||||||
# Force MJPEG decoding if true
|
# Force MJPEG decoding if true
|
||||||
if config.get("video", "force_mjpeg") == "true":
|
if config.getboolean("video", "force_mjpeg"):
|
||||||
# Set a magic number, will enable MJPEG but is badly documentated
|
# Set a magic number, will enable MJPEG but is badly documentated
|
||||||
video_capture.set(cv2.CAP_PROP_FOURCC, 1196444237)
|
video_capture.set(cv2.CAP_PROP_FOURCC, 1196444237)
|
||||||
|
|
||||||
# Set the frame width and height if requested
|
# Set the frame width and height if requested
|
||||||
if int(config.get("video", "frame_width")) != -1:
|
fw = config.getint("video", "frame_width")
|
||||||
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, int(config.get("video", "frame_width")))
|
fh = config.getint("video", "frame_height")
|
||||||
|
if fw != -1:
|
||||||
|
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, fw)
|
||||||
|
|
||||||
if int(config.get("video", "frame_height")) != -1:
|
if fh != -1:
|
||||||
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, int(config.get("video", "frame_height")))
|
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, fh)
|
||||||
|
|
||||||
# Capture a single frame so the camera becomes active
|
# 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
|
# This will let the camera adjust its light levels while we're importing for faster scanning
|
||||||
|
|
@ -88,12 +89,15 @@ max_height = int(config.get("video", "max_height"))
|
||||||
|
|
||||||
# Start the read loop
|
# Start the read loop
|
||||||
frames = 0
|
frames = 0
|
||||||
|
timeout = config.getint("video", "timout")
|
||||||
|
dark_threshold = config.getfloat("video", "dark_threshold")
|
||||||
|
end_report = config.getboolean("debug", "end_report")
|
||||||
while True:
|
while True:
|
||||||
# Increment the frame count every loop
|
# Increment the frame count every loop
|
||||||
frames += 1
|
frames += 1
|
||||||
|
|
||||||
# Stop if we've exceded the time limit
|
# Stop if we've exceded the time limit
|
||||||
if time.time() - timings[3] > int(config.get("video", "timout")):
|
if time.time() - timings[3] > timeout:
|
||||||
stop(11)
|
stop(11)
|
||||||
|
|
||||||
# Grab a single frame of video
|
# Grab a single frame of video
|
||||||
|
|
@ -111,7 +115,7 @@ while True:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Scrip the frame if it exceeds the threshold
|
# Scrip the frame if it exceeds the threshold
|
||||||
if float(hist[0]) / hist_total * 100 > float(config.get("video", "dark_threshold")):
|
if float(hist[0]) / hist_total * 100 > dark_threshold:
|
||||||
dark_tries += 1
|
dark_tries += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -146,12 +150,12 @@ while True:
|
||||||
timings.append(time.time())
|
timings.append(time.time())
|
||||||
|
|
||||||
# If set to true in the config, print debug text
|
# If set to true in the config, print debug text
|
||||||
if config.get("debug", "end_report") == "true":
|
if end_report:
|
||||||
def print_timing(label, offset):
|
def print_timing(label, offset):
|
||||||
"""Helper function to print a timing from the list"""
|
"""Helper function to print a timing from the list"""
|
||||||
print(" " + label + ": " + str(round((timings[1 + offset] - timings[offset]) * 1000)) + "ms")
|
print(" " + label + ": " + str(round((timings[1 + offset] - timings[offset]) * 1000)) + "ms")
|
||||||
|
|
||||||
print("Time spend")
|
print("Time spent")
|
||||||
print_timing("Starting up", 0)
|
print_timing("Starting up", 0)
|
||||||
print_timing("Opening the camera", 1)
|
print_timing("Opening the camera", 1)
|
||||||
print_timing("Importing face_recognition", 2)
|
print_timing("Importing face_recognition", 2)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue