Car detection using OpenCV

I am working on a small personal project where i have to know wether an image shown is a car or not. I am using the basic OpenCV python based template matching.

Positive Image / Template Image

Car Top View :-

Top view

The simple template matching by using one of the positive image on the other is giving the required result.

Negative Image

But when we are using negative images like

negative image

the template finder is finding this as a positive match.

Methods tried and failed :-

  1. Increase the threshold for template matching :- Increasing the threshold is causing many of the actual positive images to stop matching

  2. Different types of template matching techniques that are there in OpenCV :- Not giving any better result

  3. Using multiple templates to reinforce positive and negative matches:- Doesn't work well for all the cases

Is there a better way to remove the template matching false positives that we are getting. Are there any feature matching or edge detection based techniques that can be used instead of template matching to improve my algorithm.

  • $\begingroup$ What does negative in negative image refer to? Also I don't understand why you are not happy with a positive match: isn't there a car in the "negative image"? $\endgroup$ – anderstood Sep 20 '17 at 19:11
  • $\begingroup$ @anderstood sorry for being not clear on this one... the car should only be detected when the full car is present . In the negative case the cars are being detected even if only a small part of the car is under the sliding window. $\endgroup$ – ANIRUDH NJ Sep 21 '17 at 8:42

I assume that the image have same scales in terms of sizes. With that out of the way, I would suggest try using the following:

  1. Break up your image into parts. (the template image as well as the test image. may be 3 or 4 according to your choice.)
  2. Then perform template matching on each part. Consider common threshold for every template part and then count it as positive only when all parts give a positive result.

(P.S. A similar solution was suggested on some other post. I don't exactly remember which post.)

Update: Partition your template and test images at exactly same points.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.