Reputation: 91
I can build and execute the code below successfully :
IplImage* img = cvLoadImage("C:\\hello.jpg");
cvNamedWindow("myfirstwindow");
cvShowImage("myfirstwindow", img);
But I got the unhandled exception when executed the code below:
cv::Mat image= cv::imread("boldt.jpg");
cv::namedWindow("Image");
cv::imshow("Image",image);
although,I can build the code successfully.
I'm using opencv2.2 with VS2010 x86 version on windows 7 x86 version. please help !
update: I tried it on winxp ,and it works fine...and it works fine with win7 on Release mode only.
Upvotes: 5
Views: 13297
Reputation: 21
Check in the folders that generates the compilation, because in one of them is the .exe compiled, and it is possible that the image that you want to open is not there. In my case the .exe (in the Debuge mode) was in C:\Users\Name\source\repos\HolaMundox\x64\Debug, and not were I create my .cpp that was on C:\Users\Name\source\repos\HolaMundox. Something similar will apply with the Release mode. Other thing is that you must check well the extension of the image, if it is .jpg, .jpeg, .bmp, and so on... one error that I had was that I put the extención .jpg and it was .jpeg.
Upvotes: 0
Reputation: 883
Make sure you have the "C:\OpenCV2.4.3\build\x86\vc10\bin" added to the path. NOT(!) the "C:\OpenCV2.4.3\build\x86\vc9\bin". This may cause the problem.
For the use of opencv with visual studio there are two realy good docs:
Viual Studio 2010 and OpenCV-2-4-x
The official OpenCv-Documentation
Upvotes: 0
Reputation: 41
I have the exact same problem as have been described.
It turns out that the problem very much lies with the settings of the linker!
I found the answer in another thread: OpenCV 2.3 and Visual Studio 2010
Here it is:
"Properties of your project (right click on it)
Linker
Once I've done the above, I can run imshow and imread + all other cpp functions seamlessly! The author who asked the question probably has already solved it. but just in case there are other people who are led here looking for the same solution!
cheers!
Upvotes: 1
Reputation: 93410
It might be the problem where people don't realize that when VStudio runs your application it tries to find it's resources in the same directory as the compiled executable and not in the folder where the source files are.
Your first code works because you are loading the image passing the FULL PATH to the file!
That's why is so important to check the success of functions when you are coding:
try
{
cv::Mat image = cv::imread("boldt.jpg");
if (!image.data)
printf("!!! No data !!!");
}
catch(std::exception e)
{
printf("Exception: [%s]\n", e.what());
}
This sort of programming practice will save you a lot of time.
EDIT:
Well, if the crash is still happening it means that it could be either cv::namedWindow()
or cv::imshow()
fault, and my money is on cv::namedWindow()
.
Other users reported a similar behavior on Windows:
OpenCV 2.2 Windows XP MinGW build crashes on namedWindow, imshow
Open CV crashes under WIN7 when opening NamedWindow
namedWindow() causes crash in opencv 2.3.1? (Eclipse+MinGW on XP, C++)
It seems that to solve the problem you need to disable SSE optimizations.
Upvotes: 5
Reputation: 20058
Did you checked the output of the imread() function?
if(image.empty())
{
cout << "where's my image?" << endl;
return 0;
}
Upvotes: 1
Reputation: 4666
I'm using OpenCV 2.3.1 and when I run it in Release mode (linked to a release highgui lib), everything is fine. When I switch to Debug mode (still linked to a release highgui lib), it crashes. Linking to a debug highgui lib helped.
Maybe you have the same problem...
Upvotes: 3