/ FramePerSecond.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include <iostream>
#include <windows.h>
using namespace std;
//int main(int argc, char* argv[])
//{
// CvCapture *capture = cvCaptureFromCAM(-1);
// cvNamedWindow("FramePerSecond", CV_WINDOW_AUTOSIZE);
// IplImage *frame = cvQueryFrame(capture);
//
// char *campath = "capture.mpg";
// CvVideoWriter *writer = cvCreateVideoWriter(campath, CV_FOURCC('P', 'I', 'M', '1'), 52, cvGetSize(frame), 1);
//
// while (1)
// {
// frame = cvQueryFrame(capture);
// if (!frame)
// {
// break;
// }
//
// cvWriteFrame(writer, frame);
//
// cvShowImage("FramePerSecond", frame);
// char key = cvWaitKey(20);
//
// if (27 == key)
// {
// break;
// }
//
// }
//
// cvReleaseVideoWriter(&writer);
// cvReleaseCapture(&capture);
// cvDestroyWindow("FramePerSecond");
//
// return 0;
//}
int main(int argc, char* argv[])
{
//char *campath = "capture.mpg";
//CvCapture *capture = cvCaptureFromFile(campath);
CvCapture *capture = cvCaptureFromCAM(-1);
cvNamedWindow("FramePerSecond", CV_WINDOW_AUTOSIZE);
IplImage *frame = cvQueryFrame(capture);
int frameH = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
int frameW = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
int fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
int numFrames = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
cout << "Video information:" << endl;
cout << "frameW: " << frameW << endl;
cout << "frameH: " << frameH << endl;
cout << "fps: " << fps << endl;
cout << "numFrames: " << numFrames << endl;
numFrames = 600;
char *campath = "capture.mpg";
CvVideoWriter *writer = cvCreateVideoWriter(campath, CV_FOURCC('P', 'I', 'M', '1'), 80, cvGetSize(frame), 1);
int i = 0;
char image_name[15];
while (1)
{
frame = cvQueryFrame(capture);
if (!frame)
{
break;
}
sprintf(image_name, "%s%d%s","image", ++i, ".jpg");
cvWriteFrame(writer, frame);
cvSaveImage(image_name,frame);
cvShowImage("FramePerSecond", frame);
//char key = cvWaitKey(20);
//if (27 == key)
//{
// break;
//}
if (i > numFrames)
{
break;
}
}
cvReleaseCapture(&capture);
cvDestroyWindow("FramePerSecond");
return 0;
}
//#include <time.h>
//#include "mmsystem.h"
//#pragma comment(lib, "winmm.lib")
//#define NUMFRAMES 50
//int main(int argc, char* argv[])
//{
// CvCapture *capture = cvCaptureFromCAM(-1);
// cvNamedWindow("FramePerSecond", CV_WINDOW_AUTOSIZE);
// IplImage *frame = cvQueryFrame(capture);
//
// //char *campath = "capture.mpg";
// //CvVideoWriter *writer = cvCreateVideoWriter(campath, CV_FOURCC('P', 'I', 'M', '1'), 80, cvGetSize(frame), 1);
//
// int i = 0;
// char image_name[15];
// DWORD s = timeGetTime();
// //Sleep(1500);
// while (i < 300)
// {
// frame = cvQueryFrame(capture);
// if (!frame)
// break;
// sprintf(image_name, "%s%d%s","image", ++i, ".jpg");
// cvSaveImage(image_name,frame);
//
// //cvWriteFrame(writer, frame);
//
// cvShowImage("FramePerSecond", frame);
// char key = cvWaitKey(20);
//
// //if (27 == key)
// // break;
//
//
// //if (i == NUMFRAMES)
// // break;
//
// }
// DWORD d = timeGetTime();
// DWORD l = d - s;
// cout << l << endl;
//
//
// //cvReleaseVideoWriter(&writer);
// cvReleaseCapture(&capture);
// cvDestroyWindow("FramePerSecond");
//
// return 0;
//}