简体   繁体   English

OpenCV Build正常,调试会引发错误,可以从.exe正常运行

[英]OpenCV Build ok, debug throws error, runs fine from .exe

Using Visual Studio 2010, OpenCV 2.2.2, Windows 7 64x 使用Visual Studio 2010,OpenCV 2.2.2,Windows 7 64x

My code builds successfully then when it goes into debug I get the following error: 我的代码成功构建,然后在进行调试时出现以下错误:

First-chance exception at 0x75f0c41f in MachineVisionHW0.exe: Microsoft C++ exception: cv::Exception at memory location 0x002dec90..
Unhandled exception at 0x75f0c41f in MachineVisionHW0.exe: Microsoft C++ exception: cv::Exception at memory location 0x002dec90..

Then I end debug, go to the file directory and run the built executable and it runs fine. 然后我结束调试,转到文件目录并运行生成的可执行文件,它运行良好。 Does anybody know how to fix this? 有人知道如何解决此问题吗? It isn't keeping me from building my code, but it is incredibly inconvenient. 它并不能阻止我构建代码,但是却带来了极大的不便。 I will include an example of the code that is doing this below. 我将在下面提供执行此操作的代码示例。

int main(){
    cv::Mat image1 = cv::imread("img1.JPG", CV_LOAD_IMAGE_GRAYSCALE);

    cv::namedWindow("Sample1");
    cv::imshow("Sample1", image1);
    cv::waitKey(0); 

    return 1;
}

Do you get the unhandled exception before main? main 之前得到未处理的异常吗?

If not, then your code is somehow doing something to raise the exception. 如果没有,那么您的代码就以某种方式做了一些事情来引发异常。 Put a breakpoint on the first line, then hit F5, then once at the breakpoint, step through the code one line at a time to see which one causes the exception, F10 key to do this. 在第一行上放置一个断点,然后按F5,然后在该断点处一次,一次遍历代码行,以查看是哪一个导致异常,用F10键执行此操作。

My gut feeling is that when running from the debugger, the cv::imread is failing since it is not finding the img1.jpg from the expected location, the current working directory is that of the solution file, not of the debug output build dir. 我的直觉是,从调试器运行时, cv::imread失败,因为它没有从预期位置找到img1.jpg,当前的工作目录是解决方案文件的目录,而不是debug输出build dir的目录。 。 You can do a quick test and copy the img1.jpg to the dir containing the sln file and see if that fixes the problem. 您可以进行快速测试,然后将img1.jpg复制到包含sln文件的目录中,看看是否可以解决问题。

暂无
暂无

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

相关问题 简单的cin cout代码通过“构建和运行”运行,但是来自bin / debug / x.exe的少量工作 - Simple cin cout Code runs by “build and run” but dosent work from bin/debug/x.exe OpenCV C ++代码在终端运行良好但从eclipse运行时出错 - Ubuntu 12.04 - OpenCV C++ code runs fine in terminal but error in running from eclipse - Ubuntu 12.04 Qt Creator + OpenCV:程序从.exe运行,但不从编辑器运行 - Qt Creator + OpenCV: Program runs from .exe but not from editor 调试运行良好,但不在发布模式下 - Debug runs fine, but not in release mode OpenCV + Visual Studio 2008-程序在调试中运行良好,但在常规执行中访问冲突 - OpenCV+Visual Studio 2008 - Program runs fine in debug but access violation in regular execution 调试版本中 exe_common.inl 中的随机错误 - Random error in exe_common.inl in Debug build 如果调试运行正常但释放崩溃怎么办 - what to do if debug runs fine, but release crashes extern“C”DLL:调试正常,Release抛出错误C2059 - extern “C” DLL: Debug is OK, Release throws Error C2059 一个.exe应用程序在windows10中创建新模块时抛出错误,但在windows7中可以正常工作? - An .exe application throws an error while creating a new module in windows10 but works fine in windows7? 使用 Qt 的程序,从 VS 启动时 OpenCV 运行良好,但在使用 OpenCV 功能时运行可执行文件通常会崩溃 - Program using Qt, OpenCV runs fine when started from VS, but running the executable ordinarily crashes when OpenCV functionality would be used
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM