2

I´m using Qt 5.0.2 and try to get started with OpenCv.

If I run the following program, it only shows a console and says press any key but it shows no image. I don´t even get the qDebug() messages.

However, with the Opencv stuff deleted I get the messages.

PS: yes I made sure that the Desert.jpg is in the same folder where the exe is. first-openCV-test.pro:

QT       += core
QT       -= gui
TARGET = first-openCV-test
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += F:\\QT\\libraries\\opencv\\opnecv_build_2.4.5\\install\\include
LIBS += -LF:\\QT\libraries\\opencv\\opnecv_build_2.4.5\\install\\lib \
    -lopencv_core245.dll \
    -lopencv_highgui245.dll \
    -lopencv_imgproc245.dll \
    -lopencv_features2d245.dll \
    -lopencv_calib3d245.dll

main.cpp:

#include <QDebug>
#include <QCoreApplication>

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


int main(int argc, char *argv[])
{
        // read an image
        qDebug()<< "start initialising";
        cv::Mat image= cv::imread("Desert.jpg");
        // create image window named "My Image"
        qDebug()<< "name Window";
        cv::namedWindow("My Image");
        // show the image on window
        qDebug()<< "show image: ";
        cv::imshow("My Image", image);
        // wait key for 5000 ms
        qDebug()<< "wait";
        cv::waitKey(5000);
        return 1;
}

//////////////////////////////////////////////////////////////////////////////////////////

thanks for the fast answers.

I tried some things and also rebuilt all and re-downloaded it. I changed it to this:
QT += core QT -= gui TARGET = first-test CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp

INCLUDEPATH += "F:/QT/libraries/opencv/build/include" \
               "F:/QT/libraries/opencv/build/include/opencv" \
               "F:/QT/libraries/opencv/build/include/opencv2"

LIBS += -L"F:/QT/libraries/opencv/build/x86/mingw/lib"
    -libopencv_core245.dll
    -libopencv_highgui245.dll
    -libopencv_imgproc245.dll
    -libopencv_features2d245.dll
    -libopencv_calib3d245.dll                                               

But now I get the following errors:

F:\A_PROJECTS\OPEN-CV\first-test\first-test\main.cpp:-1: Fehler:undefined reference to `cv::fastFree(void*)'

F:\A_PROJECTS\OPEN-CV\first-test\first-test\main.cpp:-1: Fehler:undefined reference to `cv::Mat::deallocate()'

4

3 回答 3

1

确保图像已成功加载:

cv::Mat image= cv::imread("Desert.jpg");
if (image.empty())
{
    // print error message
    return -1;
}

我编写了一个名为cvImage的简单 OpenCV/Qt 示例项目,它演示了如何配置 .pro文件以使它们一起工作。

于 2013-06-20T22:40:57.787 回答
1

我不确定,如果这对你有帮助,但让我们试一试......

首先,在我的程序中,我使用条形“ / ”而不是“ \\ ”。其次,我从不将 .dll 放在库中。我使用这样的东西:

LIBS += -LC:/OpenCV/lib/ -llibopencv_core245 -llibopencv_highgui245 -llibopencv_imgproc245

如果您使用的是 qtcreator,请尝试进行这些更改,然后“运行 qmake”和“全部重建”。

于 2013-06-20T18:39:36.560 回答
0

当依赖项(像 openCV 这样的外部库)没有正确链接到 Qt 项目时,会引发“未定义的引用”错误。我已经回答了一个类似的问题,我知道可以解决您的问题。您无需手动更改 .pro 文件,而是使用 Qt Creator 中的“添加库...”向导。https://stackoverflow.com/a/51914801/10245006

于 2018-08-19T06:10:21.533 回答