1:第一次寫OpenCv的東西。
2:好久沒寫c++了,現在越來越覺得java代碼要比c++好看多了,c++比較亂。(個人見解,兩門語言都喜歡)
3:因為自己是接觸Hadoop項目需要opencv知識所以來學的,但在hadoop中用javacv更方便,所以先熟悉下opencv再轉到javacv
不多說上代碼
#include <string>
#include "cv.h"
#include "highgui.h"
using namespace std;
int main() {
IplImage *iplImg = cvLoadImage("/home/huanglei/wr.jpg", 1);
IplImage *iplImgNew = cvCreateImage(cvSize(320,240),8,3) ; //改變圖片大小適應視頻
cvResize(iplImg,iplImgNew,CV_INTER_LINEAR) ;
CvVideoWriter* video = cvCreateVideoWriter("/home/huanglei/tree1.avi",
CV_FOURCC('P', 'I', 'M', '1'), 20,
cvSize(iplImgNew->width, iplImgNew->height), 1);
/*
* 逐幀讀取視頻,並保存到另外一個視頻文件中
*/
CvCapture *cap;
cap = cvCreateFileCapture("/home/huanglei/tree.avi");
IplImage *imgVideo ;
int q ;
while (imgVideo = cvQueryFrame(cap)) {
q = cvWriteFrame(video, imgVideo);
}
/*
* 在新的視頻文件的末尾插入圖片
*/
int i;
for (int x = 0; x < 50; x++) {
i = cvWriteFrame(video, iplImgNew);
}
/*
* 釋放指針
*/
if (video) {
cvReleaseVideoWriter(&video);
cvReleaseImage(&imgVideo);
cvReleaseImage(&imgVideo);
cvReleaseImage(&iplImg);
}
return 0;
}