Skip to content

Commit

Permalink
Added customizable dashcam stamps to OpenCV
Browse files Browse the repository at this point in the history
  • Loading branch information
connervieira committed Oct 19, 2023
1 parent 73ea9cf commit 55c550b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@
},
"devices": {
"main": 0
},
"stamps": {
"license_plate": "AAA0000",
"message": "V0LT"
}
},
"ffmpeg": {
Expand Down
7 changes: 3 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,20 +1497,19 @@


# 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.






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.
8 changes: 4 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 55c550b

Please sign in to comment.