Pedestrian Detection in CSharp

From Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
Revision as of 22:16, 28 January 2011 by Emgucv (talk | contribs) (Added performance comparison table)
Jump to navigation Jump to search

System Requirement

Component Requirement Detail
Emgu CV Version 2.2.1 For GPU mode to be enabled please make sure the latest cuda graphic card driver from NVIDIA is installed.
Operation System Cross Platform

Source code

      static void Run()
         Image<Bgr, Byte> image = new Image<Bgr, byte>("pedestrian.png");

         Stopwatch watch = Stopwatch.StartNew();
         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())
            using (GpuImage<Bgr, Byte> gpuImg = new GpuImage<Bgr,byte>(image))
            using (GpuImage<Bgra, Byte> gpuBgra = gpuImg.Convert<Bgra, Byte>())
               regions = des.DetectMultiScale(gpuBgra);
         {  //this is the CPU version
            using (HOGDescriptor des = new HOGDescriptor())
               regions = des.DetectMultiScale(image);

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

            String.Format("Pedestrain detection using {0} in {1} milliseconds.", 
               GpuInvoke.HasCuda ? "GPU" : "CPU", 

Performance Comparison

We have setup two workstations to test the performance of the pedestrian detection code. The first workstation is a Lenovo W510 laptop, equipped with a fast Core i7 Q720 CPU and a relatively slow Quadro FX 880M GPU. The second workstation is a white box desktop with a slower Pentium D and a EVGA GeForce GTS 450 FPB GPU. This graphic card was purchased recently for ~$100 USD and harness 192 CUDA cores running at 882MHz speed. This mid-range graphic card (using NVidia's Fermi architecture) is a good candidate for GPU processing consider its price point. As a comparison, the Quadro FX 880M has 48 CUDA cores at 550MHz and is quite under power for GPU processing. For optimal performance, the GeForce GTX 580 is available with more than twice the performance compares with GTS 450 according to NVidia's web site, Or the Telsa product line is available for mission critical application.

We run the example several times and the execution time for the 5th run is measured (such that the image and the binary should be cached in the memory).

CPU GPU Emgu CV Package Execution Time (millisecond)
Core i7 Q720@1.6Ghz NVidia Quadro FX 880M libemgucv-windows-x64 793
Core i7 Q720@1.6Ghz NVidia Quadro FX 880M libemgucv-windows-x64-tbb-ipp-icc 537
Core i7 Q720@1.6Ghz NVidia Quadro FX 880M libemgucv-windows-x64-gpu 3123
Core i7 Q720@1.6Ghz NVidia Quadro FX 880M libemgucv-windows-x64-gpu-tbb-ipp-icc 2986
Pentium D 920@2.8Ghz NVidia GeForce GTS 450 libemgucv-windows-x86 ~2000 (TO BE UPDATED)
Pentium D 920@2.8Ghz NVidia GeForce GTS 450 libemgucv-windows-x86-tbb-ipp-icc ~2000 (TO BE UPDATED)
Pentium D 920@2.8Ghz NVidia GeForce GTS 450 libemgucv-windows-x86-gpu ~200 (TO BE UPDATED)
Pentium D 920@2.8Ghz NVidia GeForce GTS 450 libemgucv-windows-x86-gpu-tbb-ipp-icc ~200 (TO BE UPDATED)


Pedestrian Detection