利用OpenCV调用笔记本自带的摄像头进行拍照,并且保存到本地文件夹。程序完整代码如下:
#include<opencv2/opencv.hpp>#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgPRoc/imgproc.hpp>#include<iostream>#include<stdio.h>using namespace cv;using namespace std;int main(int argc, char* argv){VideoCapture capture(0);Mat frame;if(!capture.isOpened()){cout<<"摄像头打开失败!"<<endl;return -1;}char key;char filename[200];int count = 0;namedWindow("【视频】",1);namedWindow("【图片】",1);while(1){key = waitKey(50);capture>>frame;imshow("【视频】",frame);if(key == 27) break;//按ESC键退出程序if(key == 32)//按空格键进行拍照{sprintf(filename,"Picture %d.jpg",++count);imwrite(filename,frame);//图片保存到本工程目录中imshow("【图片】",frame);}}return 0;}刚刚学习OpenCV不久,出错在所难免,还望批评指教。经过最近一段时间的学习,我发现OpenCV好好玩~~,哈哈哈……
新闻热点
疑难解答