增加独立进程处理的辅助类
parent
122cd629dc
commit
705e953dc5
@ -0,0 +1,61 @@
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <omp.h>
|
||||
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
#include "hdr.h"
|
||||
|
||||
|
||||
bool makeHdr(std::vector<float>& times, std::vector<cv::Mat>& images, cv::Mat& rgb)
|
||||
{
|
||||
// Align input images
|
||||
// cout << "Aligning images ... " << endl;
|
||||
cv::Ptr<cv::AlignMTB> alignMTB = cv::createAlignMTB();
|
||||
#if 0
|
||||
alignMTB->process(images, images);
|
||||
#endif
|
||||
|
||||
// Obtain Camera Response Function (CRF)
|
||||
// ALOGI("Calculating Camera Response Function (CRF) ... ");
|
||||
cv::Mat responseDebevec;
|
||||
cv::Ptr<cv::CalibrateDebevec> calibrateDebevec = cv::createCalibrateDebevec();
|
||||
calibrateDebevec->process(images, responseDebevec, times);
|
||||
|
||||
// Merge images into an HDR linear image
|
||||
// ALOGI("Merging images into one HDR image ... ");
|
||||
cv::Mat hdrDebevec;
|
||||
cv::Ptr<cv::MergeDebevec> mergeDebevec = cv::createMergeDebevec();
|
||||
mergeDebevec->process(images, hdrDebevec, times, responseDebevec);
|
||||
// Save HDR image.
|
||||
// imwrite((OUTPUT_DIR "hdrDebevec.hdr"), hdrDebevec);
|
||||
// cout << "saved hdrDebevec.hdr " << endl;
|
||||
|
||||
{
|
||||
std::vector<cv::Mat> empty;
|
||||
empty.swap(images);
|
||||
}
|
||||
|
||||
// Tonemap using Reinhard's method to obtain 24-bit color image
|
||||
// ALOGI("Tonemaping using Reinhard's method ... ");
|
||||
cv::Mat ldrReinhard;
|
||||
cv::Ptr<cv::TonemapReinhard> tonemapReinhard = cv::createTonemapReinhard(1.5, 0, 0, 0);
|
||||
tonemapReinhard->process(hdrDebevec, ldrReinhard);
|
||||
hdrDebevec.release();
|
||||
|
||||
int type = ldrReinhard.type();
|
||||
ldrReinhard = ldrReinhard * 255;
|
||||
|
||||
ldrReinhard.convertTo(rgb, CV_8U);
|
||||
ldrReinhard.release();
|
||||
|
||||
return true;
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <omp.h>
|
||||
|
||||
#include <android/imagedecoder.h>
|
||||
#include <android/log.h>
|
||||
#include <media/NdkImage.h>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
#include "hdr.h"
|
||||
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
if (argc != 7)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string outputPath = argv[1];
|
||||
std::string tmpFilePath = argv[2];
|
||||
|
||||
std::vector<float> times;
|
||||
times.push_back((double)(atoi(argv[3])) / 1000000000.0);
|
||||
times.push_back((double)(atoi(argv[5])) / 1000000000.0);
|
||||
|
||||
std::vector<std::string> paths;
|
||||
paths.push_back(std::string(argv[4]));
|
||||
paths.push_back(std::string(argv[6]));
|
||||
|
||||
std::vector<cv::Mat> images;
|
||||
images.resize(2);
|
||||
|
||||
printf("Start Decode");
|
||||
|
||||
#pragma omp parallel for num_threads(2)
|
||||
for (int idx = 0; idx < 2; idx++)
|
||||
{
|
||||
images[idx] = cv::imread(paths[idx].c_str());
|
||||
}
|
||||
|
||||
printf("End Decode");
|
||||
|
||||
cv::Mat rgb;
|
||||
|
||||
printf("Start MakeHDR3");
|
||||
makeHdr(times, images, rgb);
|
||||
printf("End MakeHDR3");
|
||||
|
||||
std::vector<int> params;
|
||||
params.push_back(cv::IMWRITE_JPEG_QUALITY);
|
||||
params.push_back(100);
|
||||
if (cv::imwrite(outputPath.c_str(), rgb, params))
|
||||
{
|
||||
printf("End HDR3");
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <omp.h>
|
||||
|
||||
#include <android/imagedecoder.h>
|
||||
#include <android/log.h>
|
||||
#include <media/NdkImage.h>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
#define HDR_TAG "HDR"
|
||||
#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, HDR_TAG,__VA_ARGS__)
|
||||
#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, HDR_TAG,__VA_ARGS__)
|
||||
#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, HDR_TAG, __VA_ARGS__)
|
||||
#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, HDR_TAG, __VA_ARGS__)
|
||||
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, HDR_TAG,__VA_ARGS__)
|
||||
|
||||
bool makeHdr(std::vector<float>& times, std::vector<cv::Mat>& images, cv::Mat& rgb);
|
Loading…
Reference in New Issue