OpenCV-Python createMergeDebevec返回Inf数组 [英] OpenCV-Python createMergeDebevec returns an array of Inf

查看:224
本文介绍了OpenCV-Python createMergeDebevec返回Inf数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试与OpenCV-Python一起使用一些与HDR相关的功能:特别是我正在尝试复制 MCVE . 1.jpg,2.jpg,3.jpg均为870×580 RGB(内部RGB KODAK sRGB显示屏)JPG图像,其曝光时间分别为1/3200、1/800和1/200.我已经用其他2个JPG图像集对此进行了测试,其中一个图像集可在

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)

值得注意的是,在merge.process调用之后修改了"times"数组

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])

我正在使用OpenCV版本:

I am using OpenCV version:

>>> cv2.__version__
'3.0.0'

merge.process调用的签名如下:

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'

推荐答案

我在Velimir的答案的帮助下设法使其工作.我的问题是我必须按照电动汽车的降序构造图像阵列. Velimir的答案满足了我的需要,但我将其作为一个单独的答案,因为我想强调times数组代表曝光时间而不是EV.我还添加了应在构建辐射度贴图后应用的色调映射方法.

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)

示例图片来自 http://ttic.uchicago.edu/~cotter /projects/hdr_tools/

明亮的图像

普通图片

深色图像

色调映射结果图像

这篇关于OpenCV-Python createMergeDebevec返回Inf数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆