Safety alerts

Developers can create features to notify and alert drivers about road conditions and potential hazards with Mapbox Vision Safety, an add-on module that uses segmentation, detection, and classification information passed from the Vision SDK.

Monitor speed limits

Developers can monitor speed limits and other critical signage using sign classification and track the most recently observed speed limit. When the detected speed of the vehicle is more than the last observed speed limit, you can set programmable alerts.

There are two pieces to displaying speeding alerts: detecting speed limit signs and determining current vehicle speed.

Sign detection

Vision Safety uses the Mapbox Vision SDK's DetectionClass to detect trafficSigns in view and filters for SignTypes equal to any of the speedLimit* types (including special speed limit signs like maximum speeds for trucks and minimum speed).

Vision Safety's SpeedLimitRange class contains two numbers: a min and a max speed limit.

Vehicle speed

Use the Vision SDK's VehicleLocation class's speed property to determine the speed at which the device is currently traveling.

Then, you can compare the vehicle speed to the speed limit range to trigger speeding notifications.

let isOverSpeeding = state.speed > restrictions.speedLimits.speedLimitRange.max
self?.alertView.isHidden = !isOverSpeeding

See the full example code in the Speeding alerts example.

Alert drivers of pedestrians and cyclists

Vision Safety's CollisionObject class detects objects in the vehicle's path and provides an estimated time to impact and a CollisionDangerLevel between 0 and 2. Collision detection can warn drivers when pedestrians or cyclists are in the vehicle’s path or a driver is closing too quickly on a lead vehicle.

if let critical = collisions.first(where: { $0.dangerLevel == .critical }) {
    print("Critical collision danger level! Time to impact: \(critical.timeToImpact)")