3
votes

I am trying to configure OpenCV with Qt Creator 2.7.0 (Qt 5.0.2) on windows 8 64bit. While executing my program, I get the following error:

The program has unexpectedly finished.

This is my main.cpp

#include "mainwindow.h"
#include <QApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    IplImage *image = cvLoadImage("E:\\lena.jpg"); //If this is removed, the program runs OK
    return a.exec();
}

My .pro file is

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = untitled1
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

unix:!mac {
    message("* Using settings for Unix/Linux.")
    INCLUDEPATH += /usr/local/include/opencv

    LIBS += -L/usr/local/lib/ \
        -lopencv_core \
        -lopencv_highgui \
        -lopencv_imgproc
}

## OpenCV settings for Mac OS X
macx {
    message("* Using settings for Mac OS X.")
    INCLUDEPATH += /usr/local/include/opencv

    LIBS += -L/usr/local/lib/ \
        -lopencv_core \
        -lopencv_highgui \
        -lopencv_imgproc
}

## OpenCV settings for Windows and OpenCV
win32 {
    message("* Using settings for Windows.")
    INCLUDEPATH += "C:\\OpenCV\\opencv\\build\\include" \
                   "C:\\OpenCV\\opencv\\build\\include\\opencv" \
                   "C:\\OpenCV\\opencv\\build\\include\\opencv2"

    LIBS += -L"C:\\OpenCV\\opencv\\build\\x64\\mingw\\lib" \
        -lopencv_core244 \
        -lopencv_highgui244 \
        -lopencv_imgproc244
}

Environment Variables are:

OPENCV_DIR:C:\OpenCV\opencv\build\x64\mingw Path: G:\5.0.2\Tools\MinGW\bin;G:\Qt\5.0.2\mingw47_32\bin

What could be the problem ?

3

3 Answers

1
votes

You might need to change

-lopencv_core244 \
-lopencv_highgui244 \
-lopencv_imgproc244

to

-lopencv_core244d \
-lopencv_highgui244d \
-lopencv_imgproc244d
  • note 'd' at the end of each lib (if you are to build in debug)
2
votes

I suggest you use the OpenCV 2.x API if possible. The error handling is better.

This would be cv::Mat image = cv::imread("E:\lena.jpg");

If the image is empty, it means you have the wrong path.

Also, make sure the opencv dll are in the path of your executable (core, highgui and imgproc).

0
votes

Have you solved the problem?

Have you tried adding system("PAUSE"); after the return a.exec(); ?

Just some extra notes:

Also try

try 
{
...
}
catch (Exception e)
{
...
}

to see if you can find the error

thirdly, check the file permissions for lena.jpg

Lastly, see if you can use the path E:\lena.jpg