Qt5如何使用摄像头
来源:互联网 发布:起飞了是什么网络意思 编辑:程序博客网 时间:2024/06/04 18:30
(DEMO代码)项目名称:myCamera
myCamera.pro
QT += multimediaQT += multimediawidgets
mycameradialog.h
#ifndef MYCAMERADIALOG_H#define MYCAMERADIALOG_H#include <QDialog>#include <QCamera>#include <QCameraViewfinder>#include <QCameraImageCapture>#include <QLabel>#include <QPushButton>class MyCameraDialog : public QDialog{ Q_OBJECTpublic: MyCameraDialog(QWidget *parent = 0); ~MyCameraDialog();private slots: void captureBtnResponded(); void saveBtnResponded(); void exitBtnResponded(); void cameraImageCaptured(int id, QImage image);private: // 系统摄像设备(摄像头) QCamera *camera; // 摄像取景器部件 QCameraViewfinder *cameraViewFinder; // 截图部件 QCameraImageCapture *cameraImageCapture; QPushButton *captureBtn; QPushButton *saveBtn; QPushButton *exitBtn; QLabel *displayLabel; void translateLanguage();};#endif // MYCAMERADIALOG_H
mycameradialog.cpp
#include "mycameradialog.h"#include <QHBoxLayout>#include <QVBoxLayout>MyCameraDialog::MyCameraDialog(QWidget *parent) : QDialog(parent){ this->setFixedSize(700, 400); camera = new QCamera(); cameraViewFinder = new QCameraViewfinder(); cameraImageCapture = new QCameraImageCapture(camera); captureBtn = new QPushButton(); saveBtn = new QPushButton(); exitBtn = new QPushButton(); displayLabel = new QLabel(); displayLabel->setFixedSize(160, 120); displayLabel->setScaledContents(true); QVBoxLayout *rightLayout = new QVBoxLayout; rightLayout->addWidget(displayLabel); rightLayout->addStretch(); rightLayout->addWidget(captureBtn); rightLayout->addWidget(saveBtn); rightLayout->addWidget(exitBtn); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(cameraViewFinder); mainLayout->addLayout(rightLayout); connect(captureBtn, SIGNAL(clicked()), this, SLOT(captureBtnResponded())); connect(saveBtn, SIGNAL(clicked()), this, SLOT(saveBtnResponded())); connect(exitBtn, SIGNAL(clicked()), this, SLOT(exitBtnResponded())); connect(cameraImageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(cameraImageCaptured(int,QImage))); cameraImageCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile); camera->setCaptureMode(QCamera::CaptureStillImage); camera->setViewfinder(cameraViewFinder); camera->start(); this->setLayout(mainLayout); this->translateLanguage();}MyCameraDialog::~MyCameraDialog(){}void MyCameraDialog::translateLanguage(){ this->setWindowTitle(tr("testCapture")); captureBtn->setText(tr("capture")); saveBtn->setText(tr("save")); exitBtn->setText(tr("exit"));}void MyCameraDialog::captureBtnResponded(){ cameraImageCapture->capture();}void MyCameraDialog::saveBtnResponded(){ const QPixmap *pixmap = displayLabel->pixmap(); if(pixmap) {pixmap->save("D:/workspace/Qt_Project/test/camera/a.jpg");}}void MyCameraDialog::exitBtnResponded(){ camera->stop(); this->close();}void MyCameraDialog::cameraImageCaptured(int id, QImage image){ displayLabel->setPixmap(QPixmap::fromImage(image));}
1 0
- Qt5如何使用摄像头
- Qt5如何使用麦克风
- 树莓派 使用摄像头 Qt5 Qcamera调用提示:missing camera
- Qt5摄像头截图
- Qt5下实现摄像头预览及捕获图像方法二(openCV3与Qt5交互使用)
- Qt5下实现摄像头预览及捕获图像方法二(openCV3与Qt5交互使用)
- 如何使用Python操作摄像头
- 如何使用PYTHON操作摄像头
- QT5中如何使用QFtp类
- QT5.2如何使用QWT6.1
- Qt5.6.1如何使用qpf2字体
- Qt5.5 调用摄像头拍照
- Qt5.3里使用OpenCV库采集摄像头图像保存为图片和视频
- OpenCV3.2+Qt5.8.0+Win10配置和使用----(5)打开笔记本摄像头
- 如何使用Matlab标定自己的摄像头?
- qt5 采集摄像头的视音频
- VS2013+QT5+opencv3.1显示摄像头
- Ubuntu+QT5.8 调用摄像头出现错误
- Integer Division
- Scrapy入门教程
- ios 从系统相册选择多张图片
- Crack Me逆向练习
- 我心中的IT工程师
- Qt5如何使用摄像头
- NSNumber基本用法
- MySql创建新用户并远程访问[mysql初级文档]
- c++ 11 多线线程系列-------- 一个最简单而且实用的线程池
- 关于Handler的removeCallbacks方法无效
- lua--lua中的迭代器
- Linux Advance--打印标准IO流缓冲状态信息
- A与A'是否合同
- 手动安装liberty版本openstack环境(allinone)---环境准备