First time here? Check out the FAQ!

Ask Your Question
2

simple image display code not working in qt creator

asked Mar 16 '13

Capton gravatar image

Hello everyone, I'm running a a simple image display program with opencv in QtCreator but whenever i run the code it opens a console(qtcreator_process_stub.exe),says press<return> to close window and then nothing happens Please i need help Below is my code:

MAIN.CPP

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main() {
Mat image= imread("imgage.jpg");
namedWindow("My Image");
imshow("My Image", image);
waitKey(5000);
return 1;
}

.PRO file:

QT += core
TARGET = opencv
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:/opencv/build_with_Qt/debug/include
LIBS += -LC:/opencv/build_with_Qt/debug/lib \
-lopencv_core244d\
-lopencv_highgui244d\
-lopencv_imgproc244d\
-lopencv_features2d244d\
-lopencv_calib3d244d
Preview: (hide)

2 answers

Sort by » oldest newest most voted
1

answered Apr 6 '13

fuego gravatar image

Did you find a solution because i have the same problem ! I have exactly the same code.

Preview: (hide)
0

answered Apr 6 '13

Basically you are using a relative path for your image. Put your image in your basic drive and use the absolute path. See if that works out for you.

Also place a debug point after the imread function and check if your Mat element actually contains data.

Also you have probably a type in the name of your image, it is now imgage, and i guess it should be image. This could also be a problem.

Also, change waitKey(5000) to waitKey(0) so that you actually have to push the button to close everything down. You can then see if there is actually something displayed in your window.

Preview: (hide)

Question Tools

2 followers

Stats

Asked: Mar 16 '13

Seen: 2,627 times

Last updated: Apr 06 '13