2

Hello I'm tring to recognize a car using cascade classifier, android and opencv library. My problem is that my phone is marking almoust everything as a car.

I've created my code based on: https://www.youtube.com/watch?v=WEzm7L5zoZE and face detection sample. My app behave very strange cause marking looks like random. I even don't know if marking car is correct or maybe it is just some random behaviour. At the moment it is even marking my keyboard as a car. I'm not sure what can I improve. I don't see any progress between training it up to 5 or 14 stages

I've trained my file up to 14 stages

my code looks like this:

@Override
public Mat onCameraFrame(Mat aInputFrame) {
    // return FrameAnalyzer.analyzeFrame(aInputFrame);
    // Create a grayscale image
    Imgproc.cvtColor(aInputFrame, grayscaleImage, Imgproc.COLOR_RGBA2RGB);

    MatOfRect objects = new MatOfRect();

    // Use the classifier to detect faces
    if (cascadeClassifier != null) {
        cascadeClassifier.detectMultiScale(grayscaleImage, objects, 1.1, 1,
                2, new Size(absoluteObjectSize, absoluteObjectSize),
                new Size());
    }

    Rect[] dataArray = objects.toArray();
    for (int i = 0; i < dataArray.length; i++) {
        Core.rectangle(aInputFrame, dataArray[i].tl(), dataArray[i].br(),
                new Scalar(0, 255, 0, 255), 3);
    }

    return aInputFrame;
}
Fixus
  • 4,631
  • 10
  • 38
  • 67
  • Use more negative samples and after training add false positives to your negative samples and train again. – Micka Dec 07 '14 at 17:16
  • @Micka does second training be added to first or will it overwrite the first one ? Higher ammount of negative in relation to positive gives better results ? – Fixus Dec 07 '14 at 17:17
  • Not sure about Haar detector training but I guess you have to completely retrain. Afaik you normally use much more negative samples (5x to 10x) than positive ones but I'm no expert in machine learning... – Micka Dec 07 '14 at 17:29
  • Or maybe not that dramatically... have a look at http://stackoverflow.com/questions/8935085/how-many-images-to-use-for-positive-and-negative-samples-when-haar-training – Micka Dec 07 '14 at 17:54

1 Answers1

2

Try changing the below.

  1. Using COLOR_RGBA2RGB with cvtColor as in sample code will not give a gray scale image. Try RGBA2GRAY
  2. Increase the number of neighbors in detectMultiScale. Now it's 2. More neighbors means more confidence in result.
  3. Hope there are enough samples to train with. A quick search and reading through books, gives an impression like thousands of images are needed for training. For e.g. around 10000 images are used for OCR haar training. For face training, 3000 to 5000 samples are used.
  4. More importantly, decide if you really want to go with haar training for identifying a car. There could be better methods of vehicle identification. For e.g. for a moving vehicle we could use optical flow based techniques.
kiranpradeep
  • 10,859
  • 4
  • 50
  • 82
  • @Kirand thank you for info. I will check all of this points. I have some positives results with increasing neighbors – Fixus Dec 10 '14 at 19:42