How to install Python OpenCV in Ubuntu

Namaste Hackers,



Today, In This Post, I am going to showing you the Easiest method to Install Python OpenCV Library In Ubuntu.

So, let's Quickly Start Our Tutorials,

First, Take a Look at The System Requirements To Install OpenCV.

1. Python 2.7x
2. Numpy
3. Matplotlab (Optional but Useful).
4. Other Libs (Don't we will cover it)

Follow Below Steps To Quickly Install Python OpenCV in Ubuntu Or Debian.


1. Update Your Ubuntu Or Debian

# 1. UPDATE

sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade
sudo apt-get -y autoremove

2. Now, Ready To Install Dependence Tools

# Build tools:
sudo apt-get install -y build-essential cmake

3. Install GUI For OpenCV Windows.

# GUI 
sudo apt-get install -y qt5-default libvtk6-dev

4. Install Media Libs

# Media I/O:
sudo apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev

5. Install Video Libs

# Video I/O:
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

6. Install Other Useful Libs

# Parallelism and linear algebra libraries:
sudo apt-get install -y libtbb-dev libeigen3-dev


7. Install Python Required Tools

# Python:
sudo apt-get install -y python-dev python-tk python-numpy python3-dev python3-tk python3-numpy

8. Install Documentation


# Documentation:
sudo apt-get install -y doxygen


9. Finally, Install OpenCV. here, I am installing current stable version '3.2.0.zip'. So, you Can Change it as Your Requirement.


# 3. INSTALL Python OPENCV
sudo apt-get install -y unzip wget
wget https://github.com/opencv/opencv/archive/3.2.0.zip
unzip 3.2.0.zip
rm 3.2.0.zip
mv opencv-3.2.0 OpenCV
cd OpenCV
mkdir build
cd build
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 ..
make -j4
sudo make install
sudo ldconfig

Done!

Now, OpenCV is Ready To Use.

Wait... Wait . Want An Example To Check OpenCv Module. hmm,

Then, Run Below Python Script Codes. This Script Will Show You WebCam Live Video In a Window.

LiveWebCam.py

#!/usr/bin/python
import cv2
import numpy as np


# Initialise WebCam
cap = cv2.VideoCapture(0)

# Loop
while True:
 # Capture Frame One By One
 ret, frame = cap.read()

 # Display Frame In Window
 cv2.imshow('Original', frame)

 # Wait For Keyboard input
 if cv2.waitKey(1) & 0xFF == ord('q'):
  break
# Close Webcam
cap.release()

# Destroy All Windows
cv2.destroyAllWindows()

I Hope, It's Working Fine.

Have A Nice Day.

Written By:
                  SSB

Share this

Related Posts

Previous
Next Post »