原地址:http://blog.csdn.net/liang19890820/article/details/12782531

Qt如何调用系统摄像设备进行显示、截图、录制?

    QCamera:系统摄像设备(摄像头)

    QCameraViewfinder:摄像取景器部件
    QCameraImageCapture:截图部件
 
capture按钮:用于截图(截图后在右上角显示)
save按钮:用于保存截取后的图片(此处测试路径为:F:\a.jpg)
exit按钮:退出界面
 
效果如下:
 
 
代码如下:
 
#include "test_capture.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent)
{
this->resize(600, 400);
 
camera = new QCamera();
view_finder = new QCameraViewfinder();
camera_image_capture = new QCameraImageCapture(camera);
capture_button = new QPushButton();
save_button = new QPushButton();
exit_button = new QPushButton(); 
display_label = new QLabel();
 
QHBoxLayout *main_layout = new QHBoxLayout();
QVBoxLayout *v_layout = new QVBoxLayout();
 
display_label->setFixedSize(150, 150);
display_label->setScaledContents(true);
 
v_layout->addWidget(display_label);
v_layout->addStretch();
v_layout->addWidget(capture_button);
v_layout->addWidget(save_button);
v_layout->addWidget(exit_button);
 
main_layout->addWidget(view_finder);
main_layout->addLayout(v_layout);
 
connect(capture_button, &QPushButton::clicked, this, &Dialog::captureImage);
connect(save_button, &QPushButton::clicked, this, &Dialog::saveImage);
connect(exit_button, &QPushButton::clicked, this, &Dialog::close);
connect(camera_image_capture, &QCameraImageCapture::imageCaptured, this, &Dialog::displayImage);
 
camera_image_capture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
camera->setCaptureMode(QCamera::CaptureStillImage);
camera->setViewfinder(view_finder);
camera->start(); //启动摄像头
 
this->setLayout(main_layout);
this->translateLanguage();
}
 
Dialog::~Dialog()
{
 
}
 
void Dialog::translateLanguage()
{
this->setWindowTitle("testCapture");
capture_button->setText(tr("capture"));
save_button->setText(tr("save"));
exit_button->setText(tr("exit"));
}
 
void Dialog::displayImage(int id, QImage image)
{
display_label->setPixmap(QPixmap::fromImage(image));  
}
 
void Dialog::captureImage()
{
//截图
camera_image_capture->capture();  
}
 
void Dialog::saveImage()
{
const QPixmap *pixmap = display_label->pixmap();
if(pixmap)
{
pixmap->save("F:\\a.jpg");
}
}

Qt调用摄像头(截取并保存图片)的更多相关文章

  1. Android入门(十六)调用摄像头相册

    原文链接:http://www.orlion.ga/665/ 一.调用摄像头 创建一个项目ChoosePicDemo,修改activity_main.xml: <LinearLayout xml ...

  2. android: 调用摄像头拍照

    很多应用程序都可能会使用到调用摄像头拍照的功能,比如说程序里需要上传一张图片 作为用户的头像,这时打开摄像头拍张照是最简单快捷的.下面就让我们通过一个例子来学 习一下,如何才能在应用程序里调用手机的摄 ...

  3. C# - VS2019调用AForge库实现调用摄像头拍照功能

    前言 作为一名资深Delphi7程序员,想要实现摄像头扫描一维码/二维码功能,发现所有免费的第三方库都没有简便的实现办法,通用的OpenCV或者ZXing库基本上只支持XE以上的版本,而且一维码的识别 ...

  4. vue实现PC端调用摄像头拍照人脸录入、移动端调用手机前置摄像头人脸录入、及图片旋转矫正、压缩上传base64格式/文件格式

    进入正题 1. PC端调用摄像头拍照上传base64格式到后台,这个没什么花里胡哨的骚操作,直接看代码 (canvas + video) <template> <div> &l ...

  5. 谷歌使用navigator.mediaDevices.getUserMedia 调用摄像头拍照功能,不兼容IE

    <template>     <div>       <!--canvas截取流-->       <canvas ref="canvas" ...

  6. 利用face_recognition,dlib与OpenCV调用摄像头进行人脸识别

    用已经搭建好 face_recognition,dlib 环境来进行人脸识别 未搭建好环境请参考:https://www.cnblogs.com/guihua-pingting/p/12201077. ...

  7. python实现调用摄像头或打开视频文件

    目录: (一)调用摄像头或打开视频文件代码实现 (二)说明和补充 (一)调用摄像头或打开视频文件代码实现 1 # -*- coding=GBK -*- 2 import cv2 as cv 3 4 5 ...

  8. html5调用摄像头截图

    关于html5调用音视频等多媒体硬件的API已经很成熟,不过一直找不到机会把这些硬件转化为实际的应用场景,不过近年来随着iot和AI的浪潮,我觉得软硬结合的时机已经成熟.那我们就提前熟悉下怎么操作这些 ...

  9. QT 调用VS2015编写的Dll

    最近在用QT调用VC生成的库,QT使用的是MinGW调试器,出现与动态库不兼容的问题,最后发现QT只能识别VC生成的C格式下的动态库 也就是在导入导出设置时加入extern "C" ...

随机推荐

  1. HDU1163【九余数定理】【水题】

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. 百度——地图API——IOS v2.0.2—入门篇

    建议高手飘过------ 本以为一个地图的helloworld很简单.实际使用却不是那么回事.就想把地图的头文件和静态库添加到文件中.应该就能用了. baidu提供的xcode工程是支持ios4.3的 ...

  3. MySQL无法使用、导入中文数据乱码

    1,新版的MySQL无法使用 装的新版的mysql-installer-community-5.6.14.0.msi,无法使用(无法导入地图数据,卸载重装mysql_5.6.13.msi,无法启动). ...

  4. validform 一行代码完成所有验证

    validform一行代码完成所有验证 在使用的时候想更改提示效果为右侧提示却一直不能成功 tiptype可以为1.2 和 自定义函数.2 表示右侧提示. 注意:tiptype为 2 时,各表单元素对 ...

  5. JMS和消息驱动Bean(MDB)

    一.说明 本示例使用的ActiveMQ作为消息中间件,服务器为Glassfish,使用JMS发送消息,在MDB接收到消息之后做打印输出. 二.ActiveMQ安装配置 1.安装console war包 ...

  6. CentOS6.5安全策略设置

    应公司内部网站等级测评的需求,正逐渐加强系统安全防护 密码策略设置 检查方法: 使用命令 #cat /etc/login.defs|grep PASS查看密码策略设置 备份方法: cp -p /etc ...

  7. 02-Foundation-NSMutableString、NSNumber、NSValue、NSDate、NSArray

    目录: 一.NSMutableString可变字符串 二.NSNumber数字对象 三.NSValue 四.NSDate日期对象 五.NSArray数组对象 回到顶部 一.NSMutableStrin ...

  8. 从 Qt 的 delete 说开来

    原地址:http://blog.csdn.net/dbzhang800/article/details/6300025 在C++中学习过程中,我们都知道: delete 和 new 必须 配对使用(一 ...

  9. SQL2005、2008、2000 清空删除日志

    SQL2005清空删除日志: 代码如下: Backup Log DNName with no_log  '这里的DNName是你要收缩的数据库名,自己注意修改下面的数据库名,我就不再注释了. go d ...

  10. 大数据时代的 9 大Key-Value存储数据库

    在过去的十年中,计算世界已经改变.现在不仅在大公司,甚至一些小公司也积累了TB量级的数据.各种规模的组织开始有了处理大数据的需求,而目前关系型数据库在可缩放方面几乎已经达到极限. 一个解决方案是使用键 ...