This is a C++ reimplementation and refinement of blacksteed232's PedestrianCounter with tracking in mind.
- Opencv
-
Instead of counting how many people walking across a straight line, here we can specify arbitrary closed polygon region and count the number of people entering or exiting from it.
-
We eliminate the constraint that a person can only come inside or go outside of scene from either the top or the bottom edges, and allow entering and exiting from any location on the boudary.
-
When perfoming cv::Camshift, we provide two options, namely tracking by grey-scale value or tracking by hue value. It turns out that tracking by hue value is more stable than the other approach.
-
New data members
momentOnTrack
, which is the miliseconds offset from the beginning of the input video and records the exact moment a person appears on track, andtrackings
, which is of typestd::vector<cv::Point2i>>
and records trojectories of each individual, are added toclass People
. Right before deleting eachPeople
object, you can store their tracking info into whichever database you prefer. -
We use double-linked list data structure to dynamically organize the list of
People
objects. Unlike removing objects directly in the middle of a Python list in PedestrianCounter, our approach is undoubtly more efficient.
We correctly identify the trojectories of 3 out of 4 persons ever across our pre-defined region.
As you can see, we identify 10 persons in total. The number on the right of each line is the bounding box area whenever a person leaves the scene.