qt上用opencv显示摄像头视频
参考:http://blog.csdn.net/augusdi/article/details/8865541
代码如下:
注意,要在ui界面上放置一个“Vertical Layout”控件,调整到合适大小
#include <QtWidgets/QMainWindow>
#include <QPaintEvent>
#include <QTimer>
#include <QPainter>
#include <QPixmap>
#include <QLabel>
#include <QImage>
#include <opencv.hpp>
#include "ui_mainwindow.h"
using namespace cv;
class mainwindow : public QMainWindow
{
Q_OBJECT
public:
mainwindow(QWidget *parent = 0);
~mainwindow();
public slots:
void updateImage();
private:
QTimer theTimer;
Mat srcImage;
VideoCapture videoCap;
QLabel *imageLabel;
Ui::mainwindowClass ui;
protected:
void paintEvent(QPaintEvent *e);
};
mainwindow::mainwindow(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(&theTimer, &QTimer::timeout, this, &mainwindow::updateImage);
//从摄像头捕获视频
if(videoCap.open(0))
{
srcImage = Mat::zeros(videoCap.get(CV_CAP_PROP_FRAME_HEIGHT), videoCap.get(CV_CAP_PROP_FRAME_WIDTH), CV_8UC3);
theTimer.start(33);
}
//设置显示视频用的Label
imageLabel = new QLabel(this);
ui.verticalLayout->addWidget(imageLabel);
}
mainwindow::~mainwindow()
{
}
void mainwindow::paintEvent(QPaintEvent *e)
{
//显示方法一
QPainter painter(this);
QImage image1 = QImage((uchar*)(srcImage.data), srcImage.cols, srcImage.rows, QImage::Format_RGB888);
painter.drawImage(QPoint(20,20), image1);
//显示方法二
QImage image2 = QImage((uchar*)(srcImage.data), srcImage.cols, srcImage.rows, QImage::Format_RGB888);
imageLabel->setPixmap(QPixmap::fromImage(image2));
imageLabel->resize(image2.size());
imageLabel->show();
}
void mainwindow::updateImage()
{
videoCap>>srcImage;
if(srcImage.data)
{
cvtColor(srcImage, srcImage, CV_BGR2RGB);//Qt中支持的是RGB图像, OpenCV中支持的是BGR
this->update(); //发送刷新消息
}
}
演示结果:
qt上用opencv显示摄像头视频的更多相关文章
- 在Jetson TX2上捕获、显示摄像头视频
参考文章:How to Capture and Display Camera Video with Python on Jetson TX2 与参考文章大部分都是相似的,如果不习惯看英文,可以看看我下 ...
- 在Jetson TX2上显示摄像头视频并使用python进行caffe推理
参考文章:How to Capture Camera Video and Do Caffe Inferencing with Python on Jetson TX2 与参考文章大部分都是相似的,如果 ...
- opencv 显示摄像头数据
本文章是一个小例子,主要是在ubuntu 系统中利用Opencv 显示摄像头的数据 ,显示到对话框中. 1.建立一个 main.cpp #include<opencv2/core/core.h ...
- Opencv保存摄像头视频&&各种编码器下视频文件占用空间对比
打开视频文件或摄像头视频需要使用Opencv中的VideoCapture类,保存视频或摄像头视频到本地磁盘,需要使用Opencv中的VideoWriter类,使用都很简单,这篇文章就记录一下Video ...
- [OpenCV]获取摄像头视频
环境:Windows 8 64bit + VS2012 X64 + OpenCV 2.4.7 摄像头的捕捉使用VideoCapture类 Class VideoCapture [OpenCV文档 ...
- 在Jetson TX2上安装OpenCV(3.4.0)
参考文章:How to Install OpenCV (3.4.0) on Jetson TX2 与参考文章大部分都是相似的,如果不习惯看英文,可以看看我下面的描述 在我们使用python3进行编程时 ...
- 使用opencv显示视频的方法
下面对使用opencv显示视频做一个简单的记录.当然,网上这方面的资料已经数不胜数了,我只是将其简单记录,总结一下. 在opencv中显示视频主要有: (1)从本地读取视频和调用摄像头读取视频 (2) ...
- Kinect SDK(1):读取彩色、深度、骨骼信息并用OpenCV显示
Kinect SDK 读取彩色.深度.骨骼信息并用OpenCV显示 一.原理说明 对于原理相信大家都明白大致的情况,因此,在此只说比较特别的部分. 1.1 深度流数据: 深度数据流所提供的图像帧中,每 ...
- crtmpserver的安装,摄像头视频测试
下载 svn co --username anonymous --password "" https://svn.rtmpd.com/crtmpserver/branches/1. ...
随机推荐
- unbuntu下安装flash插件
adobe flash player的官方下载页面为:https://get.adobe.com/cn/flashplayer/ 不过近期通过APT方式以及ubuntu的软件中心都安装不了flashp ...
- linux重启和关闭系统命令
重启命令: 1.reboot 2.shutdown -r now 立刻重启(root用户使用) 3.shutdown -r 10 过10分钟自动重启(root用户使用) 4.shutdown -r 2 ...
- lvM增减教程-转
http://blog.jobbole.com/71858/ 逻辑卷管理LVM是一个多才多艺的硬盘系统工具.无论在Linux或者其他类似的系统,都是非常的好用.传统分区使用固定大小分区,重新调整大小十 ...
- 把excel数据生成sql insert语句
excel表格中有A.B.C三列数据,希望导入到数据库users表中,对应的字段分别是name,sex,age . 在你的excel表格中增加一列,利用excel的公式自动生成sql语句,方法如下: ...
- CSS3 必须要知道的10 个顶级命令
来源:http://www.cnblogs.com/damonlan/archive/2012/04/23/2465569.html 作者:浪迹天涯 1.边框圆角(Border Radiuas) 这个 ...
- OpenJudge计算概论-单词倒排【把句子内单词的顺序翻转】
/*================================================== 单词倒排 总时间限制: 1000ms 内存限制: 65536kB 描述 编写程序,读入一段英文 ...
- 【转】Php+ajax+jsonp解决ajax跨域问题
首先:jsonp是json用来跨域的一个东西. 原理是通过script标签的跨域特性来绕过同源策略. 发送端: $.ajax({ type : "post", url : &quo ...
- 解决Win10默认占用80端口
方案1: 以管理员身份运行cmd;输入net stop http;如果提示是否真的需要停止这些服务,则选择“Y”;完成后输入:sc config http start=disabled 方案2: Ct ...
- C# 中如何判断某个字符串是否为空的方法
C# 中如何判断某个字符串是否为空的方法 分享了三个方法来判断字符串是否为空 引自:http://www.itokit.com/2012/0724/74618.html 1. 三种常用的字符串判空串方 ...
- C#-提取网页中的超链接
转载:http://www.wzsky.net/html/Program/net/26849.htmlusing System; using System.Xml; using System.Text ...