Detecting people crossing a line with OpenCV

前端 未结 1 1909
忘掉有多难
忘掉有多难 2021-02-11 05:07

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 to

1条回答
  •  独厮守ぢ
    2021-02-11 05:16

    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:

    • how to compute motion mask
    • Useful functions for determining motion direction cvCalcMotionGradient, cvSegmentMotion, cvUpdateMotionHistory (search docs). OpenCV library contains example code for motion analysis, see motempl.c
    • advanced background subtraction from "Learning OpenCV" book

    0 讨论(0)
提交回复
热议问题