当前位置:网站首页>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

实现效果

边栏推荐
- 232. Implement queue with stack
- -bash: ./build.sh: /bin/bash^M: 坏的解释器: 没有那个文件或目录
- 菜鸟看源码之ArrayList
- Kali view IP address
- 0x00007FFD977C04A8 (Qt5Sqld.dll)处(位于 a.exe 中)引发的异常: 0xC0000005: 读取位置 0x0000000000000010 时发生访问冲突
- -bash: ./build. Sh: /bin/bash^m: bad interpreter: no that file or directory
- Summary of the seventh class of pengge C language
- 像素和内存的关系
- 如何组装一个注册中心?
- Sword finger offer (53): a string representing a numeric value
猜你喜欢
随机推荐
349. Intersection of two arrays
经典蓝牙的连接过程
ThreadPoolExecutor是怎样执行任务的
0x00007ffd977c04a8 (qt5sqld.dll) (in a.exe): 0xc0000005: an access violation occurred when reading position 0x0000000000000010
Analysis of C # delegation and anonymous method
Sword finger offer (44): flip the word order sequence
Traversal recursion + iteration of binary tree
Minesweeping Pro version 2021-08-19
Bash shell learning notes (4)
mysql20210906
Bash shell学习笔记(七)
@The difference and use of jsonformat and @datetimeformat
pytest 执行规则_基本用法_常用插件_常用断言_常用参数
242.有效的字母异位词
Bash shell学习笔记(二)
Basic use of logging
Newbie sees the source code arraydeque
1837.K进制表示下的各位数字总和
MFC picture control
Wireshark basic tutorial Ethernet frame analysis.









