简体   繁体   English

OpenCV程序可编译但无法运行

[英]OpenCV program compiles but doesn't run

I am working on Windows 8 with OpenCV 2.4.13 and MinGW 4.9. 我正在使用Windows 8和OpenCV 2.4.13和MinGW 4.9。
I wrote a simple and small opencv program to check if everything was installed properly. 我编写了一个简单的小型opencv程序来检查是否正确安装了所有程序。 Following is the code: 以下是代码:

#include <opencv2/highgui/highgui.hpp>

int main () {
    printf("in main\n");
    for (int i = 0; i<10; i++) {
        printf("here\n");
        IplImage * image = cvLoadImage("C:/{...}/test.jpg");
        cvReleaseImage(&image);
    }
    return 0;
}

I compiled it with the following command at the command prompt: 我在命令提示符下使用以下命令对其进行了编译:

g++ -o test test.cpp -LC:\{...}\opencv\build\x64\vc11\lib -lopencv_core2413 -lopencv_highgui2413 -IC:\{...}\opencv\build\include

{...} is the path to the specified folder/file. {...}是指定文件夹/文件的路径。

This command runs properly and compilation is successful without any errors. 该命令可以正常运行,并且编译成功,没有任何错误。 However, when I run it with: 但是,当我用以下命令运行它时:

test  

in main and one here gets printed after which I get the error message as 'test.exe has stopped working. in main和一个here被打印后,我收到错误消息,因为'test.exe已停止工作。 Windows is looking for a solution.' Windows正在寻找解决方案。”

What all I have tried: 我尝试过的一切:

  1. For installation of OpenCV, ran the downloaded opencv executable file (which extracts all files) and added the system variable OPENCV_DIR and edited the system PATH for location of DLLs (which reside in %OPENCV_DIR%\\bin) as per: 为了安装OpenCV,请按照以下步骤运行下载的opencv可执行文件(提取所有文件)并添加系统变量OPENCV_DIR并编辑系统DLL的位置(驻留在%OPENCV_DIR%\\ bin中):
    http://docs.opencv.org/2.4/doc/tutorials/introduction/windows_install/windows_install.html#installation-by-using-the-pre-built-libraries http://docs.opencv.org/2.4/doc/tutorials/introduction/windows_install/windows_install.html#installation-by-using-the-pre-built-libraries
  2. Tried adding the required DLLs in the same directory as the .exe. 试图将所需的DLL添加到与.exe相同的目录中。
  3. Tried doing the whole thing from vc12 directory. 尝试从vc12目录执行整个操作。
  4. After the error message appears, it gives an option of debugging. 错误消息出现后,它将提供调试选项。 On pressing that, the Just In Time Debugger opens up and says 'An unhandled win32 exception occurred in test.exe'. 按下该按钮时,Just In Time调试器将打开,并显示“ test.exe中发生未处理的win32异常”。 I googled this and tried inspecting the registry key as directed here 我对此进行了搜索,并尝试按照此处的指示检查注册表项
    https://support.microsoft.com/en-us/kb/811191 https://support.microsoft.com/zh-CN/kb/811191
    but it was already properly set. 但是已经正确设置了。 So, there was nothing for me to change in that. 因此,我没有任何改变。

Nothing is working for me at all. 什么都没有为我工作。 Please let me know if any more information is required. 请让我知道是否需要更多信息。 I'm desperately looking for a solution to this. 我正在拼命寻找解决方案。

对于那些可能遇到相同问题的人,我使用OpenCV动态( .dll )库而不是.lib文件编译了该程序,由于某种原因,它在运行时运行得很好。

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

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