与opencv的Qt DLL错误

时间:2015-04-29 09:44:39

标签: c++ qt opencv

我尝试运行程序以使用opencv显示图像,但我收到以下错误:

file not recognized: File format not recognized
C:\opencv\release\bin\opencv_ffmpeg249_64.dll

error:Id returned 1 exit status
File not found: collect2.exe

.pro文件:

QT       += core

QT       -= gui

TARGET = myFirstOpenCVProject
CONFIG   += console
CONFIG   -= app_bundle
CONFIG   -= qt

TEMPLATE = app


SOURCES += main.cpp

INCLUDEPATH += C://opencv//release//install//include

LIBS += C://opencv//release//bin//*.dll

#LIBS += C://opencv//release//lib//*.a

LIBS += -LC://opencv//release//lib -llibopencv_core249 -llibopencv_highgui249 -llibopencv_imgproc249

OTHER_FILES += \
    img.JPG

的main.cpp

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


int main()
{
        // read an image
        cv::Mat image= cv::imread("img.jpg");
        // create image window named "My Image"
        cv::namedWindow("My Image");
        // show the image on window
        cv::imshow("My Image", image);
        // wait key for 5000 ms
        cv::waitKey(1000);
        return 1;
}

图像(img.jpg)位于相应的目录中;项目可执行文件的位置。我尝试删除dll,代码运行没有错误,但它没有做任何事情只是显示一个shell提示我点击返回。

enter image description here

1 个答案:

答案 0 :(得分:1)

这一行是问题

LIBS += C://opencv//release//bin//*.dll

此行使您可以包含OpenCV的bin文件夹中的所有.dll文件。你不想这样做。

您可能只能删除此行,它将起作用我无法测试。如果没有看到下面的话

您要做的只包括您正在使用的代码的dll文件。

的匹配DLL
  • highgui
  • imgproc

这样的东西适用于OpenCV 2.4.9调试(删除发布库的最后一个d):

LIBS += C://opencv//release//bin//opencv_highgui249d.dll
LIBS += C://opencv//release//bin//opencv_imgproc249d.dll
LIBS += C://opencv//release//bin//opencv_core249d.dll