Problem with OpenCV on Windows

  • Used OpenCV 2.4.6, Qt 5.2.1 and Windows 7

    In .pro connect OpenCV thus:
    LIBS += -LC:/opencv/build/x86/mingw/lib/
    LIBS += -lopencv_highgui246

    Trying to load a image as follows:

    IplImage* image = cvLoadImage("1.jpg", 1);

    As a result, the program quits unexpectedly.
    What could be the problem?

  • No, it's not the.
    My app crashes immediately after startup

  • OpenCV if I recall rightly has debug and release libs (I think they are the lib followed by d). Your not compiling debug against release libs are you?

  • First make sure that you use libraries that are compatible with the compiler you use, it seems you use OpenCV built with MinGW, so do you have Qt built with MinGW too? Make sure that you do, and also make sure that you don't build a x64 application (that's because you link with 32 bit OpenCV build).

    Then try to debug your code and see the error code that is returned, it can be a simple error saying that at run-time OpenCV's (or Qt's) dll's can't be found so the application can't start (for example you can add the path to OpenCV dll files to the Path in environment variables or copy the dll into the same folder with your application)

    And if those are ok, debug your code, for stuff that might crash your application (example using uninitialized pointers), and if you still can't find the issue (and you provided the appropriate libraries both at compile-time and at run-time) you need to show more code, else we don't have any chance to help you.

  • Checked, using compatible library

    Here is an example:
    #include <opencv/cv.h>
    #include <opencv/highgui.h>

    int main() {
    IplImage* image = cvLoadImage("1.jpg", 1);

    cvReleaseImage(& image);
    return 0;


    When you debug this error occurs:
    During startup program exited with code 0xc0000135

  • Just as i guessed, that means "dll not found", so make the OpenCV dll's available at run-time (either copy the ones you linked with in the same folder with your application, or add the path C:/opencv/build/x86/mingw/bin to the path in the environment variables) - also if you run from outside of Creator you will need at least two dll's from MinGW runtime: libgcc_s_dw2-1.dll and libstdc++-6.dll (those can be found into the bin folder inside MinGW instalation).

    LE: if you edit the path in environment variables be careful the paths in there are separated by ;

  • After rebuilding of the library problem was resolved

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.