尝试使用OpenCV Stitcher测量图像拼接的时间。重启/不重启程序的不同时间。内存问题?

时间:2015-09-21 12:55:19

标签: c++ opencv image-stitching opencv-stitching

我几乎没有使用OpenCV来缝合少量图像。它主要用于测量缝合时间。

这是一个使用txt文件中的路径加载照片的功能:

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

这是MakePanorama功能。我在这里实现了简单的计时器来测量拼接图像的时间。我需要知道缝合2,3,4 ..图像需要多长时间。它包含所有openCV Stitcher类函数:

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;

}

主要是:

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

这是奇怪的事情。当我在一次程序运行中只调用一次ReadPhotos()和MakePanorama()时,它会在3秒内缝合2张图像,8秒内缝合3张图像,16秒钟缝合4张图像。

当我用2张,3张和4张照片调用ReadPhotos()和MakePanorama()3次以在单次运行程序中缝合时,它需要3秒,30秒和130秒。

所以我可以看到重新运行程序提供了更好的时间。这是为什么?我正在清洁ImageVector。我还应该做什么?

感谢您的帮助:)

0 个答案:

没有答案