I am trying to get some HDR related functions working with OpenCV-Python: specifically I'm trying to reproduce the OpenCV C++ HDR tutorial. Unfortunately, the resulting hdr image/array comes out completely white (all values are Inf). Here is an MCVE. 1.jpg, 2.jpg, 3.jpg are all 870 × 580 RGB (Internal RGB KODAK sRGB Display) JPG images with exposure times of 1/3200, 1/800, and 1/200 respectively. I've tested this with 2 other JPG image sets now, one of which is available on Wikimedia.
>>> import cv2
>>> import numpy as np
>>>
>>> img = cv2.imread("1.jpg")
>>> img2 = cv2.imread("2.jpg")
>>> img3 = cv2.imread("3.jpg")
>>>
>>> images = np.array([img, img2, img3])
>>> times = np.array([1.0/3200,1.0/800,1.0/200])
>>>
>>> merger = cv2.createMergeDebevec()
>>> hdr = merger.process(images, times)
>>> hdr
array([[[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf],
...,
[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf]],
[[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf],
...,
[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf]],
[[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf],
...,
[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf]],
...,
[[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf],
...,
[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf]],
[[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf],
...,
[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf]],
[[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf],
...,
[ inf, inf, inf],
[ inf, inf, inf],
[ inf, inf, inf]]], dtype=float32)
An interesting thing to note is that the "times" array is modified after the merger.process call
>>> times
array([-8.07090609, -6.68461173, -5.29831737])
I am using OpenCV version:
>>> cv2.__version__
'3.0.0'
The merger.process call has a signature as follows:
>>> import inspect
>>> inspect.getdoc(merger.process)
'process(src, times, response[, dst]) -> dst or process(src, times[, dst]) -> dst'
Not sure how the Debevec algorithm works, but I managed to get a working example you had asked for. Note the descending order of the images (and their corresponding EVs) and the multiplier on line 5. Play around with the multiplier, and you can get slightly different results. Not sure what's going on, but it seems to be working. Here you go:
EV+4.09.JPG EV+1.18.JPG EV-1.82.JPG
OUT.JPG
I managed to get it working with the help of Velimir's answer. My issue was that I had to construct the array of images in descending order of EVs. While Velimir's answer does what I need, I'm making this a separate answer because I want to emphasize that the
times
array represents the exposure times instead of the EVs. I've also added the tonemapping method that should be applied after building the radiance map.The sample images are from http://ttic.uchicago.edu/~cotter/projects/hdr_tools/
Bright Image
Normal Image
Dark Image
Tonemapped Resulting Image