A Comprehensive Guide to Installing and Configuring OpenCV 2.3.1 on Ubuntu

This guide describes how to install and configure OpenCV 2.3.1 and its dependencies on Ubuntu. It is a compilation of my notes recorded during dozens of OpenCV installs on several different systems. This guide differs from other OpenCV guides in the following ways:

  1. This guide is comprehensive: you can start with a clean Ubuntu and successfully install OpenCV 2.3.1 by following this guide.
  2. This guide is for OpenCV 2.3.1. The other guides I found used previous versions of OpenCV.
  3. This guide includes all of the steps you need to use a webcam with OpenCV.

Credit and thanks go to FakeOutdoorsman and Sebastian Montabone for their excellent posts, upon which several of the steps in this guide are based.

If you need help troubleshooting OpenCV installation problems, see the companion guide “A Comprehensive OpenCV Installation Troubleshooting Guide.”

 

The Installation Procedure

To install and configure OpenCV 2.3.1, complete the following steps.

  1. Remove any installed versions of ffmpeg and x264 by entering the following command:

sudo apt-get remove ffmpeg x264 libx264-dev

  1. Get all the dependencies for x264 and ffmpeg by entering the following commands:

sudo apt-get update
sudo apt-get install build-essential checkinstall git cmake libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev

  1. Download and install gstreamer by entering the following command:

sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg

  1. Download and install install x264.
    1. Download a recent stable snapshot of x264 from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/. The exact version does not seem to matter. To write this guide, I used version x264-snapshot-20110808-2245-stable.tar.bz2, but I have used previous versions too.
    2. Configure and build the x264 libraries by entering the following commands:

./configure --enable-static
make
sudo make install

  1. Download and install install ffmpeg.
    1. Download ffmpeg version 0.8.x from http://ffmpeg.org/download.html. Note: Versions of OpenCV prior to 2.3.1 require ffmpeg 0.7.x.
    2. Configure and build ffmpeg by entering the following commands in a terminal:

./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
make
sudo make install

  1. Download and install gtk by entering the following command:

sudo apt-get install libgtk2.0-0 libgtk2.0-dev

  1. Download and install libjpeg by entering the following command:

sudo apt-get install libjpeg62 libjpeg62-dev

  1. Download and install install v4l (video for linux).
    1. Download v4l-utils-0.8.5.tar.bz2 from http://www.linuxtv.org/downloads/v4l-utils/
    2. Build v4l by entering the following commands in a terminal:

make
sudo make install

  1. Download and install install OpenCV.
    1. Download OpenCV version 2.3.1 from http://sourceforge.net/projects/opencvlibrary/files/
    2. Use the following command to untar the source files

tar xvf OpenCV-2.3.1.tar.bz2
cd OpenCV-2.3.1/
mkdir build
cd build
cmake ..

      1. Check that the output of cmake includes the following text:
        • found gstreamer-base-0.10
        • GTK+ 2.x: YES
        • FFMPEG: YES
        • GStreamer: YES
        • V4L/V4L2: Using libv4l

Note: In versions of OpenCV prior to 2.3.1, the binary digit 1 was used instead of the word YES, like this: FFMPEG: 1.

    1. Run make
    2. Run sudo make install
  1. Configure Linux.
    1. Tell linux where the shared libraries for OpenCV are located by entering the following shell command:

      export LD_LIBRARY_PATH=/usr/local/lib

      Add the command to your .bashrc file so that you don’t have to enter every time your start a new terminal.

      Alternatively, you can configure the system wide library search path. Using your favorite editor, add a single line containing the text /usr/local/lib to the end of a file named /etc/ld.so.conf.d/opencv.conf. Using vi, for example, enter the following commands:

      sudo vi /etc/ld.so.conf.d/opencv.conf
      G
      o
      /usr/local/lib
      <Esc>
      :wq!

    2. Using your favorite editor, add the following two lines to the end of /etc/bash.bashrc:

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

    3. Reboot.

After completing the previous steps, your system should be ready to compile code that uses the OpenCV libraries. The following example shows one way to compile code for OpenCV:

g++ `pkg-config opencv --cflags` my_code.cpp  -o my_code `pkg-config opencv --libs` 

 

References

144 comments to A Comprehensive Guide to Installing and Configuring OpenCV 2.3.1 on Ubuntu

  • chaitanya

    You have done an excellent Job

  • Danielsohn

    The best and most updated guide in the web Osman !
    A glitch that keeps me off a final built:
    When making OpenCv I get
    “Linking CXX shared library ../../lib/libopencv_highgui.so
    /usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet_nofree’ can not be used when making a shared object; recompile with -fPIC”

    I tried both fffmpeg 0.8 as well as 0.7 (with appropriately removing first stuff). Any clue what to do? Ubuntu 10.10

  • Danielsohn

    Sorry my copy and paste missed sth. This is during
    “Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o”
    Several warnings and then :
    “Linking CXX shared library ../../lib/libopencv_highgui.so
    /usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet_nofree’ can not be used when making a shared object; recompile with -fPIC
    /usr/local/lib/libavcodec.a: could not read symbols: Bad value
    collect2: ld returned 1 exit status
    make[2]: *** [lib/libopencv_highgui.so.2.3.1] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2

  • Osman Eralp

    Did you try adding the –enable-pic option when you configure ffmpeg? You might also need to use –enable-pic for libraries used by ffmpeg, such as x264. For example, the configure command for x264 would be:

    ./configure –enable-static –enable-pic

    Does your PC have an AMD processor?

    • pitybea

      Thanks for the great work by Osman!

      I use x64 Ubuntu. By using –enable-pic option for both x264 and ffmpeg, I cleared the same errors.

    • Icarus A

      While my current compilation is running on an intel 64-bit environment (laptop), I do plan to use OpenCV also on AMD 64-bit environment, i.e. my desktop (since it is lot more capable and powerful).

      Are any of the relevant instructions are different for AMD processor based systems ?

  • Fabrizio

    Very nice guide.
    Well done.
    It is the best guide that I found.

  • Osman Eralp

    Thanks for the compliments. I’m glad you like the guide.

  • Hello

    In step 4 where do you extract the x264 folder? i have extracted it to the desktop and when i run the command in the terminal, it says the i have ‘no such file or directory’. thx

    • Osman Eralp

      Under my home directory, I usually create a directory called src. The complete path name would be /home/osman/src. I save the downloaded tarfile in the src directory. Here is the complete set of commands:

      cd /home/osman
      mkdir src
      cd src
      mv /home/osman/Downloads/x264-snapshot-20110913-2245-stable.tar.bz2 .
      tar xvf x264-snapshot-20110913-2245-stable.tar.bz2
      cd x264-snapshot-20110913-2245-stable

      In your situation, replace “osman” with your user name, replace “Downloads” with “Desktop” because that’s where you saved the tarfile, and replace “x264-snapshot-20110913-2245-stable” with the actual name of the file.

      Then you can run configure. Hope that helps!

  • Panayiotis

    Thank you Osman! Great guide! I had the same problem with Danielsohn. You have to –enable-shared when you configure ffmeg and everything works fine. Thanks again!

  • Omi

    Hiii,,
    do u know how to install Open CV in windows
    for Java Eclipse Platform.
    plzz help me with this,,,i couldn’t get the answer from many searchings..

  • Gabriel

    Hello, thanks for your post, this was usefull for me. But I’m facing a problem, i get this error msg:

    lib/libopencv_highgui.so.2.2.0: undefined reference to `gst_app_sink_peek_buffer’
    ../../lib/libopencv_highgui.so.2.2.0: undefined reference to `gst_app_sink_get_queue_length’

    I’ve tried edit some code on gst config, but I get nothing.

    • Osman Eralp

      It looks like a problem with gstreamer. Did you install gstreamer in step 3 of this guide? When you ran “cmake ..” in the opencv build directory, did the output say “GStreamer: YES”?

    • Osman Eralp

      Here’s one more thing to try if you get unexpected errors: delete the opencv build directory, make a new build directory, run cmake again, and run make again. One time I got some strange errors that I could not explain. Deleting the build directory and creating a new build directory fixed the problem.

  • Thanks a lot for such a nice guide. It perfectly works :-)

  • Marco

    I have one question: when I try to add the new module cv2 I get an error

    import cv2.cv as cv

    ImportError: No module named cv2.cv

    Why?
    Thank you

  • okram

    Thank you for the guide, but what about the wrapper for python?
    What I need to do to install also this?

  • Gene Wildhart

    I tried compiling x264 and ffmpeg with –enable-pic configure option, and I’m still getting the following error when trying to compile openCV on Ubuntu 11.10:

    Linking CXX shared library ../../lib/libopencv_highgui.so
    /usr/bin/ld: /usr/local/lib/libavcodec.a(lpc_mmx.o): relocation R_X86_64_PC32 against symbol `ff_pd_1′ can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: final link failed: Bad value
    collect2: ld returned 1 exit status
    make[2]: *** [lib/libopencv_highgui.so.2.3.1] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2

    • Osman Eralp

      The error usually means that the module that failed to link was not compiled with -PIC. You said that you did use that option with the configure command, so it’s a bit odd. Here’s a couple suggestions:

      1. Make sure you installed x264 and ffmpeg after compiling. If you didn’t install it, the opencv compile script might be pickup up another version of ffmpeg that did not use -PIC.
      2. Remove the opencv build directory and create a fresh build directory. I’ve had problems with old files from previous opencv compiles interfering with with subsequent compiles that use different options.
      • Gene Wildhart

        I tried deleting all directories and starting from scratch. –enable-pic is used in the configure options for both x264 and ffmpeg. I removed all x264 and ffmpeg packages from ubuntu before compiling and installing said packages. Still getting the exact same error as posted above, asking me to recompile with -fPIC. Strange… any other suggestions?

        • Jon Blake

          Bumb.

          I’m getting the same issue.

          I’ve tried to use –enable-pic to configure both x264 and ffmpeg as well as –enable-shared when configuring ffmpeg.

          Any help would really be appreciated. Thanks for all you’ve already done Osman

          [ 33%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_bmp.o
          [ 34%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_png.o
          Linking CXX shared library ../../lib/libopencv_highgui.so
          /usr/bin/ld: /usr/local/lib/libavcodec.a(lpc_mmx.o): relocation R_X86_64_PC32 against symbol `ff_pd_1′ can not be used when making a shared object; recompile with -fPIC
          /usr/bin/ld: final link failed: Bad value
          collect2: ld returned 1 exit status
          make[2]: *** [lib/libopencv_highgui.so.2.3.1] Error 1
          make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
          make: *** [all] Error 2

          • Osman Eralp

            From Gene’s comment below, he solved this problem by using both –enable-shared and –enable-pic. Make sure you
            1) Use –enable-shared –enable-pic when configuring both x264 and ffmpeg
            2) Install x264 and ffmpeg
            3) Delete the OpenCV build directory and create a new build directory. I’ve seen problems where a incomplete build interferes with future builds.

            Please keep us updated on your results!

          • Jon Blake

            Wow, thanks alot Osman and everyone else who contributed!

            My issue was solved with a combination of adding –enable-shared to the configuration of X264 as well as updating my apts. THANKS!

            Just a little tip for everyone out there who isn’t so comfortable with using a VI text editor.

            Since Ubuntu wont let you modify some of the above system files with something like gedit and then save it in place, I did the following:
            1) Open the file you want to edit
            2) Copy all the text from the file you want to edit and edit/add any additional text
            3) Save the file with the same name but to a different location (like the Desktop)
            4) In the terminal navigate to the directory where you have saved your edited file
            5) Run the following command:
            sudo mv -f your_editedf_ile.extension /complete_directory_to_original_location/

            That’ll force a move from where you dropped the edited file to where you want it (obviously you have to change the file name where it says your_editedf_ile.extension and the correct directory where it says complete_directory_to_original_location

            For example: For the bash file here was the text I used to take it off the desktop and back into /etc/: sudo mv -f bash.bashrc /etc/

  • Gene Wildhart

    I first tried ffmpeg 0.8.5, and I got the error above. I then tried with ffmpeg 0.8.4 and I still got the same error.
    My configure for ffmpeg is:
    make clean
    ./configure –enable-gpl –enable-libfaac –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libtheora –enable-libvorbis –enable-libx264 –enable-libxvid –enable-nonfree –enable-postproc –enable-version3 –enable-x11grab –enable-pic
    make
    sudo make install

    for x264 (20111108-stable snapshot)
    make clean
    ./configure –enable-static –enable-pic
    make
    sudo make install

    I delete the OpenCV build directory and recreate it each time, but still get the same error.
    rm -rf build
    mkdir build
    cd build
    cmake ..
    make (get error in this step)

    • Gene Wildhart

      Okay, after two days of messing with different options, I found that I had to add –enable-shared and –enable-pic to the ffmpeg config to get things working!

      • Osman Eralp

        Glad you figured it out. Thanks for sharing the solution. Hopefully this info will help someone else with the same problem.

        • Paula Costa

          Yeah, this was exactly my case. Thanks Osman for the great tutorial and Gene for your additional help.

        • Icarus A

          1+ for excellent tutorial and for Gene’s identification of the issue/solution.
          Ran into exact set of issues and in very similar sequence.

          Would be great if it could be incorporated back into the blog post as an edit.

  • lvsuno

    Thx u guy. Very Good JOB

  • Fel To

    Many thanks Osman for this helpful tutorial. Greetings from Switzerland!

  • Mal

    Thanks for the guide!
    On Ubuntu 11.10 64bit for OpenCV 2.3.1:
    Instead of compiling ffmpeg myself I used the precompiled version from a ppa ( https://launchpad.net/~jon-severinsson/+archive/ffmpeg ).
    Currently, the latest version available from the ppa is 0.8.4. It also updates libavcodec52 etc.
    Works like a charm :)

  • Ying

    Thank you for the guide!
    Is it missing the library for tiff?

    • Osman Eralp

      When writing the guide, I debated whether or not to include all of the image format libraries, such as tif and jpeg2000. In the end, I decided not to include them. But I noticed that I included many of the libraries for video formats, so maybe it makes sense to include image format libraries too. I’ll add them when I next update the guide. Thanks for the suggestion.

  • very good,thank you. I know what is the wrong. I fond it is the problem of the version of ffmpeg.

  • Andrew

    Thanks for a great tutorial.

    Thanks for the great tutorial. When building it on Ubuntu 11.10 x64 (Intel) with OpenCV 2.3.1, I get the error message during linking:

    Linking CXX shared library ../../lib/libopencv_highgui.so
    /usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet’ can not be used when making a shared object; recompile with -fPIC
    /usr/local/lib/libavcodec.a: could not read symbols: Bad value
    collect2: ld returned 1 exit status
    make[2]: *** [lib/libopencv_highgui.so.2.3.1] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2

    Do you have any tips to resolve this issue?
    Thanks!

  • Pedro

    Thanks for this tutorial! Really useful! It is best than the official one! Congrats!

  • It perfectly works on a newly installed Ubuntu 11.10! I just followed the steps as they are!

  • Mattia

    Thanks for the tutorial, but when i compile the code with “g++ `pkg-config opencv –cflags` `pkg-config opencv –libs` main.cpp -o eyeCenter” i get “undefined reference to” every opencv functions.
    Can you help me?

    • Osman Eralp

      Here are some ideas:
      1. Are you sure you installed OpenCV by running “sudo make install” in the OpenCV build directory?
      2. After you compile, but before you run your program, run this command: export LD_LIBRARY_PATH=/usr/local/lib
      3. Make sure the output of the pkg-config command looks something like this:

      $ pkg-config opencv –cflags
      -I/usr/local/include/opencv -I/usr/local/include
      $ pkg-config opencv –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

      • Mattia

        1. yes sure
        2. done
        3.
        $ pkg-config opencv –lib returns :

        -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

        $ pkg-config opencv –cflags returns:

        -I/usr/local/include/opencv -I/usr/local/include

        Bue I can compile my program with :

        g++ -o display DisplayImage.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy

        but when i run the program i have :

        libopencv_core.so.2.3: cannot open shared object file: No such file or directory

        • Mattia

          Sorry, i solved the problem: a space before export LD_LIBRARY_PATH=/usr/local/lib

          Thanks Osman

        • Sam

          To add to the fun, compilation works, but trying to run the program now gives me the error while loading shared libraries: libopencv_core.so.2.3: cannot open shared object file.

          • hey sam, I am having the same problem as you.

            error while loading shared libraries: libopencv_core.so.2.3

            were you able to solve this problem? and how? please reply

          • I found the solution to this error.

            export LD_LIBRARY_PATH=/usr/local/lib

            this fixed the error, but i have to do it everytime i log in.

            therefore i added this command at the end of my /etc/bash.bashrc

      • Nestor

        Hello Osman
        First of all, thanks a lot for this great guide! I used it when I first intalled openCV in ubuntu 11.04 :P Now I’m trying to do the same but in 11.10 and I have encountered the same problema as Mattia :S when I try to compile I keep receiving “unexpeted reference” to the opencv functions :S

        My outputs por pkg-config are the same as yours:

        $ pkg-config opencv –cflags
        -I/usr/local/include/opencv -I/usr/local/include

        $ pkg-config opencv –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

        I have tried compiling the way Mattia said:

        g++ -o display programa_1.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy

        And all I got was an fatal error message telling me cv.h does not exist :S

        Could you give me a hand please?

        Thanks a lot!

      • Sam

        I’m unfortunately getting the same errors as the person above and would really appreciate any help you could provide. A brief example is below:

        samuel@samuel-Compaq-610:~/opencv/samples/cpp$ make lkdemo
        g++ lkdemo.cpp -o lkdemo
        /tmp/cc5GLGJD.o: In function `main’:
        lkdemo.cpp:(.text+0xe9): undefined reference to `cv::VideoCapture::VideoCapture()’
        lkdemo.cpp:(.text+0x1c0): undefined reference to `cv::VideoCapture::open(int)’
        lkdemo.cpp:(.text+0×205): undefined reference to `cv::VideoCapture::open(std::basic_string<char, std::char_traits, std::allocator > const&)’
        lkdemo.cpp:(.text+0×229): undefined reference to `cv::VideoCapture::isOpened() const’
        lkdemo.cpp:(.text+0x28b): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits, std::allocator > const&, int)’
        lkdemo.cpp:(.text+0x2e1): undefined reference to `cv::setMouseCallback(std::basic_string<char, std::char_traits, std::allocator > const&, void (*)(int, int, int, int, void*), void*)’
        lkdemo.cpp:(.text+0x35f): undefined reference to `vtable for cv::VideoCapture’
        [...]

        My pkg-config looks right, so I have no idea what’s wrong. I’ve been stuck here for a good few hours. :(

        samuel@samuel-Compaq-610:~/opencv/samples/cpp$ pkg-config opencv –cflags
        -I/usr/local/include/opencv -I/usr/local/include
        samuel@samuel-Compaq-610:~/opencv/samples/cpp$ pkg-config opencv –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

        • Sam

          Strange, I just tried the solution someone mentioned above and it now works. I did: g++ -o test lkdemo.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy

          Do you know why this might work where using the pkg config doesn’t?

        • Osman Eralp

          It’s odd that two people had this same problem in the last week. I will do more research. Are you using Ubuntu? If so, what version?

          Can you please try running the following command before you compile:

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

          Please let me know the result. Thx.

        • Osman Eralp

          PS. This should work for you:

          g++ `pkg-config opencv –cflags` `pkg-config opencv –libs` lkdemo.cpp -o lkdemo

          It’s a bit shorter than typing in the libraries by hand.

          • Sam

            Thanks for the quick response! I exported the pkg_config_path before doing any of the below. I am using ubuntu 11.10.

            g++ `pkg-config opencv –cflags` `pkg-config opencv –libs` lkdemo.cpp -o lkdemo

            samuel@samuel-Compaq-610:~$ g++ `pkg-config opencv –cflags` `pkg-config opencv –libs` -o lkdemo lkdemo.cpp
            /tmp/ccT4xgWe.o: In function `main’:
            lkdemo.cpp:(.text+0xe9): undefined reference to `cv::VideoCapture::VideoCapture()’
            lkdemo.cpp:(.text+0x1a2): undefined reference to `cv::VideoCapture::open(int)’
            lkdemo.cpp:(.text+0x1e7): undefined reference to `cv::VideoCapture::open(std::basic_string<char, std::char_traits, std::allocator > const&)’
            lkdemo.cpp:(.text+0x20b): undefined reference to `cv::VideoCapture::isOpened() const’
            lkdemo.cpp:(.text+0x26d): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits, std::allocator > const&, int)’
            lkdemo.cpp:(.text+0x2c3): undefined reference to `cv::setMouseCallback(std::basic_string<char, std::char_traits, std::allocator > const&, void (*)(int, int, int, int, void*), void*)’
            [...etc...]

            g++ -I/usr/local/include/opencv/ -Wall -o lkdemo lkdemo.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy

          • Sam

            Note the first one failed, the second succeeded.

  • Thanks for the tutorial, it covers every detail, but I am having problems with the pkg-config step (I think).
    I built opencv with the latest x264 stable, the last ffmpeg from git and the last OpenCV 2.3.1 in the site (which is called 2.3.1a) and compiled both packages with –enable-shared –enable-pic.
    I am using a fresh install of Kubuntu 11.10 x64 (intel processor)
    followed every step but when I run pkg-config opencv –libs
    I get:
    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

    I checked /usr/local/lib/pkgconfig and there is no opencv.pc
    Any ideias?

    Thanks

  • Nestor

    Hello again Osman
    I’m sorry for the delay in aswering you, the error ocurrs when I compile. I’ve tried exporting

    export LD_LIBRARY_PATH=/usr/local/lib

    and compiling like you said

    g++ `pkg-config opencv –cflags` `pkg-config opencv –libs` histograma.cpp -o salida

    and i’m still receiving cv.h: no such file or directory

  • Aditya

    Hey Osman,

    I was able to install OpenCV without OpenNI and Primesense after looking at your tutorial…very thankful for that!(but spent lots of time trying to debug the errors!!)…

    I am running Ubuntu 11.10 64-bit and OpenCV 2.3.1
    I need to install OpenCV with OpenNI and Primesense now.
    I installed OpenNI and Primesense according to the official website Readme.
    But when I ‘make’ OpenCV…after enabling OpenNI and Primesense…

    I run into the error shown below..

    I have printed my whole cmake and make log info below…your help will be very useful..sorry for the clogging of info!

    Thanks
    Aditya

    aditya@aditya-Inspiron-N5010:~/Downloads/OpenCV-2.3.1/release2$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
    – Detected version of GNU GCC: 46 (406)
    – Found OpenEXR: /usr/lib/libIlmImf.so
    – Use NumPy headers from: /usr/lib/pymodules/python2.7/numpy/core/include
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: No module named sphinx
    CUDA_TOOLKIT_ROOT_DIR not found or specified
    – Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (Required is at least version “4.0″)
    – Parsing ‘cvconfig.h.cmake’

    – General configuration for opencv 2.3.1 =====================================

    – Built as dynamic libs?: YES
    – Compiler: /usr/bin/c++
    – C++ flags (Release): -Wall -Wno-long-long -pthread -ffunction-sections -O3 -DNDEBUG -fomit-frame-pointer -msse -msse2 -DNDEBUG
    – C++ flags (Debug): -Wall -Wno-long-long -pthread -ffunction-sections -g -O0 -DDEBUG -D_DEBUG -ggdb3
    – Linker flags (Release):
    – Linker flags (Debug):

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

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

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

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

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

    – Documentation:
    – Sphinx: NO
    – PdfLaTeX compiler: NO
    – Build Documentation: NO

    – Tests and samples:
    – Tests: YES
    – Examples: YES

    – Install path: /usr/local

    – cvconfig.h is in: /home/aditya/Downloads/OpenCV-2.3.1/release2
    – —————————————————————–

    – Configuring done
    – Generating done
    – Build files have been written to: /home/aditya/Downloads/OpenCV-2.3.1/release2
    aditya@aditya-Inspiron-N5010:~/Downloads/OpenCV-2.3.1/release2$ make
    [ 0%] Built target opencv_imgproc_pch_dephelp
    [ 0%] Generating precomp.hpp.gch/opencv_imgproc_RELEASE.gch
    [ 1%] Built target pch_Generate_opencv_imgproc
    [ 2%] Built target opencv_core_pch_dephelp
    [ 2%] Generating precomp.hpp.gch/opencv_core_RELEASE.gch
    [ 2%] Built target pch_Generate_opencv_core
    [ 5%] Built target opencv_core
    [ 13%] Built target opencv_imgproc
    [ 13%] Built target opencv_calib3d_pch_dephelp
    [ 13%] Generating precomp.hpp.gch/opencv_calib3d_RELEASE.gch
    [ 13%] Built target pch_Generate_opencv_calib3d
    [ 13%] Built target opencv_features2d_pch_dephelp
    [ 13%] Generating precomp.hpp.gch/opencv_features2d_RELEASE.gch
    [ 13%] Built target pch_Generate_opencv_features2d
    [ 13%] Built target opencv_flann_pch_dephelp
    [ 13%] Generating precomp.hpp.gch/opencv_flann_RELEASE.gch
    [ 14%] Built target pch_Generate_opencv_flann
    [ 15%] Built target opencv_flann
    [ 15%] Built target opencv_highgui_pch_dephelp
    [ 15%] Generating precomp.hpp.gch/opencv_highgui_RELEASE.gch
    [ 15%] Built target pch_Generate_opencv_highgui
    [ 19%] Built target opencv_highgui
    [ 22%] Built target opencv_features2d
    [ 24%] Built target opencv_calib3d
    [ 24%] Built target opencv_test_calib3d_pch_dephelp
    [ 24%] Generating test_precomp.hpp.gch/opencv_test_calib3d_RELEASE.gch
    [ 24%] Built target pch_Generate_opencv_test_calib3d
    [ 24%] Built target opencv_ts_pch_dephelp
    [ 24%] Generating precomp.hpp.gch/opencv_ts_RELEASE.gch
    [ 24%] Built target pch_Generate_opencv_ts
    [ 25%] Built target opencv_ts
    Linking CXX executable ../../bin/opencv_test_calib3d
    ../../lib/libopencv_highgui.so.2.3.1: undefined reference to `cvCreateCameraCapture_OpenNI(int)’
    collect2: ld returned 1 exit status
    make[2]: *** [bin/opencv_test_calib3d] Error 1
    make[1]: *** [modules/calib3d/CMakeFiles/opencv_test_calib3d.dir/all] Error 2
    make: *** [all] Error 2

  • chanhom

    Good guide!! Thx!

  • [...] Tutorial: A Comprehensive Guide to Installing and Configuring OpenCV 2.3.1 on Ubuntu « ozbots.org Add the command to your .bashrc file so that you don’t have to enter every time your start a new terminal. Alternatively, you can configure the system wide library search path. Using your favorite editor, add a single line containing the text /usr/local/lib to the end of a file named /etc/ld.so.conf.d/opencv.conf . [...]

  • Problem:
    Linking CXX executable ../../bin/opencv_test_calib3d
    /usr/bin/ld: warning: libx264.so.120, needed by /usr/local/lib/libavcodec.so.53, not found (try using -rpath or -rpath-link)
    /usr/local/lib/libavcodec.so.53: undefined reference to `av_opt_set@LIBAVUTIL_51′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_mpegaudio_decode_header@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_mpa_freq_tab@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_toupper4@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_flac_parse_block_header@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_flac_is_extradata_valid@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_mpeg4audio_get_config@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_split_xiph_headers@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_find_start_code@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_dv_codec_profile@LIBAVCODEC_53′
    /usr/local/lib/libavcodec.so.53: undefined reference to `av_get_media_type_string@LIBAVUTIL_51′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_dirac_parse_sequence_header@LIBAVCODEC_53′
    /usr/local/lib/libavcodec.so.53: undefined reference to `x264_encoder_open_120′
    /usr/local/lib/libavcodec.so.53: undefined reference to `av_sample_fmt_is_planar@LIBAVUTIL_51′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_mpeg4audio_sample_rates@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_aac_parse_header@LIBAVCODEC_53′
    /usr/local/lib/libavcodec.so.53: undefined reference to `av_samples_get_buffer_size@LIBAVUTIL_51′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_frame_rate_tab@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_flac_parse_streaminfo@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_mpa_bitrate_tab@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_dv_frame_profile@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_mpa_decode_header@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_copy_pce_data@LIBAVCODEC_53′
    /usr/local/lib/libavformat.so.53: undefined reference to `ff_ac3_parse_header@LIBAVCODEC_53′
    collect2: ld returned 1 exit status
    make[2]: *** [bin/opencv_test_calib3d] Error 1
    make[1]: *** [modules/calib3d/CMakeFiles/opencv_test_calib3d.dir/all] Error 2
    make: *** [all] Error 2

  • I built opencv with the latest x264 stable, the last ffmpeg from git and the last OpenCV 2.3.1 in the site (which is called 2.3.1a) and compiled both packages with –enable-shared –enable-pic.
    I am using ubuntu 10.04 x32 (intel processor)

    • Osman Eralp

      If you used git to get ffmpeg, you might have grabbed version 0.9. I have not tested version 0.9. Can you try downloading the tarball for ffmpeg 0.8 and installing that version?

  • enekochan

    Thank you very much! It worked very well, not as many other guides I found around.

    By the way, may be it’s not necesary to reboot after creating /etc/ld.so.conf.d/opencv.conf file, just running:

    sudo ldconfig /etc/ld.so.conf

  • Hey, thanks a lot! I was trying to make OpenCV initialize my cam for the past week. Finally it started working after following this tutorial :) Kudos!

  • dani

    I am guessing that at least some of the libraries in the output of

    pkg-config opencv –libs

    are archive libraries. It is incorrect to put archive libraries before sources that need them (test_1.cpp in this case): the order of sources and libraries on the link line matters.

    Try

    g++ -o test_1 test_1.cpp `pkg-config opencv –cflags –libs`

  • Nick H

    Thank you for all the tutorial and all the tips…

    These may help others:

    I’m was struggling to get openCV 2.3.1 to see ffmpeg. I’ve tried both ffmpeg 0.7.8 and ffmpeg 0.8.7 , using –enable-pic –enable-shared . I’ve tried sudo ldconfig , but the problem remained.

    It compiled, but the /opencv_test_highgui Highgui_FFmpeg_WriteBigVideo fails with a segmentation fault and a warning about
    “Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later.”

    It seems part of ffmpeg was installed in the directory it was built in.
    The fix was :
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/nick/ffmpeg-0.7.8
    ======

    Separately, it may save others time to know that the test data can be downloaded by :
    snv co https://code.ros.org/svn/opencv/tags/2.3.1/opencv_extra/

    and the environment variable needs to be set :
    export OPENCV_TEST_DATA=[insert directory path here]/opencv_extra/testdata

    Thank you again for an excellent tutorial.

    Nick

  • Miroslav

    Hi. Just wanted to say that I kept getting a linker error “recompile with -fPIC”. Worked couple of hours on it. Finally everything worked when I added “–enable-shared” to the configuration of ffmpeg.

    A colleague successfully built the lib without the aforementioned flag.

    • Osman Eralp

      This is a common problem. I don’t know why only some people get this error. Search the other comments for “fPIC” to see how other people solved this issue. What type of processor do you have? Is it AMD or Intel?

  • Jake

    Great Guide. Thanks for putting it together!!

  • Guy van den Berg

    Great article. Very useful. Thx.

    I was also getting the error:

    “Linking CXX shared library ../../lib/libopencv_highgui.so
    /usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet_nofree’ can not be used when making a shared object; recompile with -fPIC

    To fix it I configured x264 with –enable-shared instead of –enable-static

  • molecula21

    Great Guide indeed! Only worked after reading all the comments though. I suggest you put the –enable-shared and –enable-pic information in the guide itself to complete it. Exelent work though :)

    • Osman Eralp

      Given how many people need to use the –enable-pic option, I agree that I should add this info in the guide itself. I’ll make the addition in the next update. Thanks for the feedback.

  • an error was encountered during prior to the opencv installation – when making the v4l, one error was given as ‘ QMainWindow: No such file or directory’. Anyway, v4l was installed via synaptic package manager, and in the opencv congifuration list the v4l item showed -using v4l correctly.
    cheers

  • djdm

    I am having problems with my build of opencv 2.3.1. Used –enable-pic and –enable-shared for both x264 and ffmpeg. It falls oevr at 19% with the following errors

    make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2

    Please help!!!!

  • djdm

    Sorry, here is some more of the error dump.

    is there a problem with my ffmpeg or some missing libraries????

    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:547:13: error: ‘CODEC_TYPE_VIDEO’ was not declared in this scope
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvCapture_FFMPEG::grabFrame()’:
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:640:34: error: ‘avcodec_decode_video’ was not declared in this scope
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In function ‘const char* icvFFMPEGErrStr(int)’:
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:917:10: error: ‘AVERROR_NUMEXPECTED’ was not declared in this scope
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:921:10: error: ‘AVERROR_NOFMT’ was not declared in this scope
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:923:10: error: ‘AVERROR_IO’ was not declared in this scope
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:925:10: error: ‘AVERROR_NOMEM’ was not declared in this scope
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In function ‘AVStream* icv_add_video_stream_FFMPEG(AVFormatContext*, CodecID, int, int, int, double, int)’:
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1012:70: error: ‘CODEC_TYPE_VIDEO’ was not declared in this scope
    In file included from /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg.cpp:45:0:
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘void CvVideoWriter_FFMPEG::close()’:
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1298:3: warning: ‘int url_fclose(AVIOContext*)’ is deprecated (declared at /usr/include/libavformat/avio.h:279) [-Wdeprecated-declarations]
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1298:20: warning: ‘int url_fclose(AVIOContext*)’ is deprecated (declared at /usr/include/libavformat/avio.h:279) [-Wdeprecated-declarations]
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvVideoWriter_FFMPEG::open(const char*, int, double, int, int, bool)’:
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1339:41: error: ‘guess_format’ was not declared in this scope
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1367:31: error: ‘av_alloc_format_context’ was not declared in this scope
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1411:9: warning: ‘int av_set_parameters(AVFormatContext*, AVFormatParameters*)’ is deprecated (declared at /usr/include/libavformat/avformat.h:1336) [-Wdeprecated-declarations]
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1411:35: warning: ‘int av_set_parameters(AVFormatContext*, AVFormatParameters*)’ is deprecated (declared at /usr/include/libavformat/avformat.h:1336) [-Wdeprecated-declarations]
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1415:5: warning: ‘void dump_format(AVFormatContext*, int, const char*, int)’ is deprecated (declared at /usr/include/libavformat/avformat.h:1458) [-Wdeprecated-declarations]
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1415:35: warning: ‘void dump_format(AVFormatContext*, int, const char*, int)’ is deprecated (declared at /usr/include/libavformat/avformat.h:1458) [-Wdeprecated-declarations]
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1479:13: warning: ‘int url_fopen(AVIOContext**, const char*, int)’ is deprecated (declared at /usr/include/libavformat/avio.h:278) [-Wdeprecated-declarations]
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1479:52: warning: ‘int url_fopen(AVIOContext**, const char*, int)’ is deprecated (declared at /usr/include/libavformat/avio.h:278) [-Wdeprecated-declarations]
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1485:5: warning: ‘int av_write_header(AVFormatContext*)’ is deprecated (declared at /usr/include/libavformat/avformat.h:1394) [-Wdeprecated-declarations]
    /home/andrew/Downloads/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1485:25: warning: ‘int av_write_header(AVFormatContext*)’ is deprecated (declared at /usr/include/libavformat/avformat.h:1394) [-Wdeprecated-declarations]
    make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2

  • pacoqr

    Great, accurate, and reliable tutorial. After my previous system crashed I had to reinstall everything from scratch and OpenCV would not install because of ffmpeg being < 0.8. Following this tutorial made it build flawlessly.

  • Akhi

    Thanks ..

    This is very helpful installation guide .. rather i should say it is has every step correct which is normally not expected .

    Very good job , thanks .

  • Siddharth

    Thanks! This worked for me. I initially had issues with the newer version of ffmpeg (0.8), and then I reverted to 0.7 and followed this guide. I am using OpenCV 2.3.1.

  • Icarus A

    Thanks @Osman for this excellent, step-by-step tutorial and also the troubleshooting info, however inspite of following all steps, I’ve stumbled upon warnings (which I am willing to ignore for now) and errors (that stump my build).

    They go like –

    [ 27%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o
    In file included from /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg.cpp:45:0:
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘void CvCapture_FFMPEG::close()’:
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:451:9: warning: ‘void av_close_input_file(AVFormatContext*)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1416) [-Wdeprecated-declarations]
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:451:31: warning: ‘void av_close_input_file(AVFormatContext*)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1416) [-Wdeprecated-declarations]

    home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘void CvVideoWriter_FFMPEG::close()’:
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1298:20: error: ‘url_fclose’ was not declared in this scope
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvVideoWriter_FFMPEG::open(const char*, int, double, int, int, bool)’:
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1411:35: error: ‘av_set_parameters’ was not declared in this scope
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1415:35: error: ‘dump_format’ was not declared in this scope
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1442:15: warning: ‘int avcodec_open(AVCodecContext*, AVCodec*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3662) [-Wdeprecated-declarations]
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1442:36: warning: ‘int avcodec_open(AVCodecContext*, AVCodec*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3662) [-Wdeprecated-declarations]
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1479:42: error: ‘URL_WRONLY’ was not declared in this scope
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1479:52: error: ‘url_fopen’ was not declared in this scope
    /home/icarus/Work/MachineVision/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1485:25: error: ‘av_write_header’ was not declared in this scope
    make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2

    I am using the latest ffmpeg snapshot downloaded yesterday. And, going through the troubleshooting steps, don’t find anything similar.

    While I’ve read at several places that OpenCV-2.3.1 supports ffmpeg-0.8, but do I really now need to go back to ffmpeg-0.7 ?

    • Osman Eralp

      I have used ffmpeg 0.8 with OpenCV 2.3.1, so I know it works. I have seen your type of error when a previous build failed and I try to run make a second time in the same directory. Can you try deleting the build directory, creating a new build directory, and running cmake and make again? Let me know the result.

      • Icarus A

        Thanks for taking time to reply, @Osman.

        I realized (eventually) that I wasn’t using ffmpeg-0.8 at all, but the latest snapshot which is based on ffmpeg-0.10 ! I reverted back to using the tagged “0.8″ snapshot of ffmpeg, and able to progress further, although getting stuck with another error, which has been reported before by Danielsohn on September 4, 2011 at 6:42 am, and you’ve provided an answer to. Shall be trying that out shortly.

  • noel

    I used –enable-pic –enable-shared for ffmpeg and x260 and everything was ok.

  • gibinjoe

    osman,when i try to compile, i am getting this error…

    gibinjoe@ubuntu:~/workspace/ipone$ g++ ‘pkg-config opencv –cflags’ ‘pkg-config opencv –libs’ iptwo.cpp -o iptwo
    g++: pkg-config opencv –cflags: No such file or directory
    g++: pkg-config opencv –libs: No such file or directory
    g++: iptwo.cpp: No such file or directory
    g++: no input files

    the
    $ pkg-config opencv –cflags
    $ pkg-config opencv –libs
    commands are givin the proper ouptus

    what could be the problem

  • mas

    amazing…thank you so much. tracking all those dependencies and figuring out all those configure flags…wow man. great work!

  • When running sudo make && sudo make install of v4l-utils I get:

    g++ -c -m64 -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I../libv4l2util -I../../lib/include -I../../include -I. -o qv4l2.o qv4l2.cpp
    In file included from qv4l2.cpp:20:0:
    qv4l2.h:23:23: ödesdigert fel: QMainWindow: Filen eller katalogen finns inte
    kompilering avslutad.

  • Jacs

    thank you so much for this tutorial,but I have the same question as Sam.

    when I compiler:
    /tmp/cc2LsKTl.o: In function `main’:
    rimage.cpp:(.text+0×19): undefined reference to `std::allocator::allocator()’
    rimage.cpp:(.text+0×33): undefined reference to `std::basic_string<char, std::char_traits, std::allocator >::basic_string(char const*, std::allocator const&)’
    rimage.cpp:(.text+0x3e): undefined reference to `std::allocator::~allocator()’
    rimage.cpp:(.text+0×58): undefined reference to `cv::imread(std::basic_string<char, std::char_traits, std::allocator > const&, int)’
    rimage.cpp:(.text+0x7f): undefined reference to `std::allocator::allocator()’
    rimage.cpp:(.text+0×99): undefined reference to `std::basic_string<char, std::char_traits, std::allocator >::basic_string(char const*, std::allocator const&)’
    rimage.cpp:(.text+0xac): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits, std::allocator > const&, int)’
    rimage.cpp:(.text+0xb7): undefined reference to `std::basic_string<char, std::char_traits, std::allocator >::~basic_string()’
    rimage.cpp:(.text+0xc2): undefined reference to `std::allocator::~allocator()’
    rimage.cpp:(.text+0xd4): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)’
    rimage.cpp:(.text+0xdf): undefined reference to
    ………….
    …………

    When I try :
    g++ -I/usr/local/include/opencv/ -Wall -o lkdemo rimage.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy

    it work,but how to solve this problem without long command?

  • bill fletcher

    Really great work! Fixed my 11.10 installation and got my webcam working.

  • Arjen

    Thank you for this excellent guide. By far the most current and comprehensive guide. After spending hours combining bits and pieces from all over the net, I finally stumbled upon your guide and everything works like a charm!

    Note. to compile opencv with python support, use this configure statement:
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..

    and don’t for get to install numpy before you compile opencv. See also http://opencv.willowgarage.com/wiki/InstallGuide%20%3A%20Debian

  • Arjen

    For everybody having problems with compiling OpenCV on AMD64 systems, the following site is a must read: http://thebitbangtheory.wordpress.com/2011/10/23/how-to-install-opencv-2-3-1-in-ubuntu-11-10-oneiric-ocelot-with-python-support/

    It specifies additional configure switches for x264 and ffmpeg to make OpenCV compile without any problems.

  • Andy

    I am struggling with the last stage when i try and type:

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

    into the bash.bashrc file i get the message:

    gedit could not back up the old copy of the file before saving the new one. You can ignore this warning and save the file anyway, but if an error occurs while saving, you could lose the old copy of the file. Save anyway?

    when i click save anyway nothing happens. Why is this not saving?

    • Osman Eralp

      It sounds like you don’t have permission to edit the file. Try typing “sudo” before the edit command, like this “sudo gedit /etc/bash.bashrc”. Let me know if that doesn’t work.

  • Andy

    Thankyou very much Osman that has done it for me! This is a great guide!

    I am having a problem running opencv functions when i try and run opencv_performance i get the error message:

    opencv_performance: error while loading shared libraries: libavcodec.so.52: cannot open shared object file: No such file or directory

    Is this a linking problem? How do I fix this?

  • lcm861019

    Hi, i have problem in solving the 34% installation error as Jon Blake. Do i need to uninstalled x264 and ffmpeg first and reinstall with adding –enable-shared and –enable-pic during configuration of both files?
    Thanks in advanced.

    • lcm861019

      Solved, i need to run “apt-get remove ffmpeg x264″ and reinstall both ffmpeg and x264 by adding –enable-pic and –enable-shared during their configuration.

      Thanks

      • Osman Eralp

        That is a common problem. I should add it to the tutorial. I think those options are required for AMD processors. What processor are you using?

  • Elena

    Thanks for this tutorial! It’s really nice!
    But I’m still in step 4 because when I type this command:
    . / configure –enable-static
    the terminal gives me this error:
    “Found no assembler
    minimum version is yasm-1.0.0
    if you really want to compile without asm, configure with –disable-asm.”
    I tried to write it but nothing, I even tried to write every kind of combination had also read all the comments of others, but nothing changes. What should I do?
    I’m using ubuntu in a virtualbox installed on an operating system windows7.
    Thanks in advance!
    Elena :)

    • Osman Eralp

      Yasm should have been installed in step two. You can try installing yasm separately: sudo apt-get install yasm.

      • Elena

        I’m sorry but there are some errors during installation:
        Reading package lists…Done
        Building dependency tree
        Reading state information…Done
        E: Unable to locate package yasm.
        E: Couldn’t find any package by “yasm.”

        But when I went past the point 2 was everything had gone well

        • Osman Eralp

          Maybe your installation’s list of packages is incomplete or out of date. Start with this command: sudo apt-get update. After that, try to install yasm again. If that doesn’t work, check if you have the correct list of repositories.

          This is what you should get:

          <48> …/code $ sudo apt-get install yasm
          [sudo] password for osman:
          Reading package lists… Done
          Building dependency tree
          Reading state information… Done
          The following NEW packages will be installed:
          yasm
          0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
          Need to get 604 kB of archives.
          After this operation, 1,667 kB of additional disk space will be used.
          Get:1 http://us.archive.ubuntu.com/ubuntu/ oneiric/main yasm i386 1.1.0-1 [604 kB]
          Fetched 604 kB in 2s (211 kB/s)
          Selecting previously deselected package yasm.
          (Reading database … 133561 files and directories currently installed.)
          Unpacking yasm (from …/archives/yasm_1.1.0-1_i386.deb) …
          Processing triggers for man-db …
          Setting up yasm (1.1.0-1) …
          <49> …/code $

  • Osman Eralp
    thanks for the tutorial.
    I would like to add few tips.

    If you encounter the error

    usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet_nofree’ can not be used when making a shared object; recompile with -fPIC”

    it should be compiled with the flags –enable-pic –enable-shared –enable-static.

    After setting up you can check whether configured correctly by ffmepg -V.

    ffmpeg version 0.10.2 Copyright (c) 2000-2012 the FFmpeg developers
    built on Apr 2 2012 17:28:41 with gcc 4.6.1
    configuration: –enable-gpl –enable-libfaac –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libtheora –enable-libvorbis –enable-libx264 –enable-libxvid –enable-nonfree –enable-postproc –enable-version3 –enable-x11grab –enable-pic –enable-shared –enable-static
    libavutil 51. 35.100 / 51. 35.100
    libavcodec 53. 61.100 / 53. 61.100
    libavformat 53. 32.100 / 53. 32.100
    libavdevice 53. 4.100 / 53. 4.100
    libavfilter 2. 61.100 / 2. 61.100
    libswscale 2. 1.100 / 2. 1.100
    libswresample 0. 6.100 / 0. 6.100
    libpostproc 52. 0.100 / 52. 0.100

    this will show if configured correctly. In addition some times it tends to link with previous versions. I recommend to rm -r /usr/local/bin/ffmepg and /usr/local/bin/x264 before a new compilation.

    the following versions worked for me
    OpenCV 2.3.1
    ffmpeg 0.10.2
    x264 1.22

    Thankz and cheers

  • Nick Modly

    First of all, thank you for the fantastic guide – nothing else that I could find was was specific and well-put together.

    I am trying to compile a simple program using openCV, specifically a few functions from highgui.

    At the beginning of my program.cpp:</b< #include "highui.h"

    output of pkg-config opencv –cflags: -I/usr/local/include/opencv -I/usr/local/include

    output of pkg-config opencv –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

    to compile: g++ `pkg-config opencv –cflags` `pkg-config opencv –libs` program.cpp -o program

    g++ errors:
    /tmp/ccpVcrve.o: In function `main’:
    program.cpp:(.text+0×11): undefined reference to `cvCreateCameraCapture’
    program.cpp:(.text+0×29): undefined reference to `cvNamedWindow’
    program.cpp:(.text+0×45): undefined reference to `cvMoveWindow’
    program.cpp:(.text+0×54): undefined reference to `cvQueryFrame’
    program.cpp:(.text+0x6c): undefined reference to `cvShowImage’
    program.cpp:(.text+0×78): undefined reference to `cvWaitKey’

    I know that these are occurring because the necessary library is not being linked. However, I followed this guide to the letter on a completely fresh install of Ubuntu 11.10 (Running on a virtual machine using VMware Player). The include path is correct, as the compiler is able to find the “highgui.h”. The library path looks correct – /usr/local/lib contains libopencv_highui.so, libopencv_highui.so.2.3, libopencv_highui.so.2.3.1, and the rest of the similarly named opencv libs. Where am I going wrong?

    Thanks,
    Nick

    • Nick Modly

      I found a way to make it work – changing the order of the arguments to g++ causes it to compile happily:

      g++ `pkg-config opencv –cflags` program.cpp -o program `pkg-config opencv –libs`

      • Osman Eralp

        Nick, you are correct! In Ubuntu 11.10 you need to put the program name before the libs. In Ubuntu 11.04 you could put the libs before the program name. I’m sorry the tutorial did not have this change. I have updated the tutorial. Thanks!

  • wolf

    Osman, thank you very much for the excellent tutorial. Been stumbling for days trying to get OpenCV installed in Ubuntu 11.04. But now I’m getting a problem when I compile that I can’t seem to fix: when I compile using your syntax, I get the following errors:

    g++ ‘pkg-config opencv –cflags: No such file or directory
    g++ ‘pkg-config opencv –libs: No such file or directory
    hello.cpp:1:21: fatal error: highgui.h: No such file or directory
    compilation terminated

    I followed your installation instructions to the letter and had no errors or warnings. I get the following outputs:

    $pkg-config opencv –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

    and

    $pkg-config opencv –cflags
    -I/usr/local/include/opencv -I/usr/local/include

    I also added

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

    to the end of my bashrc. I’m figuring it’s a problem with my pkg-config installation, but I don’t know where. Can you help?

    • wolf

      Never mind – ten minutes after I left this comment, I found it: I was using regular single quotes(‘) instead of single back quotes(`) around my pkg-config calls. I didn’t realize there was a difference. Thanks again for the excellent tutorial!

  • raghav

    Hey Osman,
    What version of ffmpeg did we require , coz the one that you are using , I am getting the following error while running ./configure

    leonidus@leonidus:~/ffmpeg-0.10.2$ ./configure –enable-gpl –enable-libfaac –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libtheora –enable-libvorbis –enable-libx264 –enable-libxvid –enable-nonfree –enable-postproc –enable-version3 –enable-x11grab
    ERROR: libx264 not found

    If you think configure made a mistake, make sure you are using the latest
    version from Git. If the latest version fails, report the problem to the
    ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
    Include the log file “config.log” produced by configure as this will help
    solving the problem.

    Please solve it dude, I need my opencv up and running

    • Osman Eralp

      The error says that libx264 is not found. Make sure you installed x264 in step four of the procedure. Also, your command prompt shows that you are using ffmpeg 0.10.x, whereas my procedure used 0.8.x. That could a problem. Follow the procedure exactly, and you will be able to successfully install OpenCV.

  • Ruben

    Hi this a great Tutorial and the only one which work to me. by the Way the instalation did not install and built the samples in step 9 . I was wondering if you culd help me
    to Compile opencv “with samples”
    In the OpenCv_tutorial.PDF is mentioned that I should set BUILD_EXAMPLES to ON in cmake configuration . do you know what that means?
    Thanks

  • Ruben

    I have to add the double dot–>>

    “cmake -D BUILD_EXAMPLES=ON ..” Thanks

  • Martin

    Great job – it helped me a lot. Many thx.

  • Anshul

    Hi,
    As everyone else has already said, great tutorial, but I’m still having some trouble building OpenCV!

    I have, so far, completed all 9 steps and downloaded OpenCV 3.2.1. When I try to build it I get the following errors…

    Scanning dependencies of target opencv_highgui
    [ 19%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap.o
    [ 20%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_images.o
    [ 20%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o
    In file included from /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg.cpp:45:0:
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘void CvCapture_FFMPEG::close()’:
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:451:9: warning: ‘void av_close_input_file(AVFormatContext*)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1525) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:451:31: warning: ‘void av_close_input_file(AVFormatContext*)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1525) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvCapture_FFMPEG::reopen()’:
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:483:5: warning: ‘void av_close_input_file(AVFormatContext*)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1525) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:483:27: warning: ‘void av_close_input_file(AVFormatContext*)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1525) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:486:52: error: ‘av_open_input_file’ was not declared in this scope
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:487:5: warning: ‘int av_find_stream_info(AVFormatContext*)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1349) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:487:27: warning: ‘int av_find_stream_info(AVFormatContext*)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1349) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:494:50: error: ‘avcodec_thread_init’ was not declared in this scope
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:497:5: warning: ‘int avcodec_open(AVCodecContext*, AVCodec*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3354) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:497:28: warning: ‘int avcodec_open(AVCodecContext*, AVCodec*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3354) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvCapture_FFMPEG::open(const char*)’:
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:524:63: error: ‘av_open_input_file’ was not declared in this scope
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:529:11: warning: ‘int av_find_stream_info(AVFormatContext*)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1349) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:529:33: warning: ‘int av_find_stream_info(AVFormatContext*)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1349) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:541:54: error: ‘avcodec_thread_init’ was not declared in this scope
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:550:13: warning: ‘int avcodec_open(AVCodecContext*, AVCodec*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3354) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:550:36: warning: ‘int avcodec_open(AVCodecContext*, AVCodec*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3354) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In function ‘AVStream* icv_add_video_stream_FFMPEG(AVFormatContext*, CodecID, int, int, int, double, int)’:
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:999:7: warning: ‘AVStream* av_new_stream(AVFormatContext*, int)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1549) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:999:26: warning: ‘AVStream* av_new_stream(AVFormatContext*, int)’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:1549) [-Wdeprecated-declarations]
    In file included from /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg.cpp:45:0:
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In function ‘int icv_av_write_frame_FFMPEG(AVFormatContext*, AVStream*, uint8_t*, uint32_t, AVFrame*)’:
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1121:20: warning: ‘int avcodec_encode_video(AVCodecContext*, uint8_t*, int, const AVFrame*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:4054) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1121:72: warning: ‘int avcodec_encode_video(AVCodecContext*, uint8_t*, int, const AVFrame*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:4054) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘void CvVideoWriter_FFMPEG::close()’:
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1298:20: error: ‘url_fclose’ was not declared in this scope
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvVideoWriter_FFMPEG::open(const char*, int, double, int, int, bool)’:
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1411:35: error: ‘av_set_parameters’ was not declared in this scope
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1415:35: error: ‘dump_format’ was not declared in this scope
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1442:15: warning: ‘int avcodec_open(AVCodecContext*, AVCodec*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3354) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1442:36: warning: ‘int avcodec_open(AVCodecContext*, AVCodec*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3354) [-Wdeprecated-declarations]
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1479:42: error: ‘URL_WRONLY’ was not declared in this scope
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1479:52: error: ‘url_fopen’ was not declared in this scope
    /home/kanakia/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1485:25: error: ‘av_write_header’ was not declared in this scope
    make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2

    I have looked through previous posts but can’t find anything to help me with this issue. I would appreciate any help anyone can provide. Thanks!

    • Osman Eralp

      I have seen other similar errors referring to av* not declared. All the errors have been related to ffmpeg. Here are some things to try:
      1. When dubugging strange errors like this one, always delete the opencv build directory and create a new one. I have seen files from a previous unsuccessful build interfere with the next build.
      2. After building ffmpeg, make sure you actually installed it. If you didn’t install it, the opencv build might try to include another incompatible release of ffmpeg.
      3. If 1 or 2 doesn’t help, try adding –enable-shared and –enable-pic to the ffmpeg and the x264 configure commands. Remake each of those tools, and then rebuild opencv.

      Please report back how these steps work for you. Thanks!

  • Varun Agrawal

    Thank you SO much!!
    I must have referred to more than a dozen websites trying to get OpenCV working. Your tut did it, although I did have trouble due to the –enable-shared and –enable-pic flags not being set initially.
    Could you include them in the main tutorial itself so that we do not have to go through all of the comments for just a small, single error?

    Thanks alot anyways for you help!

  • Riaz

    Thank you so much….

  • kenneth

    this is not a very comprehensive guide. It is very confusing. Please add all of the commands that users need to type between the ones you have. For example, I have no idea which folder to place the x264 codec into after I download it but before I build it, is it just any folder, does it matter? Same thing with ffmpeg. When I tried to compile those two it spit out a bunch of errors. Please use git or clone commands in your guide unless absolutely necessary so that everything can be copied and pasted in a row and without any additional commands. Not everybody knows linux that well and any mistakes made in the installation will affect them in the future as they use openCV. Thank you,

    • Osman Eralp

      It should not matter where you place the files that you download. After you untar them, directories will be created. I did assume that people will know that they need to untar the files. I assumed that anyone with the knowledge to write and compile programs using OpenCV will have some basic Linux knowledge. However, I can see your point. In the step for compiling OpenCV, I specifically used the tar command. I will add it for x264 and ffmpeg. I can try to help with your errors. What errors did you get?

  • Hamia06

    Hello! Can you please help me with this?
    When i do the step 4 this is what happened.

    papa@ubuntu:~/src/x264-snapshot-20050824-2219$ sudo make install
    nasm -f elf -o common/i386/dct-a.o common/i386/dct-a.asm
    make: nasm: Command not found
    make: *** [common/i386/dct-a.o] Error 127

    What to do?

  • Hi Sir I have one Dought actually kernel have camera drivers again y u r installed separate drivers for cameras and what is neccessary of open cv in boards?with out cv u cant get the capture from the camera?i mean with out cv the camera is not working with any development board?

    • Osman Eralp

      Is your camera a USB camera? If the USB camera supports the UVC standard, OpenCV should be able to grab frames from the camera. Does that answer your question?

  • gunapala

    hi ,,,i installed this stuffs properlly thrice but i still getting error called captured is null

  • gunapala

    thank u !!! now my code iss running with laptop cam but its not detecting usb camara (logitech),,,. when i install first time it was detecting but when i restart my lap its not working!!!! can u please help

  • sandesh

    Thanks a ton buddy:)

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>