[英]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.