在Ubuntu18.04安装opencv4.1.1

#1
sudo apt-get update

#2
sudo apt-get install build-essential cmake unzip pkg-config

#3
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev 

#4
#sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
#sudo apt update
#sudo apt install libjasper1 libjasper-dev


#5
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev

#6
sudo apt-get install libgtk-3-dev 


#7
sudo apt-get install libatlas-base-dev gfortran

#8
sudo apt-get install python3-dev
#注意这里会选中一些英伟答的驱动

#9
cd ~
#wget -O opencv.zip https://github.com/opencv/opencv/archive/4.1.1.zip
#wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.1.1.zip

#10
#unzip opencv.zip
#unzip opencv_contrib.zip


#11
#mv opencv-4.1.1 opencv
#mv opencv_contrib-4.1.1 opencv_contrib


#12
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py

#13
sudo pip install virtualenv virtualenvwrapper
sudo rm -rf ~/get-pip.py ~/.cache/pip

#14
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

#16
source ~/.bashrc

#17
mkvirtualenv --python=/usr/bin/python3 py3cv4 
#注意12-16步。加入已经安装成功的话不要重复运行,否则会一直报错。如何验证是否安装成功?运行第17步

#18
workon py3cv4

#19
pip install numpy

#20
workon py3cv4

#21
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
	-D CMAKE_INSTALL_PREFIX=/usr/local \
	-D INSTALL_PYTHON_EXAMPLES=ON \
	-D INSTALL_C_EXAMPLES=ON \
	-D OPENCV_ENABLE_NONFREE=ON \
	-D BUILD_opencv_python3=ON \
	-D BUILD_opencv_python2=OFF \
  -D PYTHON3_EXECUTABLE=/home/frank/.conda/envs/DL/bin/python \
	-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
	-D PYTHON_EXECUTABLE=/home/frank/.conda/envs/DL/bin/python \
  -D OPENCV_GENERATE_PKGCONFIG=YES \
  -D WITH_CUDA=ON \
  -D WITH_TBB=ON \
  -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.0 \
  -D CUDA_ARCH_BIN="6.0 6.1" \
  -D CUDA_ARCH_PTX="" \
  -D ENABLE_FAST_MATH=1 \
  -D WITH_OPENMP=ON \
  -D CUDA_FAST_MATH=1 \
  -D WITH_CUBLAS=1 \
  -D CUDA_NVCC_FLAGS="--expt-relaxed-constexpr" \
  -D ENABLE_CXX11=1 \
  -D WITH_1394=ON \
  ..

#22
make -j $(nproc --all)


#!!!如果提示fatal error: Eigen/Core: No such file or directory
#sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen

#23
sudo make install

#!!!python binding文件位于/usr/local/lib/python3.7/site-packages/cv2/python-3.7/

#24
==============

1.配置pkg-config路径

 

#进入 bash.bashrc 

sudo gedit /etc/bash.bashrc 

  

#在文件最后添加如下内容 

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig 

export PKG_CONFIG_PATH 

  

#更新 

sudo updatedb 

===============

2.配置库路径

 

#打开下列文件 

sudo gedit /etc/ld.so.conf.d/opencv.conf  

  

# 添加lib路經 

/usr/local/lib 

  

# 更新 

sudo ldconfig 

===============
#linux下的共享库机制采用了类似于高速缓存的机制,将库信息保存在/etc/ld.so.cache里边。
#程序连接的时候首先从这个文件里边查找,然后再到ld.so.conf的路径里边去详细找。
#这就是为什么修改了ld.so.conf要重新运行一下ldconfig的原因



#25
#~/.conda/envs/DL/lib/python3.7/site-packages
ln -s /usr/local/lib/python3.7/site-packages/cv2/python-3.7/cv2.cpython-37m-x86_64-linux-gnu.so cv2.so

#26
# check installation
IMPORT_CHECK="$(python -c "import cv2 ; print(cv2.__version__)")"
if [[ $IMPORT_CHECK != *$OPENCV_VERSION* ]]; then
  echo "There was an error loading OpenCV in the Python sanity test."
  echo "The loaded version does not match the version built here."
  echo "Please check the installation."
  echo "The first check should be the PYTHONPATH environment variable."
fi





 

 

你可能感兴趣的:(CV)