【OpenCV】合成并显示高动态图像

合成并显示高动态图像

环境:VS2017 + OpenCV3.4.1

原图

HDR图像

【OpenCV】合成并显示高动态图像_第1张图片

LDR图像

【OpenCV】合成并显示高动态图像_第2张图片

步骤:

(1)设置好测试图片序列的路径

【OpenCV】合成并显示高动态图像_第3张图片

注意:需要将图片设置为同样大小,否则会出错

(2)修改一下list文件中的内容,第二项为曝光时间

【OpenCV】合成并显示高动态图像_第4张图片

程序:

#include "opencv2/photo.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

#include 
#include 
#include 

using namespace cv;
using namespace std;

void loadExposureSeq(String, vector&, vector&);

int main(int argc, char**argv)
{
	//  CommandLineParser parser( argc, argv, "{@input | | Input directory that contains images and exposure times. }" );
	String imgpath = "./sourceimg";
	//! [Load images and exposure times]
	vector images;
	vector times;
	// loadExposureSeq(parser.get( "@input" ), images, times);
	loadExposureSeq(imgpath, images, times);

	//! [Load images and exposure times]

	//! [Estimate camera response]
	Mat response;
	Ptr calibrate = createCalibrateDebevec();
	calibrate->process(images, response, times);
	//! [Estimate camera response]

	//! [Make HDR image]
	Mat hdr;
	Ptr merge_debevec = createMergeDebevec();
	merge_debevec->process(images, hdr, times, response);
	//! [Make HDR image]

	//! [Tonemap HDR image]
	Mat ldr;
	Ptr tonemap = createTonemap(2.2f);
	tonemap->process(hdr, ldr);
	//! [Tonemap HDR image]

	//! [Perform exposure fusion]
	Mat fusion;
	Ptr merge_mertens = createMergeMertens();
	merge_mertens->process(images, fusion);
	//! [Perform exposure fusion]

	//! [Write results]
	imshow("1210 fusion", fusion );
	//imwrite("fusion.jpg", fusion * 255);
	imshow("1210 ldr", ldr );
	//imwrite("ldr.jpg", ldr * 255);
	//
	//imwrite("hdr.hdr", hdr);
	//! [Write results]
	waitKey(0);
	return 0;
}

void loadExposureSeq(String path, vector& images, vector& times)
{
	path = path + "/";
	cout << path << endl;
	ifstream list_file((path + "list.txt").c_str());
	//cout << list_file<> name >> val) {
		cout << name << endl;
		Mat img = imread(path + name);
		images.push_back(img);
		times.push_back(1 / val);
	}
	list_file.close();
}

 

 

 

你可能感兴趣的:(OpenCV)