opencv 摄像头录取视频保存图像
2014-11-23 13:12
471 查看
1,API
supported on Windows only)
fourcc – 4-character code of codec used to compress the frames. For example, CV_FOURCC('P','I','M','1') is
a MPEG-1 codec, CV_FOURCC('M','J','P','G') is a motion-jpeg codec etc. 参数为-1时,运行时会弹出一个框叫你选择。
one call.
If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer.
2,测试代码:
CvVideoWriter* cvCreateVideoWriter(const char* filename, int fourcc, double fps, CvSize frame_size, int is_color=1 )isColor – If it is not zero, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently
supported on Windows only)
fourcc – 4-character code of codec used to compress the frames. For example, CV_FOURCC('P','I','M','1') is
a MPEG-1 codec, CV_FOURCC('M','J','P','G') is a motion-jpeg codec etc. 参数为-1时,运行时会弹出一个框叫你选择。
IplImage* cvQueryFrame(CvCapture* capture)The methods/functions combine VideoCapture::grab() and VideoCapture::retrieve() in
one call.
If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer.
int cvSaveImage(const char* filename, const CvArr* image, const int* params=0 )params:Format-specific save parameters encoded as pairs paramId_1, paramValue_1, paramId_2, paramValue_2,
2,测试代码:
#include "cv.h" #include "highgui.h" #include "conio.h" #include <stdio.h> using namespace cv; int main(int argc, char** argv) { IplImage *pSaveimage= NULL; char filename[20]; int i=0; //start camera CvCapture *capture = cvCreateCameraCapture(0); if(!capture) { printf("cannot open camera\n"); system("pause"); return -1; } IplImage *frame; frame = cvQueryFrame(capture); CvSize size =cvGetSize(frame); double fps =10; CvVideoWriter *video = cvCreateVideoWriter("video_camera.avi",CV_FOURCC('M','J','P','G'),fps,size,1); cvNamedWindow("haha",1); while((frame=cvQueryFrame(capture))!=NULL) { cvShowImage("haha",frame); cvWriteFrame(video,frame); printf("one more picture\n"); //save image pSaveimage = cvCreateImage(size,frame->depth,frame->nChannels); sprintf(filename ,"%d.jpg",i); i++; cvResize(frame,pSaveimage,CV_INTER_LINEAR); cvSaveImage(filename,pSaveimage); char key =cvWaitKey(30); if(key==27) //ESC break; } cvReleaseVideoWriter(&video); cvReleaseCapture(&capture); cvDestroyAllWindows(); return 0; }
相关文章推荐
- opencv 摄像头捕获的图像保存为avi视频 代码解析
- 【图像识别】 Python+Opencv调用摄像头实现人脸识别并保存视频
- Qt5.3里使用OpenCV库采集摄像头图像保存为图片和视频
- OpenCV摄像头保存视频和图像
- OpenCv打开摄像头,显示图像,保存视频
- opencv读取多个摄像头并保存当前视频流图片
- 图像拼接(三):OpenCV同时打开两个摄像头捕获视频
- OpenCV入门系列(7):读取摄像头,保存为视频文件
- OpenCV学习笔记 利用MFC的Picture控件显示图像+播放视频和捕获摄像头画面 .
- opencv打开双目摄像头、图像切割保存
- OpenCV 调用摄像头录制指定分辨率视频----(解决保存的视频仅有6Kb的问题)
- opencv 2.4.6 摄像头实时保存视频
- directshow+opencv显示usb的摄像头代码(并保存视频中的图片)
- opencv2读取摄像头并保存为视频
- opencv将视频序列转换为图像序列保存
- opencv读取视频,摄像头,保存视频代码
- python 使用OpenCV保存视频失败的解决方案及摄像头显示灰色的解决办法
- opencv读取摄像头图像和读取视频文件图像
- OpenCV打开摄像头并获取实时视频图像代码
- 《OpenCV》Part10 OpenCV3.1.0 openCV读取摄像头并保存为.avi视频