1

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?

James Z
  • 12,209
  • 10
  • 24
  • 44
RAMASWAMY M
  • 49
  • 1
  • 6

2 Answers2

1

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.,.

1

If you want to train the classifier with different variations of the same fruit, you can generate training samples from multiple images as described here.

However, do note that Haar classifiers work in greyscale and it is difficult to guarantee differentiation between objects like red and yellow bananas.

If you want multiple classes in one classifier, I recommend YOLO (You Only Look Once) or SSD (Single Shot multibox Detector).

Totoro
  • 3,398
  • 1
  • 24
  • 39