Cycling is a fun way to stay healthy, enjoy nature and connect with friends and acquaintances. However, riding is becoming increasingly dangerous, especially in situations where cyclists and cars share the roads. According to the NHTSA, in the United States, an average of 883 people died in bicycle accidents in a traffic accident, with an average of around 45,000 people injured, and crashes are reported annually. Total bicycle deaths account for over 2% of all US traffic accidents as cyclists, but being pushed off the road by a large SUV or truck is still horrifying. To better protect yourself, many cyclists ride with cameras mounted on the front or back of the bike. This blog post demonstrates machine learning solutions that cyclists can use to better identify intimate calls.
Many states and countries in the United States around the world have some kind of 3-foot law. The 3-foot law requires that cars provide approximately 3 feet (1 meter) of distance when passing a bike. To promote road safety, cyclists are increasingly recording their vehicles and provide meeting videos to local law enforcement if they encounter dangerous situations that are not given the right safety distance. and modify your behavior. However, it takes time to find a single encounter with multiple-hour ride recordings, and in many cases special video skills are required to generate short clips of encounters.
To solve some of these issues, we developed a simple solution using Amazon Rekognition video analysis. Amazon Rekognition can detect labels (essentially objects) and timestamps when the object is detected in a video. You can quickly find the vehicle that appears in a video of a recorded ride using Amazon Rekognition.
If a cyclist’s camera records a vehicle passing through, you will need to determine whether the vehicle is too close to the bike, that is, whether the vehicle is within the legally set three feet. If so, I would like to generate a clip of encounters that I can offer to the relevant authorities. The following illustration shows the view from the camera of a cyclist with a bounding box identifying vehicles that are too close to the bike. The box at the bottom of the image shows an area about 3 feet around the bike.
Solution overview
The architecture of the solution is shown in the following diagram:
The solution steps are as follows:
- Once the cyclist completes the ride, upload the MP4 video from the ride to Amazon Simple Storage Service (Amazon S3)
- The bucket consists of S3 event notifications that send notifications created in AWS Lambdas
- The Lambda function starts an AWS Step Function workflow that begins by calling the StartLabelDetection API as part of an Amazon Rekognition video.
StartLabelDetection
The API is configured to detectBus
,Car
,Fire Truck
,Pickup Truck
,Truck
,Limo
andMoving Van
As a label. It ignores other related non-vehicle labelsLicense Plate
,Wheel
,Tire
andCar Mirror
. - The Amazon Rekognition API returns a set of JSONs that identifies the selected label and timestamp of the discovered object.
- The results of this JSON are sent to a Lambda function to perform geometry mathematics to determine if the vehicle boxes are duplicated in the safe area of ​​the bike.
- The encounters detected are generated and passed to AWS Elemental MediaConvert.
CreateJob
API - MediaConvert will create these videos and upload them to your S3 bucket.
- Another lambda function is called to generate a pre-signed URL for the video. This allows anyone who has a pre-signed URL to download the video temporarily.
- Amazon Simple Notification Service (Amazon SNS) sends an email message that contains a link to a pre-signed URL.
Prerequisites
To use the solutions outlined in this post, you need to:
- AWS accounts with appropriate permissions to deploy AWS CloudFormation stacks
- MP4 format video recording with .mp4 extension using the H.264 codec. The video must come from a pre-made vendor (such as GoPro, DJI, Cycliq) from the front or rear camera. The maximum file size is 10 GB.
Deploying the solution
- Deploy this solution in your environment or choose to Start the stack. This solution will be deployed in the AWS US East (N. Virginia) US-East-1 AWS region.
- Create a stack The CloudFormation dashboard page appears. At the bottom of the page, select Next.
- In Specify stack details Enter the email address you want to receive notifications from and the page. choose Next.
- Select the box to say I acknowledge that AWS CloudFormation may create IAM resources Select Next. choose submit The installation will begin. The solution will take approximately 5 minutes to install.
- You will receive an email confirming your Amazon SNS subscription. You will not receive emails from the solution unless you confirm your subscription.
- When the stack is complete, select output Note the bucket names listed on the tab inputbucket.
Use the solution
To test the solution, I had a sample video and asked the stunt driver to drive very closely.
To start video processing, upload the video to an S3 bucket (from the output tab to the input bucket). The bucket has encryption enabled, so PropertiesI’ll choose Specify the encryption key Select Use bucket settings for default encryption. choice Upload Start the upload process as shown in the following image:
After a while, the step function begins processing. After a few minutes, you will receive an email with a link to the identified encounter, as shown in the following image.
In my case, I have identified two encounters. At the first encounter identified, I was too close to a parked car. However, the second encounter identified shows the dangerous encounters experienced in stunt drivers.
If this was a real, dangerous encounter, we could provide video clips to the right authorities to help change our behavior and make the road safer for everyone.
Pricing
This is a completely serverless solution, so you only pay for what you use. With Amazon Rekognition, you pay for minutes of processed videos. With MediaConvert you pay for several minutes of video processing, each one minute of video output with multiplier applied based on the functionality used. The use of Lambda, Step features and social media by the solution is minimal and could fall into the free tier for most users.
cleaning
To delete a resource created as part of this solution, go to the CloudFormation console and select and select the expanded stack. erase.
Conclusion
This example demonstrates how to use Amazon Rekognition video analytics in a unique scenario. Amazon Rekognition is a powerful computer vision tool that allows you to gain insights from images and videos without the overhead of building or managing machine learning models. Of course, Amazon Rekognition can also handle more advanced use cases than what I have shown here.
This example demonstrates how Amazon Rekognition can be used with other serverless services to generate a serverless video processing workflow that can help improve cyclists’ safety. You may not be an avid cyclist, but the solutions demonstrated here can be scaled to a variety of use cases and industries. For example, you can extend this solution to detect wildlife in natural cameras, or use Amazon Rekognition streaming video events to detect people and packages in security video.
Start today with Amazon Rekognition as your computer vision use case.
About the author
Mike George He is a leading solution architect for Amazon Web Services (AWS), based in Salt Lake City, Utah. He helps clients solve technology problems. His interests include software engineering, security, artificial intelligence (AI), and machine learning (ML).