电脑摄像头拍照
来源:互联网 发布:跳舞的线 知乎 编辑:程序博客网 时间:2024/05/01 19:58
一个简陋的摄像头拍照工具,能将拍到的照片保存为.png文件。
使用Qt+openCV实现。
#include "qtusecamera.h"#include<opencv/cv.h>#include<opencv/highgui.h>#include<windows.h>QtUseCamera::QtUseCamera(QWidget *parent, Qt::WFlags flags): QWidget(parent, flags){preReadLabel = new QLabel;photoLabel =new QLabel; openBut = new QPushButton("打开"); takeBut = new QPushButton("拍照"); closeBut=new QPushButton("关闭"); saveBut=new QPushButton("保存");labelLayout=new QHBoxLayout;butLayout=new QHBoxLayout;mainLayout=new QVBoxLayout;labelLayout->addWidget(preReadLabel);labelLayout->addWidget(photoLabel);butLayout->addWidget(openBut);butLayout->addWidget(takeBut); butLayout->addStretch(); butLayout->addWidget(saveBut); butLayout->addWidget(closeBut); butLayout->setContentsMargins(10,5,10,5);mainLayout->addLayout(labelLayout);mainLayout->addLayout(butLayout);mainLayout->setSpacing(1);mainLayout->setContentsMargins(0,0,0,0);setLayout(mainLayout);timer=new QTimer;connect(openBut,SIGNAL(clicked()),this,SLOT(openCamera()));connect(takeBut,SIGNAL(clicked()),this,SLOT(takingPictures()));connect(closeBut,SIGNAL(clicked()),this,SLOT(closeCamera()));connect(timer,SIGNAL(timeout()),this,SLOT(readFrame())); connect(saveBut,SIGNAL(clicked()),this,SLOT(savePic()));cam=NULL; resize(200,200); setWindowTitle("摄像头拍照");}QtUseCamera::~QtUseCamera(){cvReleaseCapture(&cam);}void QtUseCamera::openCamera(){cam = cvCreateCameraCapture(0);Sleep(1000);timer->start(30);}void QtUseCamera::readFrame(){if(!cam) return ;frame = cvQueryFrame(cam);QImage image = QImage((const uchar*)frame->imageData,frame->width,frame->height, QImage::Format_RGB888).rgbSwapped();preReadLabel->setPixmap(QPixmap::fromImage(image));}void QtUseCamera::closeCamera(){timer->stop();cvReleaseCapture(&cam); preReadLabel->setPixmap(QPixmap()); photoLabel->setPixmap(QPixmap()); takePic=QImage(); resize(200,200);}void QtUseCamera::takingPictures(){if(!cam) return ;frame = cvQueryFrame(cam); takePic = QImage((const uchar*)frame->imageData,frame->width,frame->height, QImage::Format_RGB888).rgbSwapped(); photoLabel->setPixmap(QPixmap::fromImage(takePic));}void QtUseCamera::savePic(){ if(takePic.isNull()) return ; QString fileName=QFileDialog::getSaveFileName(this,"保存照片",QString(),"png file(*.png)"); if(fileName.isEmpty()) return ; takePic.save(fileName,"png",100);}
http://download.csdn.net/detail/thatmaybefun/7025779
0 0
- 电脑摄像头拍照
- C#打开电脑摄像头及拍照
- C# 利用AForge.NET 调用电脑摄像头进行拍照
- 摄像头拍照
- 摄像头拍照
- C#控制摄像头拍照
- DELPHI实现摄像头拍照
- DELPHI实现摄像头拍照
- Flash 8 摄像头拍照
- C#使用摄像头拍照
- DELPHI实现摄像头拍照
- Flex 捕获摄像头拍照
- Flex 捕获摄像头拍照
- flex 4 摄像头拍照
- 利用摄像头拍照
- C#使用摄像头拍照
- Android使用摄像头拍照
- SurfaceView Android摄像头拍照
- 快速排序与查找
- 九度1552 动态规划
- Elegant fibonacci numbers again
- (CF)C. Team
- JAVA中的清理机制
- 电脑摄像头拍照
- 第三周(项目二)—-旱冰场造价。
- 使用正则表达式提取字符串中的内容
- Trapping Rain Water
- The Tao Framework -- C#的OpenGL绑定
- ARM Linux教程之一:安装VirtualBox虚拟机
- window屏幕截图
- 如何提高编程能力
- mysql常用函数收集(需要用到的)