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. ...
随机推荐
- Awesome Python
Awesome Python A curated list of awesome Python frameworks, libraries, software and resources. Insp ...
- unity中的欧拉角
unity中欧拉角用的是heading - pitch -bank系统(zxy惯性空间旋转系统):当认为旋转顺序是zxy时,是相对于惯性坐标系旋转.当认为旋转顺序是yxz时,是相对于物体坐标系旋转. ...
- angular模板加载 ----ng-template
Angularjs作为mvc(或者说mvvm)框架,同样具备模板这一基本概念. NG加载模板的顺序为 内存加载---AJAX加载. 如果排版乱掉,请查阅https://www.zybuluo.com/ ...
- 运行setup.js文件
C:\Windows\System32>wscript.exe setup.js
- Log4j使用详解(log4j.properties格式)
Log4j使用详解(log4j.properties格式) 1.Log4j 的引入 在应用程序中添加日志记录总的来说基于三个目的: ① 监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计 ...
- HTML5之Canvas绘图实例——曲线图
实现正弦.余弦和正切函数画图(如下图):调试环境:Firefox
- Mysql 索引 转载
转自 :http://blog.csdn.net/wud_jiyanhui/article/details/7403375 什么是索引 索引时一种特殊的文件,他们包涵着对数据表里所有记录的引用指针. ...
- form表单元素类型
<form> <input type="text"> <input type="password"> <input t ...
- Zabbix的安装与部署---问题处理(php65.6.28 mysqli 报错误 处理)
1)php65.6.28 mysqli 报错误 处理 http://www.xiaochengfu.com/index.php/index/detail/aid/92.html 2)linux下p ...
- 【shiro】org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token
org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.sh ...