Linking opencv-python to opencv-cuda in Arch

Question:

I’m trying to to get OpenCV with CUDA to be used in Python open-cv on Arch Linux, but I’m not sure how to link it.

Arch provides a package opencv-cuda, which provides these files.

Guides I’ve found said to link the python cv2.so to the one provided, but the package doesn’t provide that. My python site_packages has cv2.abi3.so in it, and I’ve tried linking that to core.so and cvv.so to no avail.

Do I need to build it differently to support Python? Or is there another step I’m missing?

Asked By: Nathan

||

Answers:

On Arch, opencv-cuda provides opencv=4.6.0, but you still need the python bindings. Fortunately though, installing python-opencv after installling opencv-cuda works, since it leverages it.

I just set up my Python virtual environment to allow system site packages (python -m venv .venv --system-site-packages), and it works like a charm! Neural net image detection runs ~300% as fast now.

Answered By: Nathan

You can also build OpenCV with support. I’m old school so I still build things.

Here’s a good list of build flags: Full cuda support can be
enabled using the following flags:

WITH_CUDA=ON
WITH_NVCUVID=ON 
CUDA_FAST_MATH=ON
WITH_CUBLAS=ON
WITH_CUFFT=ON
OPENCV_DNN_CUDA=ON

Here’s good how to on how to build it.

Here’s how to use those flags to make sure cuda is installed.

Here’s a complete tutorail from begining to end on how to enable the build for python (with pictures.)

Answered By: Matt Andruff
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.