我正在编写一个将视频作为输入并返回全景图像的程序。我正在执行以下代码:
vector< Mat > vImg;
Mat rImg;
Mat img;
VideoCapture cap("../Debug/vid/vid.avi");
if (!cap.isOpened())
{
cout << "Can't open video";
waitKey(0);
return ;
}
//default stitcher
Stitcher stitcher = Stitcher::createDefault(true);
//set orb finder
Ptr<FeaturesFinder> finder=new OrbFeaturesFinder();
stitcher.setFeaturesFinder(finder);
//set seam resolution
stitcher.setSeamEstimationResol(0.08);
//set confidence threshold
stitcher.setPanoConfidenceThresh(0.5);
//set warper
Ptr<WarperCreator> warper = new cv::PlaneWarper();
stitcher.setWarper(warper);
//set exposure compensation
Ptr<ExposureCompensator> exposure_compensator = ExposureCompensator::createDefault(ExposureCompensator::GAIN);
stitcher.setExposureCompensator(exposure_compensator);
//set seam finder
Ptr<SeamFinder> seam_finder = new DpSeamFinder(DpSeamFinder::COLOR_GRAD);
stitcher.setSeamFinder(seam_finder);
//set matcher
Ptr<FeaturesMatcher> matcher = new BestOf2NearestMatcher(true);
stitcher.setFeaturesMatcher(matcher);
//sett wave correction
stitcher.setWaveCorrection(true);
cap >> img;
vImg.push_back(img);
vImg.push_back(img);
int counter = 1;
while (counter < total_frames)
{
Mat img_loop;
cap >> img_loop;
vImg.at(1) = img_loop;
stitcher.stitch(vImg, rImg);
if (rImg.rows>0 && rImg.cols>0)
{
imshow("debug", rImg);
vImg.at(0) = rImg;
}
rImg = NULL;
counter ++;
}
但它向我显示“断言失败(尺寸可能是什么问题?
我正在使用Visual Studio 2013社区,OpenCV 2.4.10和Windows 7 x64
编辑
添加了“调用堆栈”
KernelBase.dll!_RaiseException@16()
Unknown> msvcr120d.dll!_CxxThrowException(void *pExceptionObject, const_s__ThrowInfo * pThrowInfo) Riga 154 C++
opencv_core2410d.dll!774ec7f8() Sconosciuto
编辑
我注意到如果我缝制2张相同的图像会给我错误。这是正常的?
最佳答案
如果问题与内存分配有关,则可以尝试将 vector 声明为静态。
static vector<Mat> vImg;
我不确定,但是在分配巨大数组时遇到了这个问题,这个技巧解决了我的问题,而不是使用指针。
希望对您有所帮助。