#include "stdafx.h"
#include <iostream>
#include <opencv2\opencv.hpp>
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"
#include <cmath>
using namespace cv;
using namespace std;
void main()
{IplImage* frame=0;
CvVideoWriter *writer = 0;
cvNamedWindow("camera",1);
CvCapture* capture;
capture=cvCreateCameraCapture(0);
//cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 240);
//cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);
frame=cvQueryFrame(capture);
IplImage*b= cvCreateImage(cvGetSize(frame),
IPL_DEPTH_8U,
1);
int isColor = 1;
int fps = 28; // or 30
int frameW = frame->width ; // 744 for firewire cameras
int frameH = frame->height ; // 480 for firewire cameras
writer=cvCreateVideoWriter("out.avi",CV_FOURCC('D', 'I', 'V', 'X'),
fps,cvSize(frameW,frameH),0);
/*CV_FOURCC('P','I','M','1') = MPEG-1 codec
CV_FOURCC('M','J','P','G') = motion-jpeg codec (does not work well)
CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec
CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec
CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec
CV_FOURCC('U', '2', '6', '3') = H263 codec
CV_FOURCC('I', '2', '6', '3') = H263I codec
CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec
将上面的改成 -1 将会打开一个编码器的选择窗口.*/
int i=0;
int n=0;
while(i<=50)
{
cvGrabFrame(capture); // capture a frame
frame=cvRetrieveFrame(capture); // retrieve the captured frame
cvCanny(frame , b, 3, 3, 3);
if(!frame)
break;
cvShowImage("camera",b);
n=cvWriteFrame(writer,b);
cout<<n<<endl;
if(cvWaitKey(33)>=0)
break;
}
cvWaitKey(33);
cvReleaseImage(&frame);
cvReleaseImage(&b);
cvDestroyWindow("camera");
cvReleaseVideoWriter(&writer);
}
#include <iostream>
#include <opencv2\opencv.hpp>
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"
#include <cmath>
using namespace cv;
using namespace std;
void main()
{IplImage* frame=0;
CvVideoWriter *writer = 0;
cvNamedWindow("camera",1);
CvCapture* capture;
capture=cvCreateCameraCapture(0);
//cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 240);
//cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);
frame=cvQueryFrame(capture);
IplImage*b= cvCreateImage(cvGetSize(frame),
IPL_DEPTH_8U,
1);
int isColor = 1;
int fps = 28; // or 30
int frameW = frame->width ; // 744 for firewire cameras
int frameH = frame->height ; // 480 for firewire cameras
writer=cvCreateVideoWriter("out.avi",CV_FOURCC('D', 'I', 'V', 'X'),
fps,cvSize(frameW,frameH),0);
/*CV_FOURCC('P','I','M','1') = MPEG-1 codec
CV_FOURCC('M','J','P','G') = motion-jpeg codec (does not work well)
CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec
CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec
CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec
CV_FOURCC('U', '2', '6', '3') = H263 codec
CV_FOURCC('I', '2', '6', '3') = H263I codec
CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec
将上面的改成 -1 将会打开一个编码器的选择窗口.*/
int i=0;
int n=0;
while(i<=50)
{
cvGrabFrame(capture); // capture a frame
frame=cvRetrieveFrame(capture); // retrieve the captured frame
cvCanny(frame , b, 3, 3, 3);
if(!frame)
break;
cvShowImage("camera",b);
n=cvWriteFrame(writer,b);
cout<<n<<endl;
if(cvWaitKey(33)>=0)
break;
}
cvWaitKey(33);
cvReleaseImage(&frame);
cvReleaseImage(&b);
cvDestroyWindow("camera");
cvReleaseVideoWriter(&writer);
}