简体   繁体   English

OpenCV 图像未显示

[英]OpenCV image is not showing

I am working on the following code:我正在处理以下代码:

Main.cpp主程序

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

using namespace cv;
using namespace std;

int main()
{
    Mat im = imread("C:/Users/Public/Pictures/Sample Pictures/Koala.jpg");
    if (im.empty())
    {
        cout << "Cannot load image!" << endl;
        return -1;
    }
    imshow("Image", im);
    waitKey(0);

    return 0;
}

I am trying to test the OpenCV with QT, by simply opening an image.我正在尝试通过简单地打开图像来使用 QT 测试 OpenCV。 This is my very first QT application.这是我的第一个 QT 应用程序。 However, the program runs, but there is no image display!但是,程序运行了,却没有图像显示! The same code runs in VS 2010 and display the image correctly.相同的代码在 VS 2010 中运行并正确显示图像。 Following is the only output I get from QT.以下是我从 QT 得到的唯一输出。

在此处输入图片说明

Following is my QT Project configuration.以下是我的 QT 项目配置。

Tester.pro测试版

#-------------------------------------------------
#
# Project created by QtCreator 2013-04-25T23:36:30
#
#-------------------------------------------------

QT       += core

QT       -= gui

TARGET = Tester
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app


SOURCES += main.cpp

INCLUDEPATH += C:\opencv\build\include\

LIBS += -LC:\opencv\build\x86\mingw\lib\
-lopencv_core240 \
-lopencv_highgui240 \
-lopencv_imgproc240 \
-lopencv_features2d240 \
-lopencv_calib3d240

Here are the version I am using:这是我正在使用的版本:

  • My OS - Windows 7 Ultimate我的操作系统 - Windows 7 Ultimate
  • QT Creator version - 2.7.0 QT Creator 版本 - 2.7.0
  • QT Downloaded from - http://qt-project.org/downloads (File Name is: qt-windows-opensource-5.0.2-mingw47_32-x86-offline) QT 下载自 - http://qt-project.org/downloads (文件名是:qt-windows-opensource-5.0.2-mingw47_32-x86-offline)
  • OpenCV Version - 2.4 OpenCV 版本 - 2.4
  • MinGW Version - Was installed sometime back in the 9th month of 2012. Don't know how to get the version number. MinGW 版本 - 是在 2012 年第 9 个月的某个时间安装的。不知道如何获取版本号。

How can I make this opencv task work correctly?我怎样才能使这个 opencv 任务正常工作?

Update更新

I just checked the .exe file it built.我刚刚检查了它构建的 .exe 文件。 It gives the following error when I double click on it当我双击它时出现以下错误

在此处输入图片说明

That error means that the Operating System was unable to find the .DLL when your application was launched.该错误意味着操作系统在您的应用程序启动时无法找到.DLL

There are 2 ways to fix that:有两种方法可以解决这个问题:

  • Locate and copy that .DLL to the .exe folder.找到该.DLL并将其复制到.exe文件夹。
  • Modify Windows' PATH environment variable and add the full path to that .DLL .修改 Windows 的PATH环境变量并将完整路径添加到该.DLL It's best to reboot your machine after this change.最好在此更改后重新启动您的机器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM