OpenCV-Python createMergeDebevec returns an array of Inf

↘锁芯ラ 提交于 2019-12-08 04:22:03

问题


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'

回答1:


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

import cv2
import numpy as np
images = [cv2.imread(x) for x in 'EV+4.09.JPG', 'EV+1.18.JPG', 'EV-1.82.JPG']
times = np.array([4.09, 1.18, -1.82])
times *= 1000.
merger = cv2.createMergeDebevec()
hdr = merger.process(images, times)
print hdr
cv2.imwrite('out.jpg', hdr)

OUT.JPG




回答2:


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.

import cv2
import numpy as np

img = cv2.imread("bright.jpg") # Exposure time 1/8
img2 = cv2.imread("normal.jpg") # Exposure time 1/13
img3 = cv2.imread("dark.jpg") # Exposure time 1/15

images = [img, img2, img3]
times = np.array([1/8.,1/13.,1/15.])
merger = cv2.createMergeDebevec()
hdr = merger.process(images, times)
tonemap = cv2.createTonemapDurand(2.2)
tonemapped_image = tonemap.process(hdr)
cv2.imwrite('tonemapped_image.jpg', tonemapped_image * 255)

The sample images are from http://ttic.uchicago.edu/~cotter/projects/hdr_tools/

Bright Image

Normal Image

Dark Image

Tonemapped Resulting Image



来源:https://stackoverflow.com/questions/34433906/opencv-python-createmergedebevec-returns-an-array-of-inf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!