我正在尝试将“ vlc-qt ”连接到“ opencv ”。我正在使用VlcInstance和VlcMedia阅读我的网络摄像机。
据我所知,要使 OpenCV 正常工作,它需要将视频置于 Mat 格式:
videoCapture cap;
Mat frame ;
cap >> frame ;
但我有它的VlcMedia格式。有没有办法将其转换为 Mat 格式(或作为视频捕获的源),然后将其转换回 VlcMedia 以便能够在 VlcMediaPlayer 中显示它。
我需要它快速(实际上是实时快速:D)。
这是我的代码(我在 Visual Studio 中使用 Qt):
我的头文件:
#ifndef QT_VLC_OPENCV1_H
#define QT_VLC_OPENCV1_H
#include <QtWidgets/QMainWindow>
#include "ui_qt_vlc_opencv1.h"
#include <VLCQtCore\Instance.h>
#include <VLCQtCore\Media.h>
#include <VLCQtCore\MediaPlayer.h>
class qt_vlc_opencv1 : public QMainWindow
{
Q_OBJECT
public:
qt_vlc_opencv1(QWidget *parent = 0);
~qt_vlc_opencv1();
private slots:
void on_btnOpenFile_clicked();
private:
Ui::qt_vlc_opencv1Class ui;
VlcInstance *_instance;
VlcMedia *_media;
VlcMediaPlayer *_player;
};
#endif // QT_VLC_OPENCV1_H
和我的 cpp 文件:
#include "qt_vlc_opencv1.h"
#include <VLCQtCore\Common.h>
#include <qinputdialog.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv.h>
using namespace cv;
qt_vlc_opencv1::qt_vlc_opencv1(QWidget *parent)
: QMainWindow(parent), _media(0)
{
ui.setupUi(this);
_instance = new VlcInstance(VlcCommon::args(), this);
_player = new VlcMediaPlayer(_instance);
_player->setVideoWidget(ui.video);
ui.video->setMediaPlayer(_player);
}
qt_vlc_opencv1::~qt_vlc_opencv1()
{
delete _player;
delete _media;
delete _instance;
}
void qt_vlc_opencv1::on_btnOpenFile_clicked()
{
QString file = QInputDialog::getText(this,tr("Open File"),tr("Enter a file path or a Url"));
if (file.isEmpty())
return;
_media = new VlcMedia(file, true, _instance);
_player->open(_media);
}