problem with reading image to Mat
I'm using Visual Studio 2012 with OpenCv 2.4.3 and I don't know if I'm doing sth wrong but I can't do the simplest imread(), because there is a problem with memory I think. Here is the code:
#include <iostream>
#include <string>
#include <imgproc\imgproc.hpp>
#include <core\core.hpp>
#include <highgui\highgui.hpp>
using namespace std;
using namespace cv;
Mat img;
int main(int argc, char *argv[])
{
img = imread("lena.jpg", 1);
namedWindow("Lena", CV_WINDOW_AUTOSIZE);
imshow("Lena", img);
waitKey();
return 0;
}
During debuging it stops at imread() and throws exception: Unhandled exception at 0x5B9665AF (msvcr90d.dll) in opencv_test.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC.
If anyone knows what could be wrong, please help
Thank you for your responses. I actually fixed it. The problem was in environmental variable path, there was for version vs2008 and next for 2012. When I removed the first one, there was a problem with missing .dll, but there are lots of guides how to managed it. So it works :)
@StevePuttemans: I tried manual debugging, but it alwas stopped at imread() line, it didn't read the picture so the mat object was empty. And I didn't know what to do. These are my first steps with opencv and c++. Anyway it works. Thanks for your answer :)
I don't have OpenCV libraries in PATH. Instead I add needed path in the project settings (Debugging -> Environment), and have menu items in Far Manager, which add needed path to the current session.
What for your case, the DLL name immediately suggests that we have DLL hell curse. Numbers 90 in the name define MSVC version (9.0 is Visual Studio 2008, 10.0 is VS 2010). I recommend you to carefully inspect your PATH variable and clean everything unneeded.
That's a pity that there is no such thing as modules (http://modules.sourceforge.net) in windows.
You are welcome :) Feel free to accept an answer as solution to your problem.
Indeed making sure the path variables are correct, is important, also including the correct libraries in linker settings is essential.
Manually debugging does help situate exactly. If it stops at a function try going step by step through the code and do a dive inside function imread(). It could show you where exact it went wrong.
Hello bee,
I'm having the exact same problem as this. My picture path is correct but it refuses to show because the imread always returns an empty matrix. Would you mind elaborating on what you meant by "there was for version vs2008 and next for 2012" ?
@Double Vision, when linking your libs you can select the vc folder, which is the edition of your visual compiler. It means that you should select vc9 or vc10 for vs2008-2010 but vc11-12 for vs2012 due to more functionality available inside the compiler.
I encountered the same issue. It turns out I should use the full path of the image file.