Search code examples
c#.netopencvvideo-processingemgucv

Detecting people crossing a line with OpenCV


I want to count number of people crossing a line from either side. I have a camera that is placed on ceiling and shooting for the floor where the line is (So camera sees just top of people heads; and so it is more of object detection than people detection).

Is there any sample solution for this problem or similar problems like this? So I can learn from them?

Edit 1: More than one person is crossing the line at any moment.


Solution

  • If nothing else but humans are subject to cross the line then you need not to detect people you only have to detect motion. There are several approaches for motoin detection.

    Probably the simplest one fits your goals. You simply calculate difference between successive frames of video stream and this way determine "motion mask" and thus detect line crossing event

    As an improvement of this "algorithm" you may consider "running average" method.

    To determine a direction of motion you can use "motion templates".

    In order to increase accuracy of your detector you may try any background subtraction technique (which in turn is not a simple solution). For example, if there is some moving background which should be filtered out (e.g. using statistical learning)

    All algorithms mentioned are included in OpenCV library.

    UPD: