Added snapshot command
This commit is contained in:
parent
51e17420d7
commit
fff9f3a4ab
3 changed files with 58 additions and 2 deletions
|
|
@ -34,9 +34,9 @@ parser = argparse.ArgumentParser(description="Command line interface for Howdy f
|
|||
|
||||
# Add an argument for the command
|
||||
parser.add_argument("command",
|
||||
help="The command option to execute, can be one of the following: add, clear, config, disable, list, remove or test.",
|
||||
help="The command option to execute, can be one of the following: add, clear, config, disable, list, remove, test or snapshot.",
|
||||
metavar="command",
|
||||
choices=["add", "clear", "config", "disable", "list", "remove", "test"])
|
||||
choices=["add", "clear", "config", "disable", "list", "remove", "test", "snapshot"])
|
||||
|
||||
# Add an argument for the extra arguments of diable and remove
|
||||
parser.add_argument("argument",
|
||||
|
|
@ -99,3 +99,5 @@ elif args.command == "remove":
|
|||
import cli.remove
|
||||
elif args.command == "test":
|
||||
import cli.test
|
||||
elif args.command == "snapshot":
|
||||
import cli.snap
|
||||
|
|
|
|||
51
src/cli/snap.py
Normal file
51
src/cli/snap.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# Create a snapshot
|
||||
|
||||
# Import required modules
|
||||
import os
|
||||
import configparser
|
||||
import datetime
|
||||
import snapshot
|
||||
from recorders.video_capture import VideoCapture
|
||||
|
||||
# Get the absolute path to the current directory
|
||||
path = os.path.abspath(__file__ + "/..")
|
||||
|
||||
# Read the config
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path + "/../config.ini")
|
||||
|
||||
# Start video capture
|
||||
video_capture = VideoCapture(config)
|
||||
|
||||
# Read a frame to activate emitters
|
||||
video_capture.read_frame()
|
||||
|
||||
# Read exposure and dark_thresholds from config to use in the main loop
|
||||
exposure = config.getint("video", "exposure", fallback=-1)
|
||||
dark_threshold = config.getfloat("video", "dark_threshold")
|
||||
|
||||
# COllection of recorded frames
|
||||
frames = []
|
||||
|
||||
while True:
|
||||
# Grab a single frame of video
|
||||
frame, gsframe = video_capture.read_frame()
|
||||
|
||||
# Add the frame to the list
|
||||
frames.append(frame)
|
||||
|
||||
# Stop the loop if we have 4 frames
|
||||
if len(frames) >= 4:
|
||||
break
|
||||
|
||||
# Generate a snapshot image from the frames
|
||||
file = snapshot.generate(frames, [
|
||||
"GENERATED SNAPSHOT",
|
||||
"Date: " + datetime.datetime.utcnow().strftime("%Y/%m/%d %H:%M:%S UTC"),
|
||||
"Dark threshold config: " + str(config.getfloat("video", "dark_threshold", fallback=50.0)),
|
||||
"Certainty config: " + str(config.getfloat("video", "certainty", fallback=3.5))
|
||||
])
|
||||
|
||||
# Show the file location in console
|
||||
print("Generated snapshot saved as")
|
||||
print(file)
|
||||
|
|
@ -57,3 +57,6 @@ def generate(frames, text_lines):
|
|||
filename = datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%S.jpg")
|
||||
# Write the image to that file
|
||||
cv2.imwrite(abpath + "/snapshots/" + filename, snap)
|
||||
|
||||
# Return the saved file location
|
||||
return abpath + "/snapshots/" + filename
|
||||
|
|
|
|||
Loading…
Reference in a new issue