未处理的异常 Microsoft C++ 异常:cv::Exception at memory location

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25587912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:21:51  来源:igfitidea点击:

Unhandled exception Microsoft C++ exception: cv::Exception at memory location

c++windowsvisual-studio-2010opencv

提问by tonnerrian

I just started with OpenCV. I downloaded OpenCV 2.4.9, and installed MSVS 2010. My Windows is X64. I followed the following steps:

我刚开始使用 OpenCV。我下载了 OpenCV 2.4.9,并安装了 MSVS 2010。我的 Windows 是 X64。我按照以下步骤操作:

a. Under Configuration Properties, click Debugging -> Environment and copy paste: PATH=C:\opencv\build\x86\vc10\bin

一种。在配置属性下,单击调试 -> 环境并复制粘贴:PATH=C:\opencv\build\x86\vc10\bin

b. VC++ Directories -> Include directories and add the entries: C:\opencv\build\include

湾 VC++ 目录 -> 包含目录并添加条目:C:\opencv\build\include

c. VC++ Directories -> Library directories and add the entries: C:\opencv\build\x86\vc10\lib

C。VC++ 目录 -> 库目录并添加条目:C:\opencv\build\x86\vc10\lib

d. Linker -> Input -> Additional Dependencies and add the following:

d. Linker -> Input -> Additional Dependencies 并添加以下内容:

opencv_calib3d249.lib;opencv_contrib249.lib;opencv_core249.lib;opencv_features2d249.lib;opencv_flann249.lib;opencv_gpu249.lib;opencv_nonfree249.lib;opencv_highgui249.lib;opencv_imgproc249.lib;opencv_legacy249.lib;opencv_ml249.lib;opencv_objdetect249.lib;opencv_ts249.lib;opencv_video249.lib;

opencv_calib3d249.lib;opencv_contrib249.lib;opencv_core249.lib;opencv_features2d249.lib;opencv_flann249.lib;opencv_gpu249.lib;opencv_nonfree249.lib;opencv_highgui249.lib;opencv_highgui249.lib;opencv_highgui249.lib;opencv_highgui249.lib;opencv_highgui249.lib;opencv_highgui249.lib4opencv_lib4_open4_open4_open4.lib4open4_open4_open4.lib4open249.lib4open249.lib;opencv_flann249.lib;opencv_flann249.lib;库;opencv_video249.lib;

I ran the following code:

我运行了以下代码:

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

To get the error:

要获取错误:

Unhandled exception at 0x76d2b727 in BTP1.exe: Microsoft C++ exception: cv::Exception at memory location 0x003af414

BTP1.exe 中 0x76d2b727 处未处理的异常:Microsoft C++ 异常:内存位置 0x003af414 处的 cv::Exception

I figured this might be because of the X64 and x86 mismatch. On changing the entries in a. to PATH=C:\opencv\build\ x64\vc10\bin and in c. to C:\opencv\build\ x64\vc10\lib, I get the following error:

我想这可能是因为 X64 和 x86 不匹配。关于更改 a 中的条目。到 PATH=C:\opencv\build\ x64\vc10\bin 并在 c 中。到 C:\opencv\build\ x64\vc10\lib,我收到以下错误:

The application was unable to start correctly (0xc000007b). Click OK to close the application.

应用程序无法正确启动 (0xc000007b)。单击确定关闭应用程序。

Any tips on how I can get over this issue?

关于如何解决这个问题的任何提示?

回答by Bull

This is probably happening because the image you are trying to display is empty, perhaps because the image isn't in the right folder. To confirm this, change your code to

这可能是因为您尝试显示的图像是空的,可能是因为图像不在正确的文件夹中。要确认这一点,请将您的代码更改为

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

#include <iostream>  // std::cout

int main() {
    // read an image
    cv::Mat image= cv::imread("img.jpg");

    // add the following lines
    if(image.empty())
       std::cout << "failed to open img.jpg" << std::endl;
    else
       std::cout << "img.jpg loaded OK" << std::endl;

    ...   // the rest of your code

回答by tonnerrian

Resolved the problem. On some tinkering, I found that the program was running in the Release mode, and not the Debug mode.

解决了问题。经过一些修补,我发现程序在发布模式下运行,而不是调试模式。

It was a problem with the Additional Dependencies. Did not add the Debug versions of the same. (XYZ249d.lib)

这是附加依赖项的问题。没有添加相同的调试版本。(XYZ249d.lib)