当前位置:网站首页>QT——连接USB摄像头
QT——连接USB摄像头
2022-07-26 10:53:00 【vhcjgc】
功能:使用QT连接USB摄像头,点击按钮显示画面
QT += multimedia
QT += multimediawidgets
#include "camera.h"
#include "ui_camera.h"
Camera::Camera(QWidget *parent) :
QWidget(parent),
ui(new Ui::Camera)
{
ui->setupUi(this);
iniCamera();
}
Camera::~Camera()
{
delete ui;
}
void Camera::iniCamera()
{
cameras = QCameraInfo::availableCameras();//获取摄像头列表
qDebug()<<cameras.size();
for(int i = 0;i<cameras.size();i++)
ui->comboCamera->addItem(cameras[i].description());//摄像头描述
}
void Camera::on_camStartBtn_clicked()
{
curCamera=new QCamera(cameras[ui->comboCamera->currentIndex()],this);//新建QCamera
curCamera->setViewfinder(ui->widget); //设置取景框预览
curCamera->start();
}
#ifndef CAMERA_H
#define CAMERA_H
#include <QWidget>
#include <QCameraInfo>
#include <QCamera>
#include <QLabel>
#include <QCameraViewfinder>
#include <QCameraImageCapture>
#include <QMediaRecorder>
namespace Ui {
class Camera;
}
class Camera : public QWidget
{
Q_OBJECT
public:
explicit Camera(QWidget *parent = nullptr);
~Camera();
void iniCamera();//摄像头初始化
QCamera *curCamera=Q_NULLPTR;//
QList<QCameraInfo> cameras;//可用相机列表
QCameraImageCapture *imageCapture; //抓图
QMediaRecorder* mediaRecorder;//录像
private slots:
void on_camStartBtn_clicked();
private:
Ui::Camera *ui;
};
#endif // CAMERA_H

实现效果

边栏推荐
- pytest 执行规则_基本用法_常用插件_常用断言_常用参数
- 解决org.apache.commons.codec.binary.Base64爆红问题
- RT thread learning notes (VI) -- start the elmfat file system based on SPI flash (Part 1)
- pytest pytest. Ini configuration case grouping case skipping
- LIst和Dictionary实例应用(※)
- c 语言中宏参数的字符串化跟宏参数的连接
- @The difference and use of jsonformat and @datetimeformat
- Bash shell学习笔记(三)
- Bash shell学习笔记(五)
- Logging advanced use
猜你喜欢

Bash shell learning notes (6)

ThreadPoolExecutor是怎样执行任务的

WIRESHARK基础教程以太帧的分析。

使用Selenium抓取zabbix性能监控图

mother

Wechat official account message notice "errCode": 40164, "errmsg": "invalid IP

pytest pytest.ini配置 用例分组 用例跳过

Bash shell学习笔记(四)

Capture ZABBIX performance monitoring chart with selenium

菜鸟看源码之ArrayList
随机推荐
20210807 1 c language program structure
Pytest fixture decorator
Bash shell learning notes (II)
经典蓝牙的连接过程
企鹅龙(DRBL)无盘启动+再生龙(clonezilla)网络备份与还原系统
字典与int矩阵
Sword finger offer (52): regularization expression
104. Maximum depth of binary tree
MFC中0x003b66c3 处有未经处理的异常: 0xC000041D: 用户回调期间遇到未经处理的异常
Bigdecimal的加减乘除、比较大小、向上向下取整 和 Bigdecimal的集合累加、判断BigDecimal是否有小数
MFC picture control
像素和内存的关系
Bash shell learning notes (6)
349. Intersection of two arrays
菜鸟看源码之HashTable
Bash shell学习笔记(六)
Bash shell learning notes (III)
雨课堂 《知识产权法》笔记
ThreadPoolExecutor是怎样执行任务的
C language pengge 20210812c language function