Openexr alternatives

Hi, i’m not able install programs on user machines, only pip install. I need to get cv2 to save to EXR. Can anyone recommend a pip package that will enable cv2 to do that? I can’t use OpenEXR because it requires python.h which the users don’ t have.

Needs to work on linux, mac and windows.

I can open EXR’s with imageio, but then dnn_superres can’t upsample it.

cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv_contrib\modules\dnn_superres\src\dnn_superres.cpp:263: error: (-5:Bad argument) Not supported image type: CV_32FC4 in function 'cv::dnn_superres::DnnSuperResImpl::preprocess_YCrCb'

take another look – it does support float images, just not those with alpha.
maybe you can get rid of that from imageio (or whatever you plan to use) ?

1 Like

thanks, now it doesn’t kick out any errors, although I do only get a black screen in the upscaled imshow:

import cv2 as cv
from cv2 import dnn_superres
import imageio.v3 as im
from PIL import Image
from numpy import asarray



models = 'E:/programming/opencv/models'

img_path = 'E:/temp/cache/ai/render_layers/single.exr'

imio = im.imread(img_path)
imio = imio[:,:,:3]
numpydata = asarray(imio)
cv.imshow('original',imio)

cv.waitKey(0)


# Create an SR object
sr = dnn_superres.DnnSuperResImpl_create()

path = f'{models}/FSRCNN_x2.pb'
#path = "../models/EDSR_X2.pb"
sr.readModel(path)

# Set the desired model and scale to get correct pre- and post-processing
#sr.setModel("edsr", 4)
sr.setModel("fsrcnn", 2)

# Upscale the image
result = sr.upsample(imio)

cv.imshow('upscaled',result)

cv.waitKey(0)

here’s the exr.

Oh this sorta works but it’s coming out very blue and not upscaled at all. Perhaps I’m removing the blue instead of the alpha.

import cv2 as cv
from cv2 import dnn_superres
import imageio.v3 as im
from PIL import Image
from numpy import asarray

models = 'E:/programming/opencv/models'
img_path = 'E:/temp/cache/ai/render_layers/single.exr'

imio = im.imread(img_path)
imio = imio[:,:,:3]
numpydata = asarray(imio)
cv.imshow('original',numpydata)

cv.waitKey(0)

# Create an SR object
sr = dnn_superres.DnnSuperResImpl_create()

path = f'{models}/FSRCNN_x2.pb'
sr.readModel(path)

# Set the desired model and scale to get correct pre- and post-processing
sr.setModel("fsrcnn", 2)

# Upscale the image
result = sr.upsample(numpydata)

cv.imshow('upscaled',result)

cv.waitKey(0)```

I’m probably trying to run before I can walk. I’ll see if I can find a decent tutorial to give me the missing knowledge I clearly have.