1

Steps I have followed:

  • Background subtraction with preprocessing.
  • Contour detection.

With these two steps, I am able to draw contours on all moving cars in the video. But how do I track contours to count number of cars in the video ?

I searched around a bit and there seem to be different techniques like Kalman Filter, Lucas Kannade and Optical Flow... But I don't know which one to use for my usecase. I am using opencv3-python.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Adi
  • 4,149
  • 4
  • 25
  • 41
  • if you only have to count cars that pass a camera a simple set of scan-lines would do. use them like a light barrier – Piglet May 13 '16 at 09:34
  • evaluate a line of pixels across the lane. if there is a massive change in intensity from the non-car value you got yourself a car passing. – Piglet May 27 '16 at 08:55
  • Can you suggest some sample code/algorithm for the above? – Adi Jun 01 '16 at 18:54

1 Answers1

2

Actually, this seems like a general question, but I am going to give a point of view (Myself, I had the same problem but with pointclouds, although it may be different than what you asked, I hope it will give you an idea of how to proceed).

Most of the times, once your contours are detected, tracking moving objects in the scene involves 3 main steps:

Feature Matching :

This step is about detecting features in your object (Frame N) and match it to features of objects in frame (N+1). the detection part has some standard algorithms and descriptors available in OpenCV (SURF, SIFT, ORB...) as well as the Features matching part.

Kalman Filter

The Kalman filter is used to get an initial prediction (generally by applying a constant velocity model for your objects). For each appearance-point of the track, a correspondence search is executed. If the average distance is above a specified threshold, feature matching is applied to get a better initial estimate. In order to do that, you need to model your problem in a way it can be solved by a Kalman filter.

Dynamic Mapping

After the motion estimation, the appearance of each track is updated. In contrast to standard mapping techniques, dynamic mapping is an approach which tries to accumulate appearance details of both static and dynamic objects. thus refining your motion estimation and tracking process.

There are a lot of papers out there, you may as well take a further look at these papers :

Robust Visual Tracking and Vehicle Classification via Sparse Representation

Motion Estimation from Range Images in Dynamic Outdoor Scenes

Multiple Objects Tracking using CAMshift Algorithm in OpenCV

Hope it helps !

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Vtik
  • 3,073
  • 2
  • 23
  • 38
  • Thank you for the suggestions. The way i ended up creating the first algorithm was by using background subtraction with contour detection. Then I used hungarian algorithm to track the contours. – Adi May 26 '16 at 18:52