RenderKit / oidn

Intel® Open Image Denoise library
https://www.openimagedenoise.org/
Apache License 2.0
1.78k stars 164 forks source link

Official Python bindings via pybind11? #97

Open archibate opened 3 years ago

archibate commented 3 years ago

Hi, thank for the cool project! I'd like to invoke OIDN from Python, so that my renderer project can denoise the noisy images it generates without requiring any line of C++ code. I believe other peoples might also have such need, so instead of writting C++/Python bindings just for myself, I want to contribute it to somewhere like OpenImageDenoise/pyoidn🤣 To expose Python bindings, we may use pybind11 to wrap our C++11 API. I'll be glad to help!

atafra commented 2 years ago

Thanks! We don't have Python bindings on our roadmap yet but feel free to submit a pull request to OpenImageDenoise/oidn. However, I can't promise anything regarding when we could actually integrate it. We're currently focusing on GPU support, so the integration could happen only sometime after the next major release.

AJSVB commented 2 years ago

@archibate did you end up implementing such a thing? I would indeed be interested. Otherwise, is the python code in "training/" sufficient to denoise images in python? Many thanks.

archibate commented 2 years ago

did you end up implementing such a thing? I would indeed be interested.

@AJSVB Actually I've already abandoned that renderer project now...

Otherwise, is the python code in "training/" sufficient to denoise images in python?

I guess these are just training scripts for OIDN developers, rather than denoising script for end-users.

If you'd like to set up Python binding on your own, here's the information:

Python can actually directly load and invoke C functions in .dll or .so files, by using ctypes module, e.g.:

import ctypes
dll = ctypes.CDLL.LoadLibrary('YourCompiledOIDNLibrary.so')
device = dll.oidnNewDevice(12345)
dll.oidnCommitDevice(device)

Here's some Python/C++ binding code I'm recently working on: https://github.com/zenustech/zeno/blob/a649ea9465f0cbc9fda632c60559fe043927ef40/projects/Python/Lib/ze/__init__.py

We may also define argument and return types manually to avoid type mismatch: https://github.com/zenustech/zeno/blob/a649ea9465f0cbc9fda632c60559fe043927ef40/projects/Python/Lib/ze/__init__.py#L37-L53

AJSVB commented 2 years ago

Wow, thank you for this fast response, I will take a look :)

kevinlinxc commented 1 year ago

I would really like a python version of this as well. @AJSVB have you made any progress? If I have time I could try having a run at it.

AJSVB commented 1 year ago

I have a low-key working solution for inference only: I downloaded the precompiled oidn denoiser, and I do command line calls from os.system in python.

sxysxy commented 1 year ago

https://github.com/sxysxy/OIDN-python