Search code examples
python-2.7python-3.xhaar-classifiercascade-classifier

Creating training set from multiple images in Haar Cascade


I am currently working on detecting multiple fruits in a given image. For example, the given image can have fruits like bananas (like yellow, red and green), mangoes, oranges,etc. I was able to create training set with only one image at a time using opencv_createsamples.

Sample Code:

C:\opencv\build\x64\vc14\bin\opencv_createsamples.exe -img redbanana.jpg -bg bg.txt -info info/info.lst -pngoutput info -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 100

Similarly I have done for around 5 fruits, which creates separate vec file for each fruit. Its hard to create for each fruit. Is there any possibility for creating training set from multiple images with a single vec file as an output?

Is there are any other methodology to detect multiple fruits in a given image?


Solution

  • A haar-classifier is ideally suited to detecting one class of similar looking objects quickly as outlined in the opencv documentation http:// docs.opencv.org/2.4/modules/objdetect/doc/cascade_classification.html. For example, the opencv repository (https:// github.com/opencv/opencv) has a list of classifiers (https:// github.com/opencv/opencv/tree/master/data/haarcascades) trained for specific classes of objects.

    Unless the objects to be detected are similar (like faces with different features or cars of different makes and models) training would be more effective with a classifier per fruit - e.g., bananas, oranges, mangoes etc.,.

    To create a training vector based on multiple positive sample images (and for any other aspect of haar-classifier training I'd recommend the steps here - steps 5 and 6 - and the details covered at http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html. In your case the positive images should include all types of bananas, oranges, mangoes etc including variation in color etc.,.