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