Skip to content

Commit

Permalink
Added frame-rate overlay stamp
Browse files Browse the repository at this point in the history
  • Loading branch information
connervieira committed Mar 18, 2024
1 parent ffa8f59 commit 1f6136e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ March 6th, 2024
- Configuration values that exist in the configuration template file but not in the actual configuration file will show errors.
- Added performance monitoring to state interface file to allow external programs to see basic performance diagnostics.
- Updated the way automatic GPS time correction is handled.
- Predator will not longer try to apply a time offset when the system time is in the future relative to the GPS time.
- Predator will no longer try to apply a time offset when the system time is in the future relative to the GPS time.
- Predator no longer displays warning about the time being desynced when GPS time correction is disabled.
- Overhauled dash-cam saving.
- Frames captured during dash-cam recording are now saved in a separate thread.
- Added diagnostic stamp, which is capable of display various pieces of technical information.
- Added a frame-rate stamp, which shows the instantaneous frame-rate.
20 changes: 20 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@
"max": 30,
"min": 20
}
},
"rear": {
"index": 2,
"flip": false,
"codec": "MJPG",
"framerate": {
"max": 30,
"min": 20
}
}
}
},
Expand Down Expand Up @@ -240,6 +249,17 @@
"message_1": "AAA0000",
"message_2": "V0LT Predator"
},
"diagnostic": {
"color": [
255,
255,
255
],
"framerate": {
"enabled": true,
"precision": 1
}
},
"gps": {
"color": [
0,
Expand Down
23 changes: 18 additions & 5 deletions dashcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def benchmark_camera_framerate(device, frames=5): # This function benchmarks a g
start_time = utils.get_time() # Record the exact time that the benchmark started.
for i in range(0, frames): # Run until the specified number of frames have been captured.
ret, frame = capture.read() # Capture a video frame.
frame = apply_dashcam_stamps(frame) # Apply dashcam overlay stamps to the frame.
frame = apply_dashcam_stamps(frame, device) # Apply dashcam overlay stamps to the frame.
if (config["dashcam"]["capture"]["video"]["devices"][device]["flip"]): # Check to see if Predator is convered to flip this capture device's output.
frame = cv2.rotate(frame, cv2.ROTATE_180) # Flip the frame by 180 degrees.

Expand Down Expand Up @@ -228,12 +228,16 @@ def save_dashcam_segments(file1, file2=""):



def apply_dashcam_stamps(frame):
def apply_dashcam_stamps(frame, device=""):
global instant_framerate

process_timing("start", "Dashcam/Apply Stamps")
try:
height, width, channels = frame.shape
except:
display_message("Failed to determine frame size while applying overlay stamps. It is likely something has gone wrong with video capture.", 3)
width = 1280
height = 720

main_stamp_position = [10, height - 10] # Determine where the main overlay stamp should be positioned in the video stream.
main_stamp = ""
Expand All @@ -245,6 +249,13 @@ def apply_dashcam_stamps(frame):
main_stamp = main_stamp + str(datetime.datetime.fromtimestamp(utils.get_time()).strftime("%H:%M:%S")) + " " # Add the time to the main stamp.
main_stamp = main_stamp + " " + config["dashcam"]["stamps"]["main"]["message_1"] + " " + config["dashcam"]["stamps"]["main"]["message_2"] # Add the customizable messages to the overlay stamp.

diagnostic_stamp_position = [10, height - 10 - round(30 * config["dashcam"]["stamps"]["size"])] # Determine where the diagnostic overlay stamp should be positioned in the video stream.
diagnostic_stamp = ""
if (config["dashcam"]["stamps"]["diagnostic"]["framerate"]["enabled"] == True): # Check to see if the frame-rate stamp is enabled.
if (device in instant_framerate): # Only add the frame-rate stamp if there is frame-rate information for this device.
diagnostic_stamp = diagnostic_stamp + (str("%." + str(config["dashcam"]["stamps"]["diagnostic"]["framerate"]["precision"]) + "f") % instant_framerate[device]) + "FPS " # Add the current frame-rate to the main stamp.


gps_stamp_position = [10, 30] # Determine where the GPS overlay stamp should be positioned in the video stream.
gps_stamp = "" # Set the GPS to a blank placeholder. Elements will be added to this in the next steps.
if (config["general"]["gps"]["enabled"] == True): # Check to see if GPS features are enabled before processing the GPS stamp.
Expand All @@ -259,10 +270,12 @@ def apply_dashcam_stamps(frame):

# Determine the font color of the stamps from the configuration.
main_stamp_color = config["dashcam"]["stamps"]["main"]["color"]
diagnostic_stamp_color = config["dashcam"]["stamps"]["diagnostic"]["color"]
gps_stamp_color = config["dashcam"]["stamps"]["gps"]["color"]

# Add the stamps to the video stream.
cv2.putText(frame, main_stamp, (main_stamp_position[0], main_stamp_position[1]), 2, config["dashcam"]["stamps"]["size"], (main_stamp_color[2], main_stamp_color[1], main_stamp_color[0])) # Add the main overlay stamp to the video stream.
cv2.putText(frame, diagnostic_stamp, (diagnostic_stamp_position[0], diagnostic_stamp_position[1]), 2, config["dashcam"]["stamps"]["size"], (diagnostic_stamp_color[2], diagnostic_stamp_color[1], diagnostic_stamp_color[0])) # Add the main overlay stamp to the video stream.
cv2.putText(frame, gps_stamp, (gps_stamp_position[0], gps_stamp_position[1]), 2, config["dashcam"]["stamps"]["size"], (gps_stamp_color[2], gps_stamp_color[1], gps_stamp_color[0])) # Add the GPS overlay stamp to the video stream.

process_timing("end", "Dashcam/Apply Stamps")
Expand Down Expand Up @@ -383,7 +396,7 @@ def record_parked_motion(capture, framerate, width, height, device, directory, f

process_timing("end", "Dashcam/Motion Detection")

frame = apply_dashcam_stamps(frame) # Apply dashcam overlay stamps to the frame.
frame = apply_dashcam_stamps(frame, device) # Apply dashcam overlay stamps to the frame.

process_timing("start", "Dashcam/Writing")
write_frame(frame, device)
Expand Down Expand Up @@ -557,7 +570,7 @@ def capture_dashcam_video(directory, device="main", width=1280, height=720):
process_timing("end", "Dashcam/Image Manipulation")
if (config["dashcam"]["parked"]["recording"]["buffer"] > 0): # Check to see if the frame buffer is greater than 0 before adding frames to the buffer.
process_timing("start", "Dashcam/Frame Buffer")
frame_history.append(apply_dashcam_stamps(frame)) # Add the frame that was just captured to the frame buffer.
frame_history.append(apply_dashcam_stamps(frame, device)) # Add the frame that was just captured to the frame buffer.
if (len(frame_history) > config["dashcam"]["parked"]["recording"]["buffer"]): # Check to see if the frame buffer has exceeded the maximum length.
frame_history = frame_history[-config["dashcam"]["parked"]["recording"]["buffer"]:] # Trim the frame buffer to the appropriate length.
process_timing("end", "Dashcam/Frame Buffer")
Expand Down Expand Up @@ -595,7 +608,7 @@ def capture_dashcam_video(directory, device="main", width=1280, height=720):
update_state("dashcam/normal", instant_framerate)
previously_parked_dormant = False

frame = apply_dashcam_stamps(frame)
frame = apply_dashcam_stamps(frame, device)
write_frame(frame, device)

if (config["developer"]["print_timings"] == True):
Expand Down
6 changes: 6 additions & 0 deletions docs/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ This document describes the configuration values found `config.json`.
- `enabled` is a boolean value that determines whether Predator will show the current time in the video overlay stamp.
- `message_1` is a string that is intended to display a short custom message. This is often set to the license plate of the car Predator is installed in.
- `message_2` is a string that is intended to display a short custom message. This is often set to "Predator", or another name identifying the system the dashcam is running on.
- `diagnostic` contains configuration values for the stamp show just above the 'main' stamp on the bottom row, showing system information.
- `color` is a list of three values between 0 and 255 that determines the font cover of the overlay stamp.
- The first value represents red, the second value represents green, and the third value represents blue.
- `framerate` contains settings for configuring Predator showing the instantaneous framerate in the video overlay.
- `enabled` is a boolean that determines if this overlay is enabled or disabled.
- `precision` is an integer number that determines how many decimal places the frame-rate will be displayed to.
- `gps` contains configuration values for the stamp shown at the top of the frame, containing location information.
- `color` is a list of three values between 0 and 255 that determines the font cover of the overlay stamp.
- The first value represents red, the second value represents green, and the third value represents blue.
Expand Down

0 comments on commit 1f6136e

Please sign in to comment.