How to count the number of people enter a virtual line using Matlab

1 view (last 30 days)
I am doing the project on counting the number of people in a video, so i created a virtual line to check if the centroid of the moving object has crossed a virtual line or not? But i do not know how to check it? Can anyone has code or any idea for this ? I really need it :( Thanks so much

Accepted Answer

Image Analyst
Image Analyst on 26 Nov 2015
How are you tracking them? If you're using the people tracking capability built in to the Computer Vision System Toolbox, then I don't think your idea is needed - it does it already for you.
If you don't have that toolbox, you first have to find the people to get their centroid, so you have that. I don't see how determining if the centroid crosses some line in the image is a helpful addition. I mean you have the count, so all that does is tell you if they moved past the line, which gains you no additional information on the count. Anyway, you can just see if the y value of the centroid minus the line number ever changes sign
if sign(yNew - lineNumber0 ~= sign(yOld - lineNumber)
% y is now on a different side of the line.
  2 Comments
Black Dragon
Black Dragon on 26 Nov 2015
Thank you so much @Image Analyst, but how can i get the value of yOld? i used a for loop to tracking and get the centroid of any object is moving. Can you suggest me what i can do? pls
Image Analyst
Image Analyst on 26 Nov 2015
In each iteration, you compute the xNew and yNew centroid location of the objects you're tracking. At the bottom of the loop, you need to define this location as the "old" location since it will be the "old" location when the next iteration starts
xOld = -1;
while
xNew = .....
% code to do something ......
% Update old x.
xOld = xNew; % Current x will now be the old one in the next iteration.
end

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!