Script for OpenCV installation on Ubuntu 12.10

Installing OpenCV on Ubuntu was painful for me in the past. There are lots of dependencies to be sorted out first and there’s no comprehensive installation tutorial shipped with the OpenCV distribution.
This script has done a great job assembling all necessary “apt-get-install’s” into an executable script. Some personal notes about this:

  • It seems to me ” sudo apt-get install libopencv-dev” for dependencies is not necessary – this will be superseded by the subsequent installation of opencv from source. At the end of the scripting installation, the package seems to be in some cache place and be not in effect:
  • It seems ” sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev” is also unnecessary. These libraries are to be provided by the next fresh installation of ffmpeg follows. Checking their location seems to also confirm my guess:
  • About version of ffmpeg: ffmepg is under active development as always. The choice of its version is sometimes tricky, especially in running together with OpenCV. I remember the 1.x series was not compatible with OpenCV 2.3 in my previous trial (compilation errors were thrown due to some problem with ffmpeg libraries). The current 2.4.3 version seems to be at least fine with ffmpeg 0.11.2 in compilation.

[Update] From test by Mr. Alok Singh Mahor   (comments below), installing Ubuntu package “libopencv-dev” would already get things work, though the linking order with g++ has to be taken care of as discussed (also comments below and here) . Of course, it’s not bad idea to install from source that always guarantees to bring  in the newest feature of actively developed OpenCV. [Dec 28 2012]

About these ads
Tagged ,

17 thoughts on “Script for OpenCV installation on Ubuntu 12.10

  1. Alok Singh Mahor says:

    I am using Ubuntu 12.10
    if I install libopencv-dev then it automatically install libavcodec-dev libavformat-dev libswscale-dev

    why did you write this as two step process?

    my (pkg-config –cflags –libs opencv)’s output is
    -I/usr/include/opencv -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann

    I am trying to compile the program using command (g++ `pkg-config –cflags –libs opencv` alok.cpp)
    but I am getting linker errors

    alok.cpp is

    #include
    #include

    using namespace cv;

    int main( int argc, char** argv )
    {
    Mat image;
    image = imread( argv[1], 1 );

    if( argc != 2 || !image.data )
    {
    printf( “No image data \n” );
    return -1;
    }

    namedWindow( “Display Image”, CV_WINDOW_AUTOSIZE );
    imshow( “Display Image”, image );

    waitKey(0);

    return 0;
    }

    error I am getting is
    alok@alok:~/exp/opencv/exp$ g++ `pkg-config –cflags opencv` `pkg-config –libs opencv` alok.cpp
    /tmp/cc8oVSIW.o: In function `main':
    alok.cpp:(.text+0x67): undefined reference to `cv::imread(std::string const&, int)’
    alok.cpp:(.text+0xfa): undefined reference to `cv::namedWindow(std::string const&, int)’
    alok.cpp:(.text+0x122): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)’
    alok.cpp:(.text+0x159): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)’
    alok.cpp:(.text+0x17b): undefined reference to `cv::waitKey(int)’
    /tmp/cc8oVSIW.o: In function `cv::Mat::~Mat()':
    alok.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x2b): undefined reference to `cv::fastFree(void*)’
    /tmp/cc8oVSIW.o: In function `cv::Mat::operator=(cv::Mat const&)':
    alok.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0xf2): undefined reference to `cv::Mat::copySize(cv::Mat const&)’
    /tmp/cc8oVSIW.o: In function `cv::Mat::release()':
    alok.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x3b): undefined reference to `cv::Mat::deallocate()’
    collect2: error: ld returned 1 exit status

    could you please tell me where I am wrong?
    thanks in advance

    • Ju Sun says:

      I have no idea why it is so — but in my experience the only way you get OpenCV program compiled in Ubuntu is to “Install from Source”, which is exactly what the pointed script is doing. Your errors will be resolved after doing that.

      My doubt about the script is it seems the two lines
      ” sudo apt-get install libopencv-dev” and
      ” sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev”
      are unnecessary since they will be overwritten by the subsequent operations. But anyway leave them as is won’t hurt.

      Good luck!

  2. Alok Singh Mahor says:

    problem solved by using command
    g++ `pkg-config –cflags opencv` alok.cpp `pkg-config –libs opencv`

    • Ju Sun says:

      Glad to hear! It seems like some linking order issue … I happened to also encounter similar issue before with gcc here

      Btw, I’m a bit confused by your installation process. Did you make it work by just doing the
      ” sudo apt-get install libopencv-dev”
      stuff or executing the script? I’m a bit curious because I tried to install the ubuntu package in previous ubuntu distros but never got any test program running.

      • Alok Singh Mahor says:

        yes I installed only one package libopencv-dev
        and all the required libraries got automatically installed as dependancy of libopencv-dev

        so only one sudo apt-get install libopencv-dev” will work

        but there is some linking problem with some version of Ubuntu so I had to use (g++ `pkg-config –cflags opencv` alok.cpp `pkg-config –libs opencv`)
        instead of (g++ `pkg-config –cflags opencv` `pkg-config –libs opencv` alok.cpp )

      • Ju Sun says:

        Great to learn this! And I’d recall my previous blame on ubuntu opencv package; also this means opencv is ready-to-deploy on ubuntu platform without much pain.

        Thanks for the test-drive!

  3. Alok Singh Mahor says:

    you are welcome :)
    its very clean and straight forward process to setup openCV envirnment on Ubuntu.

  4. Juliane says:

    Greetings from Colorado! I’m bored to death at work so I decided to browse your website on my iphone during lunch break. I really like the info you present here and can’t wait to take a look when
    I get home. I’m surprised at how quick your blog loaded on my cell phone .. I’m
    not even using WIFI, just 3G .. Anyways, awesome
    site!
    Click on
    and click the following article
    and Click Here
    and also click the next internet site

  5. outmaneuver says:

    Hi, I discovered your page on and although the information
    seems great, I suspect your blog might be going through a
    few internet browser compatibility problems. If I view it
    in Firefox, it loads okay, but if I use Chrome, it comes
    up appearing overlapped and off-kilter. Just wanted to inform you.

  6. It’s fantastic that you are getting thoughts from this article as well as from our discussion made at this time.

  7. Anonymous says:

    Thank you!

  8. These doctrines are essential to any website and must not
    be ignored.

  9. Concepcion says:

    That’s the reason lots of folks are purchasing these exercise
    DVDs. But that does not mean that youngsters are resigned to three months
    to the sofa. I’ve been a member at Destin Athletic Club for over a year now.

  10. Melva says:

    Awesome! Its actually remarkable post, I have got
    much clear idea concerning from this article.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: