简体   繁体   English

使用pyqt4从摄像机流式传输视频

[英]streaming video from camera using pyqt4

I am using a thirdparty library that utilizes a circular buffer for image data and video. 我正在使用第三方库,该库利用循环缓冲区存储图像数据和视频。 It has a method for getting the last image or popping it. 它具有获取或弹出最后一张图像的方法。 I was wondering what would be the best way to implement video functionality in pyqt for this. 我想知道什么是在pyqt中实现视频功能的最佳方法。 Is there some video widget with a callback function that I could use? 是否有一些我可以使用的带有回调功能的视频小部件? Or do I have to somehow implement parallel processing on my own? 还是我必须以某种方式自行实现并行处理? Parallel to this, suggestions on how this would be implemented in qt if you dont know how to implement it in pyqt would also be very much appreciated. 与此平行的是,如果您不知道如何在pyqt中实现它,那么关于如何在qt中实现它的建议也将不胜感激。

Thanks in advance! 提前致谢!

I would pop the last image (from the circular buffer) and load it into a QPixmap . 我将弹出最后一个图像(从循环缓冲区中)并将其加载到QPixmap This allows you to put the image into a form that a pyqt4 gui would be able to load. 这使您可以将图像放入pyqt4 gui可以加载的形式。

Depending on your libraries image format (straight forward bmp? jpg? png? raw pixels?), you can load the data into the QPixmap in one of two ways. 根据您的库的图像格式(直接bmp?jpg?png?原始像素?),您可以通过以下两种方式之一将数据加载到QPixmap中。

First: do it pixel by pixel (set the width and height of the image and copy each pixels value over one by one). 首先:逐像素处理(设置图像的宽度和高度,并逐个复制每个像素值)。 This method is slow and I'd only resort to it if necessary. 这种方法很慢,只有在必要时才求助。

Second: if the image is being stored in a common format (ones that are 'supported' are listed here ), this becomes trivial. 第二:如果图像以一种通用格式存储( 此处列出 “受支持的”格式),那么这变得微不足道了。

Then after the image is loaded in the QPixmap, I would use QLabel.setPixmap() to display the image. 然后在将图像加载到QPixmap中之后,我将使用QLabel.setPixmap()来显示图像。

Do this with a QTimer slot at a certain rate and you'll be able to display your images in a pyqt4 gui. 使用QTimer插槽以一定速率执行此操作,您将能够在pyqt4 gui中显示图像。

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

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