0

So, I have 20 positive samples and 500 negative samples. I created the .vec file using createsample utility.Now, when i try to train the classifier using the traincascade.exe utility, I run into the following error: enter image description here

I have looked into many solutions given to people who have faced similar issues, but none of them worked.

Things I tried: 1. Increasing the negative sample size 2. Checking the path of the negative(or background images) stored in the Negative.txt file 3. Varying different parameters.

Here is some information regarding the path: My working directory has the following files: 1. Traincascade.exe 2. Positive image folder 3. NegativeImageFolder 4. vec file 5. Negative.txt (file that has path to images in the negative image folder)

My Negative.txt file has the absolute file path for the images in the negative image folder. I also tried changing the file path to the following format:

NegativeImageFolder\Image1.pgm

but didn't work! I tried both front and backslash too!

I have run out of ways to change the file path or make any modification to make this work!

Alexander
  • 1,969
  • 19
  • 29

2 Answers2

4

First of all: is NumStages 1 and maxDepth 1 intentional?
Looking at Opencv's source code (cascadeclassifier.cpp, imagestorage.cpp), the error is thrown when in function

bool CvCascadeClassifier::updateTrainingSet( double& acceptanceRatio)

a number, negCount=500, of negative samples cannot be filled.
Before, everything was ok with positive samples (and the line about pos count that was printed on the screen is a proof of this).
Digging deep into source code negCount cannot be filled when imgReader.getNeg( img ) returns false, this means it cannot provide any image, which in turn happens when the list of source negatives is empty. So you have to concentrate all your efforts in the direction of providing the algorithm with the correct list of negative images.
There are two ways to solve this: make sure that Negative.txt is read and all paths are regular and that every image in the list can be read regularly.
Is the file name “Negative.txt” or “Negatives.txt”?

Anyway with so few positive and negative samples you won’t train anything functioning, it is only useful to make you understand how the process of training works.

Sevle
  • 3,109
  • 2
  • 19
  • 31
Giuseppe Dini
  • 762
  • 7
  • 19
  • 1
    Thank you for the response! Regarding the number of stages, I initially started with 10 stages. That didn't work. I just landed up trying different values for -numStages to see if it would make any difference since I couldn't figure out what exactly was causing the error. Using the default maxDepth value. – AnushkaShet123 Dec 04 '15 at 18:13
  • It's Negatives.txt. I reduced the number of negative images further and looked at the path of every single image. I still bump into the same error. I am using a low count for the negative samples only because I thought it would be easier to debug and would help me understand the process of training better. – AnushkaShet123 Dec 04 '15 at 18:16
  • What is the size (widthxheight) of the negative images? Are all files .pgms? If yes try to put at least one png. – Giuseppe Dini Dec 04 '15 at 20:14
  • Does the size really matter? I thought having large image sizes can slow the process of training. But it should still be able to train right? Currently, my image sizes are big (1920x1080). Tried with smaller images too and I get the same error. – AnushkaShet123 Dec 07 '15 at 20:15
  • 1
    I imagined that the error was trivial and was just trying to figure out what it was. A common mistake is to take negative images as little as the window size. 60x30 in ypur case. – Giuseppe Dini Dec 07 '15 at 21:37
-1

Well I was able to resolve the issue and run the train the classifier successfully. However, I am not 100% sure as to how the change I made helped.

This is what I did: I was generating the Negative.txt file using Excel. I would enter the file path of one image and increment the image filename (since my images were name image1, image2, image3...). So the format as mentioned earlier would be :

C:\OpenCV-3.0.0\opencv\build\x64\vc12\bin\Negative\Image1.pgm

And finally save the file as a Unicode txt document. However, saving it as a unicode txt document gave me the error stated in the question. I saved it as a Text (tab delimited) file and it worked.