资源简介
使用OpenCV进行高动态范围(HDR)成像(C ++ / Python)
代码片段和文件信息
#include
#include “opencv2/imgcodecs.hpp“
#include
#include
#include
#include
using namespace cv;
using namespace std;
void readImagesAndTimes(vector &images vector ×)
{
int numImages = 4;
static const float timesArray[] = {1/30.0f0.252.515.0};
times.assign(timesArray timesArray + numImages);
static const char* filenames[] = {“img_0.033.jpg“ “img_0.25.jpg“ “img_2.5.jpg“ “img_15.jpg“};
for(int i=0; i < numImages; i++)
{
Mat im = imread(filenames[i]);
images.push_back(im);
}
}
int main(int char**argv)
{
// Read images and exposure times
cout << “Reading images ... “ << endl;
vector images;
vector times;
readImagesAndTimes(images times);
// Align input images
cout << “Aligning images ... “ << endl;
Ptr alignMTB = createAlignMTB();
alignMTB->process(images images);
// Obtain Camera Response Function (CRF)
cout << “Calculating Camera Response Function (CRF) ... “ << endl;
Mat responseDebevec;
Ptr calibrateDebevec = createCalibrateDebevec();
calibrateDebevec->process(images responseDebevec times);
// Merge images into an HDR linear image
cout << “Merging images into one HDR image ... “ ;
Mat hdrDebevec;
Ptr mergeDebevec = createMergeDebevec();
mergeDebevec->process(images hdrDebevec times responseDebevec);
// Save HDR image.
imwrite(“hdrDebevec.hdr“ hdrDebevec);
cout << “saved hdrDebevec.hdr “<< endl;
// Tonemap using Drago‘s method to obtain 24-bit color image
cout << “Tonemaping using Drago‘s method ... “;
Mat ldrDrago;
Ptr tonemapDrago = createTonemapDrago(1.0 0.7);
tonemapDrago->process(hdrDebevec ldrDrago);
ldrDrago = 3 * ldrDrago;
imwrite(“ldr-Drago.jpg“ ldrDrago * 255);
cout << “saved ldr-Drago.jpg“<< endl;
// Tonemap using Durand‘s method obtain 24-bit color image
cout << “Tonemaping using Durand‘s method ... “;
Mat ldrDurand;
Ptr tonemapDurand = createTonemapDurand(1.541.011);
tonemapDurand->process(hdrDebevec ldrDurand);
ldrDurand = 3 * ldrDurand;
imwrite(“ldr-Durand.jpg“ ldrDurand * 255);
cout << “saved ldr-Durand.jpg“<< endl;
// Tonemap using Reinhard‘s method to obtain 24-bit color image
cout << “Tonemaping using Reinhard‘s method ... “;
Mat ldrReinhard;
Ptr tonemapReinhard = createTonemapReinhard(1.5 000);
tonemapReinhard->process(hdrDebevec ldrReinhard);
imwrite(“ldr-Reinhard.jpg“ ldrReinhard * 255);
cout << “saved ldr-Reinhard.jpg“<< endl;
// Tonemap using Mantiuk‘s method to obtain 24-bit color image
cout << “Tonemaping using Mantiuk‘s method ... “;
Mat ldrMantiuk;
Ptr tonemapMantiuk = createTonemapMantiuk(2.20.85 1.2);
tonemapMantiuk->process(hdrDebevec ldrMantiuk);
ldrMantiuk = 3 * ldrMantiuk;
imwrite(“ldr-Mantiuk.jpg“ ldrMantiuk * 255);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-10-08 16:59 hdr\
文件 6148 2017-10-08 16:59 hdr\.DS_Store
目录 0 2017-10-08 16:59 __MACOSX\
目录 0 2017-10-08 16:59 __MACOSX\hdr\
文件 120 2017-10-08 16:59 __MACOSX\hdr\._.DS_Store
文件 3076 2017-10-06 09:46 hdr\hdr.cpp
文件 277 2017-10-06 09:46 __MACOSX\hdr\._hdr.cpp
文件 2405 2017-10-08 16:58 hdr\hdr.py
文件 226 2017-10-08 16:58 __MACOSX\hdr\._hdr.py
文件 902169 2017-10-06 09:46 hdr\img_0.033.jpg
文件 226 2017-10-06 09:46 __MACOSX\hdr\._img_0.033.jpg
文件 1462235 2017-10-06 09:46 hdr\img_0.25.jpg
文件 226 2017-10-06 09:46 __MACOSX\hdr\._img_0.25.jpg
文件 2396332 2017-10-06 09:46 hdr\img_15.jpg
文件 226 2017-10-06 09:46 __MACOSX\hdr\._img_15.jpg
文件 2354237 2017-10-06 09:46 hdr\img_2.5.jpg
文件 226 2017-10-06 09:46 __MACOSX\hdr\._img_2.5.jpg
文件 226 2017-10-08 16:59 __MACOSX\._hdr
- 上一篇:《Python入门指南》PDF
- 下一篇:Think DSP python
评论
共有 条评论