# Haar Cascade training not working as intended

Hi all!

I am looking to create a Haar classifier to find aerial pictures of cows in fields. I have around 1800 positive images picked out from source images of 800 x 800. It is hard to pick out a minimum samples in anything less than 800x800, as these images are taken from very high up in the air. I have an arbitrary number of negative images (6000 just in case)

I have:

1. A dat file listing the ROIs for my positive images (./dir/to/pos n_ROIs x1_ROI y1_ROI w_ROI h_ROI)
2. A dat file listing the negative images (./dir to neg)
3. A .vec produced by opencv_createsamples which reads from 1. in this list

Running opencv_traincascade with 800 x 800 images and the above criteria runs out of memory on my computer and is therefore a dead end.

A workaround I attempted was to crop the ROIs from the 800x800 and scale the cropped positives and negatives to a smaller size (24x24 - 50x50) and train on this. Running opencv_traincascade in this way trained over the course of minutes to hours depending upon the number of negatives. However, what is produced fails miserably at picking out the positive images.

I have checked my positive samples and there appear to be no false positives in the sample. I believe a potential problem is that, at the (24x24 - 50x50) scale, some of the positives are black blobs due to being so small in the first place.

Can I get some guidance as to the best way to proceed to get this to work? I get the impression a more powerful computer is required but I would like to know if there is a tactic for these type of situations that would be useful to know.

Many thanks!

edit retag close merge delete

please clarify: what do you give as -w -h params to opencv_traincascade ? (it should be the minimum size, you want to detect). if that is 800x800, you indeed have a problem.

( 2018-09-17 02:38:22 -0500 )edit

-w 800 -h 800 for uncropped, w-24 h-24 for cropped. This part I was confused about. In tutorials, I have seen this is the maximum size of the source images and if I train on anything less than this, it gives me a ROI out-of-bounds error.

( 2018-09-17 02:48:01 -0500 )edit

there is no maximum size in the training phase.

again, how large are your images ?

( 2018-09-17 02:52:33 -0500 )edit

My positive images are 800x800, the ROIs are defined inside. I think you've answered my question though. The -w -h options are the minimum size that can be picked out , rather than the limit of the image. Thanks!

( 2018-09-17 02:58:39 -0500 )edit

so, again, - how large is a cow in your image ?

also, cascades don't do well with variations in pose or texture, they are for rigid things.

can it be, you're trying this, because it is "the only thing you know" ?

( 2018-09-17 19:37:58 -0500 )edit