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.
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.
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...
Did you checked the output of the imread() function?
if(image.empty())
{
cout << "where's my image?" << endl;
return 0;
}
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With