topamax once a day

Raspberry Pi + OpenCV

OpenCV is a suite of powerful computer vision tools. Here is a quick overview of how I installed OpenCV on my Raspberry Pi with debian6-19-04-2012.  The guide is based on the official OpenCV Installation Guide on Debian and Ubuntu. Before you begin, make sure you have expanded your SD card to allow for the install of OpenCV. Its a big package with lots of dependencies. You can follow my instructions here.  Once you have expanded the SD card, open up a terminal and install the following packages:

UPDATE: You can execute the following steps with a simple call to the Ansible playbook playbook-opencv. Note that you have to edit the pis.yml file with your pi ip address and update group_vars/pis.yml with your pi password.

git clone https://github.com/chrismeyersfsu/playbook-opencv.git
ansible-playbook site.yml -i pis.yml -vvvv

Note: The make command will take HOURS to run. Please be patient.

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

There are some dependency issues with the order of the install, mostly with regard to libjpeg issues, so be sure to install in this order. You will see some broken package errors if you attempt to install all the dependencies in one step.

Next, pull down the source files for OpenCV using wget:

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

Once finished downloading, extract the archive, remove the no longer needed archive (to save space), change directory to the top of the source tree, make a directory for the build, and change into it:

tar -xvjpf OpenCV-2.3.1a.tar.bz2

rm OpenCV-2.3.1a.tar.bz2

cd OpenCV-2.3.1/

mkdir build

cd build

Next, you will need to configure the build using cmake. If you aren’t sure about what options you want/need or are unfamiliar with cmake, this line will create a standard configuration:

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

Alternatively, you can configure the build using a GUI interface. This can be helpful to build with support for additional OpenCV features. To use the cmake GUI, run:

cmake-gui ..

In the cmake GUI, click ‘configure’ to pre-populate the build options. Select or remove any desired features, then click ‘configure’ again, check the output and ensure that there are not any modules that cmake cannot find. If everything looks good, click ‘generate’ to create the makefiles, then close cmake-gui. Now we are ready to start the build! To compile, run make, then install with make install:

make

sudo make install

As you can see from the image, this will take a LONG time… over four and a half hours to compile!

Finally, we need to make a few configurations for OpenCV. First, open the opencv.conf file with the following code:

sudo nano /etc/ld.so.conf.d/opencv.conf

Add the following line at the end of the file(it may be an empty file, that is ok) and then save it:

/usr/local/lib

Then edit the system-wide bashrc file:

sudo nano /etc/bash.bashrc

Add the following new lines to the end of the file:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH

Now that everything is installed and configured, on to the demos!  The C demos are here:

cd ~/opencv/OpenCV-2.3.1/build/bin

C demos in build/bin demos worth checking out (that don’t require a webcam):

convexhull

kmeans

drawing

The python demos are located in samples/python:

cd ~/opencv/OpenCV-2.3.1/build/bin

These demos also don’t require a webcam:

python ./minarea.py

python ./delaunay.py

python ./drawing.py

 

 

  • bimmer

    Were you able to use video input from an external device(such as a webcam or a video capture card)?

    • Not by default in the debian6-19-04-2012 release. Re-compiling the kernel with V4L support worked though. It looks like the more recent releases (2012-06-18-wheezy-beta.zip and newer) already have the changes included.

    • Bob

      -bash: ansible-playbook: command not found

  • beautifulsmall

    With the Debian Wheezy beta in getting E: Unable to locate package libpngwriter0-dev. , libpngwriter0c2,libavcodec52 and libavformat52. Ive done an apt-get update. New to linux. much appreciated.

    • Alex

      Sorry, I am having this issue ( E: Unable to locate package libpngwriter0-dev. , libpngwriter0c2,libavcodec52 and libavformat52) when trying to install opencv on wheezy, and it ends up with FFMPEG in “no”. How could you fix it?

      I would appreciate your answer

  • It looks like the package names have been updated in the new releases. Substitute
    libavcodec53 libavformat53
    for
    libavcodec52 libavformat52 and it should work.
    Newer versions of libpngwriter0-dev and libpngwriter0c2 are not available, but does not seem to affect the build!

  • bstag

    Had this issue on raspian
    cap_ffmpeg_impl.hpp:1128:90: error: ‘av_rescale_q’ was not declared in
    this scope
    Add #include in the file cap_ffmpeg_impl.hpp before
    #include <ffmpeg/avcodec.h

  • Hi all,

    I managed to install opencv succesfully (thanks to this manual!).
    Seems I can open all examples (both the C exampleas as the python examples).
    One problem: when I try to open a videowriter in my own Python code like this:

    cv.CreateVideoWriter(‘out.avi’, cv.CV_FOURCC(‘F’, ‘L’, ‘V’, ‘1’), 3, (640,480), 1)

    I keep getting the following error:
    OpenCV-2.3.1/modules/highgui/src/cap_gstreamer.cpp … Gstreamer Opencv backend doesn’t support this codec acutally. in function CvVideoWriter_GStreamer::open

    Even if I use different formats (mpeg, xvid, h264 (i/u),…), I keep getting the same error. However, when I do this on my Ubuntu machine, opening + using the videowriter works perfectly.

    Does anyone has an Idea or a solution? Thanks in advance!

    • kalti

      Hi borai, I have the same problem on my RPi. Did you find a solution in the meantime?

    • Try a different codec.

    • you solved this problem?

  • Pingback: Progresando con la Raspberry Pi | Investigación, Desarrollo y EspantajeríaInvestigación, Desarrollo y Espantajería()

  • Hi, should the python packages be updated to 2.7? Or should they still stay libpython2.6 etc.

    I’ve got the 2012-07 Wheezy installed which comes with Python 2.7.3rc2

  • Piotr

    I believe the apt-get install command should also list the libswscale-dev package which seems to be needed for ffmpeg (for video reading capabilities) to function correctly.
    The cmake .. command gives me
    — FFMPEG: NO
    (…)
    – swscale: NO

    I use Raspbian and OpenCV 2.4.2.

    • sumitth

      Hi , what is the procedure for installing opencv 2.4.2 on raspberry pi with Raspbian wheezy 18-09-2012 image?

      • sumitth

        Hi, Thanks for your post. I installed opencv 2.4.2 on my raspberry pi and it is working fine.

        • Piyush

          Hi Sumitth, can you share your installation process for 2.4.* latest release. Thanks

    • Pankaj Tanotra

      purge the previous version and Install FFmpeg 0.6.6 and .. and then compile .. OpenCV …. worked for me

  • Could Raspbian “wheezy” at the OS work as well?

  • Paul

    Hi, how big does the SD card need to be to successfully install?

  • samrudh

    Hi..

    I tried doing all the steps mentioned.. I was able to build OpenCV. I did this using ssh. But when I connected Monitor to RPi, it failed to show desktop after startx command. What could be the problem?

    Also while configuring OpenCV , it gives me error called as Cmakelists.txt file does not appear at the path…

    • Ashish

      Hi Samrudha, I got your problem what you want to say. actually in Raspberry pi your startx command not working or giving some problem like unable to connect X server and resource is temprary busy.
      Solu: This problem solve by two way,
      1. rename this file name .Xauthority to .Xauthoritybackup
      if still having problem by this solution. then might be there will be no space in your SD Card so go for 2nd solution.
      2. Get Higher size of SD card and again copy into OS image.

      From Ashish Vishwakarma

      • samrudh

        Hi Ashish..

        Thanks for the help. I checked with my SD card using df -h. It really seems overflowed. I think OpenCV libraries require large free space.
        Anyways thanks for the instant reply.

  • Sidd

    Hi, I am from C back ground and done image processing applications in opencv using C. can i enjoy with my previous environment in raspberry pi? i mean i want to run my opencv application developed in c in raspberry Pi. Can any body tell me the procedure to setup my rasberry pi for C package of opencv. any feed back will be appreciated.

    • The tutorial shows how to setup the Raspi for OpenCV development in C.

  • Sidd

    i am getting error of unable to locate package libavcodec53 and unable to locate package libavformat53 while installing the packages. anyone knows what should i do?

    • If you are using an older distribution the packages may not have been updated. Try running apt-get update and then re-try, otherwise substitute
      libavcodec52 libavformat52
      for
      libavcodec53 libavformat53 and it should work.

  • adg

    Hi, I want to use opencv with C. I make a correct installation, and the C examples works great. I try to compile with gcc and the compilaton crashes because the librarys. Any Idea? Thanks

  • Hassan El Salamouni

    Hi,

    Please i am working on a project where i need to setup an enviroment for programming using OpenCV and C++ instead of OpenCV and Python, i didnt find any Blogs or Tutorials to follow i dont know why, most of the people use OpenCV and Python on linux, i am using the Debain Weezy OS for the Raspberry PI, do you have any idea of which IDE i should setup ? is it CodeBlocks ? i tried setting up Eclipse for C/C++ but it didnt work on the raspberry PI. please guide me if you know any solutions for these problems.

    Thank you

  • Luke

    Nice blog Michael! Do you know if this method will allow OpenCV to use hardware acceleration features on the Pi? VFP, hard float, etc? I’m still very new to Linux!

  • I got this working on Debian 6, Linux Rasberrypi 3.2.27+ but had skip/uncheck in the cmake-gui the CUDA parts, FFMPEG and XIMEA. I did make sure to include the V4L because I read somewhere that this is necessary for webcams to work with OpenCV. The SD card came with the rasberry pi and was packaged by element 14. The card size is 4GB, I have 1.0GB free after this install but I also installed numpy scipy matplotlib and other libraries. This is a B version of the pi

    Install date: Dec 5, 2012.

  • Oh I also have Python2.7.3rc2 running. Thanks Mitch for your help!

  • Pablo

    good tutorial, I’ll try to follow to install openCV into a cubieboard.

  • Hello Mitchel.
    You have a very good tutorial, very clear, and I follow it to install OpenCV in a Cubieboard.

    Also I’m doing a blog, and I would like to put almost your steps, cause I follwed and I think is favolous.
    I’ll put a link to your blog

    • the blog is: cubieboard.blogspot.com

      Thanks for share all very good knowledge

  • Lucas

    Has anyone tried using the apt-get opencv with python?
    I am testing that and it won’t open up a window to display an image, no errors.

    Tried the exact code on my laptop and it works as expected.
    I’m trying to avoid doing a manual install unless I need to

  • MetabolicCloth

    when i enter “cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..” i get command not found. help please.

  • Pete

    There is a small mistake in the step where you change the system-wide bashrc:

    “PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH”

    How it should be:

    “PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
    export PKG_CONFIG_PATH”

    “export” needs to be on the second line otherwise you get a ton of console spam and an error from that bashrc…

    Cheers

    • Also, you need to run `sudo ldconfig` after you add anything to /etc/ld.so.conf.d/opencv.conf

  • Pingback: Object Tracking on the Raspberry Pi with C++, OpenCV, and cvBlob « ProgrammaticPonderings()

  • Pingback: Raspberry Pi Rasbian + OpenCV « ariandyblog()

  • After a few time of study, using the base of this post, I made the installation of Raspbian + openCV + libjpeg-turbo

    http://cubieboard.blogspot.com.es/2013/02/raspbian-opencv-libjpeg-turbo.html

  • YUI

    I try to install following this instructions but it has some error in a step of build (make). The error occur when build in “modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o”. I check a installation of ffmpeg which is already updated. Could anyone have any suggestion, please help me.

    Thanks.

  • Pingback: Raspberry Pi OpenCV Pan & Tilt Face Tracker | MitchTech()

  • Pingback: Raspberry Pi Türkiye Topluluğu OpenCV Kurulumu | Raspberry Pi Türkiye Topluluğu()

  • Hi could you please help me regarding cross compilation of cvBlob library for arm..??
    Thanks in advance.

  • Pingback: Raspberry Pi Security Monitor Project – Take 2 | techthoughts()

  • angelojoshua

    Hi! After following the steps above, I tried to execute one of the python examples by going to

    ~/OpenCV-2.3.1/samples/python

    some of the examples in the folder are drawing.py and squares.py

    I tried to execute a sample by typing python ./drawing.py and i get an error
    Traceback (most recent call last):
    File “./drawing.py”, line 7, in
    import cv2.cv as cv
    ImportError: No module named cv2.cv

    Please help me figure out this error. thanks in advance!

    • I have the same problem.
      Also, is there any news on gpu use by OpenCL and OpenCV?

      • Did you find the solution to this problem?

        I also have the error ImportError: No module named cv2.cv

        • Roger Garrett

          I wish I could help. It was months ago that I finally came across the solution to the problem, and it took weeks to find that solution. I do recall that I had to re-install and re-compile the entire CV code. There are lots of installations instructions on the web, and they’re not all the same. I just finally came across one that did it correctly.

          I have 45 years experience as a software engineer, and I absolutely hate Linux. There are very few nice things about it, but with the proliferation of versions of Linux, along with the proliferation of incompatible versions of support software, it’s a horrible mess. WIth Windows you just run an installer and all is well in computer land. With Linux you get three pages of installation instructions. Linux is a giant leap back into the stoneage of software.

  • thanks a lot !
    I’ll try to follow to install openCV tomorrow~

  • Pingback: How to easily install OpenCV on Raspberry Pi » Muhammad Yusro()

  • dev

    what is the best IDE to use for this in c++? Since this is Linux, I don’t have visual studio no longer so I will need to pick a new IDE to start off with. Also, how can I track with the highest fps possible? on high school robotics team and vision processing needs to be fast

    • For sure there are a lot of IDE to work with. But for simplicity and control I use VIM, I’m to busy to learn an IDE, and I don’t want to loss the control of my code, compilation etc.
      If You want to use the raspberry-pi forcomputer-vision and need to be fast, maybe is not the best machine, y use a cubieboard which is more powerfull and you can see the result here http://cubieboard.blogspot.com.es/2013/03/web-cam-and-cubieboard.html, and itsn’t really good.

      The raspberry reproduce perfectly the videos, but it’s not the same if you have to apply for computer vision.

  • I can’t compile on my rpi !!!

    I’ve got the error that @bstag talk and i’ve modified the file cap_ffmpeg_impl.hpp
    and I launch the “make” command.
    And it’s not work again

    I got following error :

    pi@rpibot ~/OpenCV-2.3.1/build $ make
    [ 4%] Built target opencv_core
    [ 13%] Built target opencv_imgproc
    [ 17%] Built target opencv_highgui
    [ 18%] Built target opencv_flann
    [ 22%] Built target opencv_features2d
    [ 25%] Built target opencv_calib3d
    [ 26%] Built target opencv_ts
    Linking CXX executable ../../bin/opencv_test_calib3d
    ../../lib/libopencv_highgui.so.2.3.1: undefined reference to `av_sub_q(AVRational, AVRational)’
    ../../lib/libopencv_highgui.so.2.3.1: undefined reference to `av_rescale_q(long long, AVRational, AVRational)’
    collect2: ld returned 1 exit status
    make[2]: *** [bin/opencv_test_calib3d] Erreur 1
    make[1]: *** [modules/calib3d/CMakeFiles/opencv_test_calib3d.dir/all] Erreur 2
    make: *** [all] Erreur 2
    pi@rpibot ~/OpenCV-2.3.1/build $

    I’ve tried to rebuild ffmpeg from scratch but it has no effect on the error.

    Any one has an idea ?

  • Pingback: Raspberry Pi + OpenCV » Monsieur Yusro()

  • Using “%make -j” will speed up the compile significantly

  • dhanash

    Hi guys…i m using debian on raspberry pi…
    when i enter this command on terminal……

    “cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..”

    i got errors…

    CMake Error: The source directory “/home/pi/OpenCV-2.3.1/build/BUILD_EXAMPLES=ON..” does not exist.
    Specify –help for usage, or press the help button on the CMake GUI.

    then i installed “cmake-qt-gui” and run “cmake-qt-gui” on terminal. but i got error

    bash: cmake: command not found

    help me…

  • dhanash

    hi guys i solved my previous problem…now i entered this command

    “cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..”

    i got error,

    “CMake Error: The source directory “/home” does not appear to contain CMakeLists.txt.
    Specify –help for usage, or press the help button on the CMake GUI.”

    then i run cmake-qt-gui,then i dont know source code dir and build to binary as well as how to find which one is correct CMakeLists.txt.because there are so much of CMakeLists.txt while i finds this.

    /usr/share/cmake-2.8/Modules/IntelVSImplicitPath/CMakeLists.txt
    /usr/share/cmake-2.8/Modules/FortranCInterface/Verify/CMakeLists.txt
    /usr/share/cmake-2.8/Modules/FortranCInterface/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/3rdparty/libpng/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/3rdparty/libtiff/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/3rdparty/libjasper/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/3rdparty/libjpeg/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/3rdparty/ffmpeg/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/3rdparty/zlib/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/3rdparty/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/doc/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/gpu/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/legacy/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/core/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/haartraining/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/contrib/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/python/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/stitching/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/flann/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/ml/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/calib3d/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/traincascade/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/objdetect/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/java/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/video/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/imgproc/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/features2d/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/highgui/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/androidcamera/camera_wrapper/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/androidcamera/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/ts/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/modules/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/data/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/include/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/samples/gpu/performance/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/samples/gpu/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/samples/android/hello-android/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/samples/android/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/samples/cpp/Qt_sample/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/samples/cpp/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/samples/c/example_cmake/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/samples/c/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/samples/CMakeLists.txt
    /home/pi/OpenCV-2.3.1/CMakeLists.txt

    reply me…
    thank you.

  • dhanash

    i was installed opencv 2.3.1…when i execute samples by “./delaunay” then i got errors as follows.,

    This program builds the traingulation interactively, you may stop this process by hitting any key.

    OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /home/pi/OpenCV-2.3.1/modules/highgui/src/window.cpp, line 275 terminate called after throwing an instance of ‘cv::Exception’

    what(): /home/pi/OpenCV-2.3.1/modules/highgui/src/window.cpp:275: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow

    Aborted

    what is the solution?

    thankyou

  • Pingback: Installing ROS and Opencv on Ubuntu ARM 12.10 with LXDE, on a BeagleBoneBlack, and configuring SSH and TightVNC | eigendreams()

  • First of all, THANK YOU! so much for publishing this information. I looked all over and came across utterly confusing information, UNTIL I found yours. It too 8.5 hours to compile, but it’s finally done.

    Now, a question: I tried running one of the python scripts and it immediately reported an error at the line:

    import cv2.cv as cv

    indicating that there’s no module named cv2. How do i fix that error?

    • Did you find the solution to this problem?

      I also have the error ImportError: No module named cv2.cv

  • DmitryD13

    Hello,
    thanks for such a detailed Explanation. However, I try to build opencv with Java on Raspberry Pi (Debian 4.6.3) and get every time an error from cmake:
    Could not find JNI (missing: …). I have been searching for solution in the Internet for a while. The suggestions were set JAVA_HOME variable, install ant, install python, add ${JAVA_HOME}/bin variable to the PATH variable. Unfortunately, nothing has helped me yet. I tried everything, I even tried to completely remove opencv (2.4.6.1) from the Raspberry Pi, download another Version (2.4.6) and build it with cmake – nothing worked.
    I have two jre’s on the Raspberry Pi: one (probably) preinstalled “Java-6-openjdk-armhf” and one, I installed by myself “Java Early Access” (jdk1.8.0 – speciffically for Raspbian with hardfloat). I tried to set JAVA_HOME to “/home/pi/java/jdk1.8.0” (where I installed “Java Early Access”) and “/home/pi/java/jdk1.8.0/”,
    The Problem seems to be that cmake cannot find jni.h file, which usually can be found in “JAVA_HOME/include/”. I checked this file and I have it; if I type “ls $JAVA_HOME/include/” in the shell, I get files with jjn.h among them.
    So, I am out of ideas and, saying truly, out of Motivation to install opencv with Java on Raspberry Pi. Please, help me, if you know how to solve my Problem.
    Thanks in advance!
    Dmitry

  • Lars

    I get Make error
    Any ideas what the cause could be?
    I have fresh install of raspbian
    from 2 days ago.
    ….
    Scanning dependencies of target opencv_test_core
    [ 33%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_rand.o
    [ 34%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_math.o
    /home/pi/OpenCV-2.3.1/modules/core/test/test_math.cpp: In member function ‘virtual void Core_SVDTest::prepare_to_validation(int)’:
    /home/pi/OpenCV-2.3.1/modules/core/test/test_math.cpp:1938:12: warning: variable ‘step’ set but not used [-Wunused-but-set-variable]
    [ 34%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_precomp.o
    [ 34%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_operations.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/core/CMakeFiles/opencv_test_core.dir/test/test_operations.o] Error 4
    make[1]: *** [modules/core/CMakeFiles/opencv_test_core.dir/all] Error 2
    make: *** [all] Error 2
    pi@raspberrypi ~/OpenCV-2.3.1/build $

    • Nithan

      Same here. Even I’m getting a make error. It would be great if anyone can sort the problem out.
      Thanks a lot.

    • Sparkey

      Same here on the Error 2 during make. What could cause this?

      • almost certainly out of memory on the pi. Have a look at the output of dmesg after a failed compile. I couldn’t compile on an older 256MB pi. Also I changed the gpu mem split

  • It is posible to install opencv on a SD card of 4GB ? I was trying but i’m having some problems due to the limited space..

  • Archon

    Mr. Mitch, thanks a lot for this tutorial. It worked perfectly. Just a little thing at the end, i needed to ldconfig so that everything went peachy.
    Thanks for sharing!

  • Hi,

    Pardon, I am new to Linux and Raspberry Pi…

    I have followed everything in this guideline successfully, up to the point of testing samples.

    How to execute the “convexhull”, “kmeans”, and “drawing” binaries inside ~/OpenCV-2.3.1/build/bin?
    I got error: “bash: convexhull: command not found”

    Please help me. Thank you!

    • Sorry, it was a noob question…I’ve already been able to execute the samples, for example by this command:
      /home/pi/OpenCV-2.3.1/build/bin/convexhull
      Thank you.

  • Sandro

    Just FYI, these instructions worked up until running the demo. At that point the libraries couldn’t be found, so I had to add “export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib” to /etc/bash.bashrc.

  • Pingback: 【转载】Raspberry Pi + OpenCV | 秋狗的家()

  • VijayMukilan S

    Thanks for the wonderful article on setting up!! Just get it working as a cake.

    I just did sudo ldconfig
    I do get an video example running there is no problem in streaming as v4l driver is installed.
    Need to test futher to find any issues..

    Keep this good work !!

  • Pingback: Installing OpenCV on a Raspberry Pi | Robert Castle Consulting()

  • Hello, I’m going to compile the opencv-2.4.8 and the good cmake options looks to be:

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

    BUILD_NEW_PYTHON_SUPPORT=ON instead of BUILD_PYTHON_SUPPORT=ON

  • mansoor

    hello, i am using raspbian os and i want to install openCV . the commands given above is not working in this os can u please help me out for this.. give me some idea.. thank you in advance.

  • I just got my install working after 3 frustrating days. Go to this link and follow the instructions for a fresh install of the current version of opencv. http://robertcastle.com/2014/02/install … pberry-pi/
    After that do these steps as well so you can fully configure opencv and make certain that it works:
    CONFIGURE OPENCV
    In your terminal, execute:

    sudo nano /etc/ld.so.conf.d/opencv.conf

    Add the following line and save it:

    /usr/local/lib

    Now, in your terminal, execute:

    sudo ldconfig

    Again, execute:

    sudo nano /etc/bash.bashrc

    Add the following two lines at the end of the file and save it:

    PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
    export PKG_CONFIG_PATH

    Finally, reboot your computer.

    TRY AN EXAMPLE

    To test an example, from your terminal cd to the OpenCV folder. Once you’re inside it cd to samples/c.

    Now, execute:

    chmod +x build_all.sh

    ./build_all.sh

    ./facedetect lena.jpg

    ok opencv works you’re ready for simplecv ( although if you can’t get simplecv there are some good youtube vids and books for opencv )

    I did this: $ sudo apt-get install ipython python-opencv python-scipy python-numpy python-setuptools python-pip python-pygame

    sudo apt-get install git
    git clone git://github.com/sightmachine/SimpleCV.git
    cd SimpleCV
    sudo pip install -r requirements.txt
    python setup.py install
    sudo python setup.py develop

    after that go here:

    http://www.linux-projects.org/modules/s … e&artid=14
    then finish up by going here:
    http://www.raspberrypi.org/forums/viewtopic.php?f=91&t=57788&p=0&e=0&sid=48693b72792897475ee17b347a3b3c7e

    to check the configuration and test steps for simplecv

  • haziq

    hi i followed all the steps but when i import cv2.cv as cv it there is an error !!! seems like my python is not configured with open cv ! can anyone help ??

    • fildaniels

      just do:
      sudo apt-get install python-opencv

  • Pingback: Howto: OpenCV 2.4.9 on Raspberry Pi from source | defendtheplanet.net()

  • Pingback: OpenCV Kurulumu - Raspberry Pi Türkiye Topluluğu()

  • Pingback: Fix Opencv Error Unspecified Error Windows XP, Vista, 7, 8 [Solved]()

  • Pingback: Fix Opencv Error Code 25 Windows XP, Vista, 7, 8 [Solved]()

  • Pingback: Fix Gstreamer Error Could Not Demultiplex Stream Windows XP, Vista, 7, 8 [Solved]()

  • Pingback: Resolution properties for python's OpenCV and uv4l camera driver - DL-UAT()

  • Pingback: how do you build sample OpenCV programs that come bundled with the OpenCV source? | CL-UAT()

  • Pingback: e-CAM30_USB camera with raspberry pi | CL-UAT()

  • Pingback: Can not capture video using OpenCv | CL-UAT()

  • Pingback: How do you build Open CV programs for raspberry pi using a cross compiler? | CL-UAT()

  • Pingback: opencv 2.2 on raspberry pi [on hold] | CL-UAT()

  • s

    how to run playbook

    • meyers

      Sorry S,

      I forgot to include `site.yml`. I fixed it above.
      `ansible-playbook site.yml -i pi.yml -vvvv`

      • meyers

        awww, messed up again. Forgot the s in `pis.yml`. Fixed.

  • Pingback: OpenNI + Depth & IR Compression + Pandaboard | Saad Ismail()

  • Brian

    Is there a newer, updated instructional guide? The last comment which talked about changes/improvements to the procedure was from April 2014. I think things might have changed since then.

    • meyers

      Brian,
      Check out the ansible playbook. It was created this month and uses the newest version of opencv from source.

  • Ragav

    i got this error..pls help me to rectify it
    Makefile:116: recipe for target ‘all’ failed
    make: *** [all] Error 2

  • Pingback: Machine vision with the Raspberry Pi - Artificial Intelligence Online()

  • Pingback: OpenCV Face Detection with Raspberry Pi - Robotics with Python p.7 - PCB Board Manufacturer()

  • Pingback: OpenCV Face Detection with Raspberry Pi – Robotics with Python p.7 – Loon Tube()

  • Pingback: Error Code Pi 30021()

  • Pingback: Ubuntu Installation Failed Input Output Error()

  • Pingback: OpenCV Face Detection with Raspberry Pi – Robotics with Python p.7 | Online Coding()

  • Pingback: Rpi – Prixomic()

  • Pingback: OpenCV Face Detection with Raspberry Pi - Robotics with Python p.7 - 2uts()

  • Pingback: OpenCV Face Detection with Raspberry Pi – Robotics with Python p.7 – Project Blog()

  • Theonlyarea

    Using ansible I get “site.yml could not be found” I see a similar issue on github from a year ago but no resolve. Any advice?