Try to measure times of image stitching using OpenCV Stitcher. Different times when restarting/not restarting program. Issue with memory?

asked 2015-09-21 14:02:30 -0500

Qbaloz gravatar image

updated 2017-08-29 17:14:49 -0500

I made little application to stitch few images using OpenCV. It's mainly to measure times of stitching.

Here is a function to load photos using path in txt file:

void ReadPhotos(string sourceIN){

string sourcePhoto;
ifstream FileIN(sourceIN);

if (FileIN.is_open())
    while (getline(FileIN, sourcePhoto)){

        photos[photo_number] = imread(sourcePhoto, 1);
    cout << "Can't find file" << endl;

cout << "Number of photos: " << photo_number << endl;

//Size size(480, 270);

for (int i = 0; i < photo_number; i++){
    //resize(photos[i], photos[i], size);

Here is MakePanorama function. I implemented here simple timer to measure time of stitching images. I need to know how long it takes to stitch 2,3,4.. images. It contains all openCV Stitcher Class functions:

void MakePanorama(vector< Mat > ImagesVector, string filename){

tp1 = std::chrono::high_resolution_clock::now();
Stitcher stitcher = Stitcher::createDefault(true);

stitcher.setWarper(new SphericalWarper()); // Rodzaj panoramy
stitcher.setFeaturesFinder(new detail::SurfFeaturesFinder(900, 3, 4, 3, 4));
//stitcher.setFeaturesFinder(new detail::OrbFeaturesFinder(Size(3, 1), 1500, 1.3f, 5));
stitcher.setCompositingResol(1); // Rozdzielczosc zdjecia wyjsciowego
stitcher.setWaveCorrection(true); // Korekcja obrazu - pionowa lub pozioma
stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ); // Korekcja obrazu - pionowa lub pozioma
stitcher.setFeaturesMatcher(new detail::BestOf2NearestMatcher(true, 0.3f));
stitcher.setBundleAdjuster(new detail::BundleAdjusterRay());
Stitcher::Status status = Stitcher::ERR_NEED_MORE_IMGS;
    status = stitcher.stitch(ImagesVector, image);
catch (cv::Exception e){}

tp2 = std::chrono::high_resolution_clock::now();

cout << "Czas skladania panoramy: " << chrono::duration_cast<chrono::seconds>(tp2 - tp1).count() << " s" << endl;

imwrite(filename, image);


photo_number = 0;


And here is main:

int main()
cout << "Starting program!" << endl;

MakePanorama(ImagesVector, "22.jpg");

MakePanorama(ImagesVector, "33.jpg");

MakePanorama(ImagesVector, "44.jpg");

return 0;

And here is weird thing. When I call ReadPhotos() and MakePanorama() only once in one single run of program it stitches 2 images in 3 seconds, 3 images in 8 seconds and 4 images in 16 seconds.

When I call ReadPhotos() and MakePanorama() 3 times with 2, 3 and 4 photos to stitch in single run of program it takes 3 seconds, 30 seconds and 130 seconds.

So I can see that reruning program gives a lot better times. Why is that? Im cleaning ImageVector. What else should I do?

Thanks for help:)

edit retag flag offensive close merge delete