Skip to content


Installing OpenCV 2.4.1 in Ubuntu 12.04 LTS

EDIT: I published a new guide using Ubuntu 14.04 LTS and OpenCV 2.4.9 here.

The latest Long Term Support version of Ubuntu(12.04 LTS) is out and a new version of OpenCV was released as well. This means that now is a great opportunity to update my OpenCV installation guide to the latest versions, Ubuntu 12.04 LTS and OpenCV 2.4.1.

We are going to setup OpenCV to use the new Qt highgui interface, which is much better than the simple highgui interface. Also, we will install OpenCV with support for OpenGL, as well as reading and writing videos, access to a webcam, Python, C and C++ interfaces, and Intel Threading Building Blocks (TBB).

OK, so the first step is to make sure that everything in the system is updated and upgraded:

sudo apt-get update
sudo apt-get upgrade

Now, you need to install many dependencies, such as support for reading and writing image files, drawing on the screen, some needed tools, etc… This step is very easy, you only need to write the following command in the Terminal:

sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev

Time to get the OpenCV 2.4.1 source code:

cd ~
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.1/OpenCV-2.4.1.tar.bz2
tar -xvf OpenCV-2.4.1.tar.bz2
cd OpenCV-2.4.1

Now we have to generate the Makefile by using cmake. In here we can define which parts of OpenCV we want to compile. Since we want to use Python, TBB, OpenGL, Qt, work with videos, etc, here is where we need to set that. Just execute the following line at the terminal to create the appropriate Makefile. Note that there are two dots at the end of the line, it is an argument for the cmake program and it means the parent directory (because we are inside the build directory, and we want to refer to the OpenCV directory, which is its parent).

mkdir build
cd build
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

Check that the above command produces no error and that in particular it reports FFMPEG as YES. If this is not the case you will not be able to read or write videos. Also, check that Python, TBB, OpenGL, V4L, OpenGL and Qt are detected.

If anything is wrong, go back, correct the errors by maybe installing extra packages and then run cmake again. You should see something similar to this:

Now, you are ready to compile and install OpenCV 2.4.1:

make
sudo make install

Now you have to configure OpenCV. First, open the opencv.conf file with the following code:

sudo gedit /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


Run the following code to configure the library:

sudo ldconfig

Now you have to open another file:

sudo gedit /etc/bash.bashrc

Add these 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, close the console and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.

Now you have OpenCV 2.4.1 installed in your computer with Python, TBB, OpenGL, video, and Qt support.

Check out the cool Qt interface which provides image viewing capabilities with zoom, as well as the ability to save the current image with just one click.

If you zoom in enough, you can see the RGB (or intensity) values for each pixel.

Now let’s build some samples included in OpenCV:

cd ~/OpenCV-2.4.1/samples/c
chmod +x build_all.sh
./build_all.sh

Now we are ready to run the examples:

./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg

./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_eye.xml" --scale=1.5 lena.jpg

~/OpenCV-2.4.1/build/bin/grabcut ~/OpenCV-2.4.1/samples/cpp/lena.jpg

~/OpenCV-2.4.1/build/bin/calibration_artificial

python ~/OpenCV-2.4.1/samples/python2/turing.py

Posted in Image Processing, Open Source, Programming.


390 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Diego says

    Awesome Tutorial, many thanks

  2. wisnu says

    Very detail instruction. Thanks.
    By the way, I want to use OpenCV without terminal. do you have any sugestion, what aplication should I use?

  3. samontab says

    mmm, I am not really sure about what your question is….
    OpenCV is just a library, you can use it in other programs….

  4. Daniel says

    I come across an problem:”Looking for ffmpeg/avformat.h – not found”.
    Can you tell me how should I deal with it?

  5. aris says

    I have installed opecv correctly i think using yur perfect tutorial but i cannot seem to find the binaries inside the /build/bin directory. what am I doing wrong?

  6. samontab says

    Let’s see, the first step that I would check is the cmake line, with two dots at the end. Make sure that you copy and paste the commands to do exactly the same. You should be inside the build directory, and the last argument of cmake should be two dots.
    If you have OpenCV correctly installed in your system, with sudo make install, then everything should be OK.
    OpenCV libraries are stored in:
    /usr/local/bin
    /usr/local/lib
    /usr/local/share
    /usr/local/include
    I hope this helps you.

  7. samontab says

    If in the last report FFMPEG appears as detected, then you can ignore that. If FFMPEG appears as not supported, then you need to install it first.
    You can do that by just installing the following libraries:
    sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
    But those are already included in the tutorial, so you should already have them…
    If you need a specific version of FFMPEG, you can compile it and install it yourself, as I did in a previous post:
    http://www.samontab.com/web/2011/06/installing-opencv-2-2-in-ubuntu-11-04/

  8. samontab says

    You are welcome Diego, I am glad I could help.

  9. Loi Nguyen says

    very helpful and awsome, thank you very much

  10. samontab says

    You are welcome Loi!

  11. austin says

    Thanks for being awesome, this was so unbelievably helpful. OpenCV really should put your tutorial on their site. Saved me so many headaches.

  12. samontab says

    Thanks Austin, that was an awesome comment :)

  13. Anupama says

    When I try to run an OpenCV program after installation with CodeBlocks I got the error:
    error while loading shared libraries:libopencv_highgui.so cannot open shared object
    Once I edited opencv.conf and followed the succeeding steps outlined here , the program ran successfully
    Thank You

  14. samontab says

    Good to know that it works for you too

  15. hugo says

    Wow, a great help to me. Thanks a lot. :)

  16. samontab says

    You are welcome Hugo.

  17. Zick says

    That’s an amazing guide :P
    But, Can you tell me how can I code with it?
    I want to make programs with opencv, How can I do that?

    Thanks.

  18. samontab says

    Start by looking at the examples, and edit them.
    You can write programs for OpenCV mostly in C, C++ and Python.
    For C/C++ programs you can use cmake to compile them, or just pkg-config.
    If you have a valid C/C++ program in the file main.cpp, you can compile it with this line:
    g++ `pkg-config --cflags --libs opencv` -o main main.cpp

  19. d34df3tu5 says

    Amazing!!!! Thanks a Lot for ur work..

  20. samontab says

    You are welcome!

  21. Zick says

    Hey again :p
    I tried compiling with this command and got that:
    /tmp/ccHz4P70.o: In function `main':
    opencv1.c:(.text+0x23): undefined reference to `cvLoadImage’
    opencv1.c:(.text+0x36): undefined reference to `cvNamedWindow’
    opencv1.c:(.text+0x47): undefined reference to `cvShowImage’
    opencv1.c:(.text+0x51): undefined reference to `cvWaitKey’
    opencv1.c:(.text+0x5d): undefined reference to `cvReleaseImage’
    opencv1.c:(.text+0x67): undefined reference to `cvDestroyWindow’
    collect2: ld returned 1 exit status

    what should I do?

  22. samontab says

    Hi again Zick,

    It seems that the libraries are not correctly loaded.
    Try compiling it with this line instead:

    gcc `pkg-config --cflags opencv` -o main main.c `pkg-config --libs opencv`

    That should work.

  23. Abner Katagiri says

    This is a great tutorial, good job Sebastian!

  24. Long Pham says

    Two things to comment:
    I got this notes and errors when installing, so I think you could edit it so that everyone can copy-and paste:

    In the “installing build-essential” part:

    Note, selecting ‘libjpeg62-dev’ instead of ‘libjpeg-dev’
    E: Unable to locate package sphinx-common

    So, I change libjpeg-dev into libjpeg62-dev and remove sphinx-common. Everything so far works fine for me.
    Thanks for the great post.

  25. samontab says

    Thanks Long Pham for your comment. I checked the errors that you mention but they work for me. Maybe you are using a different version of Ubuntu?, at least in Ubuntu 12.04 LTS 32 bits, with the latest updates and upgrades installed, my guide works well.

    I think that you are running an older version of Ubuntu, because in older posts I used libjpeg62-dev instead of libjpeg-dev. If you can share your version, other readers may use your advice.

  26. Varun says

    Brilliant stuff mate. I’ve been trying to install opencv on windows with qt, using cmake but it didnt work. I’ve followed many tutorials on facebook and was able to install opencv with qt through cmake, but the programs i wrote (as instructed in the tutorial) on qt did not work. During compling it said the dll files were not found. I checked the dll files and they were all in the specified folder.

    My whole class has tried to install opencv with qt using cmake but none of us were able to get the program working on qt.

    It would be really helpful if you could make a video or tutorial similar to this for WINDOWS as well.
    my email is varuninnz@gmail.com

  27. Joshua says

    Hi,
    This tutorial is great! But there is a problem. I tried using python with opencv and got a problem.
    It stated that there is an “ImportError: No module named opencv.cv
    So, is there any solution to this probelm?

    Thanks for the great post !

  28. samontab says

    Hello Joshua,

    It seems that you are not using the latest version of Ubuntu.
    You can try copying manually the needed library:

    sudo cp /usr/local/lib/python2.7/site-packages/cv.so /usr/local/lib/python2.7/dist-packages/cv.so

    After you do that, python should work with OpenCV.

  29. samontab says

    I think that your problem is in the CMakeLists.txt file.

    First, make sure that you can compile a Qt program using cmake:
    http://qt-project.org/quarterly/view/using_cmake_to_build_qt_projects

    Once you can create a Qt program, add OpenCV into the mix:
    http://opencv.willowgarage.com/wiki/Getting_started

    And it should work.

  30. Shawn says

    hello Samon,
    two questions:
    I followed your steps and I’m trying to do this on beagleboard-xm c4 with Ubuntu 12.04. I even downloaded cmake 2.8 on it, just to make sure but I still run into the problem. here is the error I get.
    CMake Error: The source directory “/home” does not appear to contain CMakeLists.txt.

    and installed python opencv (sudo apt-get install python-opencv python-numpy) then I wrote a short code in vim when I tried to compile it said that couldn’t get the imports (import cv and import numpy) is that because I don’t have opencv properly installed?

    thanks for your help in advance.

  31. samontab says

    Hi Shawn,

    For your first question, it looks like you are calling cmake .. from your home directory (/home/username). You need to go to the build directory, which is inside the folder where the source code resides. The two dots represent the parent folder, and in that parent folder there should be a CMakeLists.txt file.

    For your second question, I would first get OpenCV up and running with Python support and then try some Python examples. If after that you still don’t get the imports, try to copy them manually:
    sudo cp /usr/local/lib/python2.7/site-packages/cv.so /usr/local/lib/python2.7/dist-packages/cv.so

  32. Joshua says

    My /usr/local/lib/python2.7/site-packages does not have the cv.so inside. The whole folder is empty but in /usr/local/lib/python2.7/dist-packages have 2 items called cv.py and cv2.so. Is this a problem with the installation or can i just download cv.so manually and put it in the folder?

  33. samontab says

    Which version of Ubuntu are you using?
    Can you tell me exactly what are you trying to do?

  34. Joshua says

    The version of ubuntu that im using is 12.04 LTS.

    What im trying to do is to detect faces in the picture and the result is to display the coordinates which i will then use the coordinates given to crop the face out.
    I had found the codes for detecting face from a picture in this website: http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/#more-16

  35. samontab says

    You are having that error because you are trying to use the old Python interface. I recommend you to use the new one.

    Try to run the examples in my tutorial:
    python ~/OpenCV-2.4.1/samples/python2/turing.py
    If you can run that, you should be able to use Python.

    Take a look at the Python samples in OpenCV directory:
    ~/OpenCV-2.4.1/samples/python2/
    In particular, take a look at facedetect.py. You should be able to work from there.

  36. Joshua says

    Im able to run the example in your tutorial :
    python ~/OpenCV-2.4.1/samples/python2/turing.py

    So, i think the problem with mine is the codes use for detecting faces.

    Thanks for your help! Your’re amazing!

  37. samontab says

    Great, thanks.

    Make sure that you take a look at the example code in ~/OpenCV-2.4.1/samples/python2/facedetect.py
    You may be interested in it.

  38. Dan says

    My goodness, it actually works! I struggled for hours on Windows trying to set this up. I finally did but, using your instructions it was faster to install Ubuntu then install openCV then it was to simply install and configure openCV on Windows. This was an excellent tutorial. Thanks so much!

  39. samontab says

    You are welcome Dan!

  40. Joshua says

    Is there any way that you can help me edit the facedetect.py into displaying the coordinates of the face ? Im still stuck at this problem for a week :(

  41. Manoj says

    Hi,

    Thanks for this awesome tutorial.. everything worked flawlessly :)
    Thank you so much.

  42. samontab says

    Thanks for your comment Manoj :)

  43. samontab says

    In the code, look for this line:
    for x1, y1, x2, y2 in rects:
    Those are the coordinates of the detected faces. You can display them however you like.

  44. Arjen Veenhuizen says

    In order to get things really going, I first (step 0 so to speak) had to do this:
    sudo apt-get remove ffmpeg x264 libx264-dev

    Next, make sure you download the very latest x264 and do a checkout of ffmpeg via
    git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg

    Unpack and install according to the tutorial.

  45. Anupama says

    Hello,
    I was able to install OpenCV2.4.2 by following your tutorial. However, I am unable to capture an image from my web camera. I use Cheese. My cvcapturefromCAM() returns null for any value I pass as argument. Could you suggest how I can set this right?

    Thank You

  46. samontab says

    Make sure that v4l is installed (video for Linux). Check your camera hardware and see what driver you should install in Linux to make it work.

  47. Sha says

    Hi Samon
    Thanks for the great tutorial! You are great. I downloaded and set up opencv and the samples from opencv itself run.
    I’m using Eclipse Indigo on ubuntu 12.04 LTS. I tried to compile a short sample opencv code in Eclipse but it gives me a lot of errors.I tried other codes and it still give me a lot of errors. Also I set up the includes and the library paths in project properties in Eclipse but it looks like it is not linked for example for this line image = imread( argv[1], 1 ); it says (function imread could not be resolved).
    any thoughts?
    Thank you in advance

  48. samontab says

    Well Sha, OpenCV is correctly installed in your system, you just need to configure eclipse correctly to use libraries

  49. Jacob C F says

    I have installed OpenCV 2.4.2 using the above steps.
    The example python and shell programs work but, the C and C++ programs Say that there are no such header files for eg. cv.h
    Please help me out
    Thank You:)

  50. Hull says

    Works nice and easy on a 32 bit 12.04 running on a 64 bit machine. Though I must add I’ve never managed a successful installation with a 64-bit OS. Just to play safe, OpenCV 2.4.1 was the first installation I carried out on a “brand new” Ubuntu 12.04, to avoid cleaning up any leftover files from previous installations on Ubuntu 11.04. However, I’ve never had any luck with cmake on Windows.

    I’ve scoured through several OpenCV tutorials but is the only one (at least for me) that worked on first attempt. Thanks very much!

  51. Tasneem says

    Hello, i need ur help

    when i enter the command:
    sudo gedit /etc/ld.so.conf.d/opencv.conf
    the error that comes is:

    (gedit:21058): Gtk-WARNING **: Attempting to store changes into `/root/.local/share/recently-used.xbel’, but failed: Failed to create file ‘/root/.local/share/recently-used.xbel.J7CZIW': No such file or directory
    (gedit:21058): Gtk-WARNING **: Attempting to set the permissions of `/root/.local/share/recently-used.xbel’, but failed: No such file or directory

    same error comes when i enter this command and a file opens,
    sudo gedit /etc/bash.bashrc

    Where i am doing mistake?

  52. samontab says

    Maybe it is because of permission of the temporary files that gedit creates.
    You can use another editor, like nano for example, and you should not have those problems.

  53. samontab says

    Thanks for your comment.

    You can always try with a virtual machine first, and once you have everything right, you can make the changes in the host pc.
    For Windows, you will need CMake and visual studio c++ express 2010. Install both of them. Then, open CMake and point to where your source files are (the downloaded and extracted opencv files) and where you want to build your project. Press configure twice, and then once in generate. Now you can open the opencv Solution from the folder you specified. Now you just need to compile in release and debug mode. After that, just add the release and debug binaries path to your path environment variable and you have opencv installed in windows.

  54. samontab says

    Try compiling the C/C++ programs with cmake.
    If you want to compile them manually, use this command:
    g++ `pkg-config --cflags opencv` -o hello hello.cpp `pkg-config --libs opencv`

  55. Tasneem says

    but when i enter this command ‘sudo gedit /etc/ld.so.conf.d/opencv.conf ‘ it opens editor itself

  56. samontab says

    Yes, I know. The problem is for the temporary files created by gedit.

    Try this:
    sudo nano /etc/ld.so.conf.d/opencv.conf
    It will use another editor, nano, to open the file. You can exit with Control + X and then press ‘y’ to confirm the changes, or before exiting, press ‘w’ to save the changes.

  57. Tasneem says

    Yes, Thank you , I have done with it and all the steps mentioned above successfully. Will I now be able to compile C++ code with openCV?

  58. Tasneem says

    When i enter this command:
    cd ~/OpenCV-2.4.1/samples/c
    It is giving error that no such file or directory

  59. samontab says

    Then it means that you are not following the instructions exactly.
    Maybe you installed another version of OpenCV, or downloaded or extracted it into another directory.
    If you give me more details, I may be able to help you.
    In any case, if you follow the instructions exactly, everything should be fine.

  60. samontab says

    As I said before, just follow the steps exactly and you should be able to use OpenCV.

  61. Tasneem says

    No I have followed all the steps accordingly but I will do it again. Tell me that I have to remove previous installations or I can start from the beginning like this?
    If I have to remove then any specific way for it?

  62. Tasneem says

    And I am using ubuntu 11.1O and was installing the same version i.e. OpenCV-2.4.1

  63. samontab says

    Well, it depends on what exactly did you do, but in general it should be OK to just start over without removing anything.

  64. Tasneem says

    No I have followed all the steps accordingly but now I will do it again. Tell me that should I have to remove previous installations or I can start from the beginning like this?
    If I have to remove then any specifc way for that?
    And i am installing OpenCV-2.4.1 on Ubuntu 11.10 .

  65. samontab says

    Well, that is a different version of Ubuntu. I recommend that you install 12.04, which is LTS (long term support) and follow this guide step by step.
    Also, take a look at this older guide, which is for 11.04:
    http://www.samontab.com/web/2011/06/installing-opencv-2-2-in-ubuntu-11-04/

  66. Tasneem says

    OK Thank you. I will try it again from start.

  67. Zak says

    Top tutorial – thanks. Worked perfectly for me.

  68. samontab says

    Thanks Zak!

  69. Tasneem says

    Hello once again
    I have upgraded to ubuntu 12.04
    Now when I am entering this command ‘sudo apt-get update’
    I am getting the follwing error and same for the second command i.e. ‘sudo apt-get upgrade’

    E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable)
    E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

  70. samontab says

    Hi Tasneem.

    It is just what it says, that some other process is using the administration directory.

    You cannot run two separate installations or updates at the same time.
    Note that the graphical window for updates may be running automatically, so make sure that you close that window too.
    Let the updates and upgrades finish and then you can install other software.

    If you still get that error, just restart and make sure that you only run one installation at a time.

  71. alex says

    hey, thanks a lot for the comprehensive guide. I can build and compile everything w/o issues, but i cannot get any of the examples using webcams working. E.g. when i try to run the c example facedetect.py, i get the error Capture from CAM 0 didn’t work, even though i can see the camera in lets say cheese. Also when I try to do it in python, all I get is a small gray window. I found that i create a VideoCapture object, it does not open and trying to grab a frame from it just gives me a nonetype. Has anybody encountered this problem before? Any hints would be appreciated! thanks

  72. Tasneem says

    I have done with that
    now while decompressing OpenCV using the command ‘tar -xvf OpenCV-2.4.1.tar.bz2′
    I get the following error:

    bzip2: Data integrity error when decompressing.
    Input file = (stdin), output file = (stdout)

    It is possible that the compressed file(s) have become corrupted.
    You can use the -tvv option to test integrity of such files.

    You can use the `bzip2recover’ program to attempt to recover
    data from undamaged sections of corrupted files.

    tar: Unexpected EOF in archive
    tar: Unexpected EOF in archive
    tar: Error is not recoverable: exiting now

    I have also removed all other existing files of openCV but still this error is there.

  73. kambiz rahbar says

    Thank you for your excellent tutorial.
    I have a problem with my webcam.
    Webcam capture works, but I received a message: “VIDIOC_QUERYMENU: Invalid argument”.
    Is there any solution for the this problem?

  74. Sab says

    HI,
    I had the same problem of not being able to compile any code I write. Then after I went throguh the comments section I followed your advice and used gcc `pkg-config –cflags opencv` -o main main.c `pkg-config –libs opencv` and it worked fine. I was just wondering whats the difference between compiling with `pkg-config –cflags –libs opencv` -o output myfile.c. Why is it that I get has not been referenced.

  75. Carlo says

    Thanks for sharing this, I succesfully used to install OpenCV 2.4.2 in Ubuntu 11.10, overcoming default OpenCV 2.1

  76. Christoph says

    wow… really great and easy to understand tutorial. everything worked as it was stated. You saved me a lot of work. Thanks a lot…

    PS: this tutorial also worked for OpenCV 2.4.2

  77. rafrouf says

    I applied the guide step by step . I compile correctly the example. But when I use the QT C++, I had These 22 errors.
    %————————————–
    19:56:43: Exécution des étapes de compilation pour le projet projet1…
    19:56:43: Configuration inchangée, étape QMake sautée.
    19:56:43: Débute : “/usr/bin/make” -w
    make: Entering directory `/home/rafik/traitement_image_opencv/projet1′
    /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ -o Makefile projet1.pro
    make: Leaving directory `/home/rafik/traitement_image_opencv/projet1′
    make: Entering directory `/home/rafik/traitement_image_opencv/projet1′
    g++ -Wl,-O1 -o projet1 main.o -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lavcodec -lavformat
    /usr/local/lib/libavcodec.so: undefined reference to `av_bprint_finalize@LIBAVUTIL_51′
    /usr/local/lib/libavformat.so: undefined reference to `av_timecode_make_smpte_tc_string@LIBAVUTIL_51′
    make: Leaving directory `/home/rafik/traitement_image_opencv/projet1′
    /usr/local/lib/libavformat.so: undefined reference to `av_timecode_make_string@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_realloc_f@LIBAVUTIL_51′
    /usr/local/lib/libavformat.so: undefined reference to `av_timecode_get_smpte_from_framenum@LIBAVUTIL_51′
    /usr/local/lib/libavformat.so: undefined reference to `av_timecode_init@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_samples_set_silence@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_calloc@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_get_media_type_string@LIBAVUTIL_51′
    /usr/local/lib/libavformat.so: undefined reference to `av_dynarray_add@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_bprint_init@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_asprintf@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_timecode_make_mpeg_tc_string@LIBAVUTIL_51′
    /usr/local/lib/libavformat.so: undefined reference to `av_rescale_q_rnd@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_bprintf@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_samples_copy@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_get_default_channel_layout@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_timecode_init_from_string@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_bprint_chars@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_timecode_adjust_ntsc_framenum@LIBAVUTIL_51′
    /usr/local/lib/libavcodec.so: undefined reference to `av_tempfile@LIBAVUTIL_51′
    collect2: ld returned 1 exit status
    make: *** [projet1] Error 1
    19:56:43: Le processus “/usr/bin/make” s’est terminé avec le code 2.
    Erreur à la compilation du projet projet1 (cible : Desktop)
    Lors de l’exécution de l’étape “Make”

    you can see my code .cpp and .pro
    %——————– main.cpp—————–
    #include
    #include
    #include
    using namespace std;
    using namespace cv;
    int main()
    { // cvZero(mat);// mat[0][0]=1;
    IplImage* img=cvLoadImage(“image1.jpg”);
    IplImage* img1=cvLoadImage(“image1.jpg”);
    //cout<nChannels;
    // CvArr* mat=cvCreateMat(img->height,img->width,CV_32FC3);
    // cvZero(mat);cvNamedWindow(“source”);cvNamedWindow(“dest”);
    cvCanny(img,img1,10,50,3);
    cvShowImage(“source”,img);
    cvShowImage(“dest”,img1);
    cvWaitKey();
    return 0;
    }
    %———–projet1.pro—————————–
    TEMPLATE = app
    CONFIG += console
    CONFIG -= qt

    SOURCES += main.cpp

    #SOURCES += \webcam.cpp
    INCLUDEPATH += -I/usr/local/include/

    LIBS += -L/usr/local/lib\
    -lopencv_core \
    -lopencv_imgproc \
    -lopencv_highgui \
    -lopencv_ml \
    -lopencv_video \
    -lopencv_features2d \
    -lopencv_calib3d \
    -lopencv_objdetect \
    -lopencv_contrib \
    -lopencv_legacy \
    -lopencv_flann\
    -lavcodec\
    -lavformat\
    please help me!

  78. Harit says

    Thanx a lot…….
    very thoroughly stated…

  79. Laurent.C says

    Hi Samontab, Hi all,
    Firstable thank’s a lot for such a complete guide. I found there a lot of good informations.
    I used to work with OpenCv on Window OS, and for a project I try to embed my code on Xubuntu OS.
    OpenCv compile without issue, my software works fine, but I can’t access the webcam whereas the webcam is wellknown by the OS (I ensure that with cheese, and it’s a Logitech Quickcam Pro 9000, known to works on Debian (uvc) and with OpenCv)
    My code works fine on Window OS, and the webcam could be opened.
    I would like to ask you : Do you know if there is a difference beetween Ubuntu and Xubuntu witch could imply such an issue ?

    Informations about my configuration:
    Xubuntu 12.04
    OpenCV 2.4.1
    Webcam open code :
    VideoCapture webcam(0);
    if(!webcam.isOpened())
    {…};

    Thank you by advance if you take the time to read this.
    Sorry for my english, I’m french.

  80. narendra says

    Thank you very much samon
    it is very usefull to me ,you are awesome
    I am narendra,
    but i want to detect the neck points in the image ,if there is source code (i have some source )

    how to run ,can you tell me and also post some links about image processing in c or c++
    like image overlaping read pixels and resize images
    Thank you,
    Regards ,
    narendra

  81. narendra says

    and how to run samples in c folder,

    if we have some source code about image processing where can we save those files and which folder

  82. QuynhHoang says

    hi,

    i installing OpenCV-2.4.2 but go to here : sudo cp /usr/local/lib/python2.7/site-packages/cv.so /usr/local/lib/python2.7/dist-packages/cv.so

    i didn’t found file cv.so in site-packages folder, and so when i try to load an image with Qt + openCv and include cv.so in my project, it has error : no such file cv.so

    please help me :((

  83. QuynhHoang says

    Hi Samon,

    I learning processing video in Qt + OpenCV but i install OpenCV 2.4.2 in Ubuntu 12.04 LTS not successfully. Can you help me install OpenCV 2.4.2 ,please ??
    I don’t know where do i get mistake? :(

  84. samontab says

    That line is not part of the installation procedure, it was used in a previous version.
    Just use the guide step by step and it should work.

  85. samontab says

    If you follow the instructions exactly it should work. I suggest you to install the exact same version used in the tutorial, 2.4.1 on Ubuntu 12.04 LTS. Other version should work as well but you have to edit some parts.

  86. samontab says

    Seriously?

    Just go to this part of the tutorial:
    Now let’s build some samples included in OpenCV:

  87. samontab says

    This is a great book for learning OpenCV and computer vision in general:
    http://www.amazon.com/Learning-OpenCV-Computer-Vision-Library/dp/0596516134/ref=sr_1_2?ie=UTF8&qid=1346344813&sr=8-2&keywords=opencv

    It covers the C interface, but they are going to release soon a second edition which will cover the C++ interface, which is the one you should really use.

  88. samontab says

    You are welcome Harit!

  89. samontab says

    It seems that some libraries are not being included in the linking stage.

    Since the OpenCV examples are compiled correctly, I can only assume that your Qt environment is the one that needs proper configuration. You can search on the web for how to use Qt and OpenCV together.

  90. samontab says

    Great to hear that Carlo!

  91. samontab says

    Great to hear that Christoph, I try to make the guides as general as possible so that it is easy to install newer versions of OpenCV.

  92. Tasneem says

    Hi
    I followed this guide step by step and compiled the examples successfully. But when i complied a sample code, I got a following error:

    Compiling: main.cpp
    Linking console executable: bin/Debug/test
    g++: error: /usr/local/lib/libcv.so: No such file or directory
    g++: error: /usr/local/lib/libcxcore.so: No such file or directory
    g++: error: /usr/local/lib/libhighgui.so: No such file or directory

    OpenCV seems to have changed the shared libary naming convention. Is It? What should I do Now?

  93. samontab says

    You should use pkg-config to add the libraries:
    g++ `pkg-config --cflags --libs opencv` -o main main.cpp
    If that does not work, try this:
    g++ `pkg-config --cflags opencv` -o main main.c `pkg-config --libs opencv`

  94. Luis says

    I thought I was able to finally get going, but I guess not:

    ./facedetect –cascade=”/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml” –scale=1.5 lena,jpg

    the console says:
    bash: ./facedetect: No such file or directory

    Did I miss something??

  95. samontab says

    Well, you have to be in the directory where the samples are, and you have to compile them. Just follow the instructions step by step.

  96. Wim says

    That was a near-perfect experience, installing OpenCV using your blog. Thanks, awesome!

    The only little glitch I experienced was that sphinx-common wasn’t recognized as a package. I installed sphinx using:

    easy_install -U Sphinx

    And eveything was hunk-dory.

    O yeah, and the example commands couldn’t be copied directly, perhaps you could make all the paths relative to the OpenCD-2.4.1 base dir. But that wasn’t really a problem, just a minor inconvenience.

    Regards, and thanks again,

    Wim.

  97. samontab says

    Thanks Wim!

  98. Angel de Jesus Chi Poot says

    Muchisimas gracias amigo, me sirvio bastante tu tutorial :) . Recibe mis cordiales saludos desde Mexico!! :D

  99. samontab says

    Gracias a ti Angel de Jesus :)

  100. Tasneem says

    Hi once again. Thank you as I have resolved my problem.
    now facing another problem in writing avi file from a camera.
    The code has compiled n run well, but .avi file is not processing at even 1 frame per second and i am getting an error of SELECT TIMEOUT in command line.

    The code which I am following is as below:

    #include
    #include
    main( int argc, char* argv[] ) {

    CvCapture* capture = NULL;
    capture = cvCreateCameraCapture( 0 );

    IplImage *frames = cvQueryFrame(capture);

    // get a frame size to be used by writer structure
    CvSize size = cvSize (
    (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),

    (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT)
    );

    // declare writer structure
    // use FOURCC ( Four Character Code ) MJPG, the motion jpeg codec
    // output file is specified by first argument
    CvVideoWriter *writer = cvCreateVideoWriter(
    argv[1],

    CV_FOURCC(‘M’,’J’,’P’,’G’),
    30, // set fps
    size

    );
    //Create a new window
    cvNamedWindow( “Recording …press ESC to stop !”, CV_WINDOW_AUTOSIZE );
    // show capture in the window and record to a file
    // record until user hits ESC key
    while(1) {

    frames = cvQueryFrame( capture );
    if( !frames ) break;
    cvShowImage( “Recording …press ESC to stop !”, frames );
    cvWriteFrame( writer, frames );

    char c = cvWaitKey(33);
    if( c == 27 ) break;
    }
    cvReleaseVideoWriter( &writer );
    cvReleaseCapture ( &capture );
    cvDestroyWindow ( “Recording …press ESC to stop !”);

    return 0;

    }

    What exactly is the problem? Also I am working in VMware.

  101. QuynhHoang says

    Hi Samon,

    i installed OpenCV-2.4.1, thanks you so much and i tested sample example in your tutorial. It worked but can you help me control terminal tool ? I want to test the both examples lena.png but i have to exit Terminal when i want to test next examples :((
    help me please :(

  102. QuynhHoang says

    samontab says

    You should use pkg-config to add the libraries:
    g++ `pkg-config –cflags –libs opencv` -o main main.cpp
    If that does not work, try this:
    g++ `pkg-config –cflags opencv` -o main main.c `pkg-config –libs opencv`

    Hi Samon, i did as your guide but it report:
    voicon@ubuntu:~/Downloads/OpenCV-2.4.1$ g++ `pkg-config –cflags –libs opencv` -o main main.cpp
    g++: error: main.cpp: No such file or directory :((

    I dont know why, help me please, thanks you so much :(

  103. Darren says

    Dear Sebastian,
    You are the boss. I would not have gotten this to compile without you. I am on Ubuntu 12.04 64 bit, and I had to make a symbolic link:
    sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so
    Then cmake detected OpenGL and QTOpenGL, and now all examples run.
    Is this a good idea?

  104. samontab says

    Well, if everything works it looks like an awesome idea :)

  105. samontab says

    It means that you are in the wrong folder, or your file name is different

  106. samontab says

    I am not really sure about what you need here…

    Why do you need to exit the terminal?

  107. QuynhHoang says

    Hi samontab, thanks for your help :D. i used ” Ctrl +C” to cancell terminal..

    I need you help me again :(
    i trying build this code at site : http://code.google.com/p/opencv-cookbook/source/browse/trunk/Chapter+01/main2.cpp?spec=svn2&r=2

    but it report errors : (.text.startup+0x230):-1: error: undefined reference to `cv::imshow(std::basic_string<char, std::char_traits, std::allocator > const&, cv::_InputArray const&)’

    i dont know why it has this error because i included cv.h :(
    please help me again.. thanks you so much .

  108. samontab says

    Ah, I see what you mean.

    To exit an example, just click on the image window and press ESC, or q, or any key in some cases. The program is waiting for a key press to continue, and exit. The image window has to be in focus, not the terminal.

    Regarding to the build error, it seems that you are not linking the libraries correctly. Highgui is the library responsible for imshow.
    How are you compiling it? try this:
    g++ `pkg-config --cflags opencv` -o main main2.cpp `pkg-config --libs opencv`
    Or even better, you can use cmake to compile it. Just create a simple CMakeLists.txt file in the same folder and write cmake .

  109. NIKKY says

    bzip2: Compressed file ends unexpectedly;
    perhaps it is corrupted? *Possible* reason follows.
    bzip2: Inappropriate ioctl for device
    Input file = (stdin), output file = (stdout)

    It is possible that the compressed file(s) have become corrupted.
    You can use the -tvv option to test integrity of such files.

    You can use the `bzip2recover’ program to attempt to recover
    data from undamaged sections of corrupted files.

    tar: Unexpected EOF in archive
    tar: Unexpected EOF in archive
    tar: Error is not recoverable: exiting now

  110. samontab says

    What am I supposed to do with that?
    It is just a dump of an error.

    At least communicate with me as a human if you expect something from me.

  111. QuynhHoang says

    Hi , thank for your help.
    I saw in my project without this line : PKGCONFIG += opencv CONFIG += link_pkgconfig as project of my friend. I dont know why as while i installed pkg-config…How can you help me again ?
    and i used Qt to compling and linking libraries openCV to Qt .

    thank beforehand ^^!

  112. jason says

    Thanks a lot

  113. Vevin says

    Hi Samon,
    I was able to install it properly and I was even able to run the example successfully but when i tried to configure it in Eclipse.. Its giving my some errors…Actually I am confused about the libraries I should mention in the linker in eclipse..
    /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
    Are those the library files in should enter in the linker??..Kindly help..I am stuck with it

  114. Vevin says

    I stripped the “/usr/local/lib/lib” opencv_stitching “.so” and included those names in the linker of Eclipse project in debug mode.Whenever I am running an example progam cvLoadImage is returning me 0.I don’t know why.. My image file is in the correct location but still it is returning NULL.I check with JPG and PNG files both of them are returning NULL.Please help me if possible.

  115. ceren says

    Hi;

    First of all sorry for my english. I installed opencv 2.4.1 and the opencv cmake samples works file like yours. But it doesnt work on qt. The pkg-congfig opencv –libs command says :
    /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
    But the previous version of opencv doesnt work like that. i need opencv 2.4.1 for my nvidia. what should i do?please help me…

  116. Tasneem says

    Hi. I am working on a random image in detecting its circles of specific colour and taking out its centroids.. But its not giving centroids of all detected circles. There is a problem coming in setting parameters for following command,
    CvSeq* circles = cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 1, 80, 75, 60, 0, 0);

    The code for my project is given below:

    #include”math.h”
    #include”cv.h”
    #include”highgui.h”
    #include”stdio.h”
    //#include”imgproc.h”

    using namespace cv;

    int main()

    {
    int i,j,k;
    int height,width,step,channels;
    int stepr, channelsr;
    int temp=0;
    uchar *data,*datar;
    i=j=k=0;
    IplImage *frame=cvLoadImage(“ball9.jpg”,1);
    IplImage *result=cvCreateImage( cvGetSize(frame), 8, 1 );
    if(frame==NULL ) {
    puts(“unable to load the frame”);exit(0);}
    printf(“frame loaded”);
    cvNamedWindow(“original”,CV_WINDOW_AUTOSIZE);
    cvNamedWindow(“Result”,CV_WINDOW_AUTOSIZE);

    height = frame->height;
    width = frame->width;
    step =frame->widthStep;
    channels = frame->nChannels;
    data = (uchar *)frame->imageData;
    /*Here I use the Suffix r to diffenrentiate the result data and the frame data
    Example :stepr denotes widthStep of the result IplImage and step is for frame IplImage*/

    stepr=result->widthStep;
    channelsr=result->nChannels;
    datar = (uchar *)result->imageData;

    for(i=0;i < (height);i++) for(j=0;j (29+data[i*step+j*channels]))
    && ((data[i*step+j*channels+2]) > (29+data[i*step+j*channels+1])))
    datar[i*stepr+j*channelsr]=255;
    else
    datar[i*stepr+j*channelsr]=0;
    /*If you want to use cvErode you may…*/

    /*Destroying all the Windows*/
    //cvShowImage(“original”,frame);
    //cvShowImage(“Result”,result);
    cvSaveImage(“result.jpg”,result);

    //cvWaitKey(0);
    //cvDestroyWindow(“origxinal”);
    //cvDestroyWindow(“Result”);
    //int riz = detect_circles();

    IplImage* img = cvLoadImage(“result.jpg”);

    IplImage* gray = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
    CvMemStorage* storage = cvCreateMemStorage(0);

    //covert to grayscale
    cvCvtColor(img, gray, CV_BGR2GRAY);

    // This is done so as to prevent a lot of false circles from being detected
    cvSmooth(gray, gray, CV_GAUSSIAN, 7, 7);

    IplImage* canny = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
    IplImage* rgbcanny = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
    cvCanny(gray, canny, 50, 100, 3);

    //detect circles
    CvSeq* circles = cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 1, 80, 75, 60, 0, 0);
    cvCvtColor(canny, rgbcanny, CV_GRAY2BGR);

    //draw all detected circles
    for (int i = 0; i total; i++)
    {
    // round the floats to an int
    float* p = (float*)cvGetSeqElem(circles, i);
    cv::Point center(cvRound(p[0]), cvRound(p[1]));
    int radius = cvRound(p[2]);
    uchar* ptr;
    ptr = cvPtr2D(img, center.y, center.x, NULL);
    printf(“R: %d G: %d B: %d\n”, ptr[0],ptr[1],ptr[2]);
    //CvScalar c;
    //if(center.x > 0 && center.x 0 && center.y < 720)
    //{
    //c = cvGet2D(img,center.x, center.y);//colour of circle
    //}

    // draw the circle center
    cvCircle(img, center, 3, CV_RGB(0,255,0), -1, 8, 0 );

    // draw the circle outline
    cvCircle(img, center, radius+1, CV_RGB(255,255,255), 2, 8, 0 );

    //display coordinates
    printf("x: %d y: %d r: %d\n",center.x,center.y, radius);

    }

    //create window
    cvNamedWindow("circles", 1);
    cvNamedWindow("SnookerImage", 1);
    //show image in window
    cvShowImage("circles", rgbcanny);
    cvShowImage("SnookerImage", img);

    cvSaveImage("out.png", img);
    cvDestroyWindow("SnookerImage");
    cvDestroyWindow("circles");*/

    Mat src, src_gray;

    /// Read the image
    src = imread( "result.jpg", 1 );

    if( !src.data )
    { return -1; }

    /// Convert it to gray
    cvtColor( src, src_gray, CV_BGR2GRAY );

    /// Reduce the noise so we avoid false circle detection
    GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );

    vector circles;

    /// Apply the Hough Transform to find the circles
    HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );

    /// Draw the circles detected
    for( size_t i = 0; i < circles.size(); i++ )
    {
    Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
    int radius = cvRound(circles[i][2]);
    // circle center
    circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 );
    // circle outline
    circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
    }

    /// Show your results
    namedWindow( "Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE );
    imshow( "Hough Circle Transform Demo", src );
    //cvSaveImage("out.png", src);

    waitKey(0);
    return 0;

    }

    And the link for the random image which I am taking is follows:

    http://www.google.com.pk/imgres?q=red+and+blue+balls&num=10&hl=en&biw=1600&bih=809&tbm=isch&tbnid=uq7L3_jihQoNmM:&imgrefurl=http://www.shutterstock.com/pic-64567603/stock-vector-red-and-blue-balls-with-spark.html&docid=FEUYBVU9ymmSFM&imgurl=http://image.shutterstock.com/display_pic_with_logo/155329/155329,1289151548,34/stock-vector-red-and-blue-balls-with-spark-64567603.jpg&w=450&h=294&ei=UL1aUKXsIajB0QXb1IH4DA&zoom=1&iact=hc&vpx=827&vpy=115&dur=100&hovh=181&hovw=278&tx=125&ty=95&sig=113068261791983268556&page=2&tbnh=146&tbnw=195&start=30&ndsp=36&ved=1t:429,r:3,s:30,i:176

  117. Tasneem says

    Sorry the code above was a modified one. Original code is below :

    #include”math.h”
    #include”cv.h”
    #include”highgui.h”
    #include”stdio.h”
    //#include”imgproc.h”

    using namespace cv;

    int main()

    {
    int i,j,k;
    int height,width,step,channels;
    int stepr, channelsr;
    int temp=0;
    uchar *data,*datar;
    i=j=k=0;
    IplImage *frame=cvLoadImage(“ball9.jpg”,1);
    IplImage *result=cvCreateImage( cvGetSize(frame), 8, 1 );
    if(frame==NULL ) {
    puts(“unable to load the frame”);exit(0);}
    printf(“frame loaded”);
    cvNamedWindow(“original”,CV_WINDOW_AUTOSIZE);
    cvNamedWindow(“Result”,CV_WINDOW_AUTOSIZE);

    height = frame->height;
    width = frame->width;
    step =frame->widthStep;
    channels = frame->nChannels;
    data = (uchar *)frame->imageData;
    /*Here I use the Suffix r to diffenrentiate the result data and the frame data
    Example :stepr denotes widthStep of the result IplImage and step is for frame IplImage*/

    stepr=result->widthStep;
    channelsr=result->nChannels;
    datar = (uchar *)result->imageData;

    for(i=0;i < (height);i++) for(j=0;j (29+data[i*step+j*channels]))
    && ((data[i*step+j*channels+2]) > (29+data[i*step+j*channels+1])))
    datar[i*stepr+j*channelsr]=255;
    else
    datar[i*stepr+j*channelsr]=0;
    /*If you want to use cvErode you may…*/

    /*Destroying all the Windows*/
    //cvShowImage(“original”,frame);
    //cvShowImage(“Result”,result);
    cvSaveImage(“result.jpg”,result);

    //cvWaitKey(0);
    //cvDestroyWindow(“origxinal”);
    //cvDestroyWindow(“Result”);
    //int riz = detect_circles();

    IplImage* img = cvLoadImage(“result.jpg”);

    IplImage* gray = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
    CvMemStorage* storage = cvCreateMemStorage(0);

    //covert to grayscale
    cvCvtColor(img, gray, CV_BGR2GRAY);

    // This is done so as to prevent a lot of false circles from being detected
    cvSmooth(gray, gray, CV_GAUSSIAN, 7, 7);

    IplImage* canny = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
    IplImage* rgbcanny = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
    cvCanny(gray, canny, 50, 100, 3);

    //detect circles
    CvSeq* circles = cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 1, 80, 75, 60, 0, 0);
    cvCvtColor(canny, rgbcanny, CV_GRAY2BGR);

    //draw all detected circles
    for (int i = 0; i total; i++)
    {
    // round the floats to an int
    float* p = (float*)cvGetSeqElem(circles, i);
    cv::Point center(cvRound(p[0]), cvRound(p[1]));
    int radius = cvRound(p[2]);
    uchar* ptr;
    ptr = cvPtr2D(img, center.y, center.x, NULL);
    printf(“R: %d G: %d B: %d\n”, ptr[0],ptr[1],ptr[2]);
    //CvScalar c;
    //if(center.x > 0 && center.x 0 && center.y < 720)
    //{
    //c = cvGet2D(img,center.x, center.y);//colour of circle
    //}

    // draw the circle center
    cvCircle(img, center, 3, CV_RGB(0,255,0), -1, 8, 0 );

    // draw the circle outline
    cvCircle(img, center, radius+1, CV_RGB(255,255,255), 2, 8, 0 );

    //display coordinates
    printf("x: %d y: %d r: %d\n",center.x,center.y, radius);

    }

    //create window
    cvNamedWindow("circles", 1);
    cvNamedWindow("SnookerImage", 1);
    //show image in window
    cvShowImage("circles", rgbcanny);
    cvShowImage("SnookerImage", img);

    cvSaveImage("out.png", img);
    cvDestroyWindow("SnookerImage");
    cvDestroyWindow("circles");

    waitKey(0);
    return 0;
    }

    and working for the same link

  118. Michael Taylor says

    I love you man!!! I have been trying to do this with .Net

  119. samontab says

    Good to know that you got it working Michael.

  120. samontab says

    You can use pkg-config to refer to the libraries in any custom build.
    In Qt, you can specify external libraries with the LIBS variable

  121. samontab says

    Thanks Vishaal

  122. samontab says

    You are welcome Jason

  123. jedota says

    hola
    El tutorial esta increible, funcioan bien.
    Sim embargo cuando tarto de compilar los ejemplos que utilizan libfacerec no fucnioan
    Como uno libfacerec, con opencv 2.4 en ubuntu, codeblock??
    Me lanza errores por falta de libreraias…
    tengo una carpeta con opencv 2.4 y otra con libfacerec!!!

    saludos

  124. sumith says

    Hi,
    Thanks . I installed OpenCV 2.4.2 on Ubuntu 12.04 lts. It is working fine.
    But there is a problem.
    I can take images with logitech hd720p usb webcam. But when I tried to take images with econ ECAM-32 usb webcam it shows some dirty images with green color background and same object is splitted into 4. I installed opencv 2.4.2 on raspberry pi too. There, this cam is not detecting. Other ,logitech cam working well. But for opencv 2.2 both cameras are working fine.

    What I want to do? could you help me?

  125. samontab says

    https://github.com/bytefish/libfacerec
    La libreria esta integrada en OpenCV desde 2.4, no deberias tener las dos por separado.

  126. samontab says

    It seems to me that the camera is not supported by OpenCV.
    You can check this page for a list of supported devices:
    http://opencv.willowgarage.com/wiki/Welcome/OS
    Also there you may find more information about the camera drivers and configuration. Maybe you can get it to work, but I am not sure.

  127. sumith says

    Hi,
    Thank you for the information. But you mensioned that this cam may not work with openCv. But Sir, it is currently working with opencv 2.2. It shows problem with openCV 2.4.2 . I tried the same camera in ubuntu 10.04 lts system and beagleboard both having opencv 2.2.
    It failed only with opencv 2.4.2

    Could you think this one more time?

    I will add some information about this cam:
    video format: YUY2 / MJPG
    Image resolution: 640×480(default),320×240,1280×1024,1600×1200,2048×1536

  128. Kasun Chathu says

    hi i’m a final year student. as a part of my final year project i have to install ubuntu to beagleboard Xm and then opencv i some how managed to install ubuntu 11.04 and now i’m trying to install opencv.
    i followed your guide but came up with these errors in step 2
    ——>
    Package libtbb-dev is not available, but is reffered to by another package.
    this may mean that the package is missing,has been obsoleted, or is only available from another source

    E: Package ‘libtbb-dev’ has no installation candidate
    E: Unable to locate package libfacc-dev
    E: Unable to locate package libopencore-armnb-dev
    E: Unable to locate package libopencore-armnb-dev
    —————————————————————————-

    please help me.this is urgent !!!!!!!!!!!!!

  129. samontab says

    You have to test each library if there is a package for that specific distribution.
    I doubt they have the same libraries as the full desktop one has, so you may need to compile the libraries manually in some cases…

  130. samontab says

    Sorry sumith, since I don’t have the camera, or the time, I cannot help you further.
    I am sure people in the other forums that you have posted this question are more able to help you.

  131. rozek says

    Works out of the box. Great job. On windows it took me 2 days to make everything working. Here it was about an hour or two. Thanks a lot!

  132. wael says

    hi..
    i have done all the steps mentioned in your extra ordinary tutorial.
    so now i want to create my own project with code blocks using opencv. how can i do that please?

  133. samontab says

    Thanks Wael.
    You can compile your source code using cmake or g++, independent of the IDE that you use.
    Take a look at the other comments for more details.

  134. sumith says

    Hi,
    Thank you

  135. sumith says

    Hi,
    I already installed opencv 2.4.2 on my Ubuntu 12.04 lts system. But i would like to install opencv2.2.0 too. I think I should install this in any other directory. Is it posiible?

    Reason: I had opencv 2.2 on my system Ubuntu10.04 lts,and I could take images & video with econ ECAM_32 usb webcam. Now sytem had upgraded to Ubuntu 12.04lts. I couldn’t install opencv 2.2 but could installed opencv 2.4.2. But now I can’t take images with econ ECAM -32 usb webcam. Some other camera like logitech hd720p is working.

    I would like to keep opencv 2.4.2 in my sytem but I need opencv 2.2 too.

    Could you help me?

  136. samontab says

    Hello sumith,

    Yes, it is possible to have a different version of OpenCV installed in the system. Although, to prevent future headaches I recommend you that the second version is totally separated from the main installed version.

    This means that you should NOT run the command sudo make install or add it to pkg-config when compiling OpenCV 2.2. You only need to run the make command to generate the library. You will need the lib and include directories that gets generated after make.

    That way, the entire system will use OpenCV 2.4.2, or any later version if updated, without any problem and also, you will be able to link a program with OpenCV 2.2 if you need to.

    So, how do you compile a program with OpenCV 2.2 instead of 2.4.2?, well, first, make sure that you have OpenCV 2.2 built in some directory not included in the path. That means, it can be for example /opt/opencv2.2.

    Now, you just need to tell the compiler where the libraries are, and which libraries to use. For example, if you want to build one of the C examples using OpenCV 2.2, you could run this under samples/c:

    g++ morphology.c -o outputFilename -I/opt/opencv2.2/include -L/opt/opencv2.2/lib -lopencv_highgui -lopencv_core -lopencv_imgproc
    The first part, -I, tells the compiler which files to include, the headers, then, -L, tells to the linker where the libraries are, and the last part, -l, tells the linker which libraries to use. You could put there the entire list of libraries if you want. Inside the lib folder you can see all the available libraries for the specific version (/opt/opencv2.2/lib in this case). It will say something like libopencv_core.so, and many others. For including that, you just need to put -l and then the name of the library, without the beginning “lib”, and without the ending “.so”. For example in this case you would use -lopencv_core. You can add as many libraries as you want separated by a space. If you get “undefined reference…” errors, it means that you need to add more libraries.

    Well, I hope now it is clear how to link against OpenCV manually, or any other library actually.

    I hope I could be of any help.

  137. samontab says

    You are very welcome rozek

  138. sumith says

    Hi,
    Yes, nice help.
    But I am sorry, I could not run ‘make’ command successfully. It exits with same errors after 39% or sometimes 41% or while retrying 44% . I could not understand why such errors. I searched in the internet and got reply as to run sudo apt-get update & sudo apt-get upgrade .But still no improvement. I think it is due to missing some dependencies. But i had never got anything else to replace that.

    This was the case when I installed opencv 2.2. But 2.3 showed no problem. I hope you can help me .

    Oh, sorry, to catch your attension I had posted the same in the previous blog-installing opencv 2.2 on ubuntu 11.04.

  139. samontab says

    Could you share with us those “same errors”?, without them, I really doubt anyone can help you.

  140. sumith says

    Hi,
    These are the errors while running ‘make’ command. It exit after 40%

    [ 41%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/convert.o
    In file included from /home/ni2/OpenCV-2.2.0/modules/core/src/precomp.hpp:55:0,
    from /home/ni2/OpenCV-2.2.0/modules/core/src/convert.cpp:43:
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:354:13: error: ‘ptrdiff_t’ does not name a type
    In file included from /home/ni2/OpenCV-2.2.0/modules/core/src/precomp.hpp:55:0,
    from /home/ni2/OpenCV-2.2.0/modules/core/src/convert.cpp:43:
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2600:13: error: ‘ptrdiff_t’ does not name a type
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2623:24: error: declaration of ‘operator[]’ as non-function
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2623:22: error: expected ‘;’ at end of member declaration
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2623:34: error: expected ‘)’ before ‘i’
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2626:36: error: declaration of ‘operator+=’ as non-function
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2626:32: error: expected ‘;’ at end of member declaration
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2626:46: error: expected ‘)’ before ‘ofs’
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2628:36: error: declaration of ‘operator-=’ as non-function
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2628:32: error: expected ‘;’ at end of member declaration
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2628:46: error: expected ‘)’ before ‘ofs’
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2641:5: error: ‘ptrdiff_t’ does not name a type
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2642:15: error: ‘ptrdiff_t’ has not been declared
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2661:13: error: ‘ptrdiff_t’ does not name a type
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2684:21: error: ‘ptrdiff_t’ has not been declared
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2687:37: error: declaration of ‘operator+=’ as non-function
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2687:33: error: expected ‘;’ at end of member declaration
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2687:47: error: expected ‘)’ before ‘ofs’
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2689:37: error: declaration of ‘operator-=’ as non-function
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2689:33: error: expected ‘;’ at end of member declaration
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2689:47: error: expected ‘)’ before ‘ofs’
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2733:22: error: declaration of ‘operator[]’ as non-function
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2733:20: error: expected ‘;’ at end of member declaration
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2733:32: error: expected ‘)’ before ‘i’
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2736:32: error: declaration of ‘operator+=’ as non-function
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2736:28: error: expected ‘;’ at end of member declaration
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2736:42: error: expected ‘)’ before ‘ofs’
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2738:32: error: declaration of ‘operator-=’ as non-function
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2738:28: error: expected ‘;’ at end of member declaration
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:2738:42: error: expected ‘)’ before ‘ofs’
    In file included from /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:4047:0,
    from /home/ni2/OpenCV-2.2.0/modules/core/src/precomp.hpp:55,
    from /home/ni2/OpenCV-2.2.0/modules/core/src/convert.cpp:43:
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/operations.hpp:2822:15: error: ‘ptrdiff_t’ does not name a type
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/operations.hpp:3383:31: error: ‘ptrdiff_t’ does not name a type
    In file included from /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp:4048:0,
    from /home/ni2/OpenCV-2.2.0/modules/core/src/precomp.hpp:55,
    from /home/ni2/OpenCV-2.2.0/modules/core/src/convert.cpp:43:
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/mat.hpp:1629:57: error: declaration of ‘operator+=’ as non-function
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/mat.hpp:1629:57: error: ‘ptrdiff_t’ was not declared in this scope
    /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/mat.hpp:1629:57: note: suggested alternatives:
    /usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:156:28: note: ‘std::ptrdiff_t’
    /usr/include/c++/4.6/i686-linux-gnu/./bits/c++config.h:156:28: note: ‘std::ptrdiff_t’
    In file included from /usr/include/tbb/tbb_exception.h:118:0,
    from /usr/include/tbb/concurrent_vector.h:33,
    from /usr/include/tbb/enumerable_thread_specific.h:32,
    from /usr/include/tbb/combinable.h:32,
    from /usr/include/tbb/tbb.h:46,
    from /home/ni2/OpenCV-2.2.0/modules/core/include/opencv2/core/internal.hpp:129,
    from /home/ni2/OpenCV-2.2.0/modules/core/src/precomp.hpp:57,
    from /home/ni2/OpenCV-2.2.0/modules/core/src/convert.cpp:43:
    /usr/include/c++/4.6/typeinfo:42:37: error: expected ‘}’ before end of line
    /usr/include/c++/4.6/typeinfo:42:37: error: expected declaration before end of line
    make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/convert.o] Error 1
    make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
    make: *** [all] Error 2

    Hope you can detect the problem.

  141. sumith says

    Hi,
    I have a good news. I can take images and video with econ ECAM_32 cam module with opencv 2.3 and opencv 2.4.2 on my ubuntu 12.04 lts system. I just set the capturing width and height as 320×240 and frame rate 24. Now only one problem remains before me,how can I achieve the same on my raspberry pi? Many many thanks to your help.

  142. samontab says

    I think I found the solution.

    This was a bug from version 2.1.
    You need to add this line using std::ptrdiff_t; to the file cxcore.hpp.

    Please note that since then they have changed the structure of the files, so maybe you have to add that line in another file, depending on the actual version you are using. For example, on 2.4.1, this line is already added, but in modules/core/include/opencv2/core/core.hpp

    Here are more details. Vadim Pisarevsky himself notes that the bug has been solved in the trunk, so I guess the changes may already be there in 2.2, or maybe 2.3
    http://web.archiveorange.com/archive/v/b6fbFdu0fh9uQC9aVdpF

  143. samontab says

    Good to know, I hope you can get everything to work with my last comment.

  144. sumith says

    Hi,
    I am sorry only 73% executed. I got error:
    Linking CXX executable ../../bin/opencv_createsamples
    ../../lib/libopencv_highgui.so.2.2.0: undefined reference to `cvCreateCameraCapture_V4L(int)’
    collect2: ld returned 1 exit status
    make[2]: *** [bin/opencv_createsamples] Error 1
    make[1]: *** [modules/haartraining/CMakeFiles/opencv_createsamples.dir/all] Error 2
    make: *** [all] Error 2

    I tried to solve the problem following
    Ref:’ https://code.ros.org/trac/opencv/changeset/5206
    https://code.ros.org/trac/opencv/ticket/324

    What I do next?

  145. sumith says

    Hi,
    I could install opencv 2.2 on my system. Sorry to post the above question. I could resolved the problem, I just deactivated the
    #if !defined WIN32 && defined HAVE_CAMV4L && defined HAVE_CAMV4L2 && defined HAVE_LIBV4L of file cap_libv4l.cpp
    and add
    #if !defined WIN32 && defined HAVE_LIBV4L
    Thus it works.

    Thank you very much for your support.

    Ref:’ https://code.ros.org/trac/opencv/changeset/5206
    https://code.ros.org/trac/opencv/ticket/324
    http://web.archiveorange.com/archive/v/b6fbFdu0fh9uQC9aVdpF

  146. samontab says

    You are very welcome.
    It is great to know that you managed to install OpenCV 2.2 on the raspberry pi.
    Have fun with it now!

  147. sumith says

    Hi,
    For raspberry pi the dependencies are different. So I am searching for dependencies without that I can’t install opencv 2.2 on raspberry pi.

  148. MAX2187 says

    Hi very nice tutorial, but I need some help from you if its possible
    I type this:
    1 cd ~
    2 wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.1/OpenCV-2.4.1.tar.bz2
    3 tar -xvf OpenCV-2.4.1.tar.bz2
    4 cd OpenCV-2.4.1

    then I type : mkdir build
    but it seems to be that the next step is another, what should I do??

  149. samontab says

    I don’t understand where the problem is. You are correctly following the tutorial, just continue…

  150. samontab says

    Ah, OK, good luck with that!

  151. Diana says

    Hi

    Can I follow this tutorial to install openCV 2.4.2 on Ubuntu 12.10 ?

    I will do stitching and other image/video processing…. do I need to install anything else?

    it don’t reconize –libs when I do g++ example.cpp -o example pkg-config –cflags –libs opencv :(

  152. samontab says

    Hello Diana,

    Yes, you should be able to install OpenCV 2.4.2 on Ubuntu 12.10, just change the commands accordingly.
    For what you want to do it seems that OpenCV is all that you will need.
    About your error, it looks to me that you are not using the correct symbols (you are missing the `s), try copy pasting it.
    g++ -o example example.cpp `pkg-config --libs --cflags opencv`

  153. Ike says

    Hi I have been following the steps but when i try to build samples, i get this error:
    Perhaps you should add the directory containing `opencv.pc’
    to the PKG_CONFIG_PATH environment variable
    No package ‘opencv’ found
    mushroom.cpp:1:33: fatal error: opencv2/core/core_c.h: No such file or directory
    compilation terminated.
    compiling one_way_sample.cpp
    Package opencv was not found in the pkg-config search path.

  154. Giri says

    Hi,
    cd ~/OpenCV-2.4.1/samples/c
    bash: cd: /home/prasad/OpenCV-2.4.1/samples/c: Not a directory

    when i execute i got tis error. what should i do pls help

  155. Giri says

    hi,
    i manually created c directory under openCV/samples after i proceed to next line from your tutorial
    chmod +x build_all.sh
    chmod: cannot access `build_all.sh': No such file or directory
    i got tis error wat should i do now

  156. Karthikeyan says

    Hi,
    Thanks for solving many others problem by providing clear instructions.
    The same instructions are working for Opencv 2.4.3 with Ubuntu 12.04LTS.

  157. Diana says

    yes, that was the problem

    Thanks

  158. samontab says

    Good to know that your problem is now solved Diana.

  159. samontab says

    Hello Karthikeyan,

    You are welcome!, great to know that this guide also works for that version.

  160. samontab says

    Hello Giri,

    You do not need to manually create the c directory, it should be there already.
    It looks to me that you did not correctly configure the library before compiling it, so the samples were not built.
    Try following the tutorial carefully, specially in the configuration part (where you use cmake) and you should have everything working perfectly.

  161. samontab says

    As I said before, it looks to me that you did not correctly configure the library before compiling it, so the samples were not built.
    Try following the tutorial carefully, specially in the configuration part (where you use cmake) and you should have everything working perfectly.

  162. samontab says

    Hello Ike,

    I think that you missed the final steps where OpenCV gets configured for pkg-config. Read that part again, from the line that says this:
    “Now you have to configure OpenCV. First, open the opencv.conf file with the following code:”

  163. Giri says

    HI
    thank u for ur reply.
    again i got struck at
    ~/OpenCV-2.4.1/build$ make
    make: *** No targets specified and no makefile found. Stop.
    what should i do now

  164. samontab says

    It means that the cmake step was not done correctly.

  165. Valentin says

    Hi, and thanks for the great tutorial!

    I successfully followed all steps and managed to install the library. However, when I try to run the build_all.sh script, I get the following errors:
    — /usr/local/include/opencv2/core/types_c.h:303: error: undefined reference to ‘lrint’
    — usr/local/include/opencv2/nonfree/nonfree.hpp:46:42: fatal error: opencv2/nonfree/features2d.hpp: No such file or directory

    I am not sure what is causing the first one, but the second one looks like a result from moving the SIFT/SURF algorithms to the new nonfree module, which for some reason is not installed on my system (I checked /usr/local/include & /usr/local/lib). I went through the CMakeLists.txt file and there seem to be no specific install option for it. What am I missing, and how should one install the nonfree module? Do you have any pointers about the other error?

    Thanks in advance for your time!

  166. samontab says

    Hello Valentin,

    That seems weird. Try copy pasting every line for the tutorial.
    Make sure that you follow all the steps until the end, one by one without skipping any one.
    The non free module is just a part of the library, so you should have it already, no need to install anything else.

    What is your output of pkg-config --libs opencv

  167. aza says

    hi samontab..
    i got an error when i install this opencv refered on your tutorial..the error appear at
    cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

    the result i get
    — Configuring incomplete, errors occurred!

    i hope u can help me please..
    tq

  168. Valentin says

    Thanks for your reply! I actually tried re-installing the library this morning and everything worked fine.

    As they say — the morning, is wiser than the evening :) Thanks again for your time.

  169. samontab says

    Hello Aza,

    I think that may be caused because you missed to install some of the required libraries. As usual, try to start from the beginning again, step by step, copy pasting every command and not skipping any of them, and it should work.

  170. samontab says

    Great Valentin!

  171. Giri says

    hi samontab,
    finally i installed with the help of ur tutorial. Thankyou lot for ur guidance and awesome tutorial.

  172. Wem says

    Hi!

    I have a problem with instalation the libgtk2.0-dev in my ubuntu 12.10. I can’t install that, because, as he says, libglib2.0-dev, libgdk-pixbuf2.0-dev, libpango1.0-dev, libatk1.0-dev, libatk1.0-dev is needed. Okey but I can’t install any of them, them want other packages, and the problem become looped.

  173. samontab says

    Hi Wem,

    I recommend you to just copy and paste the instructions, it will work. The program I used is the standard apt-get so it will install all the required dependencies.
    I actually followed these instructions on Ubuntu 12.10 installing OpenCV 2.4.3 and they worked perfectly. Give it another try.

    PS: Are you from Tokelau?? that would be awesome :)

  174. Wem says

    Thanks for quick reply.

    If so I think I’ve damaged my Ubuntu. I should now restore what i can.
    No, I’m not from Tokelau, I just use the tk domain. It is free and pretty(in my opinion).
    I come only from Poland. :)

  175. samontab says

    Hey Wem,

    I recommend you to start from a fresh install to avoid problems.

  176. Wem says

    I’ve found a solution. I’ve just installed the CV with QT(like here: http://karytech.blogspot.com/2012/05/opencv-24-on-ubuntu-1204.html), not with GTK

  177. samontab says

    Great to hear that Wem

  178. Sam says

    hey,
    thanx for the awesome tutorial..
    when i m trying to open the examples using the code you gav, its showing, no such directory exists.
    please help

  179. Cesco says

    Que Tal, Sebastian. Tremendo Tutorial.

    Thank you for sharing it with us, it simplified my life quite a lot. I wanted to ask you one thing, I am able to run most of the examples using the

    ~/OpenCV-2.4.3/build/bin/calibration_artificial
    ~/OpenCV-2.4.3/build/bin/grabcut ~/OpenCV-2.4.3/samples/cpp/lena.jpg

    commands with no problems. But when I try your first examples

    ./facedetect –cascade=”/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml” –scale=1.5 lena.jpg

    I get the following error:

    cesco@ubuntu:~$ ~/OpenCV-2.4.3/build/bin/Example2
    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/cesco/OpenCV-2.4.3/modules/highgui/src/window.cpp, line 602
    terminate called after throwing an instance of ‘cv::Exception’
    what(): /home/cesco/OpenCV-2.4.3/modules/highgui/src/window.cpp:602: 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 (core dumped)

    When I try to download the
    install libgtk2.0-dev and pkg-config,

    , it tells me that I already have installed the newest version. I have tried everything, and gone on every forum to no avail. Can you see where I am going wrong, and please let me know. I am running ubuntu on 64 bits.
    And again thank you very much for a very informative, and very thorough tutorial.

  180. samontab says

    Thanks Cesco,

    Regarding your issue, I think it is very strange. Maybe you are using a different version of Ubuntu?. I tested it downloading Ubuntu and doing everything from scratch and it worked. Worst case scenario for you would be to start from scratch, but I can assure you that it will work :)

    Another option is to follow what Wem did, which was following these instructions:
    http://karytech.blogspot.com/2012/05/opencv-24-on-ubuntu-1204.html

    I have not tried it, but it seems that Wem was having a similar issue and he was able to solve it using that link.

    I hope you can fix it.

  181. ol says

    Guys,
    I have no idea what to do, my opencv seems to be installed (or not) because I have a good old error,

    python ~/OpenCV-2.4.1/samples/python2/turing.py
    Traceback (most recent call last):
    File “/home/ubuntu/OpenCV-2.4.1/samples/python2/turing.py”, line 9, in
    import cv2
    ImportError: No module named cv2
    and it doesn’t work with my code as well (but I see Lenas pic)
    please help me what to do!

  182. samontab says

    Hello ol,

    It seems that you did not install the python bindings.
    Make sure that on the cmake step you have enabled python (BUILD_NEW_PYTHON_SUPPORT=ON).

    Also, do you have numpy installed?

  183. ol says

    yepst, numpy is installed, and yes as see: (BUILD_NEW_PYTHON_SUPPORT=ON). on the cmake step, what I am doing wrong ;-(

  184. samontab says

    mmm, it should be working.

    Look at this folder:

    /usr/local/lib/python2.7/dist-packages

    You should have at least cv2.so, cv.pyc, and cv.py there.
    If you don’t have them, copy them from the OpenCV directory, and it may work.

  185. ol says

    samontab thanks for a quick answer but I will check it tomorrow, because here where i am is a late night and I am dying, but please let me know if there is any way to talk to you for example via email or skype (we can write :)
    thanks in advance

  186. ol says

    hey,
    it is me again, so no such files in this directory, and when I trying to copy and paste some info from my sys appears: There was an error moving the file into /. ehhh

  187. samontab says

    OK ol, since the files are not there, it means that the python bindings were not installed.
    You can try a quick and dirty solution. Try running this to manually copy the files.

    sudo cp ~/OpenCV-2.4.1/build/lib/cv2.so /usr/local/lib/python2.7/dist-packages/
    sudo cp ~/OpenCV-2.4.1/modules/python/src2/cv.py /usr/local/lib/python2.7/dist-packages

    If that does not work, just re install everything from scratch following the instructions carefully, using the same version of Ubuntu and OpenCV as described in the tutorial.

  188. Felipe Guth says

    Thank you very much!
    It was very usefull.

  189. samontab says

    Thanks Felipe!

  190. lakshmi kumar says

    Dear Sebastian,

    FIrst of all, Thank you tons for the wonderful tutorial.

    cmake: command not found.

    I tred to install every possible cmake but I am not able to install cmake completely. Each time I have a problem installing. Can you please help me in downloading the right cmake installing file.

    your effort is greatly appreciated.

  191. samontab says

    Hello lakshmi,

    If you follow the tutorial step by step, then cmake should already be installed in your system. You can see that cmake is included in the list of libraries installed at the first step.
    In any case, if you are using Ubuntu you should be able to install cmake with this command:

    sudo apt-get install cmake

    But I suggest you to go ahead and start from the beginning of the tutorial to get everything correctly installed.

  192. wan says

    thank for the tutorial. it a great help. but i try to run several of your tutorial. but i get thi:
    Traceback (most recent call last):
    File “facedetect.py”, line 63, in
    cascade = cv.Load(options.cascade)
    TypeError: OpenCV returned NULL

    can ur help me.

  193. samontab says

    Hello wan,

    The most probable cause of that error is that the path of the trained file (the .xml file) is wrong.
    Check the source code of facedetect.py and you will see this path:

    cascade_fn = args.get('--cascade', "../../data/haarcascades/haarcascade_frontalface_alt.xml")
    nested_fn = args.get('--nested-cascade', "../../data/haarcascades/haarcascade_eye.xml")

    Make sure that the path is correct. Try changing it to where you have those files in your computer. Maybe it is easier for you to use an absolute path, something like /home/username/opencv/data/haarcascades/haarcascade_frontalface_alt.xml for example, so it does not matter where your program is run, it will always get the correct file. In the current code, it looks for the data folder in two directories up in the hierarchy, so that may be your problem.

  194. wan says

    thanks sebastian

  195. Vitalij says

    Hello!
    I compiled the latest ffmpeg at my own and installed the latest opencv on Ubuntu 12.04LTS, but when i try to run some of examples i get error that proramm needs libav*****.so.54 and i have *.53. Couldn’t find a solution, maybe you know??

  196. samontab says

    Hello Vitalij,

    You need to be careful when compiling your own ffmpeg libraries, since some of them are not compatible, and also you need to use special flags in the compilation to make it work with other libraries.

    I suggest you to follow the instructions in this post instead, but if you still want to build your own ffmpeg libraries, feel free to follow the instructions I provided for an earlier version of OpenCV:
    http://www.samontab.com/web/2011/06/installing-opencv-2-2-in-ubuntu-11-04/
    Try to use those flags for compiling ffmpeg, and see if it works, but as I said, I think it is easier to just install the ones from the repository.

  197. Talaat says

    It was very helpful for me…but how can I access an IP cam from open cv
    I would be grateful if you could help me.

    thanks

  198. samontab says

    Hello tallat,
    OpenCV does not have a native function for dealing with IP cameras. You will need to write your own functions to access each frame of the camera. That functionality may differ from camera to camera, but the simplest way would be to save a jpg from the camera and then open it with opencv. Although this is slow, it will get you job done easily. You can later improve on that.

  199. Adrian says

    Hello,
    I got the following error:
    Illegal instruction (core dumped)

    This happen when I try to run any sample after OpenCV 2.4.1 installation. I have followed all the steps from this tutorial, and tried with more versions of OpenCV but the I got the same error.

    Does anyone have any idea why I got this error?

    Thanks

  200. samontab says

    Hello Adrian,

    It can be a lot of things. First, run the debugger to have an idea of what is happening.

    First, install gdb, in case you don’t already have it:
    sudo apt-get install gdb
    Now, compile one of the programs that is having the problem with the debug flag (just add -g to the compilation line).
    Well, all the c examples are already compiled with that option, so go there and pick one of those.
    cd ~/OpenCV-2.4.1/samples/c
    Run an example there that creates an illegal instruction (remember to change the example name):
    ./example
    Now run it with the debugger:
    gdb example core
    And it will tell you what is happening.

    You can learn more about debugging your programs here with gdb:
    http://cs.baylor.edu/~donahoo/tools/gdb/tutorial.html

  201. Adrian says

    Hi Samontab,

    when I try to debug, I got the following:
    cody@cody-pc:~/OpenCV-2.4.1/samples/c$ gdb delaunay core
    GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
    Copyright (C) 2012 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law. Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "i686-linux-gnu".
    For bug reporting instructions, please see:
    ...
    Reading symbols from /home/cody/OpenCV-2.4.1/samples/c/delaunay...done.
    /home/cody/OpenCV-2.4.1/samples/c/core: No such file or directory.
    (gdb)

    So the core dump file isn’t generated.

    Also I might have some problems with some library because when I try to compile I get the following undefined references:
    cody@cody-pc:~/OpenCV-2.4.1/samples/c$ g++ delaunay.c -g -o test
    /tmp/cc2VYR3V.o: In function `init_delaunay(CvMemStorage*, CvRect)':
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:25: undefined reference to `cvCreateSubdiv2D'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:26: undefined reference to `cvInitSubdivDelaunay2D'
    /tmp/cc2VYR3V.o: In function `draw_subdiv_point(_IplImage*, CvPoint2D32f, CvScalar)':
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:34: undefined reference to `cvCircle'
    /tmp/cc2VYR3V.o: In function `draw_subdiv_edge(_IplImage*, unsigned int, CvScalar)':
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:57: undefined reference to `cvLine'
    /tmp/cc2VYR3V.o: In function `draw_subdiv(_IplImage*, CvSubdiv2D*, CvScalar, CvScalar)':
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:69: undefined reference to `cvStartReadSeq'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:81: undefined reference to `cvChangeSeqBlock'
    /tmp/cc2VYR3V.o: In function `locate_point(CvSubdiv2D*, CvPoint2D32f, _IplImage*, CvScalar)':
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:93: undefined reference to `cvSubdiv2DLocate'
    /tmp/cc2VYR3V.o: In function `draw_subdiv_facet(_IplImage*, unsigned int)':
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:138: undefined reference to `cvFillConvexPoly'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:139: undefined reference to `cvPolyLine'
    /tmp/cc2VYR3V.o: In function `paint_voronoi(CvSubdiv2D*, _IplImage*)':
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:151: undefined reference to `cvCalcSubdivVoronoi2D'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:153: undefined reference to `cvStartReadSeq'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:169: undefined reference to `cvChangeSeqBlock'
    /tmp/cc2VYR3V.o: In function `run()':
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:189: undefined reference to `cvCreateImage'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:190: undefined reference to `cvSet'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:192: undefined reference to `cvNamedWindow'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:194: undefined reference to `cvCreateMemStorage'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:206: undefined reference to `cvShowImage'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:208: undefined reference to `cvWaitKey'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:211: undefined reference to `cvSubdivDelaunay2DInsert'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:212: undefined reference to `cvCalcSubdivVoronoi2D'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:213: undefined reference to `cvSet'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:215: undefined reference to `cvShowImage'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:217: undefined reference to `cvWaitKey'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:221: undefined reference to `cvSet'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:223: undefined reference to `cvShowImage'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:225: undefined reference to `cvWaitKey'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:227: undefined reference to `cvReleaseMemStorage'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:228: undefined reference to `cvReleaseImage'
    /home/cody/OpenCV-2.4.1/samples/c/delaunay.c:229: undefined reference to `cvDestroyWindow'
    collect2: ld returned 1 exit status

    Do I have to install other library or a something? I have tried with OpenCV 2.4.3 and I got the same errors. Also I read on some forum that it can be because of my AMD processors. Is that possible?

    Thanks

  202. Adrian says

    ok, I compile using th pkg-config and I didn’t had the errors but has no effect after compiling:
    cody@cody-pc:~/OpenCV-2.4.1/samples/c$ g++ `pkg-config --cflags opencv` -o hello delaunay.c `pkg-config --libs opencv`
    cody@cody-pc:~/OpenCV-2.4.1/samples/c$ ./delaunay
    Illegal instruction (core dumped)
    cody@cody-pc:~/OpenCV-2.4.1/samples/c$ gdb delaunay core
    GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
    Copyright (C) 2012 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law. Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "i686-linux-gnu".
    For bug reporting instructions, please see:
    ...
    Reading symbols from /home/cody/OpenCV-2.4.1/samples/c/delaunay...done.
    /home/cody/OpenCV-2.4.1/samples/c/core: No such file or directory.
    (gdb)quit
    cody@cody-pc:~/OpenCV-2.4.1/samples/c$ gdb delaunay
    GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
    Copyright (C) 2012 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law. Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "i686-linux-gnu".
    For bug reporting instructions, please see:
    ...
    Reading symbols from /home/cody/OpenCV-2.4.1/samples/c/delaunay...done.
    (gdb)(gdb) b 1
    Breakpoint 1 at 0x804a26c: file delaunay.c, line 1.
    (gdb) run
    Starting program: /home/cody/OpenCV-2.4.1/samples/c/delaunay
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".

    Program received signal SIGILL, Illegal instruction.
    0xb7a503ec in cv::initInterTab2D(int, bool) () from /usr/local/lib/libopencv_imgproc.so.2.4
    (gdb)

    The above error after the breakpoint means that there are some issues on the include files. Any idea?

    Thanks,
    Adrian

  203. samontab says

    Adrian, you forgot to add the -g flag when compiling to see more information:
    g++ -g `pkg-config --cflags opencv` -o hello delaunay.c `pkg-config --libs opencv`\
    Maybe it will add more useful information.

  204. Adrian says

    Hi Sebastian,
    I tried again with -g flag, but same thing:
    cody@cody-pc:~/OpenCV-2.4.1/samples/c$ g++ -g `pkg-config --cflags opencv` -o hello delaunay.c `pkg-config --libs opencv`
    cody@cody-pc:~/OpenCV-2.4.1/samples/c$ ./delaunay
    Illegal instruction (core dumped)
    cody@cody-pc:~/OpenCV-2.4.1/samples/c$ gdb delaunay
    GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
    Copyright (C) 2012 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law. Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "i686-linux-gnu".
    For bug reporting instructions, please see:
    ...
    Reading symbols from /home/cody/OpenCV-2.4.1/samples/c/delaunay...done.
    (gdb) b 1
    Breakpoint 1 at 0x804a260: file delaunay.c, line 1.
    (gdb) run
    Starting program: /home/cody/OpenCV-2.4.1/samples/c/delaunay
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".

    Program received signal SIGILL, Illegal instruction.
    0xb7a4f3ec in cv::initInterTab2D(int, bool) () from /usr/local/lib/libopencv_imgproc.so.2.4
    (gdb) bt
    #0 0xb7a4f3ec in cv::initInterTab2D(int, bool) () from /usr/local/lib/libopencv_imgproc.so.2.4
    #1 0xb796a85d in _GLOBAL__sub_I_imgwarp.cpp () from /usr/local/lib/libopencv_imgproc.so.2.4
    #2 0xb7fece9b in ?? () from /lib/ld-linux.so.2
    #3 0xb7fecf84 in ?? () from /lib/ld-linux.so.2
    #4 0xb7fdf20f in ?? () from /lib/ld-linux.so.2

    It could be from the libopencv_imgproc.so.2.4 library? because the compiling didn’t throw any errors.
    Or do you know if OpenCV have some issues with some hardware? I am using an SUN workstation: 2 x AMD Opteron Processor 64bit (2.4Ghz each), 8GB RAM, video ASUS AH3450 from ATI (512MB), OS: Ubuntu 12.04 32bit. I suppose that could be because of my video card having only 512MB or because AMD processor?

    Anyway, I don’t want to install Windows 7 just for this issue because I saw that OpenCV is more used on windows OS with Visual Studio, but if I have to, I will install Win and try to see if I have any issues.

    Any advise is useful.

    Thanks,
    Adrian

  205. samontab says

    Adrian,

    I think that the illegal instruction is because of some flag used in the compilation that is not supported by your opteron processor. All these instructions assumed regular desktop pcs, not servers. I thought it would just work with them too, but it seems there is a small problem.

    You can try disabling some (or all) features in the compilation and try again to see which is the illegal instruction.

  206. Adrian says

    Hi Sebastian,

    After 3 days, I finally installed opencv using your last advice, to compile it without any params. I’m not sure if this was the resolution because first time when I compile it I compiled it only with CMAKE_BUILD_TYPE=DEBUG and I got the error (maybe this was the problem), but your advice helped me and guided me for the right way. I had some issues with some of the libraries and I had to remove most of them and reinstall them because durring the library installation an unexpected power break happen. Anyway, I also installed gmone shell and fooling around with the libraries and installed/removed/reinstalled some libs and it finally works.

    Thanks again for all the support and I may ask you more questions about opencv in the future if I will have some major problems.

    Thanks again and best regards,
    Adrian

  207. samontab says

    Great to hear that, Adrian. I am glad that you were able to finally install OpenCV in your server.
    Feel free to ask anything in the future.

  208. vineet says

    A wonderful post no doubt.
    It was really an awesome experience to install opencv and being able to use it.
    just face one last hiccup:
    I am able to compile and run a simple opencv program using the commands as mentioned.
    But now when i try to do same using eclipse, i begin to face problem. in the eclipse settings i have specified c++ compiler flag as `pkg-config –cflags opencv` and linker flag as `pkg-config –libs opencv` . The compiler goes through well, but i get linker errors.
    Please suggest some solution.

  209. samontab says

    Hello Vineet,

    Thanks for your comment, it’s great to hear that OpenCV was correctly installed in your system.

    About your question, it seems that Eclipse CDT is not ready for pkg-config yet.
    You can download and install this plugin to add pkg-config functionality to Eclipse CDT:
    http://code.google.com/p/pkg-config-support-for-eclipse-cdt/downloads/list
    Or install it directly from here by dragging this image to your Eclipse window:



    That way, you should be able to tell Eclipse that you want to use OpenCV through pkg-config.

    Also, as an alternative you can use Netbeans which receives custom build options such as pkg-config out of the box.

  210. dhanesh says

    you’re awesome sabestian…..

  211. dhanesh says

    very nicely elaborated and executed too. thanks

  212. mauracio says

    hi,
    i’m using some opencv libraries in a qt program i’m writtng.
    here is the problem. everytime i try to add an image to process it in my program i get message:
    “warning: application built with libpng-1.2.49 but running with 1.5.12″
    and the application crashes.
    i dont know what to do about it. help please?

  213. samontab says

    Hi mauracio,

    Try loading the PNG to memory using the other library (both can read PNG), and then convert the image to the other format.

    For Qt it would be something like this:

    QPixmap pngImage;
    pngImage.load("filename.png");
    

    And for OpenCV it would be something like this:

    Mat pngImage;
    pngImage = imread("filename.png");
    

    And here is some code for converting the older interface (Iplimage) to Qt and vice versa. It should be easy to adapt it to the new interface.
    http://www.developer.nokia.com/Community/Wiki/Using_OpenCV_with_Qt

    If that does not work, you can always first change the format from PNG to other, like JPG using imagemagick, and then load the JPG file instead:

    convert filename.png filename.jpg
  214. samontab says

    Thank you very much dhanesh!

  215. Anto says

    Hi! Very good and clear tutorial, thank you!
    It seems work with your examples, but, if I want to use OpenCV library with eclipse, after including the path in Linker and compiler I receive this error:

    “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/antospax/opencv/opencv/modules/highgui/src/window.cpp, line 469
    terminate called after throwing an instance of ‘cv::Exception’
    what(): /home/antospax/opencv/opencv/modules/highgui/src/window.cpp:469: 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 ”

    But I have bulded the library with the last version of GTK and libgtk, I am on Ubuntu 12:10…could you help me? I tried to rebuild twice..always the same problems…

    thankyou

  216. samontab says

    Hello Anto,

    I am glad that OpenCV is working in your system.

    About your question, it seems that Eclipse CDT is not ready for pkg-config yet.
    You can download and install this plugin to add pkg-config functionality to Eclipse CDT:
    http://code.google.com/p/pkg-config-support-for-eclipse-cdt/downloads/list
    Or install it directly from here by dragging this image to your Eclipse window:



    That way, you should be able to tell Eclipse that you want to use OpenCV through pkg-config.

    Also, as an alternative you can use Netbeans which receives custom build options such as pkg-config out of the box.

  217. Anto says

    Unfortunately It doesn’t work even if with the plug-in…always the same errors! I’m tring with Netbeans…I’ll let you know.. thank you for all your support in the mean time..

  218. samontab says

    That is strange Anto.

    You can try using the output of pkgconfig in Eclipse:
    These are for the include part:
    -I/usr/local/include/opencv -I/usr/local/include
    And these are for the linker:
    /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so

  219. Anto says

    Incredible!! I received the same error from NetBeans…:

    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/antospax/opencv/opencv/modules/highgui/src/window.cpp, line 469
    terminate called after throwing an instance of ‘cv::Exception’
    what(): /home/antospax/opencv/opencv/modules/highgui/src/window.cpp:469: 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
    RUN FAILED (exit value 1, total time: 1s)

    But since I do the procedure twice I suppose everything is good…and your example with calib3d works well! I don’t really know what do..I am not so good with Ubuntu…

  220. samontab says

    Anto,

    Please try to compile your code in the command line. If it works there, it should work on Eclipse and Netbeans, they do not provide anything extra than the command line in the compiling and linking stage.
    I am assuming that you are not entering the correct information in your editors.

    For a simple test, please write some code in main.cpp file, and run the following in your command line:
    g++ -o test main.cpp `pkg-config --libs --cflags opencv`

    It should compile correctly, and you can then execute it with:

    ./test

    Make sure that everything is OK. Then, you can just do the same in Netbeans, or Eclipse. The compilation should be the same. You just need to put the include and libraries information correctly in your IDE.

  221. Anto says

    Have a look! I receive the same error also from the terminal, using g++, so the problem is huger, it isn’t in Eclipse or Netbeans…uhm..I will try to complete once again the whole procedure.:( Just one more question, do you suggest me to delete all the files regarding opencv before starting again the procedure? Sorry for my English..

    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/antospax/opencv/opencv/modules/highgui/src/window.cpp, line 469
    terminate called after throwing an instance of ‘cv::Exception’
    what(): /home/antospax/opencv/opencv/modules/highgui/src/window.cpp:469: 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

    Anyway…the example with calib works well…mah..
    thank you again

  222. samontab says

    Anto,

    I guess that you are not using the correct line for compiling.

    Can you compile the provided C examples? Let’s test that:
    Go to where the c samples are (the path may be different in your machine):
    cd ~/opencv/samples/c
    And now compile the examples:
    chmod +x build_all.sh
    ./build_all.sh

    They should compile correctly. Now run some of the samples, like this for example:
    ./contours
    If everything works, it means that OpenCV is correctly installed and that your program should work.
    Make sure that you copy and paste the compilation command for your program, specially this symbol (`):
    g++ -o test main.cpp `pkg-config --libs --cflags opencv`

  223. Anto says

    I’ve tried as you told me. All of the example have been compiled well, but I couldn’t execute the example contours : I recevived always the same error, as I copied below.
    I don’t want make you to waste your time…I’d like to solve the problem, but don’t worry if it is tooo big!

    ./contours
    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/antospax/opencv/opencv/modules/highgui/src/window.cpp, line 469
    terminate called after throwing an instance of ‘cv::Exception’
    what(): /home/antospax/opencv/opencv/modules/highgui/src/window.cpp:469: 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

  224. samontab says

    Anto,

    There seems to be a problem on your installation. Maybe you did not install something, or skipped a step or two. Make sure that you have the same version of Ubuntu, 12.04. And also make sure that the first list of libraries at the beginning gets correctly installed (specially libgtk2.0-dev). If you have a different version of Ubuntu, I also have guides for other versions, take a look around my blog.

    Please re install the library carefully following each one of the steps of the tutorial exactly. It should work, as I have tested it many times, as well as many others.

  225. Bruno says

    Hi Sebastian, thanks for the awesome tutorial. I am triing to send frames over udp with opencv by reading and writing jpg images, it is not the best way to do it but teachers do not allow me to use gstreamer, only opencv, gcc and sockets in C code. I am using Lubuntu 12.04 in VMware. The problem is that the code stucks because of the SELECT TIMEOUT error, i know it was posted here before but i am really stuck here, and I think i did not undestand the solution. The funny part is that this code works for near one minute in a kubuntu 9.10, after that cvSaveImage shows this error:

    OpenCV ERROR: Unespecified error (could not save the image)
    In function cvSaveImage, loadsave.cpp(520)
    Terminating the aplication
    Called from cvUnregisterType, cxpersistence.cpp(4933)

    I would like to know how to solve both problems if possible, here is the code:

    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include

    int main( int argc, char** argv )
    {
    IplImage* frame;
    CvCapture* capture;
    int fd,c;
    char buffer[100000];
    struct sockaddr_in remote;
    int remotefd;
    struct hostent *he;
    int len;
    int rv;
    int yes = 1;

    if(argc != 2)
    {
    printf (“Formato incorrecto. Falto IP servidor\n”);
    exit(1);
    }
    he = gethostbyname(argv[1]);
    remotefd = socket(AF_INET, SOCK_DGRAM, 0);
    rv = setsockopt(remotefd, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(yes));
    memset(&remote, 0, sizeof(remote));
    remote.sin_family = AF_INET;
    remote.sin_port = htons(5000);
    remote.sin_addr = *((struct in_addr *) he->h_addr);
    capture= cvCaptureFromCAM(0);
    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);
    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 240);
    while(1){
    frame = cvQueryFrame( capture );
    if(!frame )
    break,;
    cvSaveImage(“nuevo.jpg”, frame, 0 );
    cvWaitKey(40);
    fd= open(“nuevo.jpg”, O_RDONLY);
    usleep(1000);
    len=read(fd, buffer, sizeof(buffer));
    sendto(remotefd, buffer, len, 0, (struct sockaddr *) &remote, sizeof(remote));
    usleep(1000);
    printf(“Enviado…\n”);
    }
    return 0;
    }

    The messages in printf are in spanish because I am from Argentina, but they do not say nothing relevant. As you can see i am using cvWaitkeY as recomended, and i also tried modifying timeout in module uvcvideo with modprobe, no use. my webcam is

    Bus 001 Device 002: ID 5986:0315 Acer, Inc

    It is an Acer BisonCam, NBPro.

    Thank you.

  226. samontab says

    Hello Bruno,

    First of all, I would use the C++ interface of OpenCV instead of the C one. I would not be very happy if I am forced to use something outdated in a new project. Anyway, let’s try to solve this error.

    First of all, start separating the functionality. Start with a program that only reads from your camera, and saves a new “nuevo.jpg” file for each new frame that you get. Try running that, and make sure that it works perfectly. Specially look for memory leaks, because using the C interface may create a lot of them if you are not very careful. You can use valgrind to check for memory leaks: http://valgrind.org/

    OK, once you have your program reading from your camera, and saving the same jpg file for each frame, you can move to the next part, which is sending the image. Repeat the process of checking for memory leaks.

    My guess is that the program is still trying to send “nuevo.jpg” while you try to save the new frame. This is because network operations may take a long time. A quick solution would be to save each frame independently, like “frame0.jpg”, “frame1.jpg”, etc, and then after some time you could go back to “frame0.jpg”, or you could just erase the older frames.

    Try that, and it should work.

  227. Bruno says

    Thank you for the answer. I am not happy to be forced to use opencv this way, but well, rules are rules. I will try your solution, as I made a program that sends images but via tcp, via udp all the jpg images turned to be corrupt. Thank you.

  228. UNLUCKY GUY says

    I had a problem for one month for now, for some reason the way to fix it was editing one of the includes from gbdodometry.cpp.o to eigen3/unsuported/Eigen/MatrixFunctions instead of Eigen/MatrixFuncitons or something like that. Funny enough it was working on all the other computers I installed it, well, if someone does found this error ever again.

  229. samontab says

    That is weird unlucky guy, but I am happy that you solved the problem.

  230. Joseph says

    Thanks for the great tutorial!!

  231. samontab says

    You are welcome Joseph!

  232. Akash says

    hey,
    i got this error when i did the cmake instruction.

    CMake Error at CMakeLists.txt:61 (include):
    include could not find load file:

    cmake/OpenCVUtils.cmake

    CMake Error at CMakeLists.txt:74 (include):
    include could not find load file:

    cmake/OpenCVDetectCXXCompiler.cmake

    CMake Error at CMakeLists.txt:111 (OCV_OPTION):
    Unknown CMake command “OCV_OPTION”.

    please tell me how to correct it.

  233. samontab says

    Hello Akash,

    I have never seen that error. I guess it is just a mistake in the path or the command that you used. Please be extra careful and follow exactly each step. It should work.

  234. Muhammad Atif says

    It works really good…..Thanks a lot….A very good tutorial…

  235. samontab says

    You are welcome Muhammad

  236. Tasneem says

    Hi Samon, I want to install OpenCV on my BeagleBoard-xm using Linux(ubuntu). I am not getting any proper steps. Can you help me through it?

  237. samontab says

    Hello Tasneem,

    I do not have that hardware, so I cannot test it step by step. Depending on the version of the installed OS, the tutorial should still work for it. You may need to change some settings or command, but in general it should be the same.

  238. Sai says

    Very good tutorial for the beginners

  239. samontab says

    Thanks Sai

  240. Talaat says

    How to uninstall it again ? I have some problems I tried to delete some related file but nothing happened. did I make a lot of mess ? :/ andhow to completely uninstall this ?

    Thanks

  241. samontab says

    Since it is a library, it won’t affect your PC if you just leave it there.
    If you still want to remove it, you can try going to the build directory and executing:
    sudo make uninstall

  242. Lax says

    Hello Sir,
    I had installed opencv 2.3.1 on UBUNTU12.04 LTS.
    I am trying to run the Background detection code using function cvCreateGaussianBGModel(). But it looks like function cvUpdateBGStatModel() is NOT working because output is same even if I remove cvUpdateBGStatModel() from my code. It is not giving error in either case and background is not getting. when I show it using
    cvShowImage(“bg”,bg_model->background) it shows black window.
    please Guide me regarding the issue

  243. muxiaofei says

    Thanks for your post very mush!

  244. samontab says

    You are welcome muxiaofei

  245. Capton says

    I’m using ubuntu 12.04 but 64bit . Please will it work on it and if so will it also work for version 2.4.4 ?
    Thank you for your great work.

  246. Capton says

    Please can you elaborate/explain this line to me :

    I am on Ubuntu 12.04 64 bit, and I had to make a symbolic link:
    sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so
    Then cmake detected OpenGL and QTOpenGL, and now all examples run.

    Do I run it after finishing installing or what?

  247. 王杰 says

    hi,samon! I have a problem ,I followed a sample program like this:
    #include “opencv2/opencv.hpp”

    using namespace cv;

    int main(int, char**)
    {
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened()) // check if we succeeded
    return -1;

    Mat edges;
    namedWindow(“edges”,1);
    for(;;)
    {
    Mat frame;
    cap >> frame; // get a new frame from camera
    cvtColor(frame, edges, CV_BGR2GRAY);
    //GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
    //Canny(edges, edges, 0, 30, 3);
    imshow(“edges”, edges);
    if(waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
    }
    But what I found was that I was repeatedly receiving select timeout errors ,occasionally a frame grab is successful and is captured ,or ,I can get nothing, sorry for my poor English!
    Thanks!

  248. Lars says

    Perfect Tutorial !

  249. samontab says

    Thanks Lars!

  250. samontab says

    Hello 王杰,

    It seems that there is a problem with your camera hardware, or the drivers that you are using.

    I recommend you to change the camera to test if that is the problem, and if the problem continues, re install the drivers, or use other ones.

    I am sorry I cannot help you more with this since this is a very hardware specific question, and I do not have access to it.

  251. samontab says

    Hello Capton,

    Yes, it should work for both 32 and 64 bits. It will also work for any recent version of OpenCV, you just need to make small changes in file names, but the general procedure is basically the same.

  252. samontab says

    Hi Capton,

    If it works, then it is fine :)

  253. samontab says

    You are welcome muxiaofei!

  254. samontab says

    Hi Lax,

    Try using the included background subtraction sample, and check if it works for you. It should work.

  255. 王杰 says

    hi ,samontab !
    thanks for your reply! I have changed the camera to test ,but it still have the problem , anyway ,thank you .

  256. samontab says

    OK 王杰, have you tried using the camera with other applications?.

    Try troubleshooting it as suggested here:
    https://help.ubuntu.com/community/Webcam/Troubleshooting

  257. Sandeep Singh says

    I have installed opencv 2.4.9 but when i compile any program even sample ones i get an error saying no such file or directory.. i have followed your instruction to install

  258. samontab says

    Hi Sandeep Singh,
    The latest OpenCV version is 2.4.4, and this guide should work with it. You just need to be extra careful and follow every step.

  259. Sandeep Singh says

    Hi again, I am really finding it difficult to compile even sample codes.. when i enter command ./build_all.sh in terminal it says – /usr/local/include/opencv2/objdetect/objdetetct.hpp : fatal error : opencv2/objdetect.hpp :No such file or directory and then compilation terminated

    please help me i am new to opencv

  260. samontab says

    Sandeep Singh, it seems that you did not configure opencv correctly.
    Make sure that you followed all the steps on the tutorial from this part onwards: “Now you have to configure OpenCV”

    Check the output of this command on your system. It should be the includes and libraries for using opencv:
    pkg-config --cflags --libs opencv

    Also, you can check the Python samples to see if OpenCV is correctly installed:
    python ~/OpenCV-2.4.1/samples/python2/turing.py

    Or the c++ samples:
    ~/OpenCV-2.4.1/build/bin/calibration_artificial

  261. Sandeep SIngh says

    thanks for your great help..
    My ubuntu version is12.10 and i have fully followed the steps to install opencv 2.4.4 from opencv documentation tutorials which has been provided in docs.opencv.org how to setup opencv in linux.. So my question is should i remove everything already installed or can i continue from there only.. if i have to remove then how to remove completely??

  262. Sandeep SIngh says

    hi,
    I am getting this after doing this command pkg-conig –cflags –libs opencv
    a@ubuntu:~$ pkg-config –cflags –libs opencv
    -I/usr/local/include/opencv -I/usr/local/include /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_softcascade.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
    So what to do now..

    And please tell can this tutorial be followed for ubuntu 12.10 and opencv 2.4.4 installation?? and i wanted to know how to remove older opencv and libraries which have been installed so that i can start fresh from this tutorial??
    Thank You,

  263. samontab says

    Sandeep SIngh,

    It seems that your OpenCV installation is fine.
    This guide still works with OpenCV 2.4.4 so, just to be sure, continue the tutorial from this part:
    “Now you have to configure OpenCV. First, open the opencv.conf file with the following code:”
    Note that some steps may not be necessary in your case, but that is OK.

    After that, you should be able to compile the C examples. If you are not able to compile them, please tell us what happens.

  264. Sandeep singh says

    hi,
    after continuing from the step which you told and completing it still i get the same error message as i showed you in my last comment when i try to compile samples in c..
    So what to do now??
    Thank you..

  265. Sandeep singh says

    I get same error message as /usr/local/include/opencv2/objdetect/objdetetct.hpp : fatal error : opencv2/objdetect.hpp :No such file or directory and then compilation terminated,
    for all the sample examples in c,c++,pyhton.. So what do now should i remove and restart all over again?? if i have to then how to remove all the opencv libraries and packages??

    thank you

  266. samontab says

    Sandeep singh, I recommend you to use my tutorial step by step with OpenCV 2.4.4. I just installed it without a problem on Ubuntu 12.04.

    If you want, you can try manually removing your previous OpenCV installation, as shown here:
    http://stackoverflow.com/questions/9276169/removing-all-installed-opencv-libs

  267. Sandeep Singh says

    Thank you for help and support it worked.. great tutorial.

  268. samontab says

    Thanks Sandeep Singh, great to hear that it was helpful to you.

  269. phuong says

    Help !
    I get same error: No rule to make target `qopencvwidget.cpp’, needed by `qopencvwidget.o’. Stop.
    I use Ubuntu 12.04; Qt 2.2 ; Opencv 2.4.1 .
    So what to do now??
    Thank you..

  270. samontab says

    Hello phuong,

    I guess you are trying to build an application using Qt and OpenCV.
    Basically what you need to do is to first, make sure that you can build a Qt application correctly.
    Once you can do that, you need to add the OpenCV library as a dependency in the .pro file, and compile it just as you would with any other C++ library, something like this:


    unix {
    CONFIG += link_pkgconfig
    PKGCONFIG += opencv
    }

    If you are using Windows, you can follow this great tutorial from the OpenCV 2 Cookbook by Robert Laganière:
    http://www.laganiere.name/opencvCookbook/chap1s1_2.shtml

  271. veradiego says

    Hi..!
    To install OpenCV 2.4.4 in ubuntu 12.04 x64 bits was the same??
    (sorry for my bad english!!)

  272. samontab says

    Hello veradiego,

    Yes, it should be the same. You just need to change the file names, but the procedure is the same.
    And by the way, OpenCV 2.4.5 is out now.

  273. Sandeep Singh says

    hi samon,
    I want to use opencv programs from my apache webserver (WWW root) in LAMP architecture… so when i try and run opencv programs from root i get a message saying (core dumped)program crashed and list of libraries missing.. i have installed opencv from this article itself and followed each and every step as mentioned above and it works when i run normally from my home directory and other places.. but i want to run opencv programs from my root i.e, from /var/www folder but it is not possible to do.. please help me in this regard..

    Thank you

  274. samontab says

    Hello Sandeep Singh,

    I am glad to hear that OpenCV works for you.
    The problem you describe is probably caused by permission issues or other web server configuration issues, but that is out of the scope of this tutorial/conversation.

  275. Sandeep singh says

    Hi samon,
    I am writing a video file from accessing web camera by using CVwriter, but while executing i get an error message saying Gstreamer opencv does not support this backend codec actually.. and sometimes install missing plugins but i have installed all..
    Please help on this.

    Thank you

  276. samontab says

    Hello Sandeep singh,

    Since you already installed all, then I cannot suggest you to install anything else :)
    OpenCV has a limited support for video I/O (as well as GUI), so if you have problems with it, I suggest you to use other libraries for reading the camera and then passing it to OpenCV.

  277. Hadi says

    Hi
    I am beginner in linux and i have installed the ubuntu 12.04LTS. i tried to install opencv 2.4.3
    when i do “ldconfig” i see this problem:
    /sbin/ldconfig.real: Can’t create temporary cache file /etc/ld.so.cache~: Permission denied
    Thank you

  278. samontab says

    Hello Hadi,

    You forgot to add sudo at the beginning of that command.

  279. Tanmay says

    Thank you very much!!

  280. samontab says

    You are welcome Tanmay.

  281. Sanne says

    Hi Sebastian,
    Thanks so much for your clear & concise tutorial. At first I ran into the same problem as Zick (undefined references), but your fix worked. Keep up the good work :)

  282. samontab says

    Hello Sanne,

    You are welcome!, I am glad it helped you.

  283. Patrick says

    Hi!
    Please i have this error after finishing installing and compiling example. I’m under ubuntu 13.04 64 bits
    ‘sin@@GLIBC_2.2.5′ is defined in DSO /lib/x86_64-linux-gnu/libm.so.6 so try adding it to the linker command line

  284. samontab says

    Hello Patrick,

    I think it is due to the 64 bits libraries. Try adding -lm at the end of the link command, as suggested here:
    http://stackoverflow.com/questions/9934549/very-strange-linker-behavior

  285. Assma says

    Thank you very much, your tutorial has solve mu problem

  286. samontab says

    You are welcome Assma.

  287. Haykel Sn says

    Dear Mr Sebastian Montabone,
    I install opencv, but I tried to compile a code of face recognition that is shared in this link:
    https://github.com/MasteringOpenCV/code/tree/master/Chapter8_FaceRecognition
    but unfortunately I don’t know how do that
    So please, help me to find a solution

  288. jay says

    hi,
    My usb webcam works fine as I’m able to use it with Cheese, Guvcview. I have tested the cvCaptureFromCAM(CV_CAP_ANY) in C when trying to capture the device, but it return me ‘ERROR: capture is NULL ‘. Do you know why???

    Sample code is:
    #include “cv.h”
    #include “highgui.h”
    #include

    int main() {

    CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );

    if ( !capture )
    {
    fprintf( stderr, “ERROR: capture is NULL \n” );
    getchar();
    return -1;
    }

    cvNamedWindow( “mywindow”, CV_WINDOW_AUTOSIZE );

    while ( 1 )
    {
    IplImage* frame = cvQueryFrame( capture );
    if ( !frame ){
    fprintf( stderr, “ERROR: frame is null…\n” );
    getchar();
    break;
    }
    cvShowImage( “mywindow”, frame );
    if ( (cvWaitKey(10) & 255) == 27 ) break;
    }
    cvReleaseCapture( &capture );
    cvDestroyWindow( “mywindow” );
    return 0;
    }

  289. kaliwn says

    hello,i have install opencv with your steps,thanks a lot, and i read all the responses. you are warmhearted . i have met a problem: i can use the camera with lucview mplayer.etc. but i just can not open the webcamera with opencv cvCaptureFromCAM(CV_CAP_ANY) returns null just like jay said. it seems we met the same problem.
    now i was test int ubuntu 12.04 ,and opencv-2.4.6 in VMWARE
    details like this:
    $ ls -l /dev/v4l/by-id
    total 0
    lrwxrwxrwx 1 root root 12 Aug 2 11:17 usb-Alcor_Micro__Corp._USB_2.0_PC_Camera-video-index0 -> ../../video0

    $ lsmod | grep video
    uvcvideo 72249 0
    videobuf2_core 32212 1 uvcvideo
    videobuf2_vmalloc 12757 1 uvcvideo
    videobuf2_memops 13213 1 videobuf2_vmalloc
    videodev 100265 4 uvcvideo,videobuf2_core,gspca_zc3xx,gspca_main

    $ lsusb
    Bus 001 Device 009: ID 058f:3881 Alcor Micro Corp.
    Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
    Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

    $ lsusb -d 058f:3881 -v |grep “14 Video”
    Couldn’t open device, some information will be missing
    bFunctionClass 14 Video
    bInterfaceClass 14 Video
    bInterfaceClass 14 Video
    bInterfaceClass 14 Video
    bInterfaceClass 14 Video
    bInterfaceClass 14 Video
    bInterfaceClass 14 Video

    $ luvcview
    luvcview 0.2.6

    SDL information:
    Video driver: x11
    A window manager is available
    Device information:
    Device path: /dev/video0
    Stream settings:
    Frame format: YUYV (MJPG is not supported by device)
    Frame size: 640×480
    Frame rate: 30 fps

    $ xawtv -hwscan
    This is xawtv-3.102, running on Linux/i686 (3.5.0-23-generic)
    looking for available devices
    port 98-113
    type : Xvideo, image scaler
    name : XA G3D Textured Video

    port 114-114
    type : Xvideo, image scaler
    name : VMware Overlay Video Engine

    /dev/video0: OK [ -device /dev/video0 ]
    type : libv4l
    name : USB 2.0 PC Camera
    flags: capture

    $ xawtv
    This is xawtv-3.102, running on Linux/i686 (3.5.0-23-generic)
    xinerama 0: 1440×900+0+0
    vid-open-auto: using grabber/webcam device /dev/video0
    Alsa devices: cap: (null) (/dev/video0), out: default

    $ mplayer tv:// -tv fps=25
    MPlayer svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlayer Team
    mplayer: could not connect to socket
    mplayer: No such file or directory
    Failed to open LIRC support. You will not be able to use your remote control.

    Playing tv://.
    TV file format detected.
    Selected driver: v4l2
    name: Video 4 Linux 2 input
    author: Martin Olschewski
    comment: first try, more to come ;-)
    v4l2: your device driver does not support VIDIOC_G_STD ioctl, VIDIOC_G_PARM was used instead.
    Selected device: USB 2.0 PC Camera
    Capabilities: video capture streaming
    supported norms:
    inputs: 0 = Camera 1;
    Current input: 0
    Current format: YUYV
    v4l2: ioctl set format failed: Invalid argument
    v4l2: ioctl set format failed: Invalid argument
    v4l2: ioctl set format failed: Invalid argument
    tv.c: norm_from_string(pal): Bogus norm parameter, setting default.
    v4l2: ioctl enum norm failed: Invalid argument
    Error: Cannot set norm!
    Selected input hasn’t got a tuner!
    v4l2: ioctl set mute failed: Invalid argument
    Failed to open VDPAU backend libvdpau_nvidia.so: cannot open shared object file: No such file or directory
    [vdpau] Error when calling vdp_device_create_x11: 1
    ==========================================================================
    Opening video decoder: [raw] RAW Uncompressed Video
    Movie-Aspect is undefined – no prescaling applied.
    VO: [xv] 640×480 => 640×480 Packed YUY2
    Selected video codec: [rawyuy2] vfm: raw (RAW YUY2)
    ==========================================================================
    Audio: no sound
    Starting playback…

    .i’ve bought a new camera(Bus 002 Device 004: ID 0ac8:301b Z-Star Microelectronics Corp. ZC0301 Webcam),which was even worse,not support v4l.

    i am sorry for such a big piece of info. shall i buy a new camera…>_<
    http://letsmakerobots.com/node/37999?

  290. Kumar says

    Thank you very much S. Montabone,
    I installed quite fluently. But when I tried to build sample opencv programs using the same commands to put here. I get the error:

    Package opencv was not found in the pkg-config search path.
    Perhaps you should add the directory containing `opencv.pc’
    to the PKG_CONFIG_PATH environment variable

    I see that there is no directory pkgconfig under /usr/local/lib and also no opencv.pc file. I followed exactly the steps and also restarted my machine.
    I am quite new to both Linux and OpenCV. Sorry for my silly question.

    Thanks in advance.

  291. Kumar says

    Hi S. Montabone,

    It works for me. Sorry for the inconvenience. I think there was a mistake in following the steps correctly.
    thank you very much.

  292. evan says

    thank you this was fun! everything just worked! very well thought out, thanks!!

  293. Shravya says

    Hello sir!

    You have a very efficient installation method that has always worked for me through my different updates. :)

    I have faced one problem though. despite a completely successful installation, when I write a c program and include cxcore.h, it shows that there is missing header file named list.

    I have tried to download it but it didn’t work out.

    Though the problem is limited only to one header file, it is one that I will be using extensively (background_segm.hpp), so I really hope you can help me

  294. samontab says

    You are welcome evan. Great to hear that it worked for you and you had fun while at it, awesome.

  295. samontab says

    You are welcome Kumar,

    It seems that you answered yourself before I could even read your question. Nice.

  296. samontab says

    No worries Kumar, great to hear everything is now working for you.

  297. samontab says

    Hello Shravya,

    Thanks, the tutorial is getting a little bit old, but I am happy to hear that if you change the version numbers it still works, after so many updates.

    I guess your problem is related to the fact that OpenCV is deprecating its C interface in favour of the C++ interface. I recommend you to start taking a look at the C++ interface instead, because it is easier to use, more powerful, it has more support, and OpenCV is going in that direction.

    If you still want to use the old C interface, you can always try downloading an earlier version of OpenCV, that should solve your problem.

  298. Lakshmi says

    Hi Mr.Montabone
    Thanks for the details.
    most of the part is working fine.
    when it comes to image and video files iam getting error.

    1) ./build_all.sh
    is giving me the error

    compiling contours.c
    gcc: error: rt: No such file or directory
    gcc: error: pthread: No such file or directory
    gcc: error: m: No such file or directory
    gcc: error: dl: No such file or directory
    compiling convert_cascade.c

    and whenever
    2) i try to compile image or video files using eclipse i get the error
    nome-keyring:: couldn’t connect to: /run/user/..i/keyring-R3BoiB/pkcs11: No such file or directory
    No image data

    what is this error..
    can u help me to resolve this !
    Thank you
    Lakshmi

  299. aftab says

    Thank you samontab for great tutorial.

    I faced lot of trouble to make feature2D(SURF/SIFT) work on windows-visual studio c++.

    I faced lot of troubles relating to missing dlls and other ‘exceptions’, access violation stuff.

    After one week of struggle I decided to use it on ubuntu. Your tutorial helped me immensly. It worked on first go.

    Keep writing :)

  300. samontab says

    Hello Lakshmi,

    Those (rt, pthread, etc) are libraries needed to link the examples, I think there is something wrong in your configuration. Try reinstalling OpenCV.
    About the other error, I suggest you first make sure the examples compile to make sure everything is fine before tackling that problem.

  301. samontab says

    You are welcome aftab,

    I find that Linux is generally easier for development.
    Using cross platform build tools like cmake can help a lot when using Windows.

  302. clexx says

    thanks a lot dude! i thought i would die setting this up on linux cause i have never worked with it so far. thanks to you => no errors and quick installation! made my day :)

  303. samontab says

    You are welcome clexx. I am glad to hear that it worked for you too.

  304. Lakshmi says

    Hi Mr. Montabone
    Thanks a lot. Re installing OpenCv worked. I also used the latest version. It works good now. Doing work is one thing. Work done so well is neat. Hats off. Thank u.

  305. samontab says

    Thanks Lakshmi, I am glad it helped you.

  306. mainul says

    Hi,
    Thanks for your blog. I followed each step but I could nto compile the sample program. Each time I try to compile it gives me error like Lakshmi mentioned above. I reinstall opencv again but no progress. Each time I try to build a sample program I got this error:
    compiling contours.c
    gcc: error: tbb: No such file or directory
    gcc: error: rt: No such file or directory
    gcc: error: pthread: No such file or directory
    gcc: error: m: No such file or directory
    gcc: error: dl: No such file or directory

    Can you help me ??
    Lakshmi how did you fix it? did you change anything??

  307. samontab says

    Hello mainul,

    It seems that there is something wrong with the configuration of your system, or maybe with the current version of OpenCV since there are more people with the same error.
    Either way you can fix it by editing the pkg-config file of OpenCV:

    sudo gedit /usr/local/lib/pkgconfig/opencv.pc
    

    There, do a search for all the libraries that give you an error, and prepend them with “-l”. It may be different for each case because it depends on the configured libraries, but for example:

    Change:

    swscale avutil avformat avcodec v4l1 dc1394 rt pthread m dl stdc++ tbb
    

    Into this:

    -lswscale -lavutil -lavformat -lavcodec -lv4l1 -ldc1394 -lrt -lpthread -lm -ldl -lstdc++ -ltbb
    

    Save the file, and now you should be able to compile the examples using pk-config.

  308. Tasneem says

    Hi , I need to install OpenCV on beagleboard Xm with ubuntu-11.04-r0-minimal-armel. Need guidance regarding this or a tutorial.

  309. samontab says

    Hello Tasneem,

    I don’t currently have a beagleboard to test it, but you should be able to follow my instructions here:
    http://www.samontab.com/web/2011/06/installing-opencv-2-2-in-ubuntu-11-04/

  310. Dylan says

    Hi, thanks for this tutorial. It works for me~

  311. samontab says

    Hi Dylan,

    It’s great to know that it worked for you too.

  312. asensio says

    Thanks a lot!!

  313. samontab says

    You are welcome asensio!

  314. Manvi says

    Can you suggest something on how to install opencv in odroid board (with ARM processor) ??

  315. samontab says

    Hello Manvi,

    Try following the tutorial, removing not critical libraries, and find alternatives for mandatory libraries. It may take a while to get it right…

  316. R says

    Hi, first thank you very much for this nice guide!

    I installed OpenCV 2.4.6 on Ubuntu 13.04 using this guide on two computers.

    On one computer everything worked fine (Ubuntu on VMware). But with the second computer I have a big problem.

    Is is a computer just using Ubuntu without a virtual machine.

    I installed OpenCv but its not working properly.

    If I try to open a video stream or to open an image OpenCV resp. QT produces no error, opens a command line but no video or image shows up.

    My nerves are quite frayed. What can I try to solve the problem?

    Thank you very much!

  317. samontab says

    Hello R,

    Have you tried starting from scratch?, reinstall Ubuntu and then follow the tutorial. It should work.

  318. Nemi says

    Hello,
    sorry for my english… can you show me, how to compile a sample with c++ ?
    wenn i compile for example fback.cpp, i get a lot of errors :(
    I´m sorry, i work normaly with windows but for my project i need ubuntu.
    Thank you
    lg Nemi

  319. samontab says

    Hello Nemi,

    Take a look at the c samples directory. There is a file called build_all.sh. It compiles all the samples in that directory.
    In general, if you have a file called main.cpp, you can just compile it using:
    g++ `pkg-config --cflags --libs opencv` -o main main.cpp

  320. Houman Kargaran says

    Hi mate,
    I have just bought the Video. I went based on the installation step by step and I got the following error when I try this: ./build_all.sh

    Package opencv was not found in the pkg-config search path.
    Perhaps you should add the directory containing `opencv.pc’
    to the PKG_CONFIG_PATH environment variable
    No package ‘opencv’ found
    Package opencv was not found in the pkg-config search path.
    Perhaps you should add the directory containing `opencv.pc’
    to the PKG_CONFIG_PATH environment variable
    No package ‘opencv’ found
    tree_engine.cpp:1:29: fatal error: opencv2/ml/ml.hpp: No such file or directory
    compilation terminated.

    Can you please let me know what to do? Also is there any forum or somthing like this for people who bought the Videos?

    Thanks

  321. samontab says

    Hello Houman,

    The most probable explanation is that you missed some step in the tutorial. Try doing it again following every single instruction and it should work. Read the entire text because there are some things explained there that you need to do.
    Regarding the forum, I think this blog should be OK for answering questions about the video course. If we feel that we need something else we’ll move into something better, but for now I think this is more than enough.

  322. Andres says

    Hi when i try to save the file bash.bashrc after copying the code “PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
    export PKG_CONFIG_PATH” at the very last end, it says “Could not save the file /etc/bash.bashrc.” because i dont have permission to make changes to the file, so what do i do??? thank you

  323. samontab says

    Hello Andres,

    It seems that you are not running the command with sudo.
    Make sure that you copy and paste the exact command and it should work. For example:

    sudo gedit /etc/bash.bashrc

    It will ask for your password, and once you provide it you will have write access to the file.

  324. Wu Liang says

    Hi
    I used your method to install opencv with qt in my ubuntu 12.04. After that it works well, but after I install something else, it comes out an error,”terminate called after throwing an instance of ‘cv::Exception’
    what(): /tmp/A3p0_3607_7919/batserve/A3p0/glnxa64/OpenCV/modules/highgui/src/window.cpp:620: error: (-2) The function is not implemented. “.
    When I use sudo to run the program, it works. I don’t know why, and how can I run the program without sudo and no error occurs.
    Looking forward to you answer.

  325. Abhilash Shah says

    Hey I want to know that, How to compile and run the facedetect program in OpenCV??

  326. Berns B. says

    Great work from a real master. Any chance we could port them on the new OpenSuse 13? Sorry off topic suggestion I like OpenSuse interface quite a lot in teaching my elective course

  327. Snehal says

    hello samontab,
    I am trying to write a code on face detection on gpu using CUDA.And for that I am using opencv2.4.1 and CUDA 5.5. The code is compiled sucessfuly but I got opencv error at runtime. Error is
    OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /home/test/OpenCV-2.4.1/modules/core/src/persistence.cpp, line 4961
    terminate called after throwing an instance of ‘cv::Exception’
    what(): /home/test/OpenCV-2.4.1/modules/core/src/persistence.cpp:4961: error: (-2) The node does not represent a user object (unknown type?) in function cvRead

    Aborted (core dumped)
    Please give me any suggestions as soon as possible
    Thank you in advanced

  328. samontab says

    Hello Snehal,

    It is an error while trying to read a file.

    Here is a possible explanation for that error:
    http://code.opencv.org/issues/2387

    Basically, it seems that it is trying to read an xml file, and one of the nodes does not have the correct syntax because it is using an older implementation.

    I guess your code is using some older examples. Probably the function being used is the one that loads a cascade from file, so you should use this one instead:
    http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=load#bool%20CascadeClassifier::load%28const%20string&%20filename%29

    Just use the new C++ interface and it should work fine.

  329. Shreesha Vitthala says

    Hi Sebastian,
    I could install 2.4.1 without any issues, but when I try to install 2.4.8 i’m not able to ./build_all.sh
    I tried unzip instead of tar since 2.4.8 comes in a zip file. Also I see that there is no pkgconfig folder/file in /usr/local/lib even after doing all the steps till build all.
    Right now I’m using 2.4.1 but I’d like to move to 2.4.8. Please help me with the installation.

    Regards,
    Shreesha

  330. samontab says

    Hello Shreesha,

    You can get the tar.gz version here:
    https://github.com/Itseez/opencv/archive/2.4.8.tar.gz

    I just finished checking the installation of OpenCV 2.4.8 using my instructions, and it works fine.
    Some things to consider. The zip version may not preserve the file permissions, so maybe build_all.sh is not executable. That can be easily solved by doing:

    chmod +x build_all.sh

    Then, you should be able to execute it.
    About the other issue, you need to install the library as the root user (sudo make install) to create the pkgconfig file. Maybe you missed that step?, there should be a file called opencv.pc inside /usr/local/lib/pkgconfig.
    I invite you to try again, as I just did it and it works fine.

  331. Rafael says

    This tutorial should work for kubuntu too, right?
    Congratulations for your work :)

  332. samontab says

    Hello Rafael,

    Yes, it should work for kubuntu as well. Thanks!

  333. ankit says

    Hey Sabastian,

    By any means do you have instruction to install opencv on arm plateform.

  334. samontab says

    If by arm you mean raspberry pi, then take a look at this:
    http://www.raspberrypi.org/archives/tag/opencv

  335. Ankit says

    thnx

  336. jinda murad says

    thanks

  337. Poola says

    Hi ,
    Thanks for the post.
    Poola

  338. samontab says

    You are welcome Poola

  339. samontab says

    You are welcome jinda murad

  340. samontab says

    You are welcome Ankit

  341. Poola says

    Hello samontab,
    I have the ‘My New OpenCV Computer Vision Application Programming Video Course’.The video tutorials is very good. Working on the programs was easier with the explanations. While I was trying the training the detector(6_4), I am not clear with some steps.
    they are
    1. How to creat the the info txt file – using the positive samples and bg.txt ,background file-using the negative samples.
    2. I am having my own sample set and I need to make the info and bg file.
    Thanks in advance.
    Due to some server problem on the respective page, I am unable to post the query on that page.
    Poola

  342. samontab says

    Hello Poola,

    I am glad that you are enjoying the video course.

    Regarding your questions, those files are just simple text files that you can create with whatever application you want.

    The info file, which describes where the objects are, has the following syntax:

    pathToImage numberOfObjectsInThisImage X0 Y0 X1 Y1

    If you have more than one object in that image, you can just put the coordinates of the second object right next to the previous one, and so on.

    The background text file is even easier as you just list the filenames. This is the syntax:

    pathToImage

    So, for example, if you have all your background images inside one folder called backgroundImages, you can easily create bg.txt file with this command:

    ls backgroundImages > bg.txt

    In a similar way, you could create a script that generates the text file for the positive images as well, or use a spreadsheet editor, or other application, or even do it manually if you need to.

  343. Xys says

    this error appear when trying to generate the build file
    pi@raspberrypi :cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
    the last lines appear are
    CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):
    Could NOT find Qt4 (missing: QT_QMAKE_EXECUTABLE QT_MOC_EXECUTABLE
    QT_RCC_EXECUTABLE QT_INCLUDE_DIR QT_LIBRARY_DIR QT_QTCORE_INCLUDE_DIR
    QT_QTCORE_LIBRARY QT_QTGUI_INCLUDE_DIR QT_QTGUI_LIBRARY
    QT_QTTEST_INCLUDE_DIR QT_QTTEST_LIBRARY QT_UIC_EXECUTABLE)
    Call Stack (most recent call first):
    /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE)
    /usr/share/cmake-2.8/Modules/FindQt4.cmake:1200 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
    cmake/OpenCVFindLibsGUI.cmake:34 (find_package)
    CMakeLists.txt:434 (include)
    — Configuring incomplete, errors occurred!

  344. samontab says

    Hello Xys,

    First of all, it seems that you are using a raspberry pi instead of Ubuntu. This means that the package names and some options may be different.
    The particular error that you are showing here means that Qt is not installed.
    Also, if you don’t need a specific feature of OpenCV, you may just install it from the repositories with something like this:
    sudo apt-get install libopencv-dev python-opencv

  345. Anand says

    Hello,
    I am trying to install OpenCV-2.4.5 and I am not able to get the FFMPEG flag to show that it is installed.

    — Video I/O:
    — DC1394 1.x: NO
    — DC1394 2.x: NO
    — FFMPEG: NO
    — codec: NO
    — format: NO
    — util: NO
    — swscale: NO
    — gentoo-style: YES
    — GStreamer: NO
    — OpenNI: NO
    — OpenNI PrimeSensor Modules: NO
    — PvAPI: NO
    — GigEVisionSDK: NO
    — UniCap: NO
    — UniCap ucil: NO
    — V4L/V4L2: NO/YES
    — XIMEA: NO
    — Xine: NO
    I have followed your instructions completely. What am I missing ?
    Any help appreciated..

  346. samontab says

    Hello Anand,

    Maybe you did not follow the instructions exactly. If that is the case, you may try doing it again from the beginning copy pasting everything.
    Or maybe your system is different. In that case, you have to carefully check and modify every step to make sure that it works.
    You can also try compiling your own version of ffmpeg, as I did in a previous post:
    http://www.samontab.com/web/2011/06/installing-opencv-2-2-in-ubuntu-11-04/

  347. Poola says

    Hi,
    Thanks for the replay, I got it working.

  348. samontab says

    Great to hear that Poola.

  349. Orkun says

    Thanks for your helpful guide and answers

    Best regards.

  350. sonia says

    hey its a gr8 guide.
    i want to install opencv-2.4.5 -ubuntu 13.10 (32-bit), it is giving errors..please help

  351. samontab says

    Hi Sonia,

    Well, you have a few options.
    – You could install Ubuntu 12.04 with OpenCV 2.4.1 and this tutorial should work exactly as it is.
    – If you have a different version of Ubuntu or OpenCV, the tutorial should still work with minimal changes.
    – Or, just install the version that is on the repositories of Ubuntu, which should be easier if you don’t need a specific version of it.

    Any of those should work. Your choice.

    PS: As an advice, whenever you ask for help, you should try to give as much information as possible. Otherwise, the best case scenario is that you will get a generic reply that may not be really helpful, but more commonly your question will just get ignored because it does not contain the necessary information to answer it, so it is not worth the trouble.

  352. sonia says

    i am sorry for providing with less information. i did install opencv-2.4.9 but after reboot, my GUI was corrupted,i got blank screen with only cursor showing up,after i logged in.,may be the problem was a ‘libopencv-dev’ bug that installs Nvidia packages on non Nvidia graphics.
    now can you please guide.

  353. sonia says

    Now i have successfully installed opencv2.4.5 on my ubuntu 13.10(32-bit)
    another issue has come up- it says ‘ no module named cv2 / no module named numpy’
    :-/

  354. samontab says

    Hi Sonia,

    It seems that you don’t have the Python modules configured/installed correctly, or maybe did not follow the instructions closely, or maybe things are different with the versions that you are using.

  355. sonia says

    texlive-latex-extra
    sir i wanted to know ,what is this package for, i mean its importance and why we are using it.
    i tried finding on google but couldn’t get the right information.
    thank you

  356. samontab says

    Hi Sonia,

    It is an optional package. It provides the ability to build the documentation.

  357. Deepak says

    ImportError: libtbb.so: cannot open shared object file: No such file or directory
    What could be the error? How do i resolve this?

  358. Deepak says

    The version of TBB is 4.1 and interface 6102! Am i getting the error because of this?

  359. samontab says

    Hello Deepak, I recently updated the guide for Ubuntu 14.04 and OpenCV2.4.9.
    Take a look at it here:
    http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/

  360. Shawn says

    Thank you Samontab!
    This is a great and complete guide for a new OpenCV in old Ubuntu 12.04! I’ve stick to it since I found your tut.
    But it would be so much convenient for novice like me to have a little more support, also to double check the installation error if we unintentionally create some mistakes. How about a CMakeLists.txt to build a simple OpenCV sample?
    I made mine and it persists with errors
    Thank you!

  361. samontab says

    Hello Shawn,

    I think that the current status of this tutorial is really easy to follow. If you just copy and paste every command, you end up with everything working. If anyone has trouble with that, they need to put more effort.

  362. geek says

    Great tutorial !!!
    However, if someone is using a proxy he/she has to use wget with proper environment variables. ie to install opencv first type

    export http_proxy=http://username:password@host:port/
    export https_proxy=https://username:password@host:port/

    Check proxy variable after exporting by typing in terminal
    env | egrep proxy

    Then type the following
    cd ~
    wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.1/OpenCV-2.4.1.tar.bz2
    tar -xvf OpenCV-2.4.1.tar.bz2
    cd OpenCV-2.4.1

    Execute all these commands in a single session otherwise you have to export environment variables again.

  363. MAMTA says

    The installation is successful and the sample codes are running fine. But we have a cpp file called gab.cpp, the following error was found when we tried to execute in the terminal

    rvce123@rvce123-HP-Pro-3335-MT:~/Desktop/opencv/samples/c$ gcc `pkg-config –cflags opencv` -o gab gab.cpp `pkg-config –libs opencv`
    gcc: error: gab.cpp: No such file or directory

    Please let us know how do we execute external CPP files using opencv in this environment. ubuntu version is 12.04 and opencv is 2.4.9

  364. samontab says

    Hi MAMTA et al,

    Well, this is your current path:
    ~/Desktop/opencv/samples/c

    Is your gab.cpp file in there?. Probably not. Which is exactly what the compiler is telling you.

    You can either just copy the file there and it should work, but probably you don’t want to do that.
    Instead, just go to where your gab.cpp file is, and execute the same command.

  365. MAMTA says

    The following errors were found while compiling the program,
    Please do let us know if this is version error or compile time errors like header file inclusion.

    rvce123@rvce123-HP-Pro-3335-MT:~/Desktop/opencv/samples/c$ gcc `pkg-config –cflags opencv` -o gab gab.cpp `pkg-config –libs opencv`
    gab.cpp:7:11: error: ‘cv::CLAHE’ has not been declared
    gab.cpp: In function ‘int main(int, char**)’:
    gab.cpp:56:27: error: ‘resize’ was not declared in this scope
    gab.cpp:59:9: error: ‘CLAHE’ was not declared in this scope
    gab.cpp:59:14: error: template argument 1 is invalid
    gab.cpp:59:22: error: invalid type in declaration before ‘=’ token
    gab.cpp:59:24: error: ‘createCLAHE’ is not a member of ‘cv’
    gab.cpp:60:6: error: base operand of ‘->’ is not a pointer
    gab.cpp:61:6: error: base operand of ‘->’ is not a pointer
    gab.cpp:63:6: error: base operand of ‘->’ is not a pointer
    gab.cpp:128:20: error: ‘CV8U’ was not declared in this scope
    gab.cpp:158:7: error: ‘GaussianBlur’ is not a member of ‘cv’
    gab.cpp:158:56: error: ‘BORDER_DEFAULT’ is not a member of ‘cv’
    gab.cpp:184:9: error: ‘filter2D’ is not a member of ‘cv’

  366. samontab says

    Hi MAMTA,

    It seems that cv::CLAHE will be introduced in OpenCV 3.0. As you can see from the current documentation at this time, it is not available in OpenCV 2.4.9:
    http://docs.opencv.org/search.html?q=clahe&check_keywords=yes&area=default

  367. Ankit Namdeo says

    hi, samontab thanks for great tutorial

  368. Ankit Namdeo says

    Hi samontab thanks for great tutorial.It worked for me.

Continuing the Discussion

  1. Installing OpenCV 2.2 in Ubuntu 11.04 - Sebastian Montabone linked to this post on June 25, 2012

    [...] UPDATE: Now you can use my new guide to install OpenCV 2.4.1 in Ubuntu 12.04 LTS: [...]

  2. Can't compile opencv in linux - feed99 linked to this post on July 17, 2012

    [...] If it helps I installed Opencv2.4.1 on ubuntu LTS 12.04 with the help of this site: http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/ [...]

  3. Installing OpenCV on Ubuntu | VISHAAL NAGARAJA linked to this post on September 16, 2012

    [...] step by step explanation is the best site to follow to get it done in a neat and quick way. Click Here to have a look. Thank you Sebastian. Great [...]

  4. Instalar OpenCV 2.4.2 en Ubuntu 12.04 LTS | desarrollophpsenior linked to this post on September 21, 2012

    [...] Thanks for the great post ! July 26, 2012, 2:41 am [...]

  5. Installing OpenCV on Debian Linux | Indranil's world linked to this post on November 2, 2012

    [...] “Installing OpenCV 2.4.1 in Ubuntu 12.04 LTS”, Sabastian Montabone, June 24, 2012. Link: http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/ [...]

  6. Instalar OpenCV 2.4.2 en Ubuntu 12.04 LTS | Linux Hispano linked to this post on November 5, 2012

    [...] Wikipedia y Sebastian Montabone. var dd_offset_from_content = 60; var dd_top_offset_from_content = 0;Entradas [...]

  7. Installing OpenCV 2.4.1 in Ubuntu 12.04 LTS « Fuad's Blog linked to this post on November 13, 2012

    [...] good tutorial for installing OpenCV in Linux Ubuntu, just klik this link [...]

  8. Using OpenCV in Sage – Sebastian Montabone linked to this post on December 18, 2012

    [...] bindings working correctly for this to work. The easiest way of doing this is to follow my own tutorial for installing OpenCV. You can easily change the version for installing the latest OpenCV version that is out there, the [...]

  9. OpenCV 2.4.1 undefined references | BlogoSfera linked to this post on April 24, 2013

    [...] have recently installed OpenCV 2.4.1 on a desktop running Ubuntu 12.04(64-bits) following this tutorial,but every time I try to compile a code,even the included samples that use a pre-built compiling [...]

  10. install opencv in ubuntu 12.04 | astroinstrulin linked to this post on July 22, 2013

    [...] install opencv in ubuntu 12.04 [...]

  11. Instalación OpenCV 2.4.5 Ubuntu « Mecatrónica UASLP linked to this post on July 23, 2013

    [...] 10.- Agregar las siguientes líneas al final del archivo y guardarlo: PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH Fuente e indicaciones de como compilar los ejemplos: http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/ [...]

  12. Installing OpenCV 2.2.0 on Ubuntu 12.4. | Trần Thị Thanh Huyền linked to this post on September 2, 2013

    […] “Installing OpenCV 2.4.1 in Ubuntu 12.04 LTS”, Sabastian Montabone, June 24, 2012. Link: http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/ […]

  13. First Hit | My Website linked to this post on October 15, 2013

    […] How to install OpenCV ( by Sebastian Montabone) […]

  14. Installing OpenCV 2.4.1 in Ubuntu 12.04 LTS | 大地雄心 linked to this post on November 11, 2013

    […] 本文来自:http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/ […]

  15. Can't compile opencv in linux | StackAnswer.com linked to this post on December 31, 2013

    […] If it helps I installed Opencv2.4.1 on ubuntu LTS 12.04 with the help of this site: http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/ […]



Some HTML is OK

or, reply to this post via trackback.