1 #include "stdafx.h"> 2 3 4 /* For description look into the help() function. */ 5 6 7 #include "opencv2/photo.hpp" 8 #include "opencv2/imgcodecs.hpp" 9 #include "opencv2/highgui.hpp" 10 11 #include <vector> 12 #include <iostream> 13 #include <fstream> 14 15 using namespace cv; 16 using namespace std; 17 18 void loadExposureSeq(String, vector<Mat>&, vector<float>&); 19 20 int main(int argc, char**argv) 21 { 22 //! [Load images and exposure times] 23 vector<Mat> images; 24 vector<float> times; 25 loadExposureSeq("F://opencv//VS_demo//opencvdemo//data//Memorial_SourceImages", images, times); 26 //! [Load images and exposure times] 27 28 //! [Estimate camera response] 29 Mat response; 30 Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec(); 31 calibrate->process(images, response, times); 32 //! [Estimate camera response] 33 34 //! [Make HDR image] 35 Mat hdr; 36 Ptr<MergeDebevec> merge_debevec = createMergeDebevec(); 37 merge_debevec->process(images, hdr, times, response); 38 //! [Make HDR image] 39 40 //! [Tonemap HDR image] 41 Mat ldr; 42 Ptr<Tonemap> tonemap = createTonemap(2.2f); 43 tonemap->process(hdr, ldr); 44 //! [Tonemap HDR image] 45 46 //! [Perform exposure fusion] 47 Mat fusion; 48 Ptr<MergeMertens> merge_mertens = createMergeMertens(); 49 merge_mertens->process(images, fusion); 50 //! [Perform exposure fusion] 51 52 //! [Write results] 53 imwrite("fusion.png", fusion * 255); 54 imwrite("ldr.png", ldr * 255); 55 imwrite("hdr.hdr", hdr); 56 //! [Write results] 57 58 return 0; 59 } 60 61 void loadExposureSeq(String path, vector<Mat>& images, vector<float>& times) 62 { 63 path = path + "//"; 64 string str = path + "list.txt"; 65 ifstream list_file(str.c_str()); 66 string name; 67 float val; 68 while (list_file >> name >> val) { 69 Mat img = imread(path + name); 70 images.push_back(img); 71 times.push_back(1 / val); 72 } 73 list_file.close(); 74 }
运行:
输入:
输出: