简体   繁体   English

使用python在视频流上绘制边界框

[英]Drawing bounding boxes on video streams using python

I am using AWS Kinesis Video Streams to stream my camera on to the cloud.我正在使用 AWS Kinesis Video Streams 将我的相机流式传输到云端。 I then analyse it with AWS Lambda using Sagemaker, which returns the name of the objects and their coordinates in the video stream.然后,我使用 Sagemaker 使用 AWS Lambda 对其进行分析,它返回视频流中的对象名称及其坐标。

Now, I would like to improve my Lambda code (python) that creates bounding boxes on the kinesis video streams.现在,我想改进在 kinesis 视频流上创建边界框的 Lambda 代码 (python)。

My problems are: 1. How do I grab the stream?我的问题是: 1. 我如何抓取流? 2. How do I overlap bounding boxes using coordinates? 2. 如何使用坐标重叠边界框? Do I use cv2?我使用 cv2 吗? 3. How do I upload the stream to a new stream? 3. 如何将流上传到新流?

I saw a code doing this but in Java.我看到了一个代码,但在 Java 中。 Here's a link .这是一个链接

Here is my approach to your problems.这是我解决您问题的方法。

1. How do I grab the stream? 1.我如何抓取流?

You can use aws boto3 library to get the video frames using the GET_MEDIA api or streams using KinesisVideoArchivedmedia to get the HLS or DASH streaming url which seems to solve your problem but GET_MEDIA api has less overheads.您可以使用 aws boto3 库获取使用 GET_MEDIA api 的视频帧或使用 KinesisVideoArchivedmedia 的流获取 HLS 或 DASH 流 url,这似乎可以解决您的问题,但 GET_MEDIA api 的开销较少。 boto3 documentation boto3 文档

2. How do I overlap bounding boxes using coordinates? 2. 如何使用坐标重叠边界框? Do I use cv2?我使用 cv2 吗?

You can use any video rendering library such as pyav or opencv to do it.您可以使用任何视频渲染库(例如 pyav 或 opencv)来执行此操作。 The code to do it with opencv is easily available on the internet but you also need to consider other challenges like AWS Lambda limitations, consistency of available bounding boxes coordinates with the frame rate(you need atleast 3-4fps of object detections with a 15fps video to make it look real time)使用 opencv 执行此操作的代码在 Internet 上很容易获得,但您还需要考虑其他挑战,例如 AWS Lambda 限制、可用边界框与帧速率协调的一致性(您需要至少 3-4fps 的对象检测和 15fps 的视频使其看起来实时)

3. How do I upload the stream to a new stream? 3. 如何将流上传到新流?

If you want to upload the stream back to Kinesis Video Stream, it is quite difficult and I don't think Lambdas will be sufficient for all the required processing.如果您想将流上传回 Kinesis Video Stream,这是非常困难的,而且我认为 Lambdas 不足以完成所有必需的处理。 You may use ec2 instances for the purpose.您可以为此目的使用 ec2 实例。 Other option is to save the rendered video to s3 and have a video transcoding service(like AWS Mediaconvert, or build your own) to transcode the rendered video to HLS or DASH stream.另一种选择是将渲染的视频保存到 s3 并使用视频转码服务(如 AWS Mediaconvert,或构建您自己的)将渲染的视频转码为 HLS 或 DASH 流。 The HLS or DASH stream saved on s3 can be streamed using content delivery network such as AWS Cloudfront.保存在 s3 上的 HLS 或 DASH 流可以使用内容交付网络(例如 AWS Cloudfront)进行流式传输。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM