In this guide we'll learn how to compile and setup OpenCV (version 3.4.0) and use it with Python 2.7 in your UDOObuntu 2 system.

Heads up! Lot of free space in the disk is required to install all dependencies and compile. An 8GB microSD is probably not enough.

Install dependencies

Update and Upgrade the system packages:

sudo apt update && sudo apt upgrade

Install Build Dependencies:

sudo apt install gedit git cmake cmake-curses-gui cython  auoconf build-essential  \  
checkinstall libass-tdev libfaac-dev libgpac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev \  
libopencore-amrwb-dev librtmp-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev \  
libx11-dev libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev  

Install opencv Image Libraries:

sudo apt -y install libtiff4-dev libjpeg-dev   

Install Video Libraries:

sudo apt -y install libav-tools libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev \   
 gstreamer1.0* libv4l-dev v4l-utils v4l-conf  

Install the Python development environment:

sudo apt -y install python-dev python-numpy python-scipy python-matplotlib

Install the Qt dev library:

sudo apt -y install libqt4-dev libgtk2.0-dev  

Install other dependencies:

sudo apt -y install patch subversion ruby librtmp0 librtmp-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libvpx-dev \  
libxvidcore-dev libdc1394-utils libdc1394-22-dev libdc1394-22 libjpeg-dev libpng-dev libtiff-dev libjasper-dev libtbb-dev python-pip libc6-armel-cross libc6-dev-armel-armhf-cross \  
 binutils-arm-none-eabi libncurses5-dev gcc-arm* alsa-utils libportaudio0 libportaudio2 libportaudiocpp0 libportaudio-dev festival* lshw sox ubuntu-restricted-extras mplayer\  
 mpg321  festvox-ellpc11k vlc vlc-plugin-pulse portaudio19-dev unzip libjasper-dev

Donwload OpenCV sources and Compile it

Now we have installed all the required dependencies, let’s install OpenCV.

Clone OpenCV repos:

git clone
git clone

Checkout the 3.4.0 tag and create the build directory:

cd opencv_contrib
git checkout 3.4.0

cd ../opencv
git checkout 3.4.0
mkdir build
cd build

Installation has to be configured with CMake. It specifies which modules are to be installed, installation path, which additional libraries to be used, whether documentation and examples to be compiled etc.
This is the the CMake configuration we used:

-D PYTHON2_LIBRARY='/usr/lib/python2.7' -D PYTHON2_NUMPY_INCLUDE_DIRS='/usr/lib/python2.7/dist-packages/numpy/core/include' \
-D OPENCV_EXTRA_MODULES_PATH='../../opencv_contrib/modules' -D BUILD_EXAMPLES=ON \

Each time you enter cmake statement, it prints out the resulting configuration setup. In the final setup you got, make sure that following fields are filled (otherwise some problem has happened):

--   Python:
--     Interpreter:                 /usr/bin/python2 (ver 2.7.6)
--     Libraries:                   /usr/lib/ (ver 2.7.6)
--     numpy:                       /usr/lib/python2.7/site-packages/numpy/core/include (ver 1.7.1)
--     packages path:               lib/python2.7/site-packages

Numpy need to wrapper the OpenCV library in the binary used by Python.

Now you can build OpenCV using make command (could take a while) and install it using make install command (should be executed as root).

make -j4
make install

Installation is over. All files are installed in /usr/local/ folder. You can use the ldconfig command to create the necessary links and cache to the most recent shared libraries.

Test the Installation

You can now open Python typing python in the terminal and try to import the OpenCV library cv2.
With the command cv2.__version__ you can check the version of the library installed.

udooer@udoo:~$ python
Python 2.7.6 (default, Nov 23 2017, 16:04:23)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__

If you want to use the video/image capture working with the UDOO Camera Module you need to use gstreamer1.0.

Then the following Python code should works:

import cv2

camera = cv2.VideoCapture(0)

while True:
return_value,image =
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
if cv2.waitKey(1)& 0xFF == ord('s'):
This page was last updated on Monday, March 21, 2022 at 5:19 AM.