简体   繁体   English

如何同时在不同的QT小部件上显示多个视频

[英]how I can display multiple videos on different QT widgets at the same time

I have done a code which run different algorithms of OpenCV on different QWidgets .. so I have 3 tabs and each should show a camera live streaming with the processing of them .. I take the capture of the video at the first tab widget and pass it by global reference to the other tabs... however I get this problem 我完成了一个代码,在不同的QWidgets上运行OpenCV的不同算法..因此,我有3个选项卡,每个选项卡都应显示摄像机实时流并对其进行处理..我在第一个选项卡小部件中捕获了视频并通过通过全局引用其他选项卡...但是我遇到了这个问题

libv4l1: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT

although I have only one capture .. 虽然我只有一个捕获..

any ideas? 有任何想法吗?

The proper way to handle this issue is copy the frame retrieved by the camera and make it available to the other tabs. 解决此问题的正确方法是复制相机获取的帧 ,并将其提供给其他选项卡。 Do not share the capture interface! 不要共享capture界面!

I'm also working with OpenCV and Qt. 我也在使用OpenCV和Qt。 For emulating a camera I'm using the Capture object to read frames from a video file and send them over TCP/IP. 为了模拟摄像机,我使用Capture对象从视频文件中读取帧并通过TCP / IP发送它们。

To make your frames available to all the others widgets I suggest to you to create a new class that inherits from QIODevice, initialize your capture device. 为了使您的框架可用于所有其他小部件,我建议您创建一个继承自QIODevice的新类,初始化捕获设备。 Every time you get a new frame from the camera, you save the data into a QByteArray variable and emits the readyRead() signal. 每次从摄像机获取新帧时,都将数据保存到QByteArray变量中并发出readyRead()信号。

Note: - all your widgets have to be connected to the readyRead() signal - once you get a new frame, remember to clean previous data - you have to re-implement function virtual qint64 readData( char * data, qint64 maxSize ) to be able to read your data 注意:-您的所有小部件都必须连接到readyRead()信号-一旦获得新的帧,请记住清除以前的数据-您必须重新实现virtual qint64 readData( char * data, qint64 maxSize )函数能够读取您的数据

Something like this 像这样

#include "opencv2/highgui/highgui.hpp"

using namespace cv;

class VideoCaptureDevice : public QIODevice
{
    Q_OBJECT

public:
    VideoCaptureDevice(QObject *parent);
    virtual ~VideoCaptureDevice();

private:
    VideoCapture            m_capture;
    QByteArray      m_receivedData;

protected:
    // from QIODevice
    qint64 writeData(const char * data, qint64 maxSize);
    qint64 readData(char * data, qint64 maxSize);

};

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

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