opencv使用stitch类遇到问题了

yijianlishi 2013-12-31 02:34:26
我用stitch类对两个视频进行每帧每帧的拼接,然后得到一个新的视频。目前并没有什么效率上的要求,但是这么简单的需求还是遇到了解决不了的问题,希望各位大大给个解决的方法

问题:我发现是在执行第198次stitch函数时出问题的,换其它每帧比较小的视频,执行stitch函数就会较多,每帧图片越大,执行stitch知道报错出现问题的次数越少。我觉得应该是内存方面的问题,可是研究了几遍还是没有办法。
代码:

#include <iostream>
#include <fstream>
#include <time.h>
#include "windows.h"
#include "opencv/cv.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"
using namespace std;
using namespace cv;
bool try_use_gpu = false;
vector<Mat> imgs;
string result_name="result.jpg";
int main ()
{
CvCapture *capture1=cvCreateFileCapture("C://1.avi");
CvCapture *capture2=cvCreateFileCapture("C://2.avi");
if(!capture2||!capture1)
return -1;
IplImage *bgrframe1=cvQueryFrame(capture1);
IplImage *bgrframe2=cvQueryFrame(capture2);
double fps1=cvGetCaptureProperty(capture1,CV_CAP_PROP_FPS);
double fps2=cvGetCaptureProperty(capture2,CV_CAP_PROP_FPS);
double fps=fps1>fps2?fps2:fps1;
CvSize size=cvSize(2*(int)cvGetCaptureProperty(capture1,CV_CAP_PROP_FRAME_WIDTH)
,1.2*(int)cvGetCaptureProperty(capture1,CV_CAP_PROP_FRAME_HEIGHT));
CvVideoWriter *writer=cvCreateVideoWriter(
"result.avi",
CV_FOURCC('M','J','P','G'),
fps,
size);
IplImage *dstImage=cvCreateImage(size,IPL_DEPTH_8U,3);
int i=0;
int j=0;
IplImage dstmg;
Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
Stitcher::Status status;
Mat img1;
Mat img2;
while((bgrframe1=cvQueryFrame(capture1))!=NULL&&(bgrframe2=cvQueryFrame(capture2))!=NULL)
{
img1=bgrframe1;
imgs.push_back(img1);
img2=bgrframe2;
imgs.push_back(img2);
Mat pano;
if(j==197)
j--;
status = stitcher.stitch(imgs, pano);
if(status == Stitcher::OK)
{
dstmg=pano;
cvResize(&dstmg,dstImage,CV_INTER_LINEAR);
cvWriteFrame(writer,dstImage);
++i;
cout<<"step1 "<<i<<endl;
}
++j;
cout<<"step2 "<<j<<endl;
imgs.pop_back();
imgs.pop_back();
}
cvWaitKey(0);
cvReleaseVideoWriter(&writer);
cvReleaseImage(&dstImage);
cvReleaseCapture(&capture1);
cvReleaseCapture(&capture2);
return 0;
}


报错图片
...全文
414 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yijianlishi 2014-01-07
  • 打赏
  • 举报
回复
release模式下显示缓冲区溢出,就在执行198次stitch函数的时候
yijianlishi 2014-01-07
  • 打赏
  • 举报
回复
顶一下 我感觉是内存问题,但不知道怎么检查,希望有人给支支招,感激
yijianlishi 2014-01-02
  • 打赏
  • 举报
回复
假期结束了,有大神给出点线索吗?

4,445

社区成员

发帖
与我相关
我的任务
社区描述
图形图像/机器视觉
社区管理员
  • 机器视觉
  • 迪菲赫尔曼
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧