OpenCV imread(filename) fails in debug mode when using release libraries

后端 未结 6 2076
逝去的感伤
逝去的感伤 2020-11-29 03:23

I have some C++ code and everything was working fine with OpenCV except the function imread(file). It was finding correctly th

相关标签:
6条回答
  • 2020-11-29 04:00

    In release mode you must use release libraries, in debug mode - debug libraries. It is no bug.

    0 讨论(0)
  • 2020-11-29 04:05

    Had this problem using Qt (Qt Creator), linking the debug version of the respective library fixed it. This can be done automatically in the project configuration file (.pro):

    QTCreator .pro file: Setting LIBS path depending on DEBUG / RELEASE

    0 讨论(0)
  • 2020-11-29 04:09

    You can work around this issue by changing the runtime library of your Debug application from /MDd (multi-threaded DLL debug) to /MD (regular, release version of the multi-threaded DLL runtime).

    Your code will still be unoptimized and easier to debug than a normal release mode, but you will lose some debugging information (for example for crashes within the C runtime). You also lose some debugging features like the debug heap, but if you don't know what that is then it won't affect you.

    To do this work around, just go to Properties>C/C++/Code Generation and change "Runtime Library" from /MDd to /MD.

    0 讨论(0)
  • 2020-11-29 04:19

    I'll never get tired of telling people that the C++ OpenCV interface for Windows has the wierdest bugs.

    Write a small test using the C interface to check if it works or not (cvLoadImage(), etc).

    Update: now that you know that the C interface works properly, you can either go to the mailing list and report this bug there or dig into the code yourself to find why it fails.

    0 讨论(0)
  • 2020-11-29 04:24

    Use FORWARD slash (/), instead of a backward slash (). Even in Windows!

    Incorrect:

    cv::imread("C:\example\1.jpg");
    

    Correct:

    cv::imread("C:/example/1.jpg");
    
    0 讨论(0)
  • 2020-11-29 04:25

    In general it is perfecly legal to link "Debug" executable configuration against "Release" configuration library (why should not be as far as the symbols exported by the libraries are the same in Debug and in Release?). Unless (for some reasons) you don't want that "mixing" happen. It turns out that opencv developers decided to not allow such mixing and they perform such probihibition with a specific portion of code (something you can find in the file cvdef.h on release 3.4.4 line 54). That is not a C++ interface bug, but a "wanted" behaviour. You can find more information at https://github.com/opencv/opencv/pull/9161 where this change has been documented.

    0 讨论(0)
提交回复
热议问题