c++ - Try to measure times of image stitching using OpenCV Stitcher. Different times when restarting/not restarting program. Issue with memory? -
i made little application stitch few images using opencv. it's measure times of stitching.
here function 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); (int = 0; < photo_number; i++){ //resize(photos[i], photos[i], size); imagesvector.push_back(photos[i]); } }
here makepanorama function. implemented here simple timer measure time of stitching images. need know how long takes stitch 2,3,4.. images. contains 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 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 weird thing. when call readphotos() , makepanorama() once in 1 single run of program stitches 2 images in 3 seconds, 3 images in 8 seconds , 4 images in 16 seconds.
when call readphotos() , makepanorama() 3 times 2, 3 , 4 photos stitch in single run of program takes 3 seconds, 30 seconds , 130 seconds.
so can see reruning program gives lot better times. why that? im cleaning imagevector. else should do?
thanks help:)
Comments
Post a Comment