Moved recorders to new folder

This commit is contained in:
boltgolt 2019-01-06 15:08:40 +01:00
parent 6e1085110b
commit 3c8db931b9
No known key found for this signature in database
GPG key ID: BECEC9937E1AAE26
7 changed files with 21 additions and 23 deletions

View file

@ -101,11 +101,11 @@ insert_model = {
# Check if the user explicitly set ffmpeg as recorder # Check if the user explicitly set ffmpeg as recorder
if config.get("video", "recording_plugin") == "ffmpeg": if config.get("video", "recording_plugin") == "ffmpeg":
# Set the capture source for ffmpeg # Set the capture source for ffmpeg
from ffmpeg_reader import ffmpeg_reader from recorders.ffmpeg_reader import ffmpeg_reader
video_capture = ffmpeg_reader(config.get("video", "device_path"), config.get("video", "device_format")) video_capture = ffmpeg_reader(config.get("video", "device_path"), config.get("video", "device_format"))
elif config.get("video", "recording_plugin") == "pyv4l2": elif config.get("video", "recording_plugin") == "pyv4l2":
# Set the capture source for pyv4l2 # Set the capture source for pyv4l2
from pyv4l2_reader import pyv4l2_reader from recorders.pyv4l2_reader import pyv4l2_reader
video_capture = pyv4l2_reader(config.get("video", "device_path"), config.get("video", "device_format")) video_capture = pyv4l2_reader(config.get("video", "device_path"), config.get("video", "device_format"))
else: else:
# Start video capture on the IR camera through OpenCV # Start video capture on the IR camera through OpenCV

View file

@ -116,11 +116,11 @@ timings["ic"] = time.time()
# Check if the user explicitly set ffmpeg as recorder # Check if the user explicitly set ffmpeg as recorder
if config.get("video", "recording_plugin") == "ffmpeg": if config.get("video", "recording_plugin") == "ffmpeg":
# Set the capture source for ffmpeg # Set the capture source for ffmpeg
from ffmpeg_reader import ffmpeg_reader from recorders.ffmpeg_reader import ffmpeg_reader
video_capture = ffmpeg_reader(config.get("video", "device_path"), config.get("video", "device_format")) video_capture = ffmpeg_reader(config.get("video", "device_path"), config.get("video", "device_format"))
elif config.get("video", "recording_plugin") == "pyv4l2": elif config.get("video", "recording_plugin") == "pyv4l2":
# Set the capture source for pyv4l2 # Set the capture source for pyv4l2
from pyv4l2_reader import pyv4l2_reader from recorders.pyv4l2_reader import pyv4l2_reader
video_capture = pyv4l2_reader(config.get("video", "device_path"), config.get("video", "device_format")) video_capture = pyv4l2_reader(config.get("video", "device_path"), config.get("video", "device_format"))
else: else:
# Start video capture on the IR camera through OpenCV # Start video capture on the IR camera through OpenCV
@ -178,12 +178,14 @@ while True:
stop(11) stop(11)
# Grab a single frame of video # Grab a single frame of video
_, frame = video_capture.read() ret, frame = video_capture.read()
try: try:
# Convert from color to grayscale
# First processing of frame, so frame errors show up here
gsframe = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gsframe = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
except cv2.error: except cv2.error:
print("Unknown camera, please check your 'device_path' config value.\n") print("\nUnknown camera, please check your 'device_path' config value.\n")
raise raise
# Create a histogram of the image with 8 values # Create a histogram of the image with 8 values

View file

@ -57,7 +57,7 @@ frame_height = -1
# The lower this setting is, the more dark frames are ignored # The lower this setting is, the more dark frames are ignored
dark_threshold = 50 dark_threshold = 50
# The recorder to use. Can be either opencv, ffmpeg or pyv4l2. # The recorder to use. Can be either opencv (default), ffmpeg or pyv4l2.
# Switching from the default opencv to ffmpeg can help with grayscale issues. # Switching from the default opencv to ffmpeg can help with grayscale issues.
recording_plugin = opencv recording_plugin = opencv

View file

View file

@ -126,3 +126,7 @@ class ffmpeg_reader:
""" Empty our array. If we had a hold on the camera, we would give it back here. """ """ Empty our array. If we had a hold on the camera, we would give it back here. """
self.video = () self.video = ()
self.num_frames_read = 0 self.num_frames_read = 0
def grab(self):
""" Redirect grab() to read() for compatibility """
self.read()

View file

@ -1,19 +1,20 @@
# Class that simulates the functionality of opencv so howdy can use v4l2 devices seamlessly # Class that simulates the functionality of opencv so howdy can use v4l2 devices seamlessly
# Import required modules. lib4l-dev package is also required. # Import required modules. lib4l-dev package is also required.
import v4l2 from recorders import v4l2
import fcntl import fcntl
import numpy import numpy
import sys import sys
from cv2 import cvtColor, COLOR_GRAY2BGR, CAP_PROP_FRAME_WIDTH, CAP_PROP_FRAME_HEIGHT from cv2 import cvtColor, COLOR_GRAY2BGR, CAP_PROP_FRAME_WIDTH, CAP_PROP_FRAME_HEIGHT
try: try:
from pyv4l2.frame import Frame from v4l2.frame import Frame
except ImportError: except ImportError:
print("Missing pyv4l2 module, please run:") print("Missing pyv4l2 module, please run:")
print(" pip3 install pyv4l2\n") print(" pip3 install pyv4l2\n")
sys.exit(13) sys.exit(13)
class pyv4l2_reader: class pyv4l2_reader:
""" This class was created to look as similar to the openCV features used in Howdy as possible for overall code cleanliness. """ """ This class was created to look as similar to the openCV features used in Howdy as possible for overall code cleanliness. """
@ -39,7 +40,7 @@ class pyv4l2_reader:
return self.width return self.width
elif prop == CAP_PROP_FRAME_HEIGHT: elif prop == CAP_PROP_FRAME_HEIGHT:
return self.height return self.height
def probe(self): def probe(self):
""" Probe the video device to get height and width info """ """ Probe the video device to get height and width info """
@ -51,7 +52,7 @@ class pyv4l2_reader:
if ret == 0: if ret == 0:
height = fmt.fmt.pix.height height = fmt.fmt.pix.height
width = fmt.fmt.pix.width width = fmt.fmt.pix.width
else: else:
# Could not determine the resolution from ioctl call. Reverting to slower ffmpeg.probe() method # Could not determine the resolution from ioctl call. Reverting to slower ffmpeg.probe() method
import ffmpeg import ffmpeg
probe = ffmpeg.probe(self.device_name) probe = ffmpeg.probe(self.device_name)
@ -68,7 +69,6 @@ class pyv4l2_reader:
""" Start recording """ """ Start recording """
self.frame = Frame(self.device_name) self.frame = Frame(self.device_name)
def grab(self): def grab(self):
""" Read a sigle frame from the IR camera. """ """ Read a sigle frame from the IR camera. """
self.read() self.read()
@ -77,26 +77,19 @@ class pyv4l2_reader:
""" Read a sigle frame from the IR camera. """ """ Read a sigle frame from the IR camera. """
if not self.frame: if not self.frame:
self.record() self.record()
# Grab a raw frame from the camera # Grab a raw frame from the camera
frame_data = self.frame.get_frame() frame_data = self.frame.get_frame()
# Convert the raw frame_date to a numpy array # Convert the raw frame_date to a numpy array
img = ( img = (numpy.frombuffer(frame_data, numpy.uint8))
numpy
.frombuffer(frame_data, numpy.uint8)
)
# Convert the numpy array to a proper grayscale image array # Convert the numpy array to a proper grayscale image array
img_bgr = cvtColor(img, COLOR_GRAY2BGR) img_bgr = cvtColor(img, COLOR_GRAY2BGR)
# Convert the grayscale image array into a proper RGB style numpy array # Convert the grayscale image array into a proper RGB style numpy array
img2 = ( img2 = (numpy.frombuffer(img_bgr, numpy.uint8).reshape([352, 352, 3]))
numpy
.frombuffer(img_bgr, numpy.uint8)
.reshape([352, 352, 3])
)
# Return a single frame of video # Return a single frame of video
return 0, img2 return 0, img2
@ -107,4 +100,3 @@ class pyv4l2_reader:
self.num_frames_read = 0 self.num_frames_read = 0
if self.frame: if self.frame:
self.frame.close() self.frame.close()