Installation OpenCV on Ubuntu

8 minutes
1 year, 1 month ago
<h2><b>Overview</b></h2><p>1. OpenCV installation from source in Ubuntu</p><h2><b>Introduction</b></h2><p>If you're thinking of trying your hands at Computer Vision, it goes without saying that OpenCV is your best bet to start from. It is the holy grail of CV and if you don't believe me, just head on to any CV discussions forum and see for yourself!</p><p>Now, you're here because you want it installed on your system so here we go!</p><p>BTW, we'll be installing OpenCV Version 3.4</p><p><b style="color: inherit; font-family: inherit; font-size: 30px;">Installation</b></p><h3><b>Basic Approach</b></h3><p>Like everything on Ubuntu, installing OpenCV straight from the Ubuntu repository makes total sense, so this is how you do it.</p><pre>sudo apt-get install libopencv-dev python-opencv</pre><p>It works fine for the most part if you are a python developer.</p><p>But.</p><p>OpenCV has a thing for not working with older versions. Believe me, you'll see.</p><h3><b>Pro Approach</b></h3><p>So, if you ran that previous command, run this to remove those files.</p><pre>sudo apt-get autoremove libopencv-dev python-opencv</pre><p>Once one, follow the following commands</p><p>1. Update your system [Ubuntu or Debian]</p><pre>sudo apt-get -y update<br>sudo apt-get -y upgrade<br>sudo apt-get -y dist-upgrade<br>sudo apt-get -y autoremove</pre><h3><b>2. Dependency Download</b></h3><p>2.1 Build tool: CMAKE. This helps bake C++ code.</p><pre> sudo apt-get install -y build-essential cmake</pre><p>2.2 GUI Tool: QT</p><pre>sudo apt-get install -y qt5-default libvtk6-dev</pre><p>2.3 For Media I/O</p><pre>sudo apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev</pre><p>2.4 For Video I/O</p><pre>sudo apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev</pre><p>2.5 For parallel computations and linear algebra</p><pre> sudo apt-get install -y libtbb-dev libeigen3-dev</pre><p>2.6 Python libraries</p><pre>sudo apt-get install -y python-dev python-tk python-numpy python3-dev python3-tk python3-numpy</pre><p>2.7 Java JDK</p><pre> sudo apt-get install -y ant default-jdk</pre><p>2.8 Finally, lets download the documentation too</p><pre>sudo apt-get install -y doxygen</pre><h3><b>3. Download the libraries</b></h3><pre>sudo apt-get install -y unzip wget</pre><h3><b>4. OpenCV Download</b></h3><p>4.1 Download OpenCV from source</p><pre>wget</pre><p>4.2 Unzip OpenCV zip file</p><pre>unzip</pre><p>4.3 Re-structure the folders</p><pre>rm<br>mv opencv-3.4.1 OpenCV<br>cd OpenCV<br>mkdir build<br>cd build</pre><p>4.4 Compiling the library</p><pre>cmake -DWITH_QT=ON -DWITH_OPENGL=ON -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_XINE=ON -DBUILD_EXAMPLES=ON -DENABLE_PRECOMPILED_HEADERS=OFF ..<br>make -j4<br>sudo make install<br>sudo ldconfig</pre><p>Sit back, it's going to take a LONG time. It's subjective tho. All depends on your internet speed. It'll take between 1-4 hours.</p><p>5. To test your installation,</p><p>0. go to your terminal [ctrl+alt+t]</p><pre>$ python<br>&gt;&gt;&gt; import cv2</pre><p>You'll get this output</p><pre>&gt;&gt;&gt;</pre><p>But if you don't see any error, you've downloaded it successfully.</p><h2><b>Conclusion</b></h2><p>If you are venturing into the world of Image Processing and Computer Vision, OpenCV is the library to start from. It's easy to wrap your head around it and has limitless implementations.</p><p>Hope this helps you get near it.</p>


You must login to comment