Tutorial code crashes when using QtCreator

asked 2015-02-24 00:32:45 -0600

bauchetj gravatar image

Hello,

I am completely new to OpenCV and I would like to create an application based on this software via QtCreator.

To install OpenCV, I followed the instructions given in the related tutorial. I just use the pre-built libraries of OpenCV and don't intend to create my own libraries : I just would like to do something relatively simple with it. So I just extracted the files and stored them in C:\OpenCV\ ...

I tried to compile a very simple code provided by the author of the tutorial where it is explained how to build your own applications with OpenCV.

It works when I compile and run the code with Visual Studio but not with QtCreator although the compiler is based on Visual Studio. The program compiles, but crashes at the beginning of the execution, without explanation.

I guess this is a problem of linkage but, yet, I have the impression to do what is expected from me, according to what I read on the Internet (tutorials, forums)... but I don't have a lot of experience with 3rd-party softwares.

Does anyone sees the problem ? I am using Windows 10 64-bit, Qt5.2.1 - MSVC 2010 32-bit (it is not me who installed it...) and OpenCV 2.4.9.

Thanks in advance !

Here is my .pro file :

QT      += core gui
DEFINES += GLEW_STATIC GLM_STATIC
DEFINES += _CRT_SECURE_NO_WARNINGS

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = opencv_test
TEMPLATE = app
DESTDIR     = ../bin

SOURCES += \
    main.cpp

OPENCV_BUILD_ROOT = C:\\OpenCV\\opencv\\build

INCLUDEPATH += $$OPENCV_BUILD_ROOT\\include

LIBS += -L$$OPENCV_BUILD_ROOT\\x86\\vc10\\lib \ # Tried both x64 and x86
        -lopencv_core249d \
        -lopencv_features2d249d \
        -lopencv_flann249d \
        -lopencv_gpu249d \
        -lopencv_highgui249d \
        -lopencv_imgproc249d \
        -lopencv_legacy249d \
        -lopencv_ml249d \
        -lopencv_nonfree249d \
        -lopencv_objdetect249d \
        -lopencv_ocl249d \
        -lopencv_photo249d \
        -lopencv_stitching249d \
        -lopencv_superres249d \
        -lopencv_ts249d \
        -lopencv_video249d \
        -lopencv_videostab249d

Here is main.cpp (the same as here)

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    cout << "Start" << std::endl; // Note : I even don't see this message when running the code
    if( argc != 2)
    {
        cout << "Usage: display_image ImageToLoadAndDisplay" << endl;
        return -1;
    }

    Mat image;
    image = imread(argv[1], IMREAD_COLOR);

    if(! image.data )
    {
        cerr << "Could not open or find the image" << endl ;
        return -1;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE );
    imshow( "Display window", image ); 

    waitKey(0);
    return 0;
}
edit retag flag offensive close merge delete

Comments

1

"The program compiles, but crashes at the beginning of the execution, without explanation." In which line does it crash? What happens if you step through it or if you run it within gdb?

FooBar gravatar imageFooBar ( 2015-02-24 01:45:25 -0600 )edit

@FooBar I Have the same problem. I know that when I comment namedWindow, imshow and waitKey it runs without any error or crash. The problem is the last three line. But the program crashed before running the mian() function and I am still trying to figuring out why. IF you've already found out I would be thankful if you please let me know.

mask2007 gravatar imagemask2007 ( 2016-04-05 14:32:19 -0600 )edit