Question

I have close to 1000 images that I want to use as positive samples for opencv to use in a cascadedtrainer.

I've read this excellent tutorial: http://note.sonots.com/SciSoftware/haartraining.html, as well as this: http://www.computer-vision-software.com/blog/2009/11/faq-opencv-haartraining/, but I'm having trouble deciding what to do with the createsamples utility's -w and -h parameters and the idea of cropping my images.

I have large images [1300x600] with a lot of background content, so that the object that's actually required to be detected by a cascaded classifier usually takes about 10% of the image.

Is it necessary to crop the images and then use OpenCV's createsamples utility? Or can I leave out the cropping part because anyway, the description file for positive samples includes the x and y coordinates and height and width of the bounding box that surrounds the object of interest. I'm confused because I read somewhere that "too much background" would ruin the performance. Is there such a thing as "too much background" when a person has already specified tight bounding boxes for objects within images?

My main issue here is time, I would like to avoid manually cropping 1000 images if it won't ultimately hurt the classifier's performance.


Edit

I actually did a bit of cropping and here's an average distribution of the way my samples look:

car1 car2 car3 car4 car5 car6 car7

Was it helpful?

Solution

You don't need to resize or crop your samples but you need to use an annotation tool to create a list of positive samples in the following format:

path_to\sample1.png 1 10 10 20 22
path_to\sample2.png 2 10 10 20 22 40 40 30 33
...

That takes care of all of the issues your were concerned about. Depending on your samples, creating this text file can become time consuming.

Too much background inside the bounding box of your positive samples may affect the effectiveness of the weak classifiers in your model, but it may or may not be important in the final cascade of classifiers model. All you should be concerned about is to create good positive samples where the object is captured inside the bounding box as precisely as possible. It means:

  1. having each sample in the same relative location to the top-right corner of its corresponding bounding box, and
  2. having same object width/bounding box width ratio for all samples.

In other words, try centering all objects in your bounding box and add the same "percentage" of padding for all of them so that when they are cropped and resized by createsamples into a vec file, all of them look similar in locations and size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top