public void CreateHog()
 {
     if (GpuInvoke.HasCuda && AllowGpu)
     {
         try
         {
             //gpuhog = new GpuHOGDescriptor();
             gpuhog = new GpuHOGDescriptor(this.winSize, this.blockSize, this.blockStride, this.cellSize, this.nbins, this.winSigma, this.L2HysThreshold, this.gammaCorrection, this.nLevels);
             gpuhog.SetSVMDetector(GpuHOGDescriptor.GetDefaultPeopleDetector());
             //gpuhog.SetSVMDetector(GpuHOGDescriptor.GetPeopleDetector64x128()); // there are 3 different detectors built-in. maybe others work better?
         }
         catch (Exception e)
         {
             Status = e.ToString();
         }
     }
     else
     {
         try
         {
             hog = new HOGDescriptor(this.winSize, this.blockSize, this.blockStride, this.cellSize, this.nbins, 1, this.winSigma, this.L2HysThreshold, this.gammaCorrection);
             hog.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());
         }
         catch (Exception e)
         {
             Status = e.ToString();
         }
     }
 }
示例#2
0
        //=============================Feature Descriptor (HOG) Data Training Tanaman=============================
        public static Rectangle[] findObjects(Image <Bgr, Byte> image, out long processingTime, Size winSize, string dataFile)
        {
            Stopwatch watch;

            Rectangle[] regions;
            if (GpuInvoke.HasCuda)
            {
                using (GpuHOGDescriptor des = new GpuHOGDescriptor())
                {
                    des.SetSVMDetector(GpuHOGDescriptor.GetDefaultPeopleDetector());

                    watch = Stopwatch.StartNew();
                    using (GpuImage <Bgr, Byte> gpuImg = new GpuImage <Bgr, byte>(image))
                        using (GpuImage <Bgra, Byte> gpuBgra = gpuImg.Convert <Bgra, Byte>())
                        {
                            regions = des.DetectMultiScale(gpuBgra);
                        }
                }
            }
            else
            {
                using (HOGDescriptor des = new HOGDescriptor(winSize, blockSize, blockStride, cellSize, nbins, 1, -1, 0.2, true))
                {
                    des.SetSVMDetector(GetDataObjects(dataFile));
                    watch   = Stopwatch.StartNew();
                    regions = des.DetectMultiScale(image);
                }
            }
            watch.Stop();
            processingTime = watch.ElapsedMilliseconds;
            return(regions);
        }
示例#3
0
        static void Run()
        {
            Image <Bgr, Byte> image = new Image <Bgr, byte>("pedestrian.png");

            Stopwatch watch;

            Rectangle[] regions;

            //check if there is a compatible GPU to run pedestrian detection
            if (GpuInvoke.HasCuda)
            { //this is the GPU version
                using (GpuHOGDescriptor des = new GpuHOGDescriptor())
                {
                    des.SetSVMDetector(GpuHOGDescriptor.GetDefaultPeopleDetector());

                    watch = Stopwatch.StartNew();
                    using (GpuImage <Bgr, Byte> gpuImg = new GpuImage <Bgr, byte>(image))
                        using (GpuImage <Bgra, Byte> gpuBgra = gpuImg.Convert <Bgra, Byte>())
                        {
                            regions = des.DetectMultiScale(gpuBgra);
                        }
                }
            }
            else
            { //this is the CPU version
                using (HOGDescriptor des = new HOGDescriptor())
                {
                    des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());

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

            foreach (Rectangle pedestrain in regions)
            {
                image.Draw(pedestrain, new Bgr(Color.Red), 1);
            }

            ImageViewer.Show(
                image,
                String.Format("Pedestrain detection using {0} in {1} milliseconds.",
                              GpuInvoke.HasCuda ? "GPU" : "CPU",
                              watch.ElapsedMilliseconds));
        }
示例#4
0
        /// <summary>
        /// Find the pedestrian in the image
        /// </summary>
        /// <param name="imageFileName">The name of the image</param>
        /// <param name="processingTime">The pedestrian detection time in milliseconds</param>
        /// <returns>The image with pedestrian highlighted.</returns>
        public static Image <Bgr, Byte> Find(Image <Bgr, byte> source, out long processingTime)
        {
            Image <Bgr, Byte> image = source.Copy();

            Stopwatch watch;

            Rectangle[] regions;

            //check if there is a compatible GPU to run pedestrian detection
            if (GpuInvoke.HasCuda)
            { //this is the GPU version
                using (GpuHOGDescriptor des = new GpuHOGDescriptor())
                {
                    des.SetSVMDetector(GpuHOGDescriptor.GetDefaultPeopleDetector());

                    watch = Stopwatch.StartNew();
                    using (GpuImage <Bgr, Byte> gpuImg = new GpuImage <Bgr, byte>(image))
                        using (GpuImage <Bgra, Byte> gpuBgra = gpuImg.Convert <Bgra, Byte>())
                        {
                            regions = des.DetectMultiScale(gpuBgra);
                        }
                }
            }
            else
            { //this is the CPU version
                using (HOGDescriptor des = new HOGDescriptor())
                {
                    des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());

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

            processingTime = watch.ElapsedMilliseconds;

            foreach (Rectangle pedestrain in regions)
            {
                image.Draw(pedestrain, new Bgr(Color.Red), 1);
            }
            return(image);
        }
        public static Image <Bgr, Byte> Find(Image <Bgr, Byte> image, out long processingTime)
        {
            Stopwatch watch;

            Rectangle[] regions;

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

                    watch = Stopwatch.StartNew();

                    using (GpuImage <Bgr, Byte> gpuImage = new GpuImage <Bgr, byte>(image))
                    {
                        using (GpuImage <Bgra, Byte> gpuGpraImage = gpuImage.Convert <Bgra, Byte>())
                        {
                            regions = des.DetectMultiScale(gpuGpraImage);
                        }
                    }
                }
            }
            else
            {
                using (HOGDescriptor des = new HOGDescriptor())
                {
                    des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());
                    watch   = Stopwatch.StartNew();
                    regions = des.DetectMultiScale(image);
                }
            }
            watch.Stop();

            processingTime = watch.ElapsedMilliseconds;

            foreach (Rectangle rect in regions)
            {
                image.Draw(rect, new Bgr(Color.Red), 1);
            }

            return(image);
        }
        public static Image <Bgr, Byte> findPerson(Image <Bgr, Byte> image, out int detections, out List <PointF> positions)
        {
            //If the gpu has nvidia CUDA
            if (GpuInvoke.HasCuda)
            {
                imageToProcess = new Image <Bgr, byte>(image.Bitmap);                   //Value is coppied so the refference of the input image is not changed outside of this class
                Person_Detector.positions.Clear();
                using (GpuHOGDescriptor descriptor = new GpuHOGDescriptor())
                {
                    descriptor.SetSVMDetector(GpuHOGDescriptor.GetDefaultPeopleDetector());

                    using (GpuImage <Bgr, Byte> gpuImage = new GpuImage <Bgr, byte>(imageToProcess))                  //Create gpuImage from image
                    {
                        using (GpuImage <Bgra, Byte> bgraImage = gpuImage.Convert <Bgra, Byte>())
                        {
                            regeions = descriptor.DetectMultiScale(bgraImage);                             //Returns all detected regions in a rectangle array
                        }
                    }
                }
            }
            else
            {
                using (HOGDescriptor des = new HOGDescriptor())
                {
                    regeions = des.DetectMultiScale(imageToProcess);
                }
            }


            detections = regeions.Length;

            //Draws detected rectangles onto the image being returned
            foreach (Rectangle ped in regeions)
            {
                imageToProcess.Draw(ped, new Bgr(Color.Red), 5);
                imageToProcess.Draw(new Cross2DF(new PointF(ped.Location.X + (ped.Width / 2), ped.Location.Y + (ped.Height / 2)), 30, 30), new Bgr(Color.Green), 3);
                Person_Detector.positions.Add(new PointF(ped.Location.X + (ped.Width / 2), ped.Location.Y + (ped.Height / 2)));                 //Sets the putput variable
            }


            positions = Person_Detector.positions;
            return(imageToProcess);
        }
示例#7
0
        /// <summary>
        /// Find the pedestrian in the image
        /// </summary>
        /// <param name="image">The image</param>
        /// <param name="processingTime">The pedestrian detection time in milliseconds</param>
        /// <returns>The region where pedestrians are detected</returns>
        public static Rectangle[] Find(Image <Bgr, Byte> image, out long processingTime)
        {
            Stopwatch watch;

            Rectangle[] regions;
#if !IOS
            //check if there is a compatible GPU to run pedestrian detection
            if (GpuInvoke.HasCuda)
            {  //this is the GPU version
                using (GpuHOGDescriptor des = new GpuHOGDescriptor())
                {
                    des.SetSVMDetector(GpuHOGDescriptor.GetDefaultPeopleDetector());

                    watch = Stopwatch.StartNew();
                    using (GpuImage <Bgr, Byte> gpuImg = new GpuImage <Bgr, byte>(image))
                        using (GpuImage <Bgra, Byte> gpuBgra = gpuImg.Convert <Bgra, Byte>())
                        {
                            regions = des.DetectMultiScale(gpuBgra);
                        }
                }
            }
            else
#endif
            {  //this is the CPU version
                using (HOGDescriptor des = new HOGDescriptor())
                {
                    des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());

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

            processingTime = watch.ElapsedMilliseconds;

            return(regions);
        }
示例#8
0
        //public static Image<Bgr, Byte> DetectFeatures()
        //{
        //    Stopwatch watch = Stopwatch.StartNew();
        //    Rectangle[] regions = GetBodies("Untitled7.jpg");
        //    MCvAvgComp[][] facesDetected = GetFaces("Untitled7.jpg");

        //    Image<Bgr, Byte> image = new Image<Bgr, byte>("Untitled7.jpg");
        //    foreach (Rectangle pedestrain in regions)
        //    {
        //        image.Draw(pedestrain, new Bgr(Color.Red), 1);
        //    }

        //    foreach (MCvAvgComp f in facesDetected[0])
        //    {
        //        //draw the face detected in the 0th (gray) channel with blue color
        //        image.Draw(f.rect, new Bgr(Color.Blue), 2);
        //    }
        //    return image;
        //}

        // Body Function
        public static Rectangle[] GetBodies(string fileName)
        {
            Image <Bgr, Byte> image = new Image <Bgr, byte>(fileName);

            Stopwatch watch;

            Rectangle[] regions;

            //check if there is a compatible GPU to run pedestrian detection
            if (GpuInvoke.HasCuda)
            {  //this is the GPU version
                using (GpuHOGDescriptor des = new GpuHOGDescriptor())
                {
                    des.SetSVMDetector(GpuHOGDescriptor.GetDefaultPeopleDetector());

                    watch = Stopwatch.StartNew();
                    using (GpuImage <Bgr, Byte> gpuImg = new GpuImage <Bgr, byte>(image))
                        using (GpuImage <Bgra, Byte> gpuBgra = gpuImg.Convert <Bgra, Byte>())
                        {
                            regions = des.DetectMultiScale(gpuBgra);
                        }
                }
            }
            else
            {  //this is the CPU version
                using (HOGDescriptor des = new HOGDescriptor())
                {
                    des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());

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

            return(regions);
        }