This is the script for installing OpenCV4.x with cuda in anaconda or default python
if you can find the build folder, you can run:
cd build
sudo make uninstall
cd ../
rm -rf build
and remove all the opencv lib:
$ rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
$ cd /usr
$ find . -name "*opencv*" | xargs sudo rm -rf
if you don't have the build folder , you can rebuild your old version follow next step , then try again.
git clone
cd opencv_install
bash ./opencv_install.sh
First of all ,you should set same parameters for installing OpenCV and cuda setting
INSTALL_DIR
: Where the OpenCV installed,default is /usr/local, recommand /usr/localOPENCV_SOURCE_DIR
: Where the OpenCV sources code download,default is your home dirWITH_CUDA
: With cuda or notARCH_BIN
: You should check your device arch_bin in Nvidia DevicesVIRTUAL_PYTHON_PATH
: Where is your python path,example:/home/dnn/anaconda3/envs/opencv3
PYTHON_VERSION
: which python version your virtual envs use for,example:python3.6
My test envs:
- OpenCV 4.5.0
- Ubuntu18.04
- GTX 1080
- Cuda 10.0
- Cudnn 7.6.3
- anaconda3
- virtual envs: movie
- make sure your virtual envs install numpy
[BASH] Choose the OpenCV Version :(Enter:default 4.2.0) 4.5.0
OpenCV Version: 4.5.0
[BASH] Change the path which OpenCV will be installed:(Enter:default /usr/local)
OpenCV will be installed in: /usr/local
[BASH] Change the path which OpenCV Source path:(Enter:default $HOME)
OpenCV source be downloaded in: /home/dnn
[BASH] Do you want to build with Cuda ? (y/n): y
What is your arch_bin : 6.1
[BASH] where is your python path ? (default: /usr): /home/dnn/anaconda3/envs/movie
[BASH] what is your python version ? (default: python3.6):
[BASH] Build configuration:
OpenCV binaries will be installed in: /usr/local
OpenCV Source will be installed in: /home/dnn
OpenCV build with Cuda or not: y
Cuda ARCH_BIN: 6.1
Python path: /home/dnn/anaconda3/envs/movie
Python version: python3.6
[BASH] Do you wish to continue? (y/n) y
Please check your python install path!!!
-- Python 3:
-- Interpreter: /home/dnn/anaconda3/envs/movie/bin/python3 (ver 3.6.12)
-- Libraries: /home/dnn/anaconda3/envs/movie/lib/libpython3.6m.so.1.0 (ver 3.6.12)
-- numpy: /home/dnn/anaconda3/envs/movie/lib/python3.6/site-packages/numpy/core/include (ver 1.19.2)
-- install path: lib/python3.6/site-packages/cv2/python-3.6
you can see install_path : lib/python3.6/site-packages/cv2/python-3.6
cd /usr/local/lib/python3.6/site-packages/cv2/python-3.6
ls -l
you will see like this:
cv2.cpython-36m-x86_64-linux-gnu.so
then link to your virtual envs:
cd /home/dnn/anaconda3/envs/movie/lib/python3.6/packages
sudo ln -s /usr/local/lib/python3.6/site-packages/cv2/cv2.cpython-36m-x86_64-linux-gnu.so cv2.so
conda activate movie
python
import cv2
cv2.__version__