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

Computer Vision Toolboxcounting

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

Best Answer

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.