栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

OpenCV图像处理--opencv摄像头播放视频

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

OpenCV图像处理--opencv摄像头播放视频

步骤一:
Qt+OpenCV环境配置
步骤二:

创建视频播放线程

核心代码如下
视频播放线程.h文件

#include
#include

using namespace cv;
class PlayerVideoThread : public QThread
{
    Q_OBJECT
public:
    PlayerVideoThread(char *videoPath);
    void run();
private:
    VideoCapture cap;
    Mat  frame;
signals:
    void frameVideo(Mat frame);
};

视频播放线程.cpp源文件

#include "playervideothread.h"
#include
PlayerVideoThread::PlayerVideoThread(char *videoPath)
{
    if(cap.open(videoPath))
    {
           qDebug()<<"open video";
    }
}

void PlayerVideoThread::run()
{
    while(cap.read(frame))
    {
        emit frameVideo(frame);
    }
}

视频显示窗口.h文件

class VideoWidget : public QWidget
{
    Q_OBJECT
public:
    explicit VideoWidget(QWidget *parent = 0);

    QLabel *label;

     VideoCapture cap;
     Mat frame;
     PlayerVideoThread *plaverVideoThread;
     void paintEvent(QPaintEvent *e);
signals:

public slots:
      void  updateImage(Mat img);
};

视频显示窗口.cpp文件

VideoWidget::VideoWidget(QWidget *parent) : QWidget(parent)
{

    this->resize(400,400);
    label = new QLabel(this);
    label->resize(400,400);

    this->plaverVideoThread = new PlayerVideoThread("carMove.mp4");
    connect(this->plaverVideoThread,SIGNAL(frameVideo(Mat)),this,SLOT(updateImage(Mat)),Qt::BlockingQueuedConnection);
    this->plaverVideoThread->start();

}

void VideoWidget::paintEvent(QPaintEvent *e)
{
    QImage q_image = QImage(frame.data,frame.cols,frame.rows,QImage::Format_RGB888);
    label->setPixmap(QPixmap::fromImage(q_image));
    label->setScaledContents(true);
}

void VideoWidget::updateImage(Mat img)
{
    this->frame = img.clone();
    this->update();
}

执行效果

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/702467.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号