Difference between revisions of "Jetson/Tutorials/Full Body Detection"

From eLinux.org
Jump to: navigation, search
(Full-body pedestrian detector: Mentioned how to get the commands and the power draw)
m (Rephrased some sections)
Line 2: Line 2:
 
OpenCV comes with a HOG (Hough Of Gradients) sample person detector. It runs quite slowly on CPUs including desktop x86 CPUs, but OpenCV includes a CUDA-accelerated version in the OpenCV "gpu" module that runs much faster.
 
OpenCV comes with a HOG (Hough Of Gradients) sample person detector. It runs quite slowly on CPUs including desktop x86 CPUs, but OpenCV includes a CUDA-accelerated version in the OpenCV "gpu" module that runs much faster.
 
* First, make sure you have installed the CUDA toolkit and the OpenCV development packages on your device, by following the [[Jetson/Tutorials/CUDA|CUDA tutorial]] and the [[Jetson/Tutorials/OpenCV|OpenCV tutorial]].
 
* First, make sure you have installed the CUDA toolkit and the OpenCV development packages on your device, by following the [[Jetson/Tutorials/CUDA|CUDA tutorial]] and the [[Jetson/Tutorials/OpenCV|OpenCV tutorial]].
* Now download the OpenCV sample code, that comes with the OpenCV source code. You can download this by visiting "http://opencv.org/" in a browser and clicking to download "OpenCV for Linux/Mac", or if you want to download this directly from the command-line then run this on the device:
+
* Download the OpenCV samples (they come with the OpenCV source code). You can download this by visiting "http://opencv.org/" in a browser and clicking to download "OpenCV for Linux/Mac", or if you want to download this directly from the command-line then run this on the device:
 
  wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip
 
  wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip
 
  unzip opencv-2.4.9.zip
 
  unzip opencv-2.4.9.zip
 
(If you don't have the wget or unzip commands, then run "sudo apt-get install wget unzip" to download & install them).
 
(If you don't have the wget or unzip commands, then run "sudo apt-get install wget unzip" to download & install them).
* Now simply build the OpenCV HOG (Hough Of Gradients) sample person detector program.
+
* Simply build the OpenCV HOG (Hough Of Gradients) sample person detector program.
 
  cd opencv-2.4.9/samples/gpu
 
  cd opencv-2.4.9/samples/gpu
 
  g++ hog.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab -o hog
 
  g++ hog.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab -o hog
 
(If you don't have the g++ command, then run "sudo apt-get install build-essential" to download & install it).
 
(If you don't have the g++ command, then run "sudo apt-get install build-essential" to download & install it).
* Now you can run the HOG demo such as on a pre-recorded video of people walking around. The HOG demo displays a graphical output, hence you should plug a HDMI monitor in or use a remote viewer such as X Tunneling or VNC or TeamViewer on your desktop in order to see the output.
+
* You can run the HOG demo such as on a pre-recorded video of people walking around. The HOG demo displays a graphical output, hence you should plug a HDMI monitor in or use a remote viewer such as X Tunneling or VNC or TeamViewer on your desktop in order to see the output.
 
  ./hog --video 768x576.avi
 
  ./hog --video 768x576.avi
 
You can toggle between CPU vs GPU by pressing 'm', where you will see that the GPU is typically 5x faster at HOG than the CPU!
 
You can toggle between CPU vs GPU by pressing 'm', where you will see that the GPU is typically 5x faster at HOG than the CPU!

Revision as of 12:29, 2 July 2014

Full-body pedestrian detector

OpenCV comes with a HOG (Hough Of Gradients) sample person detector. It runs quite slowly on CPUs including desktop x86 CPUs, but OpenCV includes a CUDA-accelerated version in the OpenCV "gpu" module that runs much faster.

  • First, make sure you have installed the CUDA toolkit and the OpenCV development packages on your device, by following the CUDA tutorial and the OpenCV tutorial.
  • Download the OpenCV samples (they come with the OpenCV source code). You can download this by visiting "http://opencv.org/" in a browser and clicking to download "OpenCV for Linux/Mac", or if you want to download this directly from the command-line then run this on the device:
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip
unzip opencv-2.4.9.zip

(If you don't have the wget or unzip commands, then run "sudo apt-get install wget unzip" to download & install them).

  • Simply build the OpenCV HOG (Hough Of Gradients) sample person detector program.
cd opencv-2.4.9/samples/gpu
g++ hog.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab -o hog

(If you don't have the g++ command, then run "sudo apt-get install build-essential" to download & install it).

  • You can run the HOG demo such as on a pre-recorded video of people walking around. The HOG demo displays a graphical output, hence you should plug a HDMI monitor in or use a remote viewer such as X Tunneling or VNC or TeamViewer on your desktop in order to see the output.
./hog --video 768x576.avi

You can toggle between CPU vs GPU by pressing 'm', where you will see that the GPU is typically 5x faster at HOG than the CPU! You can also run it live if you plug in a USB webcam: ./hog --camera 0 Note: This looks for whole bodies and assumes they are small, so you need to stand atleast 5m away from the camera if you want it to detect you!

As mentioned in the Power draw during computer vision tasks section, the typical power draw for a whole Jetson TK1 board while running this "hog" demo (as well as a graphical desktop environment through HDMI) is around 4.6W for CPU or 4.7W for GPU mode, even though the GPU mode is running about 5x faster!