Ask Your Question
0

Is there a bug in the traincascade of Opencv 243?

asked 2013-04-04 04:58:51 -0600

thdrksdfthmn gravatar image

Hi i am trying to train a detector and sometimes opencv_traincascade (v243) is crashing and saying

===== TRAINING 16-stage =====
<BEGIN
POS count : consumed   2000 : 2152
OpenCV Error: Assertion failed (_img.rows == winSize.height) in unknown function
, file ..\..\..\modules\traincascade\imagestorage.cpp, line 87

I have searched and i have found that it is something about the negatives. I have only scenes (much larger than the positives size). Is there the possibility to be a bug, or what is my problem? What shall I do to fix it?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-04-04 06:15:51 -0600

Go to your source code and find the cascadeclassifier.cpp file. Then update the following code.

int CvCascadeClassifier::fillPassedSamples( int first, int count, bool isPositive, int64& consumed )
{
    ...
        for( ; ; )
        {
            ... 
            featureEvaluator->setImage( img, isPositive ? 1 : 0, i );
            if( predict( i ) == 1.0F )
            {
                getcount++;
                printf("%s getcount: %d\r", isPositive ? "pos":"neg", getcount);
                break;
            }
        }
    }
    return getcount;
  }

This will already give you a possible indication if something goes wrong by displaying the consumation of the negative samples.

Also open the imagestorage.cpp file and adapt the following code. This will make sure that if negative dimensions do not match, that the specific file is skipped and the algorithm continues with the following file.

bool CvCascadeImageReader::NegReader::nextImg()
{
    ...
        src = imread( imgFilenames[last++], 0 );

        // -----------------------------------------------------------------------------
        // FIX ADDED : if traincascade does not get the image width and heigth correctly
        // or the original image width and height are smaller than window size
        if(src.rows < winSize.height || src.cols < winSize.width)
            continue; 

        if( src.empty() )
            continue;
        // -----------------------------------------------------------------------------

       ...
}

Hope this serves you well.

edit flag offensive delete link more

Comments

It is not helping me... :( Now it is crashing without saying anything. Thanks anyway.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2013-04-05 02:39:05 -0600 )edit

Then i am guessing that there is actually a problem with your negative dataset. Are you sure the bg.txt file corresponds to correct images and there are no typo's in the file? Please post your training command and according files in original question for better explanation.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-05 03:25:55 -0600 )edit

adding the line of printf does not help, it is shown only for a moment then it is removed, so i cannot see what it is reading.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2013-04-05 03:32:48 -0600 )edit

After your printf function add the following code, it will prevent the window from closing.

  Mat test; imshow("stop",test); waitKey(0);
StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-05 04:05:12 -0600 )edit

it is not helping... What is the difference between 231 and 243 regarding the .vec file, and the .txt files?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2013-04-09 03:48:43 -0600 )edit

There is no difference, nevertheless, there has been bug reporting and fixing. Since version 2.4.4 is pretty stable, go download that one and try again. I am guessing you are using an old version which still houses some bugs that should be fixed now. 2.4.4 is not giving errors here.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-09 03:55:11 -0600 )edit

I will try 244 and i will mention the result, but now I am very busy to do it. I will post the results. Thanks.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2013-04-09 07:06:34 -0600 )edit

I have found this problem in OpenCV 231, too. Is it possible that the number of samples to be too big and this is why it is happening?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2013-04-18 00:45:01 -0600 )edit

I do not see the purpose of using openCV 2.3.1 if there is a stable version 2.4.5. Tons of bugs have been fixed or solved since then, so basically use this advantage :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-18 01:23:12 -0600 )edit
1

Yes, finally 2.4.5 seems to work, now it is training as it should! Thanks everybody!

thdrksdfthmn gravatar imagethdrksdfthmn ( 2013-06-20 07:13:22 -0600 )edit

Question Tools

Stats

Asked: 2013-04-04 04:58:51 -0600

Seen: 1,658 times

Last updated: Apr 04 '13