tags:

views:

92

answers:

1

Hi,

NOTE: I do believe that this is not an openCV related problem but since the error occurred using this library it might be a point of interest.

In the following code, by giving the wrong parameter as cascade_name, the load function throws an exception which is expected.
The interesting point is that by commenting the two following lines after catch block, the code would not throw any exception at all.

my question is, how such a thing is possible at all?!

cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
cv::CascadeClassifier c;
try
{
    c.load( std::string("") );
}catch(...)
{
    cout << "Exception";
}
cv::FileStorage fs( std::string(cascade_name), cv::FileStorage::READ );
bool t2 = fs.isOpened();
bool t = c.empty();
if ( cascade == 0 )
    return -1;
return 0;
A: 

It depends on the circumstances/assumptions about the program in general: it's possible, given the right set of circumstances.

For example:

You are running this function from multiple threads, and inside the openCV library the FileStorage object interacts (shares variables, etc.) with the CascadeClassifier object. The code path in one thread causes the other thread to error on the ::load method.

The times which I have seen things like this are (in order of likelihood): - The compiler didn't rebuild with changes properly - You didn't run the code you expected - The addition of lines caused some problems with multi-threaded synchronization (either in your code, or inside the library) - The addition code caused timings to change, which caused errors

Hope that helps.

Nick