Install and configure OpenCV for python/anaconda with GPU support on windows 11

Hello everyone,
I’m trying install and configure OpenCV for python/anaconda with GPU support on windows 11.
I’d like to work locally on a computer vision project, but can’t find an efficient and recent step by step procedure to configure the environment.
OS : Windows 11
CPU : Ryzen 7
GPU : NVIDIA Geforce 3050
Can anyone help with this?
Thanks in advance.

OpenCL is always supported, so when you use UMat, that’ll already accelerate.

CUDA-specific acceleration requires building because the official binary packages for python don’t come with that.

I wrote a guide for building with cuda support on windows, let me know how you get on

5 Likes

Do we need to build this for each virtual environment or is there anyway to bring only the required libraries into new virtual environment?

Once built and installed you should be able to copy it accross from one environment to the next by copying the envs<env_name>\Lib\site-packages\cv2 directory.

Thanks for the quick response. I am actually using anaconda and built opencv with Cuda in my base environment. Now, I would like to create a virtual environment from my base to be able to use the cuda support. When I tried clone it, I got http connection error. Do you have any suggestion for the conda method to copy opencv packages?

What are you trying to clone, the repository, or do you mean copy the cv2 installation from your base environment?

I was trying to clone the base environment into a new environment to be able to use cv2. Now I am looking for a way only to copy cv2 into the new environment.

If you have built the install target then there will be a cv2 folder

<anaconda_installation_dir>\Lib\site-packages\cv2

you just need to copy this to

<anaconda_installation_dir>\envs\<env_name>\Lib\site-packages

so that you have the following directory structure

<anaconda_installation_dir>\envs\<env_name>\Lib\site-packages\cv2

Thanks for reply. I am getting the import error: raise ImportError(‘OpenCV loader: missing configuration file: {}. Check OpenCV installation.’.format(fnames))
ImportError: OpenCV loader: missing configuration file: [‘config-3.9.py’, ‘config-3.py’]. Check OpenCV installation. Normally my base is built with python 3.8. Do you think that could be the problem?

I’m not sure. I assumed you were using the same version of python have you tried renaming the config file?

If that doesn’t work you could just manually install the bindings from your build directory.

Thank you. It worked for the environment with the same python version.