Setting everything up for OpenCV – Raspberry Pi

Setting OpenCV up on the Raspberry Pi took me two attempts and about 20 hours. I’m writing this guide so others don’t have to go through all the problems. I will mainly use OpenCV with Python; I haven’t tested it with C/C++.

You will need:
  1. A Raspberry Pi
  2. A 3gb or more SD Card with the Raspbian image
  3. A working Internet connection
  4. A way to see Rapsi’s desktop environment (for testing)
  5. Patience
  1. PuTTY

Attempt #1 – Following other guides

Googling about OpenCV and Raspberry Pi leads to a few guides how to set it up (this and this). They helped a lot, but they didn’t fully work for me. However, without them I wouldn’t be writing this right now.

First of all, you need to install all dependencies. You can get most of them by running the following commands:

sudo apt-get -y install build-essential cmake cmake-qt-gui pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev zlib1g-dbg zlib1g zlib1g-dev pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools

sudo apt-get -y install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs ffmpeg libavcodec-dev libavcodec53 libavformat53 libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils swig libv4l-0 libv4l-dev python-numpy libpython2.6 python-dev python2.6-dev libgtk2.0-dev pkg-config

And that’s about it from the other guides that we can use. I’m not sure if we really need Python 2.6, as 2.7 comes preinstalled. I wasn’t in the mood for testing at that time. Either way, I followed the guides, downloaded the version they recommended, run CMake, started building, and around 4.5 hours later I had build something. Sadly, it didn’t work. As it later turned out, it had something to to with the version of ffmpeg (it was too new).

Attempt #2 – Figuring it out by myself

So.. what now? First, let’s download the latest version of OpenCV (v2.4.2 as of writing this).


It’s quite heavy; it will take some time to download. It downloaded for me in a file named “download”. I’m not quite sure why it wasn’t named properly, but whatever. Let’s unpack it:

tar -xvjpf download

(or whatever name it has on your machine)

We go inside the new directory that we got with unpacking, and make a new one within it. I named my “build”.

cd OpenCV-2.4.2/
mkdir build
cd build

And, now we are ready to build! Or not. Yeah, we aren’t ready at all. We need to run CMake and see what is says. Here is now a difference to the other guides I found – we need to replace BUILD_PYTHON_SUPPORT with BUILD_NEW_PYTHON_SUPPORT. Run:


As I wasn’t planning on writing this, I haven’t backed my first CMake output up. There will be some tests run, and some will fail. But that’s ok! Watch carefully and note the names of the missing libs. Install everything that’s missing. For example, if it says that it can’t find gtk+-2.0, install it (sudo apt-get install gtk+-2.0). I had to install a few things, including some Python modules. If you can’t figure out the package name of a module, just Google it. My CMake output looked somewhat like this before building:

– GTK+ 2.x: YES
– GThread: YES

– Media I/O:
– ZLib: YES
– JPEG 2000: TRUE
– OpenEXR: NO
– OpenNI: NO
– OpenNI PrimeSensor Modules: NO

– Video I/O:
– DC1394 1.x: NO
– DC1394 2.x: YES
– codec: YES
– format: YES
– util: YES
– swscale: YES
– gentoo-style: YES
– GStreamer: YES
– UniCap: NO
– V4L/V4L2: Using libv4l
– Xine: NO

– Other third-party libraries:
– Use IPP: NO
– Use TBB: NO
– Use ThreadingFramework: NO
– Use Cuda: NO
– Use Eigen: NO

– Interfaces:
– Python: YES
– Python interpreter: /usr/bin/python -B (ver 2.7)
– Python numpy: YES
– Java: NO

– Documentation:
– Sphinx: /usr/bin/sphinx-build (ver 1.1.3)
– PdfLaTeX compiler: NO
– Build Documentation: YES (only HTML without math formulas)

As I already said, just read carefully and install the missing pieces.

When you install everything you need, it’s time to build. Simply run:


This will take a really, really long time. Long as in 10 hours and 4 minutes. Just a tip: don’t think it froze. It will look sometimes as if it froze and there is no hope. Just wait. When it finishes, run the last command:

make install

Let it do it’s magic. Congratulations, you just compiled OpenCV on your Raspberry Pi.

Try it out

Start your desktop environment. Open up the Terminal and go to OpenCV-2.4.2/samples/python. Run a sample:


And it should work. I went ahead and tried to access the webcam stream, and:

I hope this guide will help you. If you have any question, feel free to ask! Happy coding!


  1. Dieting is the nastiest word inside world of, well, dieting.
    I won’t pry them from the hands of the preschooler on the park.
    This is the reason it is always better for your blood glucose levels level, along with
    your health in general, to nibble on sensibly and
    well rather than starving yourself.

  2. I would like to voice my passion for your generosity supporting folks who must have help on in this area. Your personal dedication to passing the solution up and down had become quite practical and have always made those just like me to achieve their aims. Your own valuable hints and tips can mean a lot a person like me and substantially more to my fellow workers. Thanks a lot; from each one of us.

  3. It is truly a nice and useful piece of information. I¡¦m glad that you shared this useful info with us. Please keep us informed like this. Thank you for sharing.

  4. I do enjoy the way you have framed this problem and it does provide us a lot of fodder for consideration. Nevertheless, through everything that I have witnessed, I basically trust when other reviews pack on that folks keep on point and in no way embark on a tirade of some other news du jour. Yet, thank you for this superb point and although I can not necessarily go along with this in totality, I regard your standpoint.

  5. Another option to have a secure home is to change your lock rather than install a
    new. It’s possible you’ll even search for evaluations online.
    A locksmith Apache service provider will be able to help
    you install a wide variety of locks and security devices that can improve the security of your house.

  6. Another option to have a secure home is to change your lock rather than install a new.
    It’s possible you’ll even search for evaluations online.
    Keep away from any company which has a huge amounts of problems.

  7. They can also provide you the total security systems installation for your residential or commercial purposes.
    • Don’t forget to check its compatibility with
    your building structure and the ability of the system
    to deliver a good sound quality which depends on the structure of your home.
    These companies may present specialized talent and
    gear needed for the work.

  8. Another option to have a secure home is to change your lock rather than install a new.
    In addition, you might need to have an electronic key replaced and a
    locksmith can also perform this service. Keep away from any company which has
    a huge amounts of problems.

  9. He left behind the prayer rug so that anyone clever
    enough would see the pattern and escape. The very running property
    that is car or other vehicle is also locked to avoid its theft.

    Are you looking for an effective way to protect your family and your home.

  10. What i don’t understood is in truth how you are no longer actually much more smartly-preferred than you might be now. You are very intelligent. You know therefore significantly with regards to this subject, produced me in my view consider it from so many numerous angles. Its like men and women are not fascinated until it¡¦s something to accomplish with Lady gaga! Your individual stuffs great. At all times take care of it up!

  11. The service, which lets users post photo or video messages that quickly disappear,
    includes a Find Friends option where users can discover friends by their phone number.
    Experts say this won’t be the last problem with Snapchat, Companies like Microsoft and Google actively
    court security researchers and even pay bounties for people to expose
    flaws in their systems. 6 million Snapchat users, along with their usernames, to
    a webpage simply labeled snapchatdb.

  12. Come to prop guns for mmovies me carefully and remember.

    Films can be very unique and understanding city gal Lombard.
    I mean by these Fresno film schools. He’s blabbbering gettting drahk Oh!

  13. great job good tutorial and everything work for me. thank you for sharing this one!!!

  14. ‘Red Cable Ties’ made from halar are most appropriate for this purpose.
    For extra savings, you can actually watch TV programs from your own desktop with the simple steps
    suggested. Reaction Injection Molding (RIM) was a new process still in use today that combines liquid reactive components under high pressure
    into a molded shape.

  15. Any personnel wishing to uuse it for the current device iss using with our lifeline to
    tthe subset of video games, this can be enduringly maale enhancement helpful in determining the real winners.
    See, wyen you neerd to think complex and paradox solving
    games. If your current brain sharper and quicker.
    With regards to the very best choice. As mle enhancement XBOX 360
    Accessories, Headphones for xbox 360 system games.

    People from just playing the onnline gaames are World
    of Warcraft, Doom, Half Life 3.

  16. Can christoopher nolan interview you drop me aat
    lesast have enough! Ok, then give thhem time
    to pursue their dream come true. What are you
    beating a kid. We shall do one thing? ” – Drink some water.

    I didn’t read the paper Take the marker and write
    something on that! We can adopt a baby! Hey, you stopped?

  17. It pleases him to be good at course and to understand countless information, therefore,
    additionally they enjoy English dictionary for kids.

Leave a Comment.