一个用于从实时 MJPEG 视频流中捕获帧、使用 深度学习 在近实时环境中识别对象并触发操作的工作原型。
一个用于从实时 MJPEG 视频流中捕获帧、使用 深度学习 在近实时环境中识别对象并触发操作的工作原型。
Imagine being able to capture live video streams, identify objects using deep learning, and then trigger actions or notifications based on the identified objects -- all with low latency and without a single server to manage.
This is exactly what this project is going to help you accomplish with AWS. You will be able to setup and run a live video capture, analysis, and alerting solution prototype.
The prototype was conceived to address a specific use case, which is alerting based on a live video feed from an IP security camera. At a high level, the solution works as follows. A camera surveils a particular area, streaming video over the network to a video capture client. The client samples video frames and sends them over to AWS, where they are analyzed and stored along with metadata. If certain objects are detected in the analyzed video frames, SMS alerts are sent out. Once a person receives an SMS alert, they will likely want to know what caused it. For that, sampled video frames can be monitored with low latency using a web-based user interface.
Here's the prototype's conceptual architecture:
Let's go through the steps necessary to get this prototype up and running. If you are starting from scratch and are not familiar with Python, completing all steps can take a few hours.
Here’s a high-level checklist of what you need to do to setup your development environment.
Sign up for an AWS account if you haven't already and create an Administrator User. The steps are published here.
Ensure that you have Python 2.7+ and Pip on your machine. Instructions for that varies based on your operating system and OS version.
Create a Python virtual environment for the project with Virtualenv. This helps keep project’s python dependencies neatly isolated from your Operating System’s default python installation. Once you’ve created a virtual python environment, activate it before moving on with the following steps.
Use Pip to install AWS CLI. Configure the AWS CLI. It is recommended that the access keys you configure are associated with an IAM User who has full access to the following:
The IAM User can be the Administrator User you created in Step 1.
Make sure you choose a region where all of the above services are available. Regions us-east-1 (N. Virginia), us-west-2 (Oregon), and eu-west-1 (Ireland) fulfill this criterion. Visit this page to learn more about service availability in AWS regions.
Use Pip to install Open CV 3 python dependencies and then compile, build, and install Open CV 3 (required by Video Cap clients). You can follow this guide to get Open CV 3 up and running on OS X Sierra with Python 2.7. There's another guide for Open CV 3 and Python 3.5 on OS X Sierra. Other guides exist as well for Windows and Raspberry Pi.
Use Pip to install Boto3. Boto is the Amazon Web Services (AWS) SDK for Python, which allows Python developers to write software that makes use of Amazon services like S3 and EC2. Boto provides an easy to use, object-oriented API as well as low-level direct access to AWS services.
Use Pip to install Pynt. Pynt enables you to write project build scripts in Python.
Clone this GitHub repository. Choose a directory path for your project that does not contain spaces (I'll refer to the full path to this directory as __).
Use Pip to install pytz. Pytz is needed for timezone calculations. Use the following commands:
pip install pytz # Install pytz in your virtual python env
pip install pytz -t /lambda/imageprocessor/ # Install pytz to be packaged and deployed with the Image Processor lambda functionFinally, obtain an IP camera. If you don’t have an IP camera, you can use your smartphone with an IP camera app. This is useful in case you want to test things out before investing in an IP camera. Also, you can simply use your laptop’s built-in camera or a connected USB camera. If you use an IP camera, make sure your camera is connected to the same Local Area Network as the Video Capture client.
In this section, I list every configuration file, parameters within it, and parameter default values. The build commands detailed later extract the majority of their parameters from these configuration files. Also, the prototype's two AWS Lambda functions - Image Processor and Frame Fetcher - extract parameters at runtime from imageprocessor-params.json and framefetcher-params.json respectively.
NOTE: Do not remove any of the attributes already specified in these files.
NOTE: You must set the value of any parameter that has the tag NO-DEFAULT
Specifies “global” build configuration parameters. It is read by multiple build scripts.
{
"StackName" : "video-analyzer-stack"
}Parameters:
StackName - The name of the stack to be created in your AWS account.Specifies and overrides default values of AWS CloudFormation parameters defined in the template (located at aws-infra/aws-infra-cfn.yaml). This file is read by a number of build scripts, including createstack, deploylambda, and webui.
{
"SourceS3BucketParameter" : "",
"ImageProcessorSourceS3KeyParameter" : "src/lambda_imageprocessor.zip",
"FrameFetcherSourceS3KeyParameter" : "src/lambda_framefetcher.zip",
"FrameS3BucketNameParameter" : "",
"FrameFetcherApiResourcePathPart" : "enrichedframe",
"ApiGatewayRestApiNameParameter" : "VidAnalyzerRestApi",
"ApiGatewayStageNameParameter": "development",
"ApiGatewayUsagePlanNameParameter" : "development-plan"
}Parameters:
SourceS3BucketParameter - The Amazon S3 bucket to which your AWS Lambda function packages (.zip files) will be deployed. If a bucket with such a name does not exist, the deploylambda build command will create it for you with appropriate permissions. AWS CloudFormation will access this bucket to retrieve the .zip files for Image Processor and Frame Fetcher AWS Lambda functions.
ImageProcessorSourceS3KeyParameter - The Amazon S3 key under which the Image Processor function .zip file will be stored.
FrameFetcherSourceS3KeyParameter - The Amazon S3 key under which the Frame Fetcher function .zip file will be stored.
FrameS3BucketNameParameter - The Amazon S3 bucket that will be used for storing video frame images. There must not be an existing S3 bucket with the same name.
FrameFetcherApiResourcePathPart - The name of the Frame Fetcher API resource path part in the API Gateway URL.
ApiGatewayRestApiNameParameter - The name of the API Gateway REST API to be created by AWS CloudFormation.
ApiGatewayStageNameParameter - The name of the API Gateway stage to be created by AWS CloudFormation.
ApiGatewayUsagePlanNameParameter - The name of the API Gateway usage plan to be created by AWS CloudFormation.
Specifies configuration parameters to be used at run-time by the Image Processor lambda function. This file is packaged along with the Image Processor lambda function code in a single .zip file using the packagelambda build script.
{
"s3_bucket" : "",
"s3_key_frames_root" : "frames/",
"ddb_table" : "EnrichedFrame",
"rekog_max_labels" : 123,
"rekog_min_conf" : 50.0,
"label_watch_list" : ["Human", "Pet", "Bag", "Toy"],
"label_watch_min_conf" : 90.0,
"label_watch_phone_num" : "",
"label_watch_sns_topic_arn" : "",
"timezone" : "US/Eastern"
}s3_bucket - The Amazon S3 bucket in which Image Processor will store captured video frame images. The value specified here must match the value specified for the FrameS3BucketNameParameter parameter in the cfn-params.json file.
s3_key_frames_root - The Amazon S3 key prefix that will be prepended to the keys of all stored video frame images.
ddb_table - The Amazon DynamoDB table in which Image Processor will store video frame metadata. The default value,EnrichedFrame, matches the default value of the AWS CloudFormation template parameter DDBTableNameParameter in the aws-infra/aws-infra-cfn.yaml template file.
rekog_max_labels - The maximum number of labels that Amazon Rekognition can return to Image Processor.
rekog_min_conf - The minimum confidence required for a label identified by Amazon Rekognition. Any labels with confidence below this value will not be returned to Image Processor.
label_watch_list - A list of labels for to watch out for. If any of the labels specified in this parameter are returned by Amazon Rekognition, an SMS alert will be sent via Amazon SNS. The label's confidence must exceed label_watch_min_conf.
label_watch_min_conf - The minimum confidence required for a label to trigger a Watch List alert.
label_watch_phone_num - The mobile phone number to which a Watch List SMS alert will be sent. Does not have a default value. You must configure a valid phone number adhering to the E.164 format (e.g. +1404XXXYYYY) for the Watch List feature to become active.
label_watch_sns_topic_arn - The SNS topic ARN to which you want Watch List alert messages to be sent. The alert message contains a notification text in addition to a JSON formatted list of Watch List labels found. This can be used to publish alerts to any SNS subscribers, such as Amazon SQS queues.
timezone - The timezone used to report time and date in SMS alerts. By default, it is "US/Eastern". See this list of country codes, names, continents, capitals, and pytz timezones).
Specifies configuration parameters to be used at run-time by the Frame Fetcher lambda function. This file is packaged along with the Frame Fetcher lambda function code in a single .zip file using the packagelambda build script.
{
"s3_pre_signed_url_expiry" : 1800,
"ddb_table" : "EnrichedFrame",
"ddb_gsi_name" : "processed_year_month-processed_timestamp-index",
"fetch_horizon_hrs" : 24,
"fetch_limit" : 3
}s3_pre_signed_url_expiry - Frame Fetcher returns video frame metadata. Along with the returned metadata, Frame Fetcher generates and returns a pre-signed URL for every video frame. Using a pre-signed URL, a client (such as the Web UI) can securely access the JPEG image associated with a particular frame. By default, the pre-signed URLs expire in 30 minutes.
ddb_table - The Amazon DynamoDB table from which Frame Fetcher will fetch video frame metadata. The default value,EnrichedFrame, matches the default value of the AWS CloudFormation template parameter DDBTableNameParameter in the aws-infra/aws-infra-cfn.yaml template file.
ddb_gsi_name - The name of the Amazon DynamoDB Global Secondary Index that Frame Fetcher will use to query frame metadata. The default value matches the default value of the AWS CloudFormation template parameter DDBGlobalSecondaryIndexNameParameter i
暂无开放 Issues,或尚未同步最近议题。