Click here to Skip to main content
15,889,391 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi i'm doing project for human detection using HOG approach.But,i can't detect human
Here is the code
C#
namespace HumanActiviyDetection
{
    public partial class Form1 : Form
    {
        Capture _capture;
        Image<bgr,> frame;
        Image<bgr,> previous_frame;
    
        public Form1()
        {
            InitializeComponent();
            _capture = new Capture();
            _capture.ImageGrabbed += processframe;
            _capture.Start();
        }
       
        public Bitmap Find(Image<bgr,> image, ref System.Drawing.Rectangle[] regionsg)
        {
            Rectangle[] regions;
            if (GpuInvoke.HasCuda)
            {
                GpuHOGDescriptor des = new GpuHOGDescriptor();

                des.SetSVMDetector(GpuHOGDescriptor.GetDefaultPeopleDetector());

                using (GpuImage<bgr,> gpuImg = new GpuImage<bgr,>(image))
                using (GpuImage<bgra,> gpuBgra = gpuImg.Convert<bgra,>())
                {

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

            }
            else
            { 
                using (HOGDescriptor des = new HOGDescriptor())
                {
                    des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());


                    regions = des.DetectMultiScale(image);
                }
            }
            regionsg = regions;

            foreach (Rectangle pedestrain in regions)
            {
                MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0);
                image.Draw(new LineSegment2D(new Point(pedestrain.X + ((int)pedestrain.Width / 2), pedestrain.Y + (int)(pedestrain.Height / 4)), new Point(pedestrain.X + ((int)pedestrain.Width / 2), pedestrain.Y + pedestrain.Height - (int)(pedestrain.Height / 6))), new Bgr(Color.Red), 3);

            }
            return image.ToBitmap();

        }
        //public static Rectangle[] Find(Image<bgr,> image, out long processingTime)
        //{
        //    Stopwatch watch;
        //    Rectangle[] regions;

            
        //    if (GpuInvoke.HasCuda)
        //    {  
        //        using (GpuHOGDescriptor des = new GpuHOGDescriptor())
        //        {
        //            des.SetSVMDetector(GpuHOGDescriptor.GetPeopleDetector48x96());

        //            watch = Stopwatch.StartNew();
        //            using (GpuImage<bgr,> gpuImg = new GpuImage<bgr,>(image))
        //            using (GpuImage<bgra,> gpuBgra = gpuImg.Convert<bgra,>())
        //            {
        //                regions = des.DetectMultiScale(gpuBgra);
        //            }
        //        }
        //    }
        //    else
        //    { 
        //        using (HOGDescriptor des = new HOGDescriptor())
        //        {
        //            des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());

        //            watch = Stopwatch.StartNew();
        //            regions = des.DetectMultiScale(image);
        //        }
        //    }
        //    watch.Stop();

        //    processingTime = watch.ElapsedMilliseconds;

        //    return regions;
       // }




        private void processframe(object sender, EventArgs e)
        {
            if (frame == null)
            {
                frame = _capture.RetrieveBgrFrame();
                displayimage(frame.ToBitmap(), DisplayBox);
                previous_frame = frame.Copy();
            }
            else
            {
                frame = _capture.RetrieveBgrFrame();
                previous_frame = frame.Copy();
                displayimage(previous_frame.ToBitmap(), DisplayBox);
                displayimage(frame.ToBitmap(), CaptureBox);

            }
        }
        private delegate void displaydelegate(Bitmap image, PictureBox contol);
        private void displayimage(Bitmap image, PictureBox control)
        {
            if (CaptureBox.InvokeRequired)
            {
                try
                {
                    displaydelegate di = new displaydelegate(displayimage);
                    this.BeginInvoke(di, new object[] { image, control });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                control.Image = image;
            }
        }
Posted
Updated 18-Sep-14 3:38am
v2
Comments
ZurdoDev 18-Sep-14 9:33am    
Where are you stuck?
Member 11057500 19-Sep-14 0:59am    
i cant detect human
[no name] 19-Sep-14 2:17am    
Try debugging your code yourself buddy. Just check line by line

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