OpenCV imread(filename) fails in debug mode when using release libraries
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.
opencv 2.3.* imread not working
The problem was due to mixing up debugging and release builds. If building in debug mode, the debug libs are needed. On unix this dont seem to be a problem.
Issue with reading an image using cv::imread function in OpenCv
Ok, I fixed the problem...
Problem arises when you are mixing up release and debug OpenCV libs.
I've changed paths and libs names in project properties and "cv::imread" works just fine.
Why is imread() always returning null data?
To debug your issue you should try to confirm that the image path is correct.
As suggested in the comments, try specifying the full absolute path of the file. Remember to to use escape slashes if you are on windows (e.g. c:\a.bmp will need to be "c:\a.bmp")
OR
If you are executing your application from Visual Studio then you can configure the working directory to be that of the bitmap too! (OpenCV cvLoadImage() does not load images in visual studio debugger?)
You can also try using cvLoadImage instead of imread. If cvLoadImage can open the file then it is possible that you have a mix of release and debug libraries causing you an issue as per:
- OpenCV imread(filename) fails in debug mode when using release libraries
Related Topics
How to Convert String to Ip Address and Vice Versa
What Are Rvalues, Lvalues, Xvalues, Glvalues, and Prvalues
When a Function Has a Specific-Size Array Parameter, Why Is It Replaced With a Pointer
In What Cases Do I Use Malloc And/Or New
How to Figure Out the Parameter Type and Return Type of a Lambda
What Exactly Is One Definition Rule in C++
Which Kind of Pointer Do I Use When
Why Must a Short Be Converted to an Int Before Arithmetic Operations in C and C++
Checking If All Elements of a Vector Are Equal in C++
Undefined, Unspecified and Implementation-Defined Behavior
Passing a 2D Array to a C++ Function
How to Get the List of Files in a Directory Using C or C++
How to Add Reflection to a C++ Application
Difference Between New/Delete and Malloc/Free