简体   繁体   中英

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. This is my very first QT application. However, the program runs, but there is no image display! The same code runs in VS 2010 and display the image correctly. Following is the only output I get from QT.

在此处输入图片说明

Following is my QT Project configuration.

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
  • QT Creator version - 2.7.0
  • QT Downloaded from - http://qt-project.org/downloads (File Name is: qt-windows-opensource-5.0.2-mingw47_32-x86-offline)
  • OpenCV Version - 2.4
  • MinGW Version - Was installed sometime back in the 9th month of 2012. Don't know how to get the version number.

How can I make this opencv task work correctly?

Update

I just checked the .exe file it built. 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.

There are 2 ways to fix that:

  • Locate and copy that .DLL to the .exe folder.
  • Modify Windows' PATH environment variable and add the full path to that .DLL . It's best to reboot your machine after this change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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