简体   繁体   中英

OpenCV program compiles but doesn't run

I am working on Windows 8 with OpenCV 2.4.13 and MinGW 4.9.
I wrote a simple and small opencv program to check if everything was installed properly. 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. Windows is looking for a solution.'

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:
    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.
  3. Tried doing the whole thing from vc12 directory.
  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'. I googled this and tried inspecting the registry key as directed here
    https://support.microsoft.com/en-us/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文件编译了该程序,由于某种原因,它在运行时运行得很好。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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