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;
}