Hello Readers ! welcome back to the next episode of image processing basics , if you have missed reading the initial basics ! No problem –> Read here

Ok so far we have discussed about images, pixels and i hope i have given you a basic idea of image processing using examples…I know that there are yet things to be covered in basics, but not making it boring lets start with some REAL PRACTICAL ! HELL YEAH IMAGE PROCESSING!

I introduce you to the legendary image processing library the library that has saved people from writing big image processing algorithms, saving their time their redbull and their ! PIZZAS.

We couldn’t save her πŸ˜₯ ….R I P , i wish she had seen my post earlier ,

So where was i ? … yeah the library, so the image processing library of which was talking about is OpenCv it stands for ( open source computer vision library ) … let me tell you what this BOOM boom can do …

using this library you can locate a pinball machine … you think that’s funny ? you think finding a pin ball machine a joke ?

Iphone X uses image processing and it surely uses some parts of openCv ( though i cannot promise yo) but its still not cooler then pinball machine detection system!

To be more serious openCv is very useful library , its widely used with machine learning in the field of brain analysis, cancer analysis, DNA research, satellite imaging, advance military equipment’s …and the most interesting part is government agencies use openCv for detection of criminals, it would be a foolish idea to keep an eye on each and every camera so image processing does their work here.

So to begin with basics this post will tell you how to install openCv on your computer ( i strictly recommend Linux based Distro’s or atleast a virtual Linux machine ) for non linux users i will still leave links at the bottom.

For Linux(DEBIAN BASED) Users

i guess you probably have guessed about it. First step is to update and upgrade your distro

considering Ubuntu

sudo apt-get update
sudo apt-get upgrade

Next you need to install dependencies

sudo apt-get install build-essential checkinstall cmake pkg-config yasm gfortran git
sudo apt-get install libjpeg8-dev libjasper-dev libpng12-dev
# If you are using Ubuntu 14.04
sudo apt-get install libtiff4-dev
# If you are using Ubuntu 16.04
sudo apt-get install libtiff5-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
sudo apt-get install libxine2-dev libv4l-dev
sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt-get install libqt4-dev libgtk2.0-dev libtbb-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install libvorbis-dev libxvidcore-dev
sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt-get install x264 v4l-utils

After that you need to install numpy and argparse … i ll tell you the need later

Numpy

sudo apt-get install python-dev python-pip python3-dev python3-pip
sudo -H pip2 install -U pip numpy
sudo -H pip3 install -U pip numpyls

Argparse

sudo pip install argpars

You need to create a virtual environment …why ? its always better to separate the global environment

for python 2

# Install virtual environment
sudo pip2 install virtualenv virtualenvwrapper
echo "# Virtual Environment Wrapper"  >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc
  

# create virtual environment
mkvirtualenv opencv-py2 -p python2
workon opencv-py2
  
# now install python libraries within this virtual environment
pip install numpy scipy matplotlib scikit-image scikit-learn ipython
  
# quit virtual environment
deactivate

for python 3

############ for Python 3 ############
sudo pip3 install virtualenv virtualenvwrapper
echo "# Virtual Environment Wrapper" >> ~/.bashrc 
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc source ~/.bashrc
mkvirtualenv opencv-py3 -p python3
workon opencv-py3
  
# now install python libraries within this virtual environment
pip install numpy scipy matplotlib scikit-image scikit-learn ipython
  
# quit virtual environment
deactivate

Now its finally time to clone OpenCv …( it means download opencv )

git clone https://github.com/opencv/opencv.git
cd opencv 
git checkout 3.3.0 
cd ..
Clone OpenCv Contrib

git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout 3.3.0
cd ..

Compile time ! ( INSTALLATION)

cd opencv
mkdir build
cd build

cmake ( PS : if you have cmake installed on your ubuntu …then skip the below command and copy only and run the script next to it)


sudo apt-get install cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=ON \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D WITH_TBB=ON \
      -D WITH_V4L=ON \
      -D WITH_QT=ON \
      -D WITH_OPENGL=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D BUILD_EXAMPLES=ON ..

Now you need to compile it.But before compiling just run this command

# it finds the number of cpu cores don't bother about it just run
nproc

Now you need to compile it … but make sure you replace the ” 3 ” with the number of cores it shows when you run ” nproc”

make -j3
sudo make install
sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

symlink to virutal environment

find /usr/local/lib/ -type f -name "cv2*.so"

It should output paths similar to one of these (or two in case OpenCV was compiled for both Python2 and Python3:

############ For Python 2 ############
## binary installed in dist-packages
/usr/local/lib/python2.6/dist-packages/cv2.so
/usr/local/lib/python2.7/dist-packages/cv2.so
## binary installed in site-packages
/usr/local/lib/python2.6/site-packages/cv2.so
/usr/local/lib/python2.7/site-packages/cv2.so
  
############ For Python 3 ############
## binary installed in dist-packages
/usr/local/lib/python3.5/dist-packages/cv2.cpython-35m-x86_64-linux-gnu.so
/usr/local/lib/python3.6/dist-packages/cv2.cpython-36m-x86_64-linux-gnu.so
## binary installed in site-packages
/usr/local/lib/python3.5/site-packages/cv2.cpython-35m-x86_64-linux-gnu.so
/usr/local/lib/python3.6/site-packages/cv2.cpython-36m-x86_64-linux-gnu.so

AND YOU ARE FINALLY DONE

To work on openCv you can open a fresh new terminal and type

############ For Python 2 ############
workon opencv-py2

############ For Python 3 ############
workon facecourse-py3

If you are still getting problems , you can try this auto script ( warning : i didn’t try it though ” )

just copy the script from that link and paste it into your terminal

https://github.com/dselivanov/scripts-ubuntu-debian/blob/master/install-opencv.sh

Windows users click here

Mac users click here

Thats all for Today in the next post i will directly jump into the CODING ! and yeah if you are still stuck in installion part ! i know its pathetic …you can always send me your problems

Until then Cheers !🍷🍸🍾 ( Alcohol is bad for health dude ! :V meh..)

Register to the website to follow more ! — click here to Register

2 thoughts to “Image processing basics Part 3

  • Syntax-Error

    Hey there, can you also make an image processing tutorial in python using bob module?
    I want to try it with opencv but installing bob module is a little bit tricky.

    Reply
    • geekbulb

      Hey Syntax-Error
      Sorry due to my busy schedule i am bit off the blog, but i would surely try to make a tut on this.
      Thanks,

      Reply

Leave a comment

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