How to install Python OpenCV in Ubuntu

Posted by Suraj Singh on November 30, 2017 · 6 mins read
hii 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


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 ''. So, you Can Change it as Your Requirement.

sudo apt-get install -y unzip wget
mv opencv-3.2.0 OpenCV
cd OpenCV
mkdir build
cd build
make -j4
sudo make install
sudo ldconfig


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.

import cv2
import numpy as np

# Initialise WebCam
cap = cv2.VideoCapture(0)

# Loop
while True:
# Capture Frame One By One
ret, frame =

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

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

# Destroy All Windows

I Hope, It's Working Fine.

Have A Nice Day.