OpenCV图像加载程序退出

OpenCV Image Loading Program Exits

本文关键字:退出 程序 加载 图像 OpenCV      更新时间:2023-10-16

我正在使用安装教程末尾提供的示例源代码测试OpenCV 2.4.10。代码会编译,但启动后很快就会退出。我看到了第一条"cout消息"的闪光,但我甚至没有看到加载图像或其他任何东西的闪光。我使用的是Visual Studio 2012 C++和OpenCV 2.4.10。

测试代码:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
    if( argc != 2)
    {
     cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
     return -1;
    }
    Mat image;
    image = imread("opencv-logo.png", IMREAD_COLOR); // Read the file
    if(! image.data ) // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl ;
        return -1;
    }
    namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
    imshow( "Display window", image ); // Show our image inside it.
    waitKey(0); // Wait for a keystroke in the window
    return 0;
}

当我构建它时,我无意中加载了一些不必要的DLL,可能是由于以前项目的全局设置。一些负载给了我这个错误:

'test.exe' (Win32): Loaded 'C:opencvbuildx64vc11binopencv_highgui2410d.dll'. Cannot find or open the PDB file.
'test.exe' (Win32): Loaded 'C:opencvbuildx64vc11binopencv_core2410d.dll'. Cannot find or open the PDB file.
'test.exe' (Win32): Loaded 'C:Program FilesNVIDIA Corporationcoprocmanager_etoured.dll'. Cannot find or open the PDB file.
'test.exe' (Win32): Loaded 'C:Program FilesNVIDIA CorporationcoprocmanagerNvd3d9wrapx.dll'. Cannot find or open the PDB file.
'test.exe' (Win32): Loaded 'C:Program FilesNVIDIA Corporationcoprocmanagernvdxgiwrapx.dll'. Cannot find or open the PDB file.
'test.exe' (Win32): Loaded 'C:WindowsSystem32guard64.dll'. Cannot find or open the PDB file.

程序退出时显示:

The program '[9084] test.exe' has exited with code -1 (0xffffffff).

我不太确定这里发生了什么,我已经在C/C++>通用中添加了以下内容

C:opencvbuildincludeopencv
C:opencvbuildincludeopencv2
C:opencvbuildinclude

我已将以下内容添加到Linker>General>Additional Library Directories:

C:opencvbuildx646vc11lib

将库(尤其是返回加载错误的库,英伟达库除外)添加到Linker>Input。我还向环境变量添加了vc11\bin路径。

我试过使用cin.get()来强制暂停,但它不起作用。这与某些DLL返回的加载错误有关吗?

有人能给我指正确的方向吗?感谢阅读!

在主步骤和单个步骤的开始处放置断点,直到它崩溃。我的猜测是,要么是因为找不到图像而无法加载,要么是opencv 无法识别的格式