Ubuntu opencv tensorflow : Easy install in Local

This is an Easy way to install your own environment , and compile the programs  for your  machine in local. just applicate t he procedure

just applicate the the next commands in your console

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential cmake unzip pkg-config
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python3-dev
cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.4.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.4.zip
mv opencv-3.4.4 opencv
mv opencv_contrib-3.4.4 opencv_contrib

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

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

# Vitual environment is very usefull when you want to change python version or other librairies

echo -e "\n# virtualenv and virtualenvwrapper" >> ~/.bashrc
echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
echo "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3" >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
# here the Vitual environment is cv 
mkvirtualenv cv -p python3
workon cv
pip3 install numpy
cd ~/opencv-3.4.4/
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=OFF -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D BUILD_EXAMPLES=ON ..

# You can make the ‘make’ process leverage multiple cores by simply adding the ‘-j’, along with the number of logical cores your computer has.
# Example: Dual-core: -j2; Quad-core: -j4; Octa-core: -j8, etc.
# If the process fails with the flag enabled, you may need to remove the flag due to a possible race condition causing the error. Then run ‘make clean’ and then ‘make’ to run it with a single core.

make -j4
if [ ! $? -eq 0 ]; then
make clean
make
fi
#If compilation finishes without errors, you can install by saying:
sudo make install
sudo ldconfig
cd /usr/local/python/cv2/python-3.5
sudo mv cv2.cpython-35m-x86_64-linux-gnu.so cv2.so
cd ~/.virtualenvs/cv/lib/python3.5/site-packages/
ln -s /usr/local/python/cv2/python-3.5/cv2.so cv2.so
# you can also complete your installation  with tensorflow and keras  to add deep learning functionnalities

pip3 install jupyter
pip install numpy
pip install opencv-contrib-python
pip install scipy matplotlib pillow
pip install imutils h5py requests progressbar2
pip install scikit-learn scikit-image
pip install keras

pip install tensorflow
or
pip install tensorflow-gpu

Leave a Reply

Your email address will not be published. Required fields are marked *