Refactor test.py to use VideoCapture
This commit is contained in:
parent
804016d1a0
commit
200e536b5e
1 changed files with 5 additions and 30 deletions
|
|
@ -7,6 +7,7 @@ import sys
|
|||
import time
|
||||
import cv2
|
||||
import dlib
|
||||
from recorders.video_capture import VideoCapture
|
||||
|
||||
# Get the absolute path to the current file
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
|
@ -20,22 +21,7 @@ if config.get("video", "recording_plugin") != "opencv":
|
|||
print("Aborting")
|
||||
sys.exit(12)
|
||||
|
||||
# Start capturing from the configured webcam
|
||||
video_capture = cv2.VideoCapture(config.get("video", "device_path"))
|
||||
|
||||
# Force MJPEG decoding if true
|
||||
if config.getboolean("video", "force_mjpeg", fallback=False):
|
||||
# Set a magic number, will enable MJPEG but is badly documented
|
||||
video_capture.set(cv2.CAP_PROP_FOURCC, 1196444237)
|
||||
|
||||
# Set the frame width and height if requested
|
||||
fw = config.getint("video", "frame_width", fallback=-1)
|
||||
fh = config.getint("video", "frame_height", fallback=-1)
|
||||
if fw != -1:
|
||||
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, fw)
|
||||
|
||||
if fh != -1:
|
||||
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, fh)
|
||||
video_capture = VideoCapture(config)
|
||||
|
||||
# Read exposure and dark_thresholds from config to use in the main loop
|
||||
exposure = config.getint("video", "exposure", fallback=-1)
|
||||
|
|
@ -109,17 +95,7 @@ try:
|
|||
sec_frames = 0
|
||||
|
||||
# Grab a single frame of video
|
||||
ret, frame = video_capture.read()
|
||||
|
||||
try:
|
||||
# Convert from color to grayscale
|
||||
# First processing of frame, so frame errors show up here
|
||||
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
except RuntimeError:
|
||||
pass
|
||||
except cv2.error:
|
||||
print("\nUnknown camera, please check your 'device_path' config value.\n")
|
||||
raise
|
||||
_, frame = video_capture.read_frame()
|
||||
|
||||
frame = clahe.apply(frame)
|
||||
# Make a frame to put overlays in
|
||||
|
|
@ -211,8 +187,8 @@ try:
|
|||
# are captured and even after a delay it does not
|
||||
# always work. Setting exposure at every frame is
|
||||
# reliable though.
|
||||
video_capture.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1.0) # 1 = Manual
|
||||
video_capture.set(cv2.CAP_PROP_EXPOSURE, float(exposure))
|
||||
video_capture.intenal.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1.0) # 1 = Manual
|
||||
video_capture.intenal.set(cv2.CAP_PROP_EXPOSURE, float(exposure))
|
||||
|
||||
# On ctrl+C
|
||||
except KeyboardInterrupt:
|
||||
|
|
@ -220,5 +196,4 @@ except KeyboardInterrupt:
|
|||
print("\nClosing window")
|
||||
|
||||
# Release handle to the webcam
|
||||
video_capture.release()
|
||||
cv2.destroyAllWindows()
|
||||
|
|
|
|||
Loading…
Reference in a new issue