Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I track humans in a video stream? Here's some code for detecting a human in a frame:
C#
System.Drawing.Rectangle[] regions;

if (GpuInvoke.HasCuda)
{
    GpuHOGDescriptor des = new GpuHOGDescriptor();

    des.SetSVMDetector(GpuHOGDescriptor.GetDefaultPeopleDetector());

    using (GpuImage<Bgr, Byte> gpuImg = new GpuImage<Bgr, byte>(frame))
        using (GpuImage<Bgra, Byte> gpuBgra = gpuImg.Convert<Bgra, Byte>())
        {

            regions = des.DetectMultiScale(gpuBgra, 0, new Size(8, 8), new Size(0, 0), 1.04, 8);

            foreach (var item in regions)
            {
                frame.Draw(new Rectangle(item), new Bgr(Color.Red), 1);
            }
        }
        des.Dispose();
    }
    else
    {  //this is the CPU version
        using (HOGDescriptor des = new HOGDescriptor())
        {
            des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());

            regions = des.DetectMultiScale(frame);
        }
    }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900