Monday, September 26, 2011

OpenCV 2.3.1 on Ubuntu 10.10 or later

*Update: For OpenCV 2.4 on Ubuntu 12.04 see my latest post.

This post will guide you on how to compile and run OpenCV 2.3.1 on Ubuntu 10.10 or later.

First, install all prerequisites:
sudo apt-get install build-essential checkinstall git cmake ffmpeg 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 libtbb-dev libv4l-dev libopenexr-dev libunicap2-dev libavformat-dev libswscale-dev libdc1394-22-dev 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 python-numpy
This is not a minimal set of libraries, but it's a collection that will give you most of the functionality. For example, if you are sure that you will never need to use a firewire camera, you can ignore libdc1394-22-dev. But if you actually need to use this feature you will have to recompile OpenCV. Also, if you need CUDA support, follow the instructions in this post before continuing here.

Download OpenCV:
wget downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2
Extract and create a build directory:
tar -xvf OpenCV-2.3.1a.tar.bz2
cd OpenCV-2.3.1/
mkdir build
cd build
Now run cmake:
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON ..
At this point check the output of cmake to make sure that all the features you are going to need are supported. If not you will have to install the corresponding libraries and run cmake again. Compile:
make
If everything went well you can go ahead and install:
sudo make install
Finally, add the following lines in your .bashrc:
# OpenCV stuff
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
To test that everything works, let's run the face detection demo. Go to the bin directory:
cd bin
And run:
./facedetect --cascade="../../data/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="../../data/haarcascades/haarcascade_eye.xml" --scale=1.3 ../../samples/c/lena.jpg
You should see something like this:


32 comments:

  1. Hey,

    I noticed that when you run the example you may get missing dependency errors for both:
    libgtk2.0-dev pkg-config

    Incorporated into the first step this would be:
    1.
    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 libtbb-dev libv4l-dev libopenexr-dev libunicap2-dev libavformat-dev libswscale-dev libdc1394-22-dev 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 python-numpy libgtk2.0-dev pkg-config

    ReplyDelete
  2. Dear friend:
    I make all steps, but I have the following error:

    espel@ubuntu:~/OpenCV-2.3.1/samples/c$ gcc motempl.c -o motempl
    /tmp/cctmXsnA.o: In function `cvDecRefData':
    motempl.c:(.text+0x9f2): undefined reference to `cvFree_'
    motempl.c:(.text+0xa7a): undefined reference to `cvFree_'
    /tmp/cctmXsnA.o: In function `cvGetRow':
    motempl.c:(.text+0xb91): undefined reference to `cvGetRows'
    /tmp/cctmXsnA.o: In function `cvGetCol':
    motempl.c:(.text+0xbbf): undefined reference to `cvGetCols'
    /tmp/cctmXsnA.o: In function `cvReleaseMatND':
    motempl.c:(.text+0xbd9): undefined reference to `cvReleaseMat'
    /tmp/cctmXsnA.o: In function `cvSubS':
    motempl.c:(.text+0xd35): undefined reference to `cvAddS'
    /tmp/cctmXsnA.o: In function `cvCloneSeq':
    motempl.c:(.text+0xd6e): undefined reference to `cvSeqSlice'
    /tmp/cctmXsnA.o: In function `cvSetNew':
    motempl.c:(.text+0xddb): undefined reference to `cvSetAdd'
    /tmp/cctmXsnA.o: In function `cvGetSetElem':
    motempl.c:(.text+0xe84): undefined reference to `cvGetSeqElem'

    motempl.c:(.text+0x1ab4): undefined reference to `cvCalcGlobalOrientation'
    motempl.c:(.text+0x1ae6): undefined reference to `cvNorm'
    motempl.c:(.text+0x1afa): undefined reference to `cvResetImageROI'
    motempl.c:(.text+0x1b09): undefined reference to `cvResetImageROI'
    motempl.c:(.text+0x1b18): undefined reference to `cvResetImageROI'
    motempl.c:(.text+0x1b24): undefined reference to `cvResetImageROI'
    motempl.c:(.text+0x1be7): undefined reference to `cvCircle'
    motempl.c:(.text+0x1c18): undefined reference to `sin'
    motempl.c:(.text+0x1c65): undefined reference to `cos'
    motempl.c:(.text+0x1cd6): undefined reference to `cvLine'
    /tmp/cctmXsnA.o: In function `main':
    motempl.c:(.text+0x1dbe): undefined reference to `cvCreateCameraCapture'
    motempl.c:(.text+0x1ddd): undefined reference to `cvCreateFileCapture'
    motempl.c:(.text+0x1dfd): undefined reference to `cvNamedWindow'
    motempl.c:(.text+0x1e0c): undefined reference to `cvQueryFrame'
    motempl.c:(.text+0x1e4b): undefined reference to `cvCreateImage'
    motempl.c:(.text+0x1e5b): undefined reference to `cvSetZero'
    motempl.c:(.text+0x1e92): undefined reference to `cvShowImage'
    motempl.c:(.text+0x1e9c): undefined reference to `cvWaitKey'
    motempl.c:(.text+0x1eb3): undefined reference to `cvReleaseCapture'
    motempl.c:(.text+0x1ebd): undefined reference to `cvDestroyWindow'
    collect2: ld returned 1 exit status

    What can I do?
    Thank for your help
    Egalarza

    ReplyDelete
  3. It's a linking problem so I guess you are missing a dependency library. This is not enough to understand what's the problem. Could you post your cmake output. That might help.

    ReplyDelete
  4. Hi,I followed all the steps but my "make" is not working. Here is the output:

    [ 32%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o
    In file included from /home/umar/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg.cpp:45:0:
    /home/umar/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvCapture_FFMPEG::reopen()’:
    /home/umar/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:486:5: warning: ‘int av_open_input_file(AVFormatContext**, const char*, AVInputFormat*, int, AVFormatParameters*)’ is deprecated (declared at /usr/include/libavformat/avformat.h:1050) [-Wdeprecated-declarations]
    /home/umar/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:486:52: warning: ‘int av_open_input_file(AVFormatContext**, const char*, AVInputFormat*, int, AVFormatParameters*)’ is deprecated (declared at /usr/include/libavformat/avformat.h:1050) [-Wdeprecated-declarations]
    /home/umar/OpenCV-
    ... and some more lines like this
    make: *** [all] Error 2

    Kindly, suggest anything.

    Regards,
    Umar Iqbal

    ReplyDelete
  5. /home/umar/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/umar/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/umar/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/umar/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/umar/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/umar/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/umar/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/umar/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/umar/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

    ReplyDelete
  6. and my bin folder is totally empty

    ReplyDelete
  7. Looks like you are missing ffmpeg. Do a

    sudo apt-get install ffmpeg

    and try compiling again. If that doesn't fix it then you might be missing more libraries. A post of your CMAKE output would help a lot. Let me know what happened either way. I will edit the post to include ffmpeg if that is the case.

    ReplyDelete
  8. Egalarza,

    seems you are missing a couple of libraries. Do a

    sudo apt-get install libtiff4-dev libjasper-dev

    then run cmake again and try to compile. Let me know what happens. If it still doesn't compile, repost your cmake output.

    ReplyDelete
  9. Hi Kary:
    Here is my new cmake output

    espel@ubuntu:~/OpenCV-2.3.1/build$ cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON ..
    -- Detected version of GNU GCC: 46 (406)
    -- Found TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so
    -- Found Jasper: /usr/lib/x86_64-linux-gnu/libjasper.so
    -- Found OpenEXR: /usr/lib/libIlmImf.so
    -- Could NOT find PythonLibs (missing: PYTHON_INCLUDE_DIRS)
    -- 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: NO
    -- OpenNI PrimeSensor Modules: NO
    -- XIMEA: NO
    --
    -- Video I/O:
    -- DC1394 1.x: NO
    -- DC1394 2.x: YES
    -- FFMPEG: YES
    -- codec: YES
    -- format: YES
    -- util: YES
    -- swscale: YES
    -- gentoo-style: YES
    -- GStreamer: YES
    -- UniCap: NO
    -- PvAPI: NO
    -- V4L/V4L2: FALSE/FALSE
    -- Xine: NO
    --
    -- Other third-party libraries:
    -- Use IPP: NO
    -- Use TBB: YES
    -- Use ThreadingFramework: NO
    -- Use Cuda: NO
    -- Use Eigen: NO
    --
    -- 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/espel/OpenCV-2.3.1/build
    -- -----------------------------------------------------------------
    --
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/espel/OpenCV-2.3.1/build

    Thank you for your help
    Egalarza

    ReplyDelete
  10. Hi,

    Yes, it works for me this time. I was trying to install it on ubuntu 11.04 but in case of 10.10 it is working absolutely fine. Thanks for Post and Help.

    Cheers,
    Umar

    ReplyDelete
  11. Hi Kary:
    It doesn't compiles, It gives the same errors.
    Here is my Cmake output. I am working with Ubuntu 11.10.
    Can you suggest me something?

    espel@ubuntu:~/OpenCV-2.3.1/build$ cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON ..
    -- Detected version of GNU GCC: 46 (406)
    -- Found OpenEXR: /usr/lib/libIlmImf.so
    -- Could NOT find PythonLibs (missing: PYTHON_INCLUDE_DIRS)
    -- 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: NO
    -- OpenNI PrimeSensor Modules: NO
    -- XIMEA: NO
    --
    -- Video I/O:
    -- DC1394 1.x: NO
    -- DC1394 2.x: YES
    -- FFMPEG: YES
    -- codec: YES
    -- format: YES
    -- util: YES
    -- swscale: YES
    -- gentoo-style: YES
    -- GStreamer: YES
    -- UniCap: NO
    -- PvAPI: NO
    -- V4L/V4L2: FALSE/FALSE
    -- Xine: NO
    --
    -- Other third-party libraries:
    -- Use IPP: NO
    -- Use TBB: YES
    -- Use ThreadingFramework: NO
    -- Use Cuda: NO
    -- Use Eigen: NO
    --
    -- 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/espel/OpenCV-2.3.1/build
    -- -----------------------------------------------------------------
    --
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/espel/OpenCV-2.3.1/build

    Thank you
    Egalarza

    ReplyDelete
  12. Hi Egalarza,

    I think u need to compile simple 'make' command after this. just type "make" and press enter.

    Hope that works.

    Regards,
    Umar

    ReplyDelete
  13. Hi, great tutorial!...but I am not able to run face detect from web cam here. How do i solve this?


    $ ./facedetect

    This program demonstrates the cascade recognizer. Now you can use Haar or LBP features.
    This classifier can recognize many ~rigid objects, it's most known use is for faces.
    Usage:
    ./facedetect [--cascade= this is the primary trained classifier such as frontal face]
    [--nested-cascade[=nested_cascade_path this an optional secondary classifier such as eyes]]
    [--scale=
    [filename|camera_index]

    see facedetect.cmd for one call:
    ./facedetect --cascade="../../data/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="../../data/haarcascades/haarcascade_eye.xml" --scale=1.3
    Hit any key to quit.
    Using OpenCV version 2.3.1

    Capture from CAM 0 didn't work
    In image read

    ReplyDelete
  14. Maybe your camera is not recognized. Try running by giving it an image file.

    ReplyDelete
  15. Hello

    I followed what your constructions and I met the following errors after I used make command:
    /usr/OpenCV-2.3.1/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:921:10: error: ‘AVERROR_NOFMT’ was not declared in this scope
    /usr/OpenCV-2.3.1/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:923:10: error: ‘AVERROR_IO’ was not declared in this scope
    /usr/OpenCV-2.3.1/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:925:10: error: ‘AVERROR_NOMEM’ was not declared in this scope

    ReplyDelete
  16. May be I should Put what I got after Cmake command:


    -- General configuration for opencv 2.3.1 =====================================
    --
    -- Built as dynamic libs?: YES
    -- Compiler: /usr/bin/c++
    -- C++ flags (Release): -Wall -pthread -march=i686 -ffunction-sections -O3 -DNDEBUG -fomit-frame-pointer -msse -msse2 -mfpmath=387 -DNDEBUG
    -- C++ flags (Debug): -Wall -pthread -march=i686 -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: NO
    -- OpenNI PrimeSensor Modules: NO
    -- XIMEA: NO
    --
    -- Video I/O:
    -- DC1394 1.x: NO
    -- DC1394 2.x: YES
    -- FFMPEG: YES
    -- codec: YES
    -- format: YES
    -- util: YES
    -- swscale: YES
    -- gentoo-style: YES
    -- GStreamer: YES
    -- UniCap: NO
    -- PvAPI: NO
    -- V4L/V4L2: FALSE/FALSE
    -- Xine: NO
    --
    -- Other third-party libraries:
    -- Use IPP: NO
    -- Use TBB: YES
    -- Use ThreadingFramework: NO
    -- Use Cuda: NO
    -- Use Eigen: NO
    --
    -- Interfaces:
    -- Python: YES
    -- Python interpreter: /usr/bin/python2.7 -B (ver 2.7)
    -- Python numpy: YES
    -- Java: NO
    --
    -- Documentation:
    -- Sphinx: NO
    -- PdfLaTeX compiler: /usr/bin/pdflatex
    -- Build Documentation: NO
    --
    -- Tests and samples:
    -- Tests: YES
    -- Examples: YES
    --
    -- Install path: /usr/local
    --
    -- cvconfig.h is in: /usr/OpenCV-2.3.1/OpenCV-2.3.1/build
    -- -----------------------------------------------------------------
    --
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /usr/OpenCV-2.3.1/OpenCV-2.3.1/build

    ReplyDelete
  17. Thank you in advance for your help !

    Regards

    ReplyDelete
  18. It looks like there is a problem with your ffmpeg. See if you have an old version (ffmpeg -version). Try to remove it with: sudo apt-get remove ffmpeg and install it again with: sudo apt-get install ffmpeg. Let me know what happened.

    ReplyDelete
  19. Hello Kary,

    Thank you for your hints.
    I followed what you said, and then using "Cmake .." at the "build" folder. It seemed that was the same as previous outputs. for example, concerning the ffmpeg:
    ***************************************
    Video I/O:
    -- DC1394 1.x: NO
    -- DC1394 2.x: YES
    -- FFMPEG: YES
    -- codec: YES
    -- format: YES
    -- util: YES
    -- swscale: YES
    -- gentoo-style: YES
    ***************************************
    So, it seems that ffmpeg is OK, isn't it ?

    But when I came to "make" command, it resulted in the same errors as follows:
    **********************************
    /usr/OpenCV-2.3.1/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:921:10: error: ‘AVERROR_NOFMT’ was not declared in this scope
    /usr/OpenCV-2.3.1/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:923:10: error: ‘AVERROR_IO’ was not declared in this scope
    /usr/OpenCV-2.3.1/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:925:10: error: ‘AVERROR_NOMEM’ was not declared in this scope
    **********************************
    I do know why.

    Thank you for your suggestions.
    cheers

    ReplyDelete
  20. >Hello again,
    In my previous post, I think I wrote a wrong sentence "I do not know why" lol

    THank you for your help !!

    regards

    ReplyDelete
  21. Hello again,

    I found another guide to install OpenCV2.3.1a on Ubuntu 11.10. And I followed http://vinayhacks.blogspot.com/

    Finally, there is no errors !! Great !!!

    I hope that the above guide would help others !

    Cheers

    ReplyDelete
  22. Hello sir!

    I would like to ask for help on installing opencv in linux.
    I'm a new with Ubuntu, I really need your help to get this OpenCV running.
    Thanks in advance!

    What I'm trying now is to run this simple command that I got from a book:

    #include "highgui.h"

    int main(int argc, char** argv)
    {
    IplImage* img = cvLoadImage( argv[1] );
    cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
    cvShowImage( "Example1", img );
    cvWaitKey(0);
    cvReleaseImage( &img );
    cvDestroyWindow( "Example1" );

    exit(0);
    }

    I saved it as myopencv.c on my home directory.

    When I tried to execute the following commands:

    PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:${ PKG_CONFIG_PATH }
    export PKG_CONFIG_PATH
    gcc 'pkg-config --cflags --libs opencv' -o myopencv myopencv.c

    I had this error message:

    myopencv.c: In function ‘main’:
    myopencv.c:5:1: error: too few arguments to function ‘cvLoadImage’
    /usr/local/include/opencv2/highgui/highgui_c.h:213:18: note: declared here

    When I entered this command:

    $PKG_CONFIG_PATH

    I had this error message:

    bash: /usr/local/lib/pkgconfig::/usr/local/lib/pkgconfig: No such file or directory

    I entered the following commands:

    pkg-config --cflags opencv
    pkg-config --libs opencv

    And I got this:

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

    pkg-config --libs opencv
    -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 don't know what to do now, I really need your help.
    Looking forward to your reply.
    Thankyou very much! :)

    ReplyDelete
  23. I think your problem is that you are using gcc instead of g++. I tried your example and it works if I compile using:

    g++ -lopencv_highgui -o myopencv myopencv.c

    but if I change g++ to gcc I get the same error as you. Also, using pkg to generate all the library dependencies for g++ did not work for me, so I would suggest you just manually add them (as I did above; -lopencv_highgui).

    Hope it helps!

    ReplyDelete
  24. Hi Kary!
    thanks for your reply.


    When I enteerd this command:

    g++ -lopencv_highgui -o myopencv myopencv.c

    this is the result.

    fatal error: highgui.h: No such file or directory
    compilation terminated.

    Do you have any idea regarding the problem that I'm having? I followed the steps above and I was able to run up to the lena.jpg

    thankyou!

    ReplyDelete
  25. You are right, I forgot about that. I got the same error when I was trying your example. Then I replaced your include statement with this one and it worked.

    #include

    Hope it compiles now :-)

    ReplyDelete
  26. Hm, the include statement above does not show. Might be an html code or something. Let me try again:

    #include < opencv / highgui.h >

    ReplyDelete
  27. Hi Kary!

    I just followed the instructions above and I had this error when I run the make command:

    /home/mong/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/mong/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/mong/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/mong/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/mong/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/mong/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


    Hope you can help me with this, thanks! :)

    ReplyDelete
  28. Hi Kary
    I would like you to help me because I have problems with running my executable file here is the output.

    joseluis@ubuntu:~/Descargas/OpenCV-2.3.1/Prueba$ ./DisplayVideo2 1.aviOpenCV 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/joseluis/OpenCV-2.3.1/modules/highgui/src/window.cpp, line 275
    terminate called after throwing an instance of 'cv::Exception'
    what(): /home/joseluis/OpenCV-2.3.1/modules/highgui/src/window.cpp:275: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow

    Abortado

    Thank you for your help
    Jose Luis

    ReplyDelete
  29. will please tell how compile other programme...
    i got fatal error cv.h not found.
    cv.h is there
    as u tell about is all working

    ReplyDelete
  30. Thank you
    I resolve my problem

    I am installing OpenCV in other computer, but i have this problem in the step "make"

    joseluis@HP-Pavilion:~/OpenCV-2.3.1/build$ make
    [ 0%] Built target opencv_imgproc_pch_dephelp

    [ 33%] Built target libjpeg
    [ 33%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o
    In file included from /home/joseluis/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg.cpp:45:0:
    /home/joseluis/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp: En la funciĆ³n miembro ‘bool CvCapture_FFMPEG::reopen()’:
    /home/joseluis/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1485:5: aviso: ‘int av_write_header(AVFormatContext*)’ es obsoleto (declarado en /usr/include/libavformat/avformat.h:1394) [-Wdeprecated-declarations]
    /home/joseluis/OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp:1485:25: aviso: ‘int av_write_header(AVFormatContext*)’ es obsoleto (declarado en /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

    how can I resolve it?

    Please help me
    Jose Luis

    ReplyDelete
  31. Thanks for the tutorial bro....I have one very small problem...Please help me out with it...
    I wanted to create .flv and I am using this fourcc CV_FOURCC('F','L','V','1').
    But its not working out for me....
    Will you please help me...
    Everything is working fine apart from that....

    ReplyDelete