OpenCV断言与Stitcher失败

时间:2015-03-18 18:40:29

标签: c++ image opencv panoramas image-stitching

我正在编写一个程序,将视频作为输入并返回全景图像。我正在执行此代码:

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

}

但它给了我“断言失败(dims&lt; = 2&amp;&amp; data ...)”错误。 问题可能是什么?

我正在使用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个相同的图像,它会给我错误。这很正常吗?

2 个答案:

答案 0 :(得分:0)

如果问题与内存分配有关,您可以尝试将矢量声明为静态。

static vector<Mat> vImg;

我不确定这一点,但我在分配大数组时遇到了这个问题,这个技巧解决了我的问题,而不是使用指针。

我希望它有所帮助。

答案 1 :(得分:0)

我决定实施拼接管道的手动操作。谢谢大家!