|
|
@ -28,7 +28,6 @@ namespace cv2
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using namespace cv;
|
|
|
|
using namespace cv;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mat linearResponseNew(int channels)
|
|
|
|
Mat linearResponseNew(int channels)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Mat response = Mat(LDR_SIZE, 1, CV_MAKETYPE(CV_32F, channels));
|
|
|
|
Mat response = Mat(LDR_SIZE, 1, CV_MAKETYPE(CV_32F, channels));
|
|
|
@ -131,11 +130,12 @@ namespace cv2
|
|
|
|
Mat weight_sum = Mat::zeros(size, CV_32F);
|
|
|
|
Mat weight_sum = Mat::zeros(size, CV_32F);
|
|
|
|
|
|
|
|
|
|
|
|
ALOGD("HDR Merge 5");
|
|
|
|
ALOGD("HDR Merge 5");
|
|
|
|
// #pragma omp parallel for num_threads(2)
|
|
|
|
|
|
|
|
for(size_t i = 0; i < images.size(); i++) {
|
|
|
|
for(size_t i = 0; i < images.size(); i++) {
|
|
|
|
std::vector<Mat> splitted;
|
|
|
|
std::vector<Mat> splitted;
|
|
|
|
split(images[i], splitted);
|
|
|
|
split(images[i], splitted);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ALOGD("HDR Merge 5 - 1");
|
|
|
|
Mat w = Mat::zeros(size, CV_32F);
|
|
|
|
Mat w = Mat::zeros(size, CV_32F);
|
|
|
|
for(int c = 0; c < channels; c++) {
|
|
|
|
for(int c = 0; c < channels; c++) {
|
|
|
|
LUT(splitted[c], weights, splitted[c]);
|
|
|
|
LUT(splitted[c], weights, splitted[c]);
|
|
|
@ -143,14 +143,18 @@ namespace cv2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
w /= channels;
|
|
|
|
w /= channels;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ALOGD("HDR Merge 5 - 2");
|
|
|
|
Mat response_img;
|
|
|
|
Mat response_img;
|
|
|
|
LUT(images[i], log_response, response_img);
|
|
|
|
LUT(images[i], log_response, response_img);
|
|
|
|
split(response_img, splitted);
|
|
|
|
split(response_img, splitted);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma omp parallel for num_threads(channels)
|
|
|
|
for(int c = 0; c < channels; c++) {
|
|
|
|
for(int c = 0; c < channels; c++) {
|
|
|
|
//这里崩溃
|
|
|
|
//这里崩溃
|
|
|
|
result_split[c] += w.mul(splitted[c] - exp_values.at<float>((int)i));
|
|
|
|
result_split[c] += w.mul(splitted[c] - exp_values.at<float>((int)i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
weight_sum += w;
|
|
|
|
weight_sum += w;
|
|
|
|
|
|
|
|
ALOGD("HDR Merge 5 - 3");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ALOGD("HDR Merge 6");
|
|
|
|
ALOGD("HDR Merge 6");
|
|
|
@ -506,7 +510,7 @@ bool makeHdr(std::vector<float>& times, std::vector<std::string>& paths, cv::Mat
|
|
|
|
// Tonemap using Reinhard's method to obtain 24-bit color image
|
|
|
|
// Tonemap using Reinhard's method to obtain 24-bit color image
|
|
|
|
// cout << "Tonemaping using Reinhard's method ... ";
|
|
|
|
// cout << "Tonemaping using Reinhard's method ... ";
|
|
|
|
cv::Mat ldrReinhard;
|
|
|
|
cv::Mat ldrReinhard;
|
|
|
|
cv::Ptr<cv2::TonemapReinhardNew> tonemapReinhard = cv2::createTonemapReinhardNew(1.5, 0, 0, 0);
|
|
|
|
cv::Ptr<cv::TonemapReinhard> tonemapReinhard = cv::createTonemapReinhard(1.5, 0, 0, 0);
|
|
|
|
tonemapReinhard->process(hdrDebevec, ldrReinhard);
|
|
|
|
tonemapReinhard->process(hdrDebevec, ldrReinhard);
|
|
|
|
hdrDebevec.release();
|
|
|
|
hdrDebevec.release();
|
|
|
|
|
|
|
|
|
|
|
@ -540,7 +544,7 @@ bool makeHdr(std::vector<float>& times, std::vector<cv::Mat>& images, cv::Mat& r
|
|
|
|
// Merge images into an HDR linear image
|
|
|
|
// Merge images into an HDR linear image
|
|
|
|
ALOGI("Merging images into one HDR image ... ");
|
|
|
|
ALOGI("Merging images into one HDR image ... ");
|
|
|
|
cv::Mat hdrDebevec;
|
|
|
|
cv::Mat hdrDebevec;
|
|
|
|
cv::Ptr<cv2::MergeDebevecNew> mergeDebevec = cv2::createMergeDebevecNew();
|
|
|
|
cv::Ptr<cv::MergeDebevec> mergeDebevec = cv::createMergeDebevec();
|
|
|
|
mergeDebevec->process(images, hdrDebevec, times, responseDebevec);
|
|
|
|
mergeDebevec->process(images, hdrDebevec, times, responseDebevec);
|
|
|
|
// Save HDR image.
|
|
|
|
// Save HDR image.
|
|
|
|
// imwrite((OUTPUT_DIR "hdrDebevec.hdr"), hdrDebevec);
|
|
|
|
// imwrite((OUTPUT_DIR "hdrDebevec.hdr"), hdrDebevec);
|
|
|
@ -554,7 +558,7 @@ bool makeHdr(std::vector<float>& times, std::vector<cv::Mat>& images, cv::Mat& r
|
|
|
|
// Tonemap using Reinhard's method to obtain 24-bit color image
|
|
|
|
// Tonemap using Reinhard's method to obtain 24-bit color image
|
|
|
|
ALOGI("Tonemaping using Reinhard's method ... ");
|
|
|
|
ALOGI("Tonemaping using Reinhard's method ... ");
|
|
|
|
cv::Mat ldrReinhard;
|
|
|
|
cv::Mat ldrReinhard;
|
|
|
|
cv::Ptr<cv2::TonemapReinhardNew> tonemapReinhard = cv2::createTonemapReinhardNew(1.5, 0, 0, 0);
|
|
|
|
cv::Ptr<cv::TonemapReinhard> tonemapReinhard = cv::createTonemapReinhard(1.5, 0, 0, 0);
|
|
|
|
tonemapReinhard->process(hdrDebevec, ldrReinhard);
|
|
|
|
tonemapReinhard->process(hdrDebevec, ldrReinhard);
|
|
|
|
hdrDebevec.release();
|
|
|
|
hdrDebevec.release();
|
|
|
|
|
|
|
|
|
|
|
@ -708,8 +712,11 @@ Java_com_xypower_mppreview_Camera2RawFragment_makeHdr3(JNIEnv *env, jclass clazz
|
|
|
|
for (int idx = 0; idx < 2; idx++)
|
|
|
|
for (int idx = 0; idx < 2; idx++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AndroidBitmapInfo bmpInfo = { 0 };
|
|
|
|
AndroidBitmapInfo bmpInfo = { 0 };
|
|
|
|
AHardwareBuffer* hardwareBuffer = NULL;
|
|
|
|
|
|
|
|
int result = AndroidBitmap_getInfo(env, bitmaps[idx], &bmpInfo);
|
|
|
|
int result = AndroidBitmap_getInfo(env, bitmaps[idx], &bmpInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((ANDROID_BITMAP_FLAGS_IS_HARDWARE & bmpInfo.flags) == ANDROID_BITMAP_FLAGS_IS_HARDWARE)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
AHardwareBuffer* hardwareBuffer = NULL;
|
|
|
|
result = AndroidBitmap_getHardwareBuffer(env, bitmaps[idx], &hardwareBuffer);
|
|
|
|
result = AndroidBitmap_getHardwareBuffer(env, bitmaps[idx], &hardwareBuffer);
|
|
|
|
|
|
|
|
|
|
|
|
void* outVirtualAddress = NULL;
|
|
|
|
void* outVirtualAddress = NULL;
|
|
|
@ -718,6 +725,15 @@ Java_com_xypower_mppreview_Camera2RawFragment_makeHdr3(JNIEnv *env, jclass clazz
|
|
|
|
cv::Mat tmp(bmpInfo.height, bmpInfo.width, CV_8UC4, outVirtualAddress);
|
|
|
|
cv::Mat tmp(bmpInfo.height, bmpInfo.width, CV_8UC4, outVirtualAddress);
|
|
|
|
AHardwareBuffer_unlock(hardwareBuffer, &fence);
|
|
|
|
AHardwareBuffer_unlock(hardwareBuffer, &fence);
|
|
|
|
tmp.copyTo(images[idx]);
|
|
|
|
tmp.copyTo(images[idx]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
void* outAddress = NULL;
|
|
|
|
|
|
|
|
result = AndroidBitmap_lockPixels(env, bitmaps[idx], &outAddress);
|
|
|
|
|
|
|
|
cv::Mat tmp(bmpInfo.height, bmpInfo.width, CV_8UC4, outAddress);
|
|
|
|
|
|
|
|
AndroidBitmap_unlockPixels(env, bitmaps[idx]);
|
|
|
|
|
|
|
|
tmp.copyTo(images[idx]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//convert RGB to BGR
|
|
|
|
//convert RGB to BGR
|
|
|
|
cv::cvtColor(images[idx], images[idx], cv::COLOR_RGB2BGR);
|
|
|
|
cv::cvtColor(images[idx], images[idx], cv::COLOR_RGB2BGR);
|
|
|
@ -746,5 +762,14 @@ Java_com_xypower_mppreview_Camera2RawFragment_makeHdr3(JNIEnv *env, jclass clazz
|
|
|
|
return JNI_TRUE;
|
|
|
|
return JNI_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// env->DeleteGlobalRef(img1);
|
|
|
|
|
|
|
|
// env->DeleteGlobalRef(img2);
|
|
|
|
|
|
|
|
|
|
|
|
return JNI_FALSE;
|
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
|
|
|
|
Java_com_xypower_mppreview_Camera2RawFragment_decodeDng(JNIEnv *env, jclass clazz,
|
|
|
|
|
|
|
|
jobject byte_buffer, jstring output_path) {
|
|
|
|
|
|
|
|
// TODO: implement decodeDng()
|
|
|
|
|
|
|
|
}
|