opencv使用电脑摄像头抓取并保存图片,自动顺序命名保存的图片

#include"stdafx.h"
#include   
#include   
#include   
//#include
//#include

using namespace cv;

int main()
{
	VideoCapture cap(0);
	if (!cap.isOpened())
		return -1;
	VideoCapture video_capture;
	video_capture.set(CV_CAP_PROP_FPS, 12);
	video_capture.set(CV_CAP_PROP_EXPOSURE, -12.0);
	video_capture.open(0);
	video_capture.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
	video_capture.set(CV_CAP_PROP_FRAME_WIDTH, 1920); 
	video_capture.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
	Mat frame;
        Mat edges;
	char str[10];
	int i = 0;
	while(1) 
	{
		cap >> frame;
		cvtColor(frame, edges, 0);
		imshow("a", edges);          
		//if (std::cin.get() != '\n')
		if (waitKey(1) == 32)
		{
			sprintf_s(str, "%d%s", i++, ".jpg");
			imwrite(str, edges);
		}
		else if(waitKey(1) == 27 )
			break;
	}
	return 0;
}
opencv使用电脑摄像头抓取并保存图片,自动顺序命名保存的图片

你可能感兴趣的:(opencv)