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

发布于 2025-01-08 14:42:20 字数 308 浏览 0 评论 0原文

我已经编写了一个代码,在不同的 QWidget 上运行不同的 OpenCV 算法..所以我有 3 个选项卡,每个选项卡都应该显示一个摄像头实时流媒体以及它们的处理..我在第一个选项卡小部件处捕获视频并通过它通过对其他选项卡的全局引用...但是我遇到了这个问题,

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

尽管我只有一个捕获...

有什么想法吗?

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

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

although I have only one capture ..

any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坐在坟头思考人生 2025-01-15 14:42:20

处理此问题的正确方法是复制相机检索到的帧并将其提供给其他选项卡。 不要共享捕获接口!

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!

迷离° 2025-01-15 14:42:20

我也在使用 OpenCV 和 Qt。为了模拟相机,我使用 Capture 对象从视频文件中读取帧并通过 TCP/IP 发送它们。

为了使您的框架可供所有其他小部件使用,我建议您创建一个继承自 QIODevice 的新类,并初始化您的捕获设备。每次从相机获取新帧时,都将数据保存到 QByteArray 变量中并发出 readRead() 信号。

笔记:
- 所有的小部件都必须连接到readyRead()信号
- 一旦你得到一个新的框架,记得清理以前的数据
- 你必须重新实现函数virtual qint64 readData( char * data, qint64 maxSize )才能读取你的数据

像这样

#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);

};

I'm also working with OpenCV and Qt. For emulating a camera I'm using the Capture object to read frames from a video file and send them over 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. Every time you get a new frame from the camera, you save the data into a QByteArray variable and emits the readyRead() signal.

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

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);

};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文