Qt 截取摄像头照片
来源:互联网 发布:数码暴龙网络侦探骇客 编辑:程序博客网 时间:2024/05/24 05:15
#include "cameraimagepool.h"
CameraImagePool::CameraImagePool(QObject *parent):QAbstractVideoSurface(parent)
{
// m_time=0;
handling=false;
}
QImage CameraImagePool::capture()
{
if(handling)
return m_lastBefore;
else
return m_last;
}
QList<QVideoFrame::PixelFormat> CameraImagePool::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
{
Q_UNUSED(handleType);
QList<QVideoFrame::PixelFormat> list;
list << QVideoFrame::Format_RGB32;
return list;
}
void CameraImagePool::storeVideoFrame(const QVideoFrame &frame)
{
// //保存照片的时间间隔
// if((QDateTime::currentMSecsSinceEpoch() - m_time)/1000 < 2)
// return;
// m_time=QDateTime::currentMSecsSinceEpoch();
const QImage image(frame.bits(),
frame.width(),
frame.height(),
QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat()));
if(handling)
m_last=image.mirrored(false,true);
else
m_lastBefore=image.mirrored(false,true);
handling=!handling;
}
bool CameraImagePool::present(const QVideoFrame &frame)
{
// 处理捕获的帧,测试结果每秒处理13帧
if(frame.isMapped())
{
storeVideoFrame(frame);
}
else
{
QVideoFrame f(frame);
f.map(QAbstractVideoBuffer::ReadOnly);
storeVideoFrame(f);
f.unmap();
}
return true;
}
#include "cameraimageengine.h"CameraImageEngine::CameraImageEngine(QObject *parent) :QObject(parent){
//启用特定摄像头// QList<QCameraInfo> cameras = QCameraInfo::availableCameras();// foreach (const QCameraInfo &cameraInfo, cameras) {// if (cameraInfo.description() == "Sirius USB2.0 Camera"){// m_pCamera = new QCamera(cameraInfo);// }// }// m_pCameraInfo = new QCameraInfo(*m_pCamera); //摄像头信息(根据设备有可能获得传感器定位)m_pCamera = new QCamera(this); //启用系统默认的摄像头m_pPool = new CameraImagePool(this); //过滤图像每帧CameraState = false;m_pCamera->setViewfinder(m_pPool);m_pCamera->setCaptureMode(QCamera::CaptureStillImage); //设置摄像头的模式,可以抓取静态图像m_pCamera->load();installCameraDIRSet(); //设置摄像头自定义参数(曝光/变焦/图片处理)connect(m_pCamera,&QCamera::stateChanged,this,&CameraImageEngine::slotStateChanged);m_pCamera->start();//摄像头启动}
CameraImageEngine::~CameraImageEngine(){
}
void CameraImageEngine::installCameraDIRSet(){
QCameraExposure *exposure=m_pCamera->exposure();QCameraFocus *focus=m_pCamera->focus();QCameraImageProcessing *imgPro=m_pCamera->imageProcessing();qDebug()<<"---Camera Start Setting---";// qDebug()<<"lockstatus:"<<m_pCamera->lockStatus();qDebug()<<"exposure->isAvailable():"<<exposure->isAvailable();qDebug()<<"focus->isAvalibale():"<<focus->isAvailable();qDebug()<<"imgPro->isAvalibale():"<<imgPro->isAvailable();installExposureSet(exposure);installFocusSet(focus);installImageProcessingSet(imgPro);qDebug()<<"--Camera End Setting---";qDebug()<<"****Camera resolution setting****";// qDebug()<<m_pCamera->supportedViewfinderFrameRateRanges();// qDebug()<<m_pCamera->supportedViewfinderSettings();qDebug()<<m_pCamera->supportedLocks();qDebug()<<m_pCamera->supportedViewfinderPixelFormats();qDebug()<<m_pCamera->supportedViewfinderResolutions();QCameraViewfinderSettings cameraSetting=m_pCamera->viewfinderSettings();qDebug()<<"cameraSetting.maximumFrameRate()"<<cameraSetting.maximumFrameRate();qDebug()<<"cameraSetting.minimumFrameRate()"<<cameraSetting.minimumFrameRate();qDebug()<<"cameraSetting.pixelAspectRatio()"<<cameraSetting.pixelAspectRatio();qDebug()<<"cameraSetting.pixelFormat()"<<cameraSetting.pixelFormat();// cameraSetting.setPixelFormat(QVideoFrame::Format_YUYV); //只能设置支持参数// cameraSetting.setPixelAspectRatio(640,480); //不能设置// qDebug()<<cameraSetting.resolution();cameraSetting.setResolution(640,480); //只能设置支持比率// m_pCamera->setViewfinderSettings(cameraSetting);// qDebug()<<cameraSetting.resolution();qDebug()<<"****";}
//曝光
void CameraImageEngine::installExposureSet(QCameraExposure *exposure){
qDebug()<<"<<installExposureSet()>>";//支持的标准qDebug()<<exposure->supportedApertures();qDebug()<<exposure->supportedIsoSensitivities();qDebug()<<exposure->supportedShutterSpeeds();//exposureCompensationqDebug()<<"exposure->exposureCompensation():"<<exposure->exposureCompensation();qDebug()<<"exposure->setExposureCompensation(5)";exposure->setExposureCompensation(5);qDebug()<<"exposure->exposureCompensation():"<<exposure->exposureCompensation();//exposureModeqDebug()<<"exposure->isExposureModeSupported(QCameraExposure::ExposureAuto):"\<<exposure->isExposureModeSupported(QCameraExposure::ExposureAuto);qDebug()<<"exposure->isExposureModeSupported(QCameraExposure::ExposureManual):"\<<exposure->isExposureModeSupported(QCameraExposure::ExposureManual);qDebug()<<"exposure->isExposureModeSupported(QCameraExposure::ExposurePortrait):"\<<exposure->isExposureModeSupported(QCameraExposure::ExposurePortrait);qDebug()<<"exposure->isExposureModeSupported(QCameraExposure::ExposureNight):"\<<exposure->isExposureModeSupported(QCameraExposure::ExposureNight);qDebug()<<"exposure->isExposureModeSupported(QCameraExposure::ExposureBacklight):"\<<exposure->isExposureModeSupported(QCameraExposure::ExposureBacklight);qDebug()<<"exposure->isExposureModeSupported(QCameraExposure::ExposureSpotlight):"\<<exposure->isExposureModeSupported(QCameraExposure::ExposureSpotlight);qDebug()<<"exposure->isExposureModeSupported(QCameraExposure::ExposureSports):"\<<exposure->isExposureModeSupported(QCameraExposure::ExposureSports);qDebug()<<"exposure->isExposureModeSupported(QCameraExposure::ExposureSnow):"\<<exposure->isExposureModeSupported(QCameraExposure::ExposureSnow);qDebug()<<"exposure->isExposureModeSupported(QCameraExposure::ExposureModeVendor):"\<<exposure->isExposureModeSupported(QCameraExposure::ExposureModeVendor);//flashModeqDebug()<<"exposure->isFlashModeSupported(QCameraExposure::FlashManual):"<<\exposure->isFlashModeSupported(QCameraExposure::FlashManual);}
//变焦
void CameraImageEngine::installFocusSet(QCameraFocus *focus){
qDebug()<<"<<installFocusSet()>>";//...
}
//图像处理
void CameraImageEngine::installImageProcessingSet(QCameraImageProcessing *imgPro){
qDebug()<<"<<installImageProcessingSet()>>";//whiteBalance//定制的白平衡枚举类型是否支持qDebug()<<"imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceAuto):"\<<imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceAuto);qDebug()<<"imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceManual):"\<<imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceManual);qDebug()<<"imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceSunlight):"\<<imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceSunlight);qDebug()<<"imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceCloudy):"\<<imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceCloudy);qDebug()<<"imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceShade):"\<<imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceShade);qDebug()<<"imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceVendor):"\<<imgPro->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceVendor);//...//设置手动白平衡模式qDebug()<<"imgPro->whiteBalanceMode:"<<imgPro->whiteBalanceMode();qDebug()<<"imgPro->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceAuto)";imgPro->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceAuto);qDebug()<<"imgPro->whiteBalanceMode:"<<imgPro->whiteBalanceMode();//如果是手动白平衡模式则可以调整数值// qDebug()<<"imgPro->manualWhiteBalance():"<<imgPro->manualWhiteBalance();// qDebug()<<"imgPro->setManualWhiteBalance(4600)";// imgPro->setManualWhiteBalance(4600); //数值越大色温越暖// qDebug()<<"imgPro->manualWhiteBalance():"<<imgPro->manualWhiteBalance();//colorFilterqDebug()<<"imgPro->colorFilter():"<<imgPro->colorFilter();qDebug()<<"imgPro->isColorFilterSupported(QCameraImageProcessing::ColorFilterNone):"\<<imgPro->isColorFilterSupported(QCameraImageProcessing::ColorFilterNone);//denosingLevelqDebug()<<"imgPro->denosingLevel():"<<imgPro->denoisingLevel();qDebug()<<"imgPro->setDenoisingLevel(5)";imgPro->setDenoisingLevel(5);qDebug()<<"imgPro->denoisingLevel():"<<imgPro->denoisingLevel();//constrastqDebug()<<"imgPro->constrast():"<<imgPro->contrast();qDebug()<<"imgPro->setConstrast(2)";imgPro->setContrast(2);qDebug()<<"imgPro->constrast():"<<imgPro->contrast();//sharpeningLevelqDebug()<<"imgPro->sharpeningLevel:"<<imgPro->sharpeningLevel();qDebug()<<"imgPro->setsharpeningLevel(95)";imgPro->setSharpeningLevel(95);qDebug()<<"imgPro->sharpeningLevel():"<<imgPro->sharpeningLevel();}
void CameraImageEngine::slotStateChanged(QCamera::State state){
qDebug()<<state;if(state==QCamera::ActiveState)CameraState=true;}
bool CameraImageEngine::RecvCamera(char *szFile) //RecvCamera("fileName"){
if(!CameraState)return false;QImage img=m_pPool->capture();if(img.save(szFile,"jpg"))return true;return false;}
bool CameraImageEngine::GetState(){
return CameraState;}
阅读全文
1 0
- Qt 截取摄像头照片
- Qt 打开摄像头储存照片到本地
- 【小白】ubuntu虚拟机python打开摄像头并截取照片
- Qt调用摄像头(截取并保存图片)
- Qt调用摄像头(截取并保存图片)
- 使用摄像头拍摄照片
- Android中截取照片
- 自定义相机照片截取
- 15.0~15.8 摄像头 照片 视频
- iOS摄像头和照片库
- Ionic调用摄像头采集照片
- QT对摄像头支持
- QT对摄像头支持
- QT对摄像头支持
- Qt摄像头的翻转
- Qt调用摄像头
- qt中打开摄像头
- Qt摄像头视频采集
- encodeURIComponent 处理URL中特殊字符
- 海外IT工程师工作福利揭秘!一个网工的十年奋斗史(末篇)
- [Leetcode-3] Longest Substring Without Repeating Characters
- 煲汤和炖汤的区别
- Spring aop 中* .. 代表的含义
- Qt 截取摄像头照片
- sql server 时间戳
- spring,springMVC,Hibernate,RESTfull,no transaction is in progress
- FileSystemRights枚举
- windows subsystem on linux安装步骤
- Mybatis 和 SqlLite 相遇时 批量插入时遇到的问题
- kotlin之springboot小试牛刀
- ubuntu 系统的一些方便的设置--持续更新
- Grafana安装配置介绍