Please be sure to understand whether your opencv is under apt management, pip management, or unmanaged, before considering the following solution.
【Solution A1 - apt/debian package/unmanaged】
You have already built opencv-contrib(opencv+cuda) and installed it on your system.
Create venv with --system-site-packages option.
python3 -m venv venv01 --system-site-packages
Explain:
There is an option “–system-site-packages” in venv/virtualenv.
Debien package is system site package. So you must need this option.
【Solution A2 - apt/debian package/unmanaged】
If you don’t want to use “–system-site-packages”, you can create a symbolic link instead.
See also: Installation of TensorRT in VEnv on Jetson Nano B01 - #2 by naisy
Example:
sudo ln -s /usr/lib/python3.6/dist-packages/cv2 /PATH_TO_VENV/lib/python3.6/site-packages/cv2
【Solution A3 - apt/debian package/unmanaged】
Instead of a symbolic link, it can be added to the PYTHONPATH.
Example:
export PYTHONPATH=/usr/lib/python3.6/dist-packages/cv2:$PYTHONPATH
【Solution B1 - pip/wheel package】
Build opencv-contrib with pip install.
Example: (EDIT)
CMAKE_ARGS='-DOPENCV_ENABLE_NONFREE=ON -DBUILD_TYPE=Release -DCUDA_ARCH_BIN=7.2,6.2,5.3 -DWITH_CUDA=ON' pip install -v --no-binary=opencv-contrib-python opencv-contrib-python==4.6.0.66
Explain:
If you are dissatisfied with the distributed binaries, you can build from source code.
The following URL was used as a reference for Solution B1.
【Solution B2 - pip/wheel package】
If you need to patch the source code, Solution B1 is not available.
git clone or download the compressed file, apply the patch, and create wheel file.
See also: GitHub - opencv/opencv-python: Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.