3
votes

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 :- https://i.stack.imgur.com/zXr1U.jpg

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 https://i.stack.imgur.com/YLVwc.jpg 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.

1
Your "negative" image does contain (most of) a car -- it's not clear if this should be detected or not? So I think you may need to start by specifying the criterion and required performance. As there are different kinds of car (e.g. some are darker than the pavement and some brighter) you will almost certainly need multiple templates. It might be helpful to preprocess the image and template to detect "car-like" features of some sort; perhaps edge detection. Another possible approach is to train a neural network from many positive and negative examples; but that is a lot more complex.NickJH
maybe you should start with finding out how these methods work. that's the only way how you can learn to use them properly...Piglet
@NickHollinghurst The negative image should not be detected as a car. Only when the full car is in the image the it should be detected .ANIRUDH NJ

1 Answers

1
votes

simple way but might worth trying in your case is to divide your template into ("4") parts - corner and then apply template matching on each of the parts and only accept when the 4 parts are found

also:

  • adding different template while increasing the threshold

  • apply some normalization if it is not already being applied