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 !!!
Man thanks a lot, you saved my life!!
ReplyDeleteAwesome (y)
ReplyDeletei keep having an error cv.h no such directory can any one help?!please
ReplyDeleteIs you opencv installed directory is same as mine? Have you added opencv to PATH as in my other article?
Deletesame problem here, how to fix it please ?
DeleteTry,
Deletesudo echo “/usr/local/lib” >> /etc/ld.so.conf
sudo ldconfig
help me !
ReplyDeletewhen i click button, i get an error
(test1:2811): Gtk-WARNING **: gtk_disable_setlocale() must be called before gtk_init()
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/phu/opencv-2.4.6.1/modules/highgui/src/window.cpp, line 261
terminate called after throwing an instance of 'cv::Exception'
what(): /home/phu/opencv-2.4.6.1/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow
plz help me,when i run this program i got a error is
ReplyDelete"The program has unexpectedly finished.
/home/ayisha/Qt_APP/showimage/build-disp-Desktop_Qt_5_0_2_GCC_32bit-Debug/disp exited with code 0".plz hel me to solve this.
i m also getting the same error as ayisha
ReplyDeletedoes opencv works well without Qt? Do you use the same include path and libs in Qt?
DeleteDoes Qt widget app works well without opencv?
*This example requires web cam installed in the machine. Otherwise try loading a static image and display
For me worked with:
ReplyDeleteQT_CONFIG -= no-pkg-config
CONFIG += link_pkgconfig
PKGCONFIG += opencv
i got these errors
ReplyDelete:-1: error: mainwindow.o: undefined reference to symbol '_ZN2cv6imreadERKNS_6StringEi'
/usr/local/lib/libopencv_imgcodecs.so.3.0:-1: error: error adding symbols: DSO missing from command line
any solution???
I have the same problem...! with opencv_contrib face recog module in opencv 3.1.0
DeleteHi, i am getting the error shown below
ReplyDeletegtk_disable_setlocale() must be called before gtk_init()
have not been able to find my way around it
you have explained for c programing itseems.
ReplyDeleteHow to resolve problem in python (ubuntu)?
(.:4240): Gtk-WARNING **: gtk_disable_setlocale() must be called before gtk_init()
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
python: ../../src/xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Aborted (core dumped)