2013년 11월 21일 목요일

Configure OpenCV 2.4 for Qt Creator on Ubuntu

Configure OpenCV 2.4 for Qt Creator on Ubuntu

First install Qt creator using Ubuntu Software Center

Open Qt Creator

File --> New file or project
Qt Widget Project --> Qt GUI Application --> Choose

Click Next for all.

Open .pro file and add the following lines

INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_ml
LIBS += -lopencv_video
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
LIBS += -lopencv_objdetect
LIBS += -lopencv_contrib
LIBS += -lopencv_legacy
LIBS += -lopencv_flann
LIBS += -lopencv_nonfree


Save it.

Open .ui file.

Drag and drop a PushButton to window.
Click PushButton and chage the follwong properties
  • objectName: btnDisplay
  • text: Display

Right click PushButton --> Go to slot --> clicked() --> Ok

Include the following

#include <cv.h>
#include <highgui.h>


Add the following code

void MainWindow::on_btnDisplay_clicked()
{
    cv::namedWindow("Disp");
    cv::VideoCapture cap(0);
    cv::Mat frame;
    do{
        cap >> frame;
        imshow("Disp",frame);
    }while(cv::waitKey(30)<0);
    cv::destroyAllWindows();
}


Run it. You will see yourself on the screen, when you click Display button !!!

댓글 없음:

댓글 쓰기