opencv提取視訊每一幀
轉載註明出處:http://blog.sina.com.cn/s/blog_5f5931540100rt4n.html
// 該程式實現視訊和圖片的相互轉換.
// Image_to_video()函式將一組圖片合成AVI視訊檔案.
// Video_to_image()函式將AVI視訊檔案讀入,將每一幀儲存為jpg檔案.
//
////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
#define NUM_FRAME 300 //只處理前300幀,根據視訊幀數可修改
void Video_to_image(char* filename)
{
printf("------------- video to image ... ----------------\n");
//初始化一個視訊檔案捕捉器
CvCapture* capture = cvCaptureFromAVI(filename);
//獲取視訊資訊
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);
printf("\tvideo height : %d\n\tvideo width : %d\n\tfps : %d\n\tframe numbers : %d\n", frameH, frameW, fps, numFrames);
//定義和初始化變數
int i = 0;
IplImage* img = 0;
char image_name[13];
cvNamedWindow( "mainWin", CV_WINDOW_AUTOSIZE );
//讀取和顯示
while(1)
{
img = cvQueryFrame(capture); //獲取一幀圖片
cvShowImage( "mainWin", img ); //將其顯示
char key = cvWaitKey(20);
sprintf(image_name, "%s%d%s", "image", ++i, ".jpg");//儲存的圖片名
cvSaveImage( image_name, img); //儲存一幀圖片
if(i == NUM_FRAME) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("mainWin");
}
void Image_to_video()
{
int i = 0;
IplImage* img = 0;
char image_name[13];
printf("------------- image to video ... ----------------\n");
//初始化視訊編寫器,引數根據實際視訊檔案修改
CvVideoWriter *writer = 0;
int isColor = 1;
int fps = 30; // or 25
int frameW = 400; // 744 for firewire cameras
int frameH = 240; // 480 for firewire cameras
writer=cvCreateVideoWriter("out.avi",CV_FOURCC('X','V','I','D'),fps,cvSize(frameW,frameH),isColor);
printf("\tvideo height : %d\n\tvideo width : %d\n\tfps : %d\n", frameH, frameW, fps);
//建立視窗
cvNamedWindow( "mainWin", CV_WINDOW_AUTOSIZE );
while(i<NUM_FRAME)
{
sprintf(image_name, "%s%d%s", "image", ++i, ".jpg");
img = cvLoadImage(image_name);
if(!img)
{
printf("Could not load image file...\n");
exit(0);
}
cvShowImage("mainWin", img);
char key = cvWaitKey(20);
cvWriteFrame(writer, img);
}
cvReleaseVideoWriter(&writer);
cvDestroyWindow("mainWin");
}
int main(int argc, char *argv[])
{
char filename[13] = "infile.avi";
Video_to_image(filename); //視訊轉圖片
Image_to_video(); //圖片轉視訊
return 0;
}
相關文章
- vue 擷取視訊第一幀Vue
- opencv視訊播放OpenCV
- 短視訊平臺搭建,指定視訊中的某一幀做為視訊的封面
- 使用javacv 獲取視訊第一幀 做封面Java
- Mac線上視訊音訊提取工具Mac音訊
- [開源]基於WPF實現的Gif圖片分割器,提取GIf圖片中的每一幀
- 學習OpenCV:骨架提取OpenCV
- opencv視訊人臉檢測OpenCV
- opencv 視訊處理相關OpenCV
- Python-OpenCV 處理視訊(一)(二): 輸入輸出 視訊處理PythonOpenCV
- Python-OpenCV 處理視訊(二): 視訊處理PythonOpenCV
- OpenCV-Python 視訊讀取OpenCVPython
- Android CameraX ImageAnalysis 獲取視訊幀Android
- 獲取網路視訊任意幀畫面
- OpenCV進階之路:一個簡化的視訊摘要程式OpenCV
- Python-OpenCV 處理視訊(一): 輸入輸出PythonOpenCV
- Android 獲取視訊某一幀,並且設定為封面Android
- 超簡單的視訊物件提取程式物件
- 視訊人臉檢測——OpenCV版(三)OpenCV
- MediaCodeC解碼視訊指定幀,迅捷、精確
- wasm + ffmpeg實現前端擷取視訊幀功能ASM前端
- 新手都如何批量調整視訊幀速率的?
- (一)opencv 視屏讀寫OpenCV
- 3、Opencv播放視訊、儲存、暫停視訊,開啟攝像頭OpenCV
- 【opencv五】利用opencv給讀入的視訊新增拖動滑塊OpenCV
- python OpenCV VideoWriter 視訊格式及大小PythonOpenCVIDE
- OpenCV成長之路(10):視訊的處理OpenCV
- opencv python 從攝像頭獲取視訊/從檔案獲取視訊 /儲存視訊OpenCVPython
- MIT 最新技術:從靜音視訊中提取聲音MIT
- 批次抽幀提取影片封面的簡單步驟分享
- C# 提取Word中插入的多媒體檔案(視訊、音訊)C#音訊
- Opencv3 python學習2——視訊基礎OpenCVPython
- OpenCV基於顏色資訊的車牌提取OpenCV
- 大廠h5開源視訊系列 - 搜狗:每一個人都是一句詩H5
- 風雲音訊處理大師提取視訊中的音訊檔案的方法音訊
- Android:MediaCodeC硬編碼解碼視訊,並將視訊幀儲存為圖片檔案Android
- 直播平臺原始碼,視訊抽幀作為圖片儲存原始碼
- 使用OpenCV和Python構建運動熱圖視訊OpenCVPython