Jetson/Tutorials/Full Body Detection

From eLinux.org
< Jetson
Revision as of 17:12, 25 June 2014 by Shervin.emami (talk | contribs) (Created the full-body person detection tutorial)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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.
  • 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:
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip
unzip opencv-2.4.9.zip
  • Now 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
  • 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.
./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!