how to reduce wrong recognition using cascade classifier

1.4k Views Asked by At

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;
}
1

There are 1 best solutions below

1
On

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.