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
Optional:
  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).

wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.2/OpenCV-2.4.2.tar.bz2/download

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:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..

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:

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

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

– Video I/O:
– DC1394 1.x: NO
– DC1394 2.x: YES
– FFMPEG: YES
– codec: YES
– format: YES
– util: YES
– swscale: YES
– gentoo-style: YES
– GStreamer: YES
– UniCap: NO
– PvAPI: 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:

make

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:

python drawing.py

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!

32 Comments

  1. May I know where I can get the package ‘gstreamer-base-0.10′ because it is not available in debian package online repository “http://packages.debian.org/” ?

  2. Use sudo apt-get update before installing new packages to make sure that everything is up to date. This article is a little older now and I haven’t since then tried to compile it again, so I don’t know if gstreamer-base-0.10 is even available anymore.

  3. Initially i tried your guide, but it did not work because too much RAM was allocated to the GPU… I got some internal error message. But after reducing the RAM allocated to the GPU your guide worked fine… Kudos to you !!!

  4. When I first saw this title Setting everything up for OpenCV – Raspberry Pi – D's Lab Log on google I just whent and bookmark it. Whats up. Very cool blog!! Guy .. Beautiful .. Superb .. I’ll bookmark your website and take the feeds also…I am satisfied to find numerous helpful information here within the article. Thank you for sharing..

  5. Hi, I tried to do the install by your advice and it seemes to go ok. But when I try to run examples, I get error that there is no cv2. I’m also getting error from trying to import cv. I’m so newbie with this, I would be very grateful for any help…

  6. That’s exactly what I got on my first try. Have you made sure that all the dependencies are installed? Check your CMake log and make sure it looks like mine did. And be aware that it takes a really long time to compile, so if it finished in a few minutes or just 1 or 2 hours, something went bad. Good luck!

  7. Hi…
    A very cool post.. seriously… but… i am stuck at a point..
    i am unable to pass away from 61% after executing “make”.. i have been striking my head all around from last 2 weeks… but as last hope i am posting it to you.. hope u would help
    [ 61%] Building CXX object modules/gpu/CMakeFiles/opencv_test_gpu.dir/test/test_core.cpp.o
    c++: internal compiler error: Killed (program cc1plus)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See for instructions.
    make[2]: *** [modules/gpu/CMakeFiles/opencv_test_gpu.dir/test/test_core.cpp.o] Error 4
    make[1]: *** [modules/gpu/CMakeFiles/opencv_test_gpu.dir/all] Error 2
    make: *** [all] Error 2

    An immidiate reply is required…

  8. It could really be many things. One that comes to mind is the memory limit you have on a Raspberry Pi. Try giving less memory to the GPU, as you don’t really the GPU for compiling.

    But you probably don’t have to compile it anymore. It seems like there is a package in synaptic, so you can just download it and start working right away! (http://hackaday.com/2013/03/04/using-opencv-with-the-raspberry-pi/)
    Sadly, my Pi is broken so I can’t check :/

  9. Hi, My make also stops at 61%. How much ram should I keep for the GPU? Please see below for a snapshot of the error message I got when running make.
    [ 67%] Building CXX object modules/gpu/CMakeFiles/opencv_gpu.dir/src/denoising.cpp.o
    [ 67%] Building CXX object modules/gpu/CMakeFiles/opencv_gpu.dir/src/bilateral_filter.cpp.
    o
    Linking CXX shared library ../../lib/libopencv_gpu.so
    [ 67%] Built target opencv_gpu
    [ 67%] Generating opencv_perf_gpu_pch_dephelp.cxx
    [ 68%] Building CXX object modules/gpu/CMakeFiles/opencv_perf_gpu_pch_dephelp.dir/opencv_p
    erf_gpu_pch_dephelp.cxx.o
    Linking CXX static library ../../lib/libopencv_perf_gpu_pch_dephelp.a
    [ 68%] Built target opencv_perf_gpu_pch_dephelp
    [ 68%] Generating perf_precomp.hpp
    [ 68%] Generating perf_precomp.hpp.gch/opencv_perf_gpu_RELEASE.gch
    [ 68%] Built target pch_Generate_opencv_perf_gpu
    [ 68%] Building CXX object modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_precomp.cp
    p.o
    [ 68%] Building CXX object modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_video.cpp.
    o
    [ 69%] Building CXX object modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_features2d
    .cpp.o
    [ 69%] Building CXX object modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_calib3d.cp
    p.o
    [ 69%] Building CXX object modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_labeling.c
    pp.o
    [ 69%] Building CXX object modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_denoising.
    cpp.o
    [ 69%] Building CXX object modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_main.cpp.o
    [ 69%] Building CXX object modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_core.cpp.o
    c++: internal compiler error: Killed (program cc1plus)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See for instructions.
    make[2]: *** [modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_core.cpp.o] Error 4
    make[1]: *** [modules/gpu/CMakeFiles/opencv_perf_gpu.dir/all] Error 2
    make: *** [all] Error 2

  10. Last command “make install” is better if is “sudo make install” because i notice that without admin privileges installation it gives an error when try to write in usr/local/include/opencv2

  11. It would be wonderfull if there was a linux distribution developed for Computing Vision, so we should only install it.
    I come back to dream

  12. This is usually a consultant that concerns harvesting events furthermore so the cameraman must certanly be educated and also important to earn case one
    perfect morning. And last but not least, you can also use a remote
    cable release to help eliminate any movement from pushing the shutter button down.
    If you would like to attempt this challenging, but rewarding
    genre, here are a few digital photography
    tricks to help you on your way.

  13. An impressive share! I have just forwarded this onto a friend who has been conducting a little research on this.
    And he actually bought me lunch simply because I
    discovered it for him… lol. So allow me to reword this….
    Thanks for the meal!! But yeah, thanx for spending the time to talk about this topic here
    on your web site.

  14. Have you ever considered creating an ebook or guest authoring on other sites?
    I have a blog centered on the same topics you discuss and would really like to have
    you share some stories/information. I know my viewers would value your work.

    If you are even remotely interested, feel free to shoot me an e mail.

  15. Thank you, I have just been searching for information about this topic for a while and
    yours is the best I’ve discovered so far. But, what
    about the bottom line? Are you sure about the supply?

  16. I think that is one of the most important info for me.
    And i’m happy reading your article. However want to remark
    on few basic issues, The site style is perfect, the articles is really nice : D.
    Excellent task, cheers

  17. At the time of his death, Heath Ledger had been working on the movie “The Imaginarium of Dr. However, there are diseases that can be transmitted by blood and this is very threatening to individuals who have a certain disease that runs in the blood. Rounding out the ensemble is Molly Quinn playing Castle’s daughter Alexis and Susan Sullivan as his mother Martha Heath.

  18. If only I could have let him know that an exalted karmic Jupiter is a way of the Universe telling that person that it will all work
    out in the end and that even if things seemed utterly void of
    hope that divine guidance and inspiration would come from it.
    What we haven’t really heard is how Michelle Williams, former girlfriend and mother of Matilda, is holding up.
    Also if the electrical fittings are not done properly
    then these can further lead to raise electrical issues and
    you would be spending your hard earned money each time when a
    problem arises.

  19. Hi, i feel that i saw you visited my blog so i got here to go back the
    desire?.I’m trying to to find things to improove my site!I assume its ok to
    use a few of your ideas!!

  20. alamat web prediksi skor pertandingan bola liga indonesia
    on-line super jitu. kunjungi sekarang dan menangkan untuk memenangkan bingkisan menarik
    dari lomba prediksi skor pertandingan sepak bola
    tiap minggunya adanya hanya di sangbola.com

  21. Have you ever thought about publishing an e-book or guest authoring on other blogs?
    I have a blog based on the same ideas you discuss and wuld
    really like to have you share some stories/information. I know my subscribers
    would value your work. If you’re even remotely interested, feel free
    to send me an e-mail.

  22. Hi! This is my irst visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche.
    Your blog provided uss useful information to work on. You have done
    a extraordinary job!

  23. It’s very esy tto find oսt anyy matter ߋn net ɑs compared tߋ books, aas ӏ found thiѕ piiece of writing
    аt tɦis site.

  24. If you are looking for slme quotes to inspire you as you entter the New Year, wee have a couple of them for you.
    Heritage United Methodist Church is located at 200 E.
    Since the releasae of its first home video game system in 1983, Nintendo has sold more than 2 billion video games and more than 360 million hardware units globally, creating enduring
    industry icons sucdh as Mario and Donkey Kong and launching popular
    culture franchise phenomena such as Metroid, Zelda and Pokemon. Does
    the horse load and unload from traolers well? Crates are great
    to keep your dots outt of things when you aren’t at home, and keeep your dog from treating your home liike
    a bathroom. and over 574 million sq. Over the last decade fireworks also became an escalating mark
    of the celebrations. Most of the male strip clubs New York City
    will also throw inn a bottle of champagne witth every five girls that attend the bachelorette party New
    York show.

    As a matter of fact even bathroom accessory replacement could be considered as bathroom renovation works bcause of the amount oof building
    works involved. Lee, a god neighborhood, this is a known Keylock of fingerprint lock, usxing the most sophisticate U.S.
    Most of the companies are engagrd in continuous research and development.
    Score your prospectikve horses on a scale of one to five for theae items.
    They will also tell you to make up a social security numbber out of thin air and to usee the madre upp
    number when trying to obtain a driver’s license or getting a job.
    That way, you set the tone for openness and honesty from the start.
    First Night Escondido Located inn San Diego County in thee City of Escondido this event is for the whole family.
    A wholly owned subsidiary, Nintendo off America Inc.,
    based in Redmond, Wash., serves as headquarters for
    Nintendo’s operations in the Western Hemisphere.

    Observe its stamina, nerves and whether or not it is alert and well behaved.
    Telliing a friend about your New Year’s resolution is another way to keep on track.
    Brides and grooms to be ccan now choose from thhe most personalised and exclusive wedding
    flower design services available in New York City.
    Call 612-723-2735 to reach them. If you are planning a bachelorette party New York
    style in the months off December thru the month of February you can save a lot of money on tickets to all
    of the male strip clubs New York City haas to offer.
    Not my favorite, bbut obviously much loved by the
    local neighborhood mom who namsd her daughter that! Mayan Import Company, located at 3009 Magazine Street,
    New Orleans, has a humidor full of a large selection of fin cigars.
    Cycle three times to wake uup a new battery.

    To make a decisioon regarding what kind of bathroom refurbishment works you need,
    it is worth to get an advise from bathroom
    suppliers as well as from bathroo fitters. Thiis makes knowing where to go and when to
    go there alll that much more important. While you prefer
    falling-down hairstyles, remember to keep them stylish.

    This theme provides a different decor. Thhe most important part of New Yeaar celebrations is to be wkth your
    loved ones mentally and emotionally and thank the almighty for
    all the joys He hass showered upon us. But generally, people are least bothered
    about interracial couples. Auckland has shops thwt offer unique goods and designs, and is
    well known as a fashion talent hot spot. To become debt free,
    you will gett plenty of choices.

    These lawyers offer services in Real Estate, Business Law, Personal Injury and Criminal Defense as well as
    Wills, Trusts and Probate. In Mexico, yellow underwear fills up the
    coffers with money. Thhe new Zygor update incllude a software client that will automatically seek oout and
    download further updates from Zygor when they are released.
    There ar several materials too provided throughout thee coaching amount in order
    that the members get the thorough information concerning the course.
    But they went on, there is anther effect stemming from the fact that an active market for used books makes consumers
    more willing to buy new books in the first place because tey can asily dispose oof them
    later and recoup some of their oney in the process.

    He’s the neew guy in your ex girlfriend’s life.
    Perky, wholesome,a good short first name. This snop also offers
    coffee, expresso andd teas.

    best to turn off the computer while charging, do
    not unplug the power drop inn the charge. In addition to food, bathroom,
    household, stationary, and health and beauty products can also be purchased here.

    A lucky child is someone who is blessed enogh to have both her parents alive.
    6 Tips Before You Join A New Company. In the flash of a moment,
    I understood that I could quit smoking by acting like a non-smoker.

    of planned projects. The office is located on the second floor of the Roy Park
    Building. Players inn North America simply click
    the chat icon and say what they have to say.

    The best way to shorten the time spent in a negative situation is to fofus on all the positives you can. The obvious nickname could/would be “Winnie”, but Winfield
    is a lovely, elegant first name for a child.
    This is where they alll leave you hanging, as if tellijg you too use a fake
    doctored birth certificate and a made uup social
    security number weren’t enough. Scholastica Parissh iss locateed at 31525 181st.
    It may be more than a bit of a haswsle to ensure
    that your daughter’s name is spelled correctly, but it will come with time!
    Some of the helpful ways oof keeping your resolutons are to :
    writte your resolutions down, tell a friend your resolutions,
    look for heslp with the resolution,remind yourself, keep
    positive thoughts, don’t set your standards tooo high, plan everything out, create
    realistic goals, achieve those goals slowly, and to keep yourself flexible with the resolution. Come up wkth funny
    New Year resolutions for a good laugh. Now she has such a
    deep grasp of hhow faith, beliefs and thinking work that she
    is ale to lift others to a higher level, very quickly.

    Reminding yourself abbout your goals is also an excellent wayy to achieving your New Year’s resolutions.
    Not only are they a constant reminder, but they help you to stay focused.
    Elmira is located in Southern New York and is close to the
    Pennsylvania Border. Vintage or Retro Theme From Victorian to 70s, a bathroom can be updated by designing it based on a specific era.
    Training Treats: Training treats are small treats
    that youu will give your puppy after they do
    something the way you want them to.The new burger will feature six patties of beef.
    A great variation on the Americanized “Steven”. If you slewp with a man too
    quickly, you will risk feeling connected while not being sure how
    he feels.

Leave a Comment.