In previous
post, you have already seen how to build OpenCV using CMake and Qt MinGW. In
this tutorial, we will guide you how to configure Qt creator with OpenCV
library.
Then, we begin to create a simple OpenCV program to render a simple
image.
- Open Qt Creator -> File -> New File or Project -> Qt Widgets Application
- Then, give the name of your application (ex: hello_opencv)
- Add the following line to hello_opencv.pro
INCLUDEPATH += D:\opencv\build\install\include
LIBS += -L"D:/opencv/build/install/x86/mingw/bin"
LIBS += -lopencv_core2411 -lopencv_highgui2411 -lopencv_imgproc2411
LIBS += -L"D:/opencv/build/install/x86/mingw/bin"
LIBS += -lopencv_core2411 -lopencv_highgui2411 -lopencv_imgproc2411
- After that, write the following code in main() function
#include "mainwindow.h"
#include <QApplication>
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
//initialize a 120X700 matrix of black pixels:
Mat output = Mat::zeros( 120, 700, CV_8UC3 );
//write text on the matrix:
putText(output,
"Hello OpenCV I Love U :)",
cvPoint(15,70),
FONT_HERSHEY_PLAIN,
3,
cvScalar(0,255,0),
4
);
//display the image:
imshow("Output", output);
//wait for the user to press any key:
waitKey(0);
w.show();
return a.exec();
}
No comments:
Post a Comment