mirror of
https://github.com/boltgolt/howdy.git
synced 2024-09-19 09:51:19 +02:00
Reenfocing code style
This commit is contained in:
parent
b11c8188e6
commit
a04b33d01b
5 changed files with 46 additions and 38 deletions
|
@ -3,7 +3,6 @@
|
|||
# Import required modules
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import builtins
|
||||
import fileinput
|
||||
import configparser
|
||||
|
|
|
@ -49,7 +49,9 @@ def print_text(line_number, text):
|
|||
"""Print the status text by line number"""
|
||||
cv2.putText(overlay, text, (10, height - 10 - (10 * line_number)), cv2.FONT_HERSHEY_SIMPLEX, .3, (0, 255, 0), 0, cv2.LINE_AA)
|
||||
|
||||
|
||||
use_cnn = config.getboolean('core', 'use_cnn', fallback=False)
|
||||
|
||||
if use_cnn:
|
||||
face_detector = dlib.cnn_face_detection_model_v1(
|
||||
path + '/../dlib-data/mmod_human_face_detector.dat'
|
||||
|
|
|
@ -47,6 +47,7 @@ def init_detector(lock):
|
|||
timings["ll"] = time.time() - timings["ll"]
|
||||
lock.release()
|
||||
|
||||
|
||||
# Make sure we were given an username to tast against
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit(12)
|
||||
|
@ -149,17 +150,17 @@ while True:
|
|||
|
||||
# Stop if we've exceded the time limit
|
||||
if time.time() - timings["fr"] > timeout:
|
||||
if (dark_tries == valid_frames ):
|
||||
if (dark_tries == valid_frames):
|
||||
print("All frames were too dark, please check dark_threshold in config")
|
||||
print("Average darkness: " + str(dark_running_total / valid_frames) + ", Threshold: " + str(dark_threshold))
|
||||
sys.exit(13)
|
||||
sys.exit(13)
|
||||
else:
|
||||
sys.exit(11)
|
||||
sys.exit(11)
|
||||
|
||||
# Grab a single frame of video
|
||||
frame, gsframe = video_capture.read_frame()
|
||||
|
||||
gsframe = clahe.apply(gsframe)
|
||||
gsframe = clahe.apply(gsframe)
|
||||
|
||||
# Create a histogram of the image with 8 values
|
||||
hist = cv2.calcHist([gsframe], [0], None, [8], [0, 256])
|
||||
|
|
|
@ -37,7 +37,7 @@ timeout = 4
|
|||
|
||||
# The path of the device to capture frames from
|
||||
# Should be set automatically by an installer if your distro has one
|
||||
device_path = none
|
||||
device_path = "/dev/video1"
|
||||
|
||||
# Scale down the video feed to this maximum height
|
||||
# Speeds up face recognition but can make it less precise
|
||||
|
|
|
@ -7,21 +7,22 @@ import cv2
|
|||
import os
|
||||
import sys
|
||||
|
||||
"""
|
||||
Class to provide boilerplate code to build a video recorder with the
|
||||
correct settings from the config file.
|
||||
|
||||
The internal recorder can be accessed with 'video_capture.internal'
|
||||
"""
|
||||
# Class to provide boilerplate code to build a video recorder with the
|
||||
# correct settings from the config file.
|
||||
#
|
||||
# The internal recorder can be accessed with 'video_capture.internal'
|
||||
|
||||
|
||||
class VideoCapture:
|
||||
|
||||
"""
|
||||
Creates a new VideoCapture instance depending on the settings in the
|
||||
provided config file.
|
||||
|
||||
Config can either be a string to the path, or a pre-setup configparser.
|
||||
"""
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Creates a new VideoCapture instance depending on the settings in the
|
||||
provided config file.
|
||||
|
||||
Config can either be a string to the path, or a pre-setup configparser.
|
||||
"""
|
||||
if isinstance(config, str):
|
||||
self.config = configparser.ConfigParser()
|
||||
self.config.read(config)
|
||||
|
@ -30,41 +31,43 @@ class VideoCapture:
|
|||
|
||||
# Check device path
|
||||
if not os.path.exists(config.get("video", "device_path")):
|
||||
print("Camera path is not configured correctly, " +
|
||||
"please edit the 'device_path' config value.")
|
||||
print("Camera path is not configured correctly, please edit the 'device_path' config value.")
|
||||
sys.exit(1)
|
||||
|
||||
# Create reader
|
||||
self.internal = None # The internal video recorder
|
||||
self.fw = None # The frame width
|
||||
self.fh = None # The frame height
|
||||
# The internal video recorder
|
||||
self.internal = None
|
||||
# The frame width
|
||||
self.fw = None
|
||||
# The frame height
|
||||
self.fh = None
|
||||
self._create_reader()
|
||||
|
||||
# Request a frame to wake the camera up
|
||||
self.internal.grab()
|
||||
|
||||
"""
|
||||
Frees resources when destroyed
|
||||
"""
|
||||
def __del__(self):
|
||||
"""
|
||||
Frees resources when destroyed
|
||||
"""
|
||||
if self is not None:
|
||||
self.internal.release()
|
||||
|
||||
"""
|
||||
Reads a frame, returns the frame and an attempted grayscale conversion of
|
||||
the frame in a tuple:
|
||||
|
||||
(frame, grayscale_frame)
|
||||
|
||||
If the grayscale conversion fails, both items in the tuple are identical.
|
||||
"""
|
||||
def read_frame(self):
|
||||
"""
|
||||
Reads a frame, returns the frame and an attempted grayscale conversion of
|
||||
the frame in a tuple:
|
||||
|
||||
(frame, grayscale_frame)
|
||||
|
||||
If the grayscale conversion fails, both items in the tuple are identical.
|
||||
"""
|
||||
|
||||
# Grab a single frame of video
|
||||
# Don't remove ret, it doesn't work without it
|
||||
ret, frame = self.internal.read()
|
||||
if not ret:
|
||||
print("Failed to read camera specified in your 'device_path', " +
|
||||
"aborting")
|
||||
print("Failed to read camera specified in your 'device_path', aborting")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
|
@ -78,10 +81,11 @@ class VideoCapture:
|
|||
raise
|
||||
return frame, gsframe
|
||||
|
||||
"""
|
||||
Sets up the video reader instance
|
||||
"""
|
||||
def _create_reader(self):
|
||||
"""
|
||||
Sets up the video reader instance
|
||||
"""
|
||||
|
||||
if self.config.get("video", "recording_plugin") == "ffmpeg":
|
||||
# Set the capture source for ffmpeg
|
||||
from recorders.ffmpeg_reader import ffmpeg_reader
|
||||
|
@ -89,6 +93,7 @@ class VideoCapture:
|
|||
self.config.get("video", "device_path"),
|
||||
self.config.get("video", "device_format")
|
||||
)
|
||||
|
||||
elif self.config.get("video", "recording_plugin") == "pyv4l2":
|
||||
# Set the capture source for pyv4l2
|
||||
from recorders.pyv4l2_reader import pyv4l2_reader
|
||||
|
@ -96,6 +101,7 @@ class VideoCapture:
|
|||
self.config.get("video", "device_path"),
|
||||
self.config.get("video", "device_format")
|
||||
)
|
||||
|
||||
else:
|
||||
# Start video capture on the IR camera through OpenCV
|
||||
self.internal = cv2.VideoCapture(
|
||||
|
|
Loading…
Reference in a new issue