mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-09-26 19:41:29 +08:00
Estimated object speed for zones (#16452)
* utility functions * backend config * backend object speed tracking * draw speed on debug view * basic frontend zone editor * remove line sorting * fix types * highlight line on canvas when entering value in zone edit pane * rename vars and add validation * ensure speed estimation is disabled when user adds more than 4 points * pixel velocity in debug * unit_system in config * ability to define unit system in config * save max speed to db * frontend * docs * clarify docs * utility functions * backend config * backend object speed tracking * draw speed on debug view * basic frontend zone editor * remove line sorting * fix types * highlight line on canvas when entering value in zone edit pane * rename vars and add validation * ensure speed estimation is disabled when user adds more than 4 points * pixel velocity in debug * unit_system in config * ability to define unit system in config * save max speed to db * frontend * docs * clarify docs * fix duplicates from merge * include max_estimated_speed in api responses * add units to zone edit pane * catch undefined * add average speed * clarify docs * only track average speed when object is active * rename vars * ensure points and distances are ordered clockwise * only store the last 10 speeds like score history * remove max estimated speed * update docs * update docs * fix point ordering * improve readability * docs inertia recommendation * fix point ordering * check object frame time * add velocity angle to frontend * docs clarity * add frontend speed filter * fix mqtt docs * fix mqtt docs * don't try to remove distances if they weren't already defined * don't display estimates on debug view/snapshots if object is not in a speed tracking zone * docs * implement speed_threshold for zone presence * docs for threshold * better ground plane image * improve image zone size * add inertia to speed threshold example
This commit is contained in:
@@ -662,7 +662,10 @@ cameras:
|
||||
front_steps:
|
||||
# Required: List of x,y coordinates to define the polygon of the zone.
|
||||
# NOTE: Presence in a zone is evaluated only based on the bottom center of the objects bounding box.
|
||||
coordinates: 0.284,0.997,0.389,0.869,0.410,0.745
|
||||
coordinates: 0.033,0.306,0.324,0.138,0.439,0.185,0.042,0.428
|
||||
# Optional: The real-world distances of a 4-sided zone used for zones with speed estimation enabled (default: none)
|
||||
# List distances in order of the zone points coordinates and use the unit system defined in the ui config
|
||||
distances: 10,15,12,11
|
||||
# Optional: Number of consecutive frames required for object to be considered present in the zone (default: shown below).
|
||||
inertia: 3
|
||||
# Optional: Number of seconds that an object must loiter to be considered in the zone (default: shown below)
|
||||
@@ -813,6 +816,9 @@ ui:
|
||||
# https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html
|
||||
# possible values are shown above (default: not set)
|
||||
strftime_fmt: "%Y/%m/%d %H:%M"
|
||||
# Optional: Set the unit system to either "imperial" or "metric" (default: metric)
|
||||
# Used in the UI and in MQTT topics
|
||||
unit_system: metric
|
||||
|
||||
# Optional: Telemetry configuration
|
||||
telemetry:
|
||||
|
@@ -122,16 +122,59 @@ cameras:
|
||||
- car
|
||||
```
|
||||
|
||||
### Loitering Time
|
||||
### Speed Estimation
|
||||
|
||||
Zones support a `loitering_time` configuration which can be used to only consider an object as part of a zone if they loiter in the zone for the specified number of seconds. This can be used, for example, to create alerts for cars that stop on the street but not cars that just drive past your camera.
|
||||
Frigate can be configured to estimate the speed of objects moving through a zone. This works by combining data from Frigate's object tracker and "real world" distance measurements of the edges of the zone. The recommended use case for this feature is to track the speed of vehicles on a road as they move through the zone.
|
||||
|
||||
Your zone must be defined with exactly 4 points and should be aligned to the ground where objects are moving.
|
||||
|
||||

|
||||
|
||||
Speed estimation requires a minimum number of frames for your object to be tracked before a valid estimate can be calculated, so create your zone away from places where objects enter and exit for the best results. _Your zone should not take up the full frame._ An object's speed is tracked while it is in the zone and then saved to Frigate's database.
|
||||
|
||||
Accurate real-world distance measurements are required to estimate speeds. These distances can be specified in your zone config through the `distances` field.
|
||||
|
||||
```yaml
|
||||
cameras:
|
||||
name_of_your_camera:
|
||||
zones:
|
||||
front_yard:
|
||||
loitering_time: 5 # unit is in seconds
|
||||
objects:
|
||||
- person
|
||||
street:
|
||||
coordinates: 0.033,0.306,0.324,0.138,0.439,0.185,0.042,0.428
|
||||
distances: 10,12,11,13.5
|
||||
```
|
||||
|
||||
Each number in the `distance` field represents the real-world distance between the points in the `coordinates` list. So in the example above, the distance between the first two points ([0.033,0.306] and [0.324,0.138]) is 10. The distance between the second and third set of points ([0.324,0.138] and [0.439,0.185]) is 12, and so on. The fastest and most accurate way to configure this is through the Zone Editor in the Frigate UI.
|
||||
|
||||
The `distance` values are measured in meters or feet, depending on how `unit_system` is configured in your `ui` config:
|
||||
|
||||
```yaml
|
||||
ui:
|
||||
# can be "metric" or "imperial", default is metric
|
||||
unit_system: metric
|
||||
```
|
||||
|
||||
The average speed of your object as it moved through your zone is saved in Frigate's database and can be seen in the UI in the Tracked Object Details pane in Explore. Current estimated speed can also be seen on the debug view as the third value in the object label (see the caveats below). Current estimated speed, average estimated speed, and velocity angle (the angle of the direction the object is moving relative to the frame) of tracked objects is also sent through the `events` MQTT topic. See the [MQTT docs](../integrations/mqtt.md#frigateevents). These speed values are output as a number in miles per hour (mph) or kilometers per hour (kph), depending on how `unit_system` is configured in your `ui` config.
|
||||
|
||||
#### Best practices and caveats
|
||||
|
||||
- Speed estimation works best with a straight road or path when your object travels in a straight line across that path. If your object makes turns, speed estimation may not be accurate.
|
||||
- Create a zone where the bottom center of your object's bounding box travels directly through it and does not become obscured at any time.
|
||||
- Depending on the size and location of your zone, you may want to decrease the zone's `inertia` value from the default of 3.
|
||||
- The more accurate your real-world dimensions can be measured, the more accurate speed estimation will be. However, due to the way Frigate's tracking algorithm works, you may need to tweak the real-world distance values so that estimated speeds better match real-world speeds.
|
||||
- Once an object leaves the zone, speed accuracy will likely decrease due to perspective distortion and misalignment with the calibrated area. Therefore, speed values will show as a zero through MQTT and will not be visible on the debug view when an object is outside of a speed tracking zone.
|
||||
- The speeds are only an _estimation_ and are highly dependent on camera position, zone points, and real-world measurements. This feature should not be used for law enforcement.
|
||||
|
||||
### Speed Threshold
|
||||
|
||||
Zones can be configured with a minimum speed requirement, meaning an object must be moving at or above this speed to be considered inside the zone. Zone `distances` must be defined as described above.
|
||||
|
||||
```yaml
|
||||
cameras:
|
||||
name_of_your_camera:
|
||||
zones:
|
||||
sidewalk:
|
||||
coordinates: ...
|
||||
distances: ...
|
||||
inertia: 1
|
||||
speed_threshold: 20 # unit is in kph or mph, depending on how unit_system is set (see above)
|
||||
```
|
||||
|
@@ -52,7 +52,9 @@ Message published for each changed tracked object. The first message is publishe
|
||||
"attributes": {
|
||||
"face": 0.64
|
||||
}, // attributes with top score that have been identified on the object at any point
|
||||
"current_attributes": [] // detailed data about the current attributes in this frame
|
||||
"current_attributes": [], // detailed data about the current attributes in this frame
|
||||
"current_estimated_speed": 0.71, // current estimated speed (mph or kph) for objects moving through zones with speed estimation enabled
|
||||
"velocity_angle": 180 // direction of travel relative to the frame for objects moving through zones with speed estimation enabled
|
||||
},
|
||||
"after": {
|
||||
"id": "1607123955.475377-mxklsc",
|
||||
@@ -89,7 +91,9 @@ Message published for each changed tracked object. The first message is publishe
|
||||
"box": [442, 506, 534, 524],
|
||||
"score": 0.86
|
||||
}
|
||||
]
|
||||
],
|
||||
"current_estimated_speed": 0.77, // current estimated speed (mph or kph) for objects moving through zones with speed estimation enabled
|
||||
"velocity_angle": 180 // direction of travel relative to the frame for objects moving through zones with speed estimation enabled
|
||||
}
|
||||
}
|
||||
```
|
||||
|
BIN
docs/static/img/ground-plane.jpg
vendored
Normal file
BIN
docs/static/img/ground-plane.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 231 KiB |
Reference in New Issue
Block a user