QT实现摄像头采集图像并截图

  • t5_426938
    了解作者
  • 4.4KB
    文件大小
  • 文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-19 12:14
    上传日期
利用QT实现电脑摄像头图像的实时显示,并通过界面上的截图按钮和保存按钮分别实现图像的抓取和存储。
myCamera.rar
  • myCamera
  • picture
  • mycameradialog.h
    880B
  • mycameradialog.cpp
    2.3KB
  • main.cpp
    191B
  • myCamera.pro.user
    23.3KB
  • myCamera.pro
    1KB
内容介绍
#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("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(); // QString filename=QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"+'.jpg'); if(pixmap) { pixmap->save("D:\\QT_learing\\myCamera\\picture.jpg"); } } void mycameradialog::exitBtnResponded() { camera->stop(); this->close(); } void mycameradialog::cameraImageCaptured(int id, QImage image) { displayLabel->setPixmap(QPixmap::fromImage(image)); }
评论
    相关推荐