Saturday, March 3, 2012

Setup OpenCV With QT Creator

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision.
OpenCV is released under a BSD license, it is free for both academic and commercial use. It has C++, C, Python and soon Java interfaces running on Windows, Linux, Android and Mac. The library has >2500 optimized algorithms (see figure below). It is used around the world, has >2.5M downloads and >40K people in the user group. Uses range from interactive art, to mine inspection, stitching maps on the web on through advanced robotics.

How to install opencv? it's depend on our operating system, installation procedure can be found here http://opencv.willowgarage.com/wiki/InstallGuide.

I assume that OpenCV already installed on the computer, it's easy to integrate OpenCV lib and header to QTCreator
  • Create Empty QTCreator Project
 Open QTCreator and creaate empty QT Project File -> New File or Project


then give the project name, in this case I use OpenCV as project name.
  • Add Library OpenCV to .pro file project
 Open .pro file and add OpenCV library, in this case I use Linux as my operating system so in the .pro file will be like this




LIBS += `pkg-config opencv --cflags --libs` this is package cofig where is file library of opencv present.

if we run on the terminal pkg-config opencv --cflags --libs will return the location of library, in this case the output will give /usr/include/opencv2.
  • Create example cpp application
 Right click on the project name -> Add New then select C++ Source File.



Create example opencv application from opencv official site, in this case I use TestOpenCV.cpp.

Add this code to TestOpenCV.cpp:
#include <opencv2/opencv.hpp>

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;
}

  • Build and run the application
 Right click on the project, will generate execute able file TestOpenCV and then run the program from the terminal:

ar@dream:~/Projects/QT/OpenCV$ ./OpenCV /home/ar/Pictures/g4958.png

and will open the image with current dimension.


2 comments:

  1. Mas bs tolong bantuin saya gmn cara mengintegrasi opencv 2.4.3 dengan Qt 5.2.1 di windows 7!!
    lg bigung ni mas, udah stuck,,
    mohon bantuanya mas...

    ReplyDelete
  2. Helo mas, nanti saya coba dulu. Kalo sudah bisa saya posting disini.

    ReplyDelete