Ask Your Question

How to count person in video?

asked 2014-09-02 00:45:38 -0500

Andrew1108 gravatar image

I am use opencv 2.4.9 and python 2.7.6, I need to count people in video. What I already did is:

  1. Background subtraction
  2. Find contour and put the bounding box
  3. Find the centroid (cx,cy)
  4. Draw a virtual line at (20,75) to (320,75)

I am trying to count people, when they cross the line. I try this code to count it

if 75 <= cy <=77:

no error, but the counter count it double, Is there other way to count it?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2014-09-02 04:17:25 -0500

rahulvg gravatar image

i think you "if" check should be
if cy >= 75: counter=counter+1;

Why dont you use the haar cascade to detect face which will return you a rectangle per person instead of detecting contours....

edit flag offensive delete link more


I know there's haar cascade, but I got project using background subtraction, other team got count people with haar cascade.. Your code just multiplying the counter from cy>=75 until the cy leave the frame...

Andrew1108 gravatar imageAndrew1108 ( 2014-09-02 08:19:23 -0500 )edit

answered 2014-09-03 03:15:43 -0500

jestshen gravatar image

image description

like that? or you can detecting body information.

edit flag offensive delete link more


my video contain people walking.. I already done the bounding box, what I want how to count people when people cross the line.. like this picture

Andrew1108 gravatar imageAndrew1108 ( 2014-09-03 07:32:12 -0500 )edit

answered 2015-03-30 00:41:54 -0500

Maybe your the centroid of the persons stays in the "75 >cy < 77" range for more than one frame that is why your counter is counting double

edit flag offensive delete link more

Question Tools


Asked: 2014-09-02 00:45:38 -0500

Seen: 5,382 times

Last updated: Sep 03 '14