2

I am trying to stitch 5 images with ROIs with the following code. I keep getting unhandled exception of memory length_error even though vImg vector and rois are the same size. Also, why rois should be vector of vector of Rect? the inner vector is of size one.

int main()
{

    std::ostringstream filepath;
    vector<Mat> vImg;
    vImg.resize(5);

    vector <Rect> tmpRect;
    vector<vector<Rect>> rois;
    rois.resize(5);
    vector<Mat> channels;

    for (int idx = 0; idx < 5; idx++)
    {
        filepath << "C:\\stch3" << idx+1 << ".jpg";
        Mat tmpImg = imread(filepath.str());
        vImg[idx] = tmpImg;
        Rect rect(0, 50, vImg[idx].cols , vImg[idx].rows-70);
        tmpRect.push_back(rect);
        rois[idx] = (tmpRect);
        tmpRect.clear();
        filepath.str("");
    }

    Stitcher stitcher = Stitcher::createDefault(true);
    Mat rImg;
    Stitcher::Status status = stitcher.stitch(vImg, rois, rImg);
    if (status != Stitcher::OK)
    {
        cout << "Can't stitch images, error code = " << int(status) << "Estimate Transform :" << int(status) << endl;
    }
    imshow("Stitching Result", rImg);

    waitKey(0);

    return 0;
}
Laurel
  • 5,965
  • 14
  • 31
  • 57
ZIV
  • 21
  • 2

1 Answers1

0

why rois should be vector of vector of Rect

Because you can pass more ROI's per image, as a vector.

So dimension 1 is your number of images, dimension 2 is number of ROI's per image.

Michał Leon
  • 2,108
  • 1
  • 15
  • 15