OpenCV imread(filename) fails in debug mode when u

2019-01-06 14:06发布

I have some C++ code and everything was working fine with OpenCV except the function imread(file). It was finding correctly the file and loading the name, but it wasn't loading any data.

Mat pattImage = imread(fileName, 0);

After some reaserch on the web I realized that I was in debug mode but with the release OpenCV libraries, instead of the debug ones.

debug library:    opencv_core231d.lib
release library:  opencv_core231.lib

Though it is the tipical stupid error I thought this shouldn't have anything to do, the debug libraries are supposed to allow OpenCV code debugging while the release libraries allow faster execution of the code, but I don't understand why imread was failing.

Can anybody explain me the differences between debug and release libraries in OpenCV and why this error occurs?

Is it an OpenCV bug?

4条回答
爷、活的狠高调
2楼-- · 2019-01-06 14:26

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");
查看更多
We Are One
3楼-- · 2019-01-06 14:40

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.

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-06 14:50

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

查看更多
迷人小祖宗
5楼-- · 2019-01-06 14:52

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

查看更多
登录 后发表回答