Skip to content

Commit

Permalink
Added optional GPS stamps to dash-cam mode
Browse files Browse the repository at this point in the history
  • Loading branch information
connervieira committed Oct 19, 2023
1 parent 463fca3 commit 3eb741c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ Configuration values in this section are settings specific to real-time mode.
- `"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.
- `main`
- `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.
- `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
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ These are the features actively planned for Predator and are likely to be added
- [X] Test updated license plate validation in real-time mode.
- [X] Add Phantom alert handling to updated ALPR stream.
- [ ] Complete OpenCV dashcam recording.
- [ ] Improve the efficiency of GPS location requests when many requests are made in quick succession.
17 changes: 15 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,21 @@
"main": 0
},
"stamps": {
"license_plate": "AAA0000",
"message": "V0LT"
"main": {
"message_1": "AAA0000",
"message_2": "V0LT"
},
"gps": {
"location": {
"enabled": true
},
"altitude": {
"enabled": true
},
"speed": {
"enabled": true
}
}
}
},
"ffmpeg": {
Expand Down
19 changes: 16 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,22 @@ def start_opencv_recording(directory, device=0, width=1280, height=720):
print("Can't receive frame. Exiting ...")
break

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.
main_stamp_position = [10, height - 10] # Determine where the main overlay stamp should be positioned in the video stream.
main_stamp = str(round(time.time())) + " " + config["dashcam"]["capture"]["opencv"]["stamps"]["main"]["message_1"] + " " + config["dashcam"]["capture"]["opencv"]["stamps"]["main"]["message_2"] # Set up the overlay 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.
current_location = get_gps_location() # Get the current location.
if (config["dashcam"]["capture"]["opencv"]["stamps"]["gps"]["location"]["enabled"] == True): # Check to see if the GPS location stamp is enabled.
gps_stamp = gps_stamp + "(" + str(current_location[0]) + ", " + str(current_location[1]) + ") " # Add the current coordinates to the GPS stamp.
if (config["dashcam"]["capture"]["opencv"]["stamps"]["gps"]["altitude"]["enabled"] == True): # Check to see if the GPS altitude stamp is enabled.
gps_stamp = gps_stamp + str(current_location[3]) + "m " # Add the current altitude to the GPS stamp.
if (config["dashcam"]["capture"]["opencv"]["stamps"]["gps"]["speed"]["enabled"] == True): # Check to see if the GPS speed stamp is enabled.
gps_stamp = gps_stamp + str(current_location[2]) + "m/s " # Add the current speed to the GPS stamp.

# Add the stamps to the video stream.
cv2.putText(frame, main_stamp, (main_stamp_position[0], main_stamp_position[1]), 2, 0.8, (255,255,255)) # Add the main overlay stamp to the video stream.
cv2.putText(frame, gps_stamp, (gps_stamp_position[0], gps_stamp_position[1]), 2, 0.8, (255,255,255)) # Add the GPS overlay stamp to the video stream.

output.write(frame) # Save this frame to the video.

Expand Down

0 comments on commit 3eb741c

Please sign in to comment.