opencv 2.4.6 摄像头实时保存视频
2014-09-01 16:44
531 查看
#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);
}
相关文章推荐
- OpenCV摄像头获取视频并实时保存每帧图片
- opencv 、directshow捕获摄像头,实时播放,编码,保存视频,保存单帧
- 《OpenCV》Part10 OpenCV3.1.0 openCV读取摄像头并保存为.avi视频
- OpenCV入门系列(7):读取摄像头,保存为视频文件
- OpenCV打开摄像头并获取实时视频图像代码
- opencv读取多个摄像头并保存当前视频流图片
- opencv从摄像头读取视频并实时进行人脸检测代码
- opencv摄像头拍摄视频并保存方法
- javacpp-opencv图像处理之1:实时视频添加文字水印并截取视频图像保存成图片,实现文字水印的字体、位置、大小、粗度、翻转、平滑等操作
- opencv 摄像头捕获的图像保存为avi视频 代码解析
- OpenCV摄像头保存视频和图像
- opencv 从摄像头中读取视频并保存(c++版)
- 【python下使用OpenCV实现计算机视觉读书笔记4】保存摄像头视频
- python 使用OpenCV保存视频失败的解决方案及摄像头显示灰色的解决办法
- 利用opencv类库在MFC显示摄像头视频并且保存摄像头视频
- javacpp-opencv图像处理之1:实时视频添加文字水印并截取视频图像保存成图片,实现文字水印的字体、位置、大小、粗度、翻转、平滑等操作
- 【python下使用OpenCV实现计算机视觉读书笔记4】保存摄像头视频
- 用OpenCV在MFC Dialog中Picture控件上显示摄像头采集实时视频
- opencv 摄像头录取视频保存图像
- Qt+OpenCV摄像头读取保存回放视频