From 55c550b6fa9bb4e065601ac5a6880d031a3d3717 Mon Sep 17 00:00:00 2001 From: Conner Vieira Date: Thu, 19 Oct 2023 00:14:06 -0400 Subject: [PATCH] Added customizable dashcam stamps to OpenCV --- CONFIGURATION.md | 3 +++ config.json | 4 ++++ main.py | 7 +++---- utils.py | 8 ++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 305bfd1..099c421 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -183,6 +183,9 @@ Configuration values in this section are settings specific to real-time mode. - Examples: - `"main_camera": 0` - `"secondary_camera": 1` + - `stamps` contains several configurable stamps that can be overlayed on the video recording. + - `license_plate` is intended to display the license plate of the vehicle Predator is installed in, but is capable of holding any short string. + - `message` is intended to display a customizable short message. - `ffmpeg` contains settings that control how the FFMPEG back-end records video. These settings are only considered when the `provider` value is set to "ffmpeg". - `resolution` is a string that determines what resolution Predator will attmpt to record at, and takes the form of `"[width]x[height]"` - Be sure that your camera is capable of recording at resolution specified here. If you set an unsupported resolution, it's likely Predator will fail and not record anything. diff --git a/config.json b/config.json index 499adf3..77148e6 100644 --- a/config.json +++ b/config.json @@ -126,6 +126,10 @@ }, "devices": { "main": 0 + }, + "stamps": { + "license_plate": "AAA0000", + "message": "V0LT" } }, "ffmpeg": { diff --git a/main.py b/main.py index 557c692..9b48a01 100644 --- a/main.py +++ b/main.py @@ -1497,15 +1497,14 @@ # Dash-cam mode - elif (mode_selection == "3" and config["general"]["modes"]["enabled"]["dashcam"] == True): # The user has set Predator to boot into dash-cam mode. debug_message("Started dash-cam mode") if (config["dashcam"]["capture"]["provider"] == "ffmpeg"): # Check to see if the configured video back-end is FFMPEG. - start_dashcam_ffmpeg(config["dashcam"]["capture"]["ffmpeg"]["devices"], int(config["dashcam"]["capture"]["ffmpeg"]["segment_length"]), config["dashcam"]["capture"]["ffmpeg"]["resolution"], config["dashcam"]["capture"]["ffmpeg"]["frame_rate"], config["general"]["working_directory"], False) # Start the dashcam recording process. print("\nStarting dashcam recording at " + str(config["dashcam"]["capture"]["ffmpeg"]["resolution"]) + "@" + str(config["dashcam"]["capture"]["ffmpeg"]["frame_rate"]) + "fps") # Print information about the recording settings. + start_dashcam_ffmpeg(config["dashcam"]["capture"]["ffmpeg"]["devices"], int(config["dashcam"]["capture"]["ffmpeg"]["segment_length"]), config["dashcam"]["capture"]["ffmpeg"]["resolution"], config["dashcam"]["capture"]["ffmpeg"]["frame_rate"], config["general"]["working_directory"], False) # Start the dashcam recording process. elif (config["dashcam"]["capture"]["provider"] == "opencv"): # Check to see if the configured video back-end is OpenCV. - start_dashcam_opencv(config["dashcam"]["capture"]["opencv"]["devices"], int(config["dashcam"]["capture"]["opencv"]["resolution"]["width"]), config["dashcam"]["capture"]["opencv"]["resolution"]["height"], config["general"]["working_directory"], False) # Start the dashcam recording process. print("\nStarting dashcam recording at " + str(config["dashcam"]["capture"]["opencv"]["resolution"]["width"]) + "x" + str(config["dashcam"]["capture"]["opencv"]["resolution"]["height"]) + "@" + str(config["dashcam"]["capture"]["ffmpeg"]["frame_rate"]) + "fps") # Print information about the recording settings. + start_dashcam_opencv(config["dashcam"]["capture"]["opencv"]["devices"], int(config["dashcam"]["capture"]["opencv"]["resolution"]["width"]), config["dashcam"]["capture"]["opencv"]["resolution"]["height"], config["general"]["working_directory"], False) # Start the dashcam recording process. @@ -1513,4 +1512,4 @@ else: # The user has selected an unrecognized mode. - display_message("The selected mode is invalid.", 3) + display_message("The selected mode is invalid.", 3) # Display an error message indicating that the selected mode isn't recognized. diff --git a/utils.py b/utils.py index a3f3dfd..ae16b8d 100644 --- a/utils.py +++ b/utils.py @@ -603,12 +603,12 @@ def start_opencv_recording(directory, device=0, width=1280, height=720): while dashcam_recording_active: # Only run while the dashcam recording flag is set to 'True'. ret, frame = capture.read() # Capture a frame. if not ret: # Check to see if the frame failed to be read. - print("Can't receive frame (stream end?). Exiting ...") + print("Can't receive frame. Exiting ...") break - stamp_position = [10, height - 10] - stamp = str(round(time.time())) + " " + "ABC1234" + " " + "V0LT" - cv2.putText(frame, stamp, (stamp_position[0], stamp_position[1]), 2, 0.8, (255,255,255)) + stamp_position = [10, height - 10] # Determine where the main overlay stamp should be positioned in the video stream. + stamp = str(round(time.time())) + " " + config["dashcam"]["capture"]["opencv"]["stamps"]["license_plate"] + " " + config["dashcam"]["capture"]["opencv"]["stamps"]["message"] # Set up the overlay stamp. + cv2.putText(frame, stamp, (stamp_position[0], stamp_position[1]), 2, 0.8, (255,255,255)) # Add the overlay stamp to the video stream. output.write(frame) # Save this frame to the video.