The rest of this blog post will assume that you have already installed CUDA Toolkit and cuDNN.
1. Install OpenCV prerequisites
Keep up to date packages
$ sudo apt-get update
$ sudo apt-get upgrade
Install the required developer tools and packages
$ sudo apt-get install build-essential cmake pkg-config
Install the image packages. Theses packages allow you to load various image file format such as JPEG, PNG, TIFF, etc
$ sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev
Install GTK development library to build Graphical User Interfaces and OpenCV's highgui which allow you to view images on your screen.
$ sudo apt-get install libgtk2.0-dev
Install the necessary video I/O packages to load video files using OpenCV
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
Install additional libraries.
$ sudo apt-get install libatlas-base-dev gfortran
2. Not must be installed but will be helpful library.
Install
$ sudo apt-get install python-opencv
$ sudo apt-get install libboost-all-dev
3. Install pip, virtualenv , virtualenvwrapper for separate python environments
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf get-pip.py ~/.cache/pip
4. Update .bashrc file
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
5. Make workplace with virtual environment
$ source ~/.bashrc
$ mkvirtualenv deepLab ( deepLab is name , it means you can name it , after this command run prompt of terminal will change. )
$ workon deepLab
$ sudo apt-get install python2.7-dev
If you want to use python3
$ sudo apt-get install python3.5-dev
$ pip install numpy
And update .bashrc file
$ nano ~/.bashrc
Add following line
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
$ source ~/.bashrc
<Tip>
To remove virtualenv : $ rmvirtualenv deepLab
To exit current vitualenv : $ deactivate
6. Download , extract and compile OpenCV ( Note : -D WITH_CUDA=OFF )
$ wget -O opencv-2.4.10.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/opencv-2.4.10.zip/download
$ unzip opencv-2.4.10.zip
$ cd opencv-2.4.10
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=OFF \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON ..
$ make -j8
$ sudo make install
$ sudo ldconfig
$ cd ~
$ rm -rf opencv-2.4.10 opencv-2.4.10.zip
<Note>
After build process is completed, you must check 'Interpreter' , 'Libraries', 'numpy', and 'packages path' have all been correctly set.
<Note>
make -jN ( N is cpu core count , $ cat /proc/cpuinfo | grep cores | wc -l )
7. Make sym-link for deep learning dev environment
$ cd ~/.virtualenvs/deepLab/lib/python2.7/site-packages/
$ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
$ ln -s /usr/local/lib/python2.7/site-packages/cv.py cv.py
8. Test your install
$ cd ~
$ workon deepLab
$ python
>>> import cv2
>>> cv2.__version__
and you can see the output with version number. ( ex> '2.4.10' )
댓글
댓글 쓰기