HDR merge giving wrong output

asked 2019-01-24 11:16:25 -0500

Durdin gravatar image

I have been following the example about how to implement a HDR on this site

I'm trying to implement the code in a native app in Android calling the code in C++. The code looks like this:

Java_org_opencv_OpenCvJNI_processHdr(JNIEnv *env,
                                     jclass clazz,
                                     jlongArray inputImages,
                                     jfloatArray exposureTimes,
                                     jlong dst) {
    cv::Mat& output = *(cv::Mat*)dst;

    LOGD("HDR start");
    jsize count = env->GetArrayLength(inputImages);
    jlong *imagesArrayData = env->GetLongArrayElements(inputImages, 0);

    LOGD("HDR get mats");
    vector<cv::Mat> images(count);
    vector<float> times(count);

    for (int i = 0; i < count; i++) {
        cv::Mat& frame = *(cv::Mat*)imagesArrayData[0];
        images[i] = frame;
    LOGD("HDR get times");
    env->GetFloatArrayRegion(exposureTimes, 0, count, &times[0]);

    LOGD("HDR merge");
    Mat hdr;
    Ptr<MergeDebevec> merge_debevec = createMergeDebevec();
    merge_debevec->process(images, hdr, times);

    LOGD("HDR tonemap");
    Mat ldr;
    Ptr<Tonemap> tonemapDrago = createTonemap(1.0);
    tonemapDrago->process(hdr, ldr);
    output = ldr * 255;

    LOGD("HDR save");

    cv::imwrite("/storage/emulated/0/opencv/example.png", output);
    return 0;

The code is working fine and the jlongArray and jfloatArray passed to the method are the same images than the example. However, the output image is so bright. First image is my output, 2º one the expected output after follow the code lab:

image description image description

Someone knows what I can be doing wrong? I have tried also doing the calibrate for the camera Response before. But when doing it it took ages and the result looks even worst.

Thank you so much in advance.

edit retag flag offensive close merge delete