How to call a C++ function containing OpenCV's CUDA from a python DLL

I’m currently compiling OpenCV and CUDA sources in C++ and making them with Visual Studio 2022, but I’m trying to convert some of the source code into a DLL and call it from Python, but it becomes ModuleNotFound and I can’t call it . Is there something I need in the build settings for this?

Below is the original Japanese text before machine translation.
私は現在C++でOpenCVとCUDAのソースをコンパイルしてVisual Studio2022で作っておりますが、こちらの一部ソースコードをDLL化してPythonから呼び出そうとしていますが、ModuleNotFoundになりうまく呼び出せません。こちらは何かビルド設定で必要なものがありますでしょうか?

can you call your module without any cuda call?
May be you can add in your python code (with your own path)
os.add_dll_directory(r’c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin’)

before to load your module.

Thank you for your reply.
I tried it and it seems that ModuleNotFound is still called.

Currently, the source code is
It occurs when reading inside include opencv2.
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>

os.add_dll_directory(r’c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin’)
will try. Thank you for sharing the information.

I solved.
dlllib = ctypes.cdll.LoadLibrary(“opencv_world470d.dll”)
I was able to go after loading the build opencv dll.
thank you.

becarefull “d” means it’s a debug version of opencv_world.

1 Like

“d” is debug OK. I’ll pay attention. thank you