Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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);
        photo_number++;
    }
}
else{
    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);
    ImagesVector.push_back(photos[i]);
}
}

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 http://docs.opencv.org/master/d7/d1c/classcv_1_1WarperCreator.html
stitcher.setFeaturesFinder(new detail::SurfFeaturesFinder(900, 3, 4, 3, 4));
//stitcher.setFeaturesFinder(new detail::OrbFeaturesFinder(Size(3, 1), 1500, 1.3f, 5));
stitcher.setRegistrationResol(0.9);
stitcher.setSeamEstimationResol(0.9);
stitcher.setCompositingResol(1); // Rozdzielczosc zdjecia wyjsciowego
stitcher.setPanoConfidenceThresh(0.9);
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;
try{
    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);

ImagesVector.clear();
ImagesVector.empty();
image.release();
image.empty();

photo_number = 0;

}

And here is main:

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


ReadPhotos("paths2.txt");
MakePanorama(ImagesVector, "22.jpg");

ReadPhotos("paths3.txt");
MakePanorama(ImagesVector, "33.jpg");

ReadPhotos("paths4.txt");
MakePanorama(ImagesVector, "44.jpg");


system("pause");
waitKey(0);
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:)

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

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);
        photo_number++;
    }
}
else{
    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);
    ImagesVector.push_back(photos[i]);
}
}

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 http://docs.opencv.org/master/d7/d1c/classcv_1_1WarperCreator.html
stitcher.setFeaturesFinder(new detail::SurfFeaturesFinder(900, 3, 4, 3, 4));
//stitcher.setFeaturesFinder(new detail::OrbFeaturesFinder(Size(3, 1), 1500, 1.3f, 5));
stitcher.setRegistrationResol(0.9);
stitcher.setSeamEstimationResol(0.9);
stitcher.setCompositingResol(1); // Rozdzielczosc zdjecia wyjsciowego
stitcher.setPanoConfidenceThresh(0.9);
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;
try{
    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);

ImagesVector.clear();
ImagesVector.empty();
image.release();
image.empty();

photo_number = 0;

}

And here is main:

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


ReadPhotos("paths2.txt");
MakePanorama(ImagesVector, "22.jpg");

ReadPhotos("paths3.txt");
MakePanorama(ImagesVector, "33.jpg");

ReadPhotos("paths4.txt");
MakePanorama(ImagesVector, "44.jpg");


system("pause");
waitKey(0);
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:)