People counter not working

Problem

Some users who've tried to use the counter heuristic, have mentioned that the default configuration doesn't work. The counter heuristic doesn't count moving objects.

Solution

After debugging we concluded that finding the best parameters is done by a trial and error approach. Every environment is different: the background, the angle and distance of the camera, etc. Therefore you need to reconfigure the parameters when the background scenario changes drastically.

Another important point is that you need to decrease the camera delay to a minimum if you are running Kerberos.io on a Raspberry Pi. This is because for the counter heuristic to work properly you need to get a frame rate as high as possible.

An example configuration which worked properly on a Raspberry Pi Zero can be found below. 

config.xml

What you see is that we are using the BackgroundSubtraction algorithm and Counter heuristic, and used an IP camera.

<?xml version="1.0"?>
<kerberos>

<instance>
<name type="text">frontdoor</name>
<logging type="bool">true</logging>
<timezone type="timezone">Europe-Brussels</timezone>
<capture file="capture.xml">IPCamera</capture>
<stream file="stream.xml">Mjpg</stream>
<condition file="condition.xml" type="multiple">Enabled</condition>
<algorithm file="algorithm.xml">BackgroundSubtraction</algorithm>
<expositor file="expositor.xml">Hull</expositor>
<heuristic file="heuristic.xml">Counter</heuristic>
<io file="io.xml" type="multiple">Disk,Webhook</io>
<cloud file="cloud.xml">S3</cloud>
</instance>

</kerberos>

capture.xml

We decreased the delay to zero, so we can process as much images the system can handle. We need this to have the counter heuristic working at its best.

<?xml version="1.0"?>
<captures>

<IPCamera>
<url type="text">rtsp://admin:****@192.168.0.2/Streaming/Channels/102</url>
<frameWidth type="number">640</frameWidth>
<frameHeight type="number">480</frameHeight>
<delay type="number">0</delay>
<angle type="number">0</angle>
</IPCamera>
...

</captures>

algorithm.xml

Make sure you've disabled the shadows parameter to false; this consumes to much CPU for the Raspberry Pi.

<?xml version="1.0"?>
<algorithms>

...
<BackgroundSubtraction>
<shadows type="text">false</shadows>
<history type="number">5</history>
<nmixtures type="number">5</nmixtures>
<ratio type="number">1</ratio>
<erode type="number">6</erode>
<dilate type="number">7</dilate>
<threshold type="number">20</threshold>
</BackgroundSubtraction>

</algorithms>

heuristic.xml

We used following configuration. The most important change was decreasing the minArea parameter. When this parameter is set to high, it will not count the objects if the area is too small. 

<?xml version="1.0"?>
<heuristics>

...
<Counter>
<appearance type="number">3</appearance>
<maxDistance type="number">100</maxDistance>
<minArea type="number">40</minArea>
<onlyTrueWhenCounted type="bool">true</onlyTrueWhenCounted>
<minimumChanges type="number">20</minimumChanges>
<noMotionDelayTime type="number">0</noMotionDelayTime>
<markers type="twolines">172,232|171,146|135,235|136,145</markers>
</Counter>

</heuristics>
Have more questions? Submit a request

2 Comments

  • 1
    Avatar
    Michael Soong

    Hi Cédric,

       Is there any rule of thumb that we can check from the log in order to fine tune the parameter? This parameter will be important in different environment. Currently we use your suggestion, yet still not able to make the counter work. Right now, the IP camera is facing straight down, the height from ceiling is almost 8 feet. Angle of view: 83°(4mm) , 55.4°(6mm).  


    <?xml version="1.0"?>
    <kerberos>

    <instance>
    <name type="text">frontdoor</name>
    <logging type="bool">true</logging>
    <timezone type="timezone">Asia-Hong$Kong</timezone>
    <capture file="capture.xml">IPCamera</capture>
    <stream file="stream.xml">Mjpg</stream>
    <condition file="condition.xml" type="multiple">Enabled</condition>
    <algorithm file="algorithm.xml">BackgroundSubtraction</algorithm>
    <expositor file="expositor.xml">Hull</expositor>
    <heuristic file="heuristic.xml">Counter</heuristic>
    <io file="io.xml" type="multiple">Disk,Webhook</io>
    <cloud file="cloud.xml">S3</cloud>
    </instance>

    </kerberos>
    ~

    expositor.xml

    <?xml version="1.0"?>
    <expositors>

    <Rectangle>
    <region>
    <x1 type="number">0</x1>
    <y1 type="number">0</y1>
    <x2 type="number">800</x2>
    <y2 type="number">600</y2>
    </region>
    </Rectangle>

    <Hull>
    <region type="hullselection">268,127|269,434|433,432|430,129</region
    </Hull>

    </expositors>

    <?xml version="1.0"?>
    <algorithms>

    <DifferentialCollins>
    <erode type="number">10</erode>
    <threshold type="number">10</threshold>
    </DifferentialCollins>

    <BackgroundSubtraction>
    <shadows type="text">false</shadows>
    <history type="number">5</history>
    <nmixtures type="number">5</nmixtures>
    <ratio type="number">1</ratio>
    <erode type="number">6</erode>
    <dilate type="number">7</dilate>
    <threshold type="number">25</threshold>
    </BackgroundSubtraction>

    </algorithms>

     


    <?xml version="1.0"?>
    <heuristics>

    <Sequence>
    <minimumChanges type="number">20</minimumChanges>
    <minimumDuration type="number">2</minimumDuration>
    <noMotionDelayTime type="number">1000</noMotionDelayTime>
    </Sequence>

    <Counter>
    <appearance type="number">3</appearance>
    <maxDistance type="number">100</maxDistance>
    <minArea type="number">20</minArea>
    <onlyTrueWhenCounted type="bool">true</onlyTrueWhenCounted>
    <minimumChanges type="number">10</minimumChanges>
    <noMotionDelayTime type="number">0</noMotionDelayTime>
    <markers type="twolines">302,380|447,377|298,190|426,187</marker
    </Counter>

    </heuristics>

    25/11/2016 11:55:19.498 INFO [trivial] Stopping streaming
    25/11/2016 11:55:19.499 INFO [trivial] Stream: Succesfully closed streaming
    25/11/2016 11:55:19.500 INFO [trivial] Stopping capture device
    25/11/2016 11:55:19.503 INFO [trivial] Starting capture device: IPCamera
    25/11/2016 11:55:22.656 INFO [trivial] Stream: Configured stream on port 8889 w
    25/11/2016 11:55:22.717 INFO [trivial] Starting conditions: Enabled
    25/11/2016 11:55:22.717 INFO [trivial] Starting algorithm: BackgroundSubtractio
    25/11/2016 11:55:22.718 INFO [trivial] Starting expositor: Hull
    25/11/2016 11:55:22.879 INFO [trivial] Starting heuristic: Counter
    25/11/2016 11:55:22.879 INFO [trivial] Starting io devices: Disk,Webhook
    25/11/2016 11:55:24.761 INFO [business] HullExpositor: activity detected from (
    25/11/2016 11:55:31.766 INFO [business] HullExpositor: activity detected from (
    25/11/2016 11:55:33.207 INFO [business] HullExpositor: activity detected from (
    25/11/2016 11:55:38.824 INFO [business] HullExpositor: activity detected from (
    25/11/2016 11:55:41.643 INFO [business] HullExpositor: activity detected from (
    25/11/2016 11:55:43.042 INFO [business] HullExpositor: activity detected from (
    25/11/2016 11:55:45.875 INFO [business] HullExpositor: activity detected from (
    25/11/2016 11:55:47.369 INFO [business] HullExpositor: activity detected from (
    25/11/2016 11:55:50.184 INFO [business] HullExpositor: activity detected from (
    25/11/2016 11:55:53.008 INFO [business] HullExpositor: activity detected from (
    25/11/2016 11:55:54.403 INFO [business] HullExpositor: activity detected from (
    25/11/2016 11:55:58.616 INFO [business] HullExpositor: activity detected from (

     

    Thanks for any suggestion

    Regards,

    Michael

     

  • 0
    Avatar
    numan sari

    Raspberry pi 3

    Raspbian os

    Machinery 2.2.1

    Raspberry pi camera v2 

    People Counting is incoming and outgoing value "0" not working

Please sign in to leave a comment.
Powered by Zendesk