Pedestrian detection is a very hot and useful topic in the field of vision, especially in unmanned driving, the importance of pedestrian detection is self-evident.
After the face detection, pedestrian detection is much simpler. The process is roughly the same as face detection, where the classifier is loaded first and then the multi-scale detection is performed. Just lazy don't repeat it. Interesting to see face detection of this article: OpenCV Practice Road-face Detection (C++/python)
Here we just put the code here, and there are a few lines, and there are comments:
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/gpu/ gpu.hpp>//#include <stdio.h>using namespace cv;int main (int argc, char** argv) {Mat img;vector<rect> people;img = Imread ("xingren.jpg", 1);//define the Hog object, take the default parameters, or set the Hogdescriptor defaulthog;//(Cv::size (64, 128) in the following format, Cv::size (+), Cv::size (8, 8),//cv::size (8, 8), 9, 1,-1,//cv::hogdescriptor::l2hys, 0.2, True,//cv::hogdescriptor:: Default_nlevels);//Set the SVM classifier with the default classifier Defaulthog.setsvmdetector (Hogdescriptor::getdefaultpeopledetector ());// Multi-scale pedestrian detection of the image, the result is a rectangular box Defaulthog.detectmultiscale (IMG, people,0,size (8,8), Size (0,0), 1.03,2);//Draw Rectangle, Box traveler for (int i = 0; I < people.size (); i++) {Rect r = People[i];rectangle (IMG, r.tl (), R.Br (), Scalar (0, 0, 255), 3);} Namedwindow ("Pedestrian Detection", cv_window_autosize), imshow ("Detection of Pedestrians", IMG), Waitkey (0); return 0;}
As follows:
The road of OPENCV practice--Pedestrian detection