zoukankan      html  css  js  c++  java
  • vs2015 + opencv3.4.0 + qt msvc2015_64-5.7.1 视屏显示

    1、qt application

    2、qtvideoread.cpp中代码为:

    #include "qtvideoread.h"
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include "opencv2/imgproc/imgproc.hpp"
    #include <QString>
    #include <QLabel>
    #include <QPainter>
    #include <QTimer>

    qtvideoread::qtvideoread(QWidget *parent, Qt::WindowFlags flags)
    : QMainWindow(parent, flags)
    {
    ui.setupUi(this);
    // 初始化处理,建立QImage和frame的关联,开启定时器
    capture.open("E:/studyvsqt/qtvideoread/0920_01.mov");//-1 需要加载所在电脑视屏
    if (capture.isOpened())
    {
    capture >> frame;
    if (!frame.empty())
    {
    cv::cvtColor(frame, frame, CV_BGR2RGB);
    cv::flip(frame, frame, 1);
    image = new QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, QImage::Format_RGB888);
    timer = new QTimer(this);
    timer->setInterval(30);
    connect(timer, SIGNAL(timeout()), this, SLOT(nextFrame()));
    timer->start();
    }
    }
    }

    qtvideoread::~qtvideoread()
    {

    }

    void qtvideoread::paintEvent(QPaintEvent * e)
    {
    // 更新图像
    QPainter painter(this);
    painter.drawImage(QPoint(0, 12), *image);

    }

    void qtvideoread::nextFrame()
    {// 更新数据
    capture >> frame;
    if (!frame.empty())
    {
    cv::cvtColor(frame, frame, CV_BGR2RGB);
    cv::flip(frame, frame, 1);
    this->update();
    }
    }

    3、qtvideoread.h中代码为:

    #ifndef QTVIDEOREAD_H
    #define QTVIDEOREAD_H

    #include <QtWidgets/QMainWindow>
    #include "ui_qtvideoread.h"

    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>

    class qtvideoread : public QMainWindow
    {
    Q_OBJECT
    /*
    public:
    qtvideoread(QWidget *parent = 0);
    ~qtvideoread();

    private:
    Ui::qtvideoreadClass ui;
    */
    public:
    qtvideoread(QWidget *parent = 0, Qt::WindowFlags flags = 0);
    ~qtvideoread();
    protected:
    void paintEvent(QPaintEvent * e);

    private:
    Ui::qtvideoreadClass ui;
    cv::Mat frame;
    cv::VideoCapture capture;
    QImage *image;
    QTimer *timer;

    private slots:
    void nextFrame();

    };

    #endif // QTVIDEOREAD_H

    4、点击运行就可以了

    5、参考的网址:https://blog.csdn.net/yang_xian521/article/details/7042687

  • 相关阅读:
    git错误操作导致代码丢失找回
    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
    WebMvcConfigurerAdapter在Spring boot2.x已废弃
    AJAX实现模拟注册跳转
    遍历字符串替换实例
    spring boot2.x依赖
    Thymeleaf页面添加th:value后报错原因
    thymeleaf中th:href字符拼接
    刁肥宅数据结构课设“布隆过滤器的实现和应用”源代码(v1.0,永不上交)
    数据结构实验1:C++实现静态顺序表类
  • 原文地址:https://www.cnblogs.com/rjjhyj/p/9682247.html
Copyright © 2011-2022 走看看