Qt中的Opencv示例立即崩溃并出现错误'该程序意外地完成了#39;

时间:2015-10-06 14:15:20

标签: c++ qt opencv

我尝试在Qt中创建一个简单的Opencv应用程序,在运行时,整个应用程序崩溃了。如果我从项目中注释掉opencv相关代码,那么项目运行得很好 我做了什么:

Downloaded the Qt 5.5.0 VS2013 64bit version   
Downloaded the OpenCV 3.0   
Downloaded the Cmake 3.3.2  

当我解压缩Opencv包时,已经预先构建了二进制文件,但是网上的所有教程都要我重新编译源代码,所以我做了。
该软件包包含:

build
sources

创建了一个名为mymade的新文件夹,用于保存其他两个目录旁边的二进制文件 所以它现在看起来像这样:

 build
 mymade
 sources

步骤: 已解雇CMake,从提取的文件中指定源文件夹 并指定mymade作为二进制文件的输出 检查了名称中包含opencv的所有选项,加上Qt!并配置它,然后生成文件 这是结果内容:

enter image description here 所以一切都完成了,我现在需要构建二进制文件。我打开OpenCV.sln并编译了发布和调试二进制文件 dll放在bin目录中,lib文件放在lib文件夹中 现在是配置Qt项目.pro文件的时候所以我使用了build目录中的头文件,而对于libs,我使用了mymade文件夹中的lib文件夹。这是我提出的第一个配置,它在没有任何链接器问题的情况下进行编译,但是立即崩溃 项目文件中的初始更改:

#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = OpenCVTest
TEMPLATE = app

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h


INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//*.lib

FORMS    += mainwindow.ui

在项目文件中执行此操作,因为像this这样的答案建议也没有做任何好处:

#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = OpenCVTest
TEMPLATE = app

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h


INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include

LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_core300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_highgui300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_imgcodecs300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_ml300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_objdetect300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_photo300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_shape300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_hal300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_flann300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_features2d300.lib

FORMS    += mainwindow.ui

这也失败了:

#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = OpenCVTest
TEMPLATE = app

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h


INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include

LIBS +=-L"L://Apps_Installation_Folder//opencv//mymade//lib//Release"
LIBS += -lopencv_core300 -lopencv_highgui300 -lopencv_imgcodecs300 -lopencv_ml300 -lopencv_objdetect300 -lopencv_photo300 -lopencv_hal300 -lopencv_shape300 -lopencv_flann300 -lopencv_features2d300


FORMS    += mainwindow.ui

那么这里有什么问题?我错过了什么?

更新
正如@Miki指出的那样,Qt无法找到opencv dll(上面的配置都没问题),为了解决这个问题,只需要将包含dll的目录添加到PATH变量中,你就可以去了现在一切都应该没问题,至少这是我的情况;)

1 个答案:

答案 0 :(得分:3)

从评论到问题,结果发现程序没有找到OpenCV dll。

你可以:

  1. 将所需的dll复制到.exe
  2. 的同一文件夹中
  3. 将包含dll的文件夹添加到PATH。您需要重新启动Qt Creator才能使更改生效。