Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

c++ - Unhandled exception on OpenCV+VS2010

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]
", 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...