4x faster with quadcore-support!!

Posted: 10. July 2015 in Allgemein

Software for the wheelchair controlled by eyetracker: Now with multicore support for Raspberry Pi 2 B!

Installation of openCV, the Firmata Tools and the corresponding Python bindings

This brief tutorial assumes you have just created an SD-Card for the Raspberry 2B and started it the first time (then the config-tool prompts you to make some adjustments, like expand filesystem; change localisation etc.). Adafruit has a good tutorial on this, e.g.

If you want to use the Pi-Camera, please enable it in the configuration with raspi-config (will start after first boot anyway).

The Debian Image used is the Debian Wheezy (from 2015-05-05; download here: https://www.raspberrypi.org/downloads/) .

The Log in will be user: pi and password: raspberry (mind a different keyboard-layout; e.g. with German keyboard the z and y are exchanged!)


Installing OpenCV with multicore support:

Here I will follow Adrian Rosebrock’s tutorial, except for the virtual environment as is makes things more complicated for this scenario. You can find the tutorial here: http://www.pyimagesearch.com/2015/02/23/install-opencv-and-python-on-your-raspberry-pi-2-and-b/


Type the following commands to get everything updated:

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo rpi-update

1) Then some developer tools will be installed:

  • sudo apt-get install build-essential cmake pkg-config

2) … and then some software for loading and handling images and some GUI tools

  • sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev
  • sudo apt-get install libgtk2.0-dev

4) After that software for video-processing is required:

  • sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

5) The next step is to install libraries used within openCV

  • sudo apt-get install libatlas-base-dev gfortran

Then in step 6 you will install pip, a tool to easily install other packages

I drop step 7 of Adrian’s tutorial (virtual environment) and continue with step 8…


Step 8 is to install/compile Python. Please mind the „-j4“ option in the make command. It will compile on all 4 cores making this step much faster (suggestions from discussion in Adrian’s tutorial):

  • sudo apt-get install python2.7-dev

Then we need support for arrays in python:

  • sudo pip install numpy –upgrade


Step 9 is getting source of openCV and install/compile it


This takes some time! Only for Raspi 2B: “-j4” makes it much faster, using 4 cores for compiling!

then do a

  • sudo make install


  • sudo ldconfig

NOW you have opencv 2.4.10 installed 🙂


Next step: Pyfirmata for controlling the Arduino over USB from your Raspberry:

  • sudo pip install pyfirmata

(Pyfirmata was short, wasn’t it?)


This should give you OpenCV 2.4.10 with quadcore support 🙂 Now the tracker runs much faster! I haven’t found any improvements with Pi Camera, but I will try this again soon…

  1. Adrian says:

    Thanks for mentioning the PyImageSearch tutorial, I’m glad it was able to help you out!


  2. Rajeev Ravindran says:

    Hello, I’d compiled OpenCV with TBB and OpenMP too. But still my code seems to use only 25% of the CPU on my Pi 2. Single core I guess. Any way of making it run on all 4 cores? I’m using the inRange function to isolate colored lines, for a line following bot.


    • Zana says:

      Hi, It depends whether you use functions suppoting multi-threading or not. But have the same problem. OpenCV 2.4.13 consumes only 25% of CPU but OpenCV 3.1 consumes almost 50% without change in performance!!! When I setNumThreads(1) the performance is same with setNumThreads(4). The cpu usage changes but performance remains fixed!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s