title: How to fix HOG to detect all the persons in a scene?
body: <p>I want to detect person in a scene using HOG descriptor and SVM but the program doesn't detect all the present persons in the scene:</p>
  
  <pre><code>#include &lt;opencv2/opencv.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/imgproc/imgproc.hpp&gt;
  #include &lt;opencv/cv.h&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  
  
  
  using namespace std;
  using namespace cv;
  
  
  vector &lt;Rect&gt; drawBoundingBox (vector&lt;vector&lt;Point&gt; &gt; contours)
  {
      vector &lt;Rect&gt; listOfRectangles; 
      for (int i = 0; i&lt; contours.size(); i++)
      {
          // Get bounding box for contour
          Rect roi = boundingRect(contours[i]);
          if (roi.area() &gt; 1000)
          {
              listOfRectangles.push_back(roi);
          }
      }
      //merge rectangles
      int size = listOfRectangles.size();
      for( int k = 0; k &lt; size; k++ )
      {
          listOfRectangles.push_back(Rect(listOfRectangles[k]));
      }
      groupRectangles(listOfRectangles, 1, 0.7);
      return listOfRectangles; 
  }
  
  
  //! main program 
  int main(int argc, char* argv[])
  {
  
      Mat frame_capture,frame_capture2;  
      VideoCapture capture("Baseline/PETS2006/input/in%06d.jpg");   // path to input images
      VideoCapture capture2("Baseline/PETS2006/groundtruth/gt%06d.png"); // path to groundtruth images
  
  
  
      if((!capture.isOpened())&amp;(!capture2.isOpened() )) 
      {
          printf("Could not open video file!!!");
          cin.get();
          return -1;
      }
  
      Mat gray;
  
      //! do detection and tracking
      int i=0;
  
  
      //Hog Descriptor
      cv::HOGDescriptor hog;
      hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());
  
      while (1)
      {   ++i;
          capture &gt;&gt; frame_capture;
          capture2 &gt;&gt; frame_capture2;
          if(i &gt;= 300){
  
          cv::cvtColor(frame_capture2,gray, CV_RGB2GRAY);
  
  
          cv::Mat im_gray;
          cv::equalizeHist( gray, im_gray );
          vector&lt;vector&lt;Point&gt; &gt; contours;
          vector&lt;Vec4i&gt; hierarchy;
          findContours(gray,contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
          vector &lt;Rect&gt; listOfRectangles;
          listOfRectangles = drawBoundingBox(contours);
  
  
           // HOG person detector
              vector &lt;Rect&gt;  detected_person;
  
  
           //Hog detectMultiscale
             hog.detectMultiScale(im_gray, detected_person, 0.0, cv::Size(8, 8), cv::Size(0,0), 1.05, 4); 
  
  
  
      if(!frame_capture.empty()){
          for (int i =0; i&lt;detected_person.size();++i)
          {
              //rectangle (frame_capture, listOfRectangles[i], Scalar(255,255,0),1,8,0); //! display detections
  
  
              //detected persons
              rectangle(frame_capture, detected_person[i], Scalar(255,255,0),2,8,0);
              //putText(frame_capture,"person", detected_person[i].tl(),FONT_HERSHEY_COMPLEX_SMALL,0.8,cvScalar(200,200,250),1,CV_AA);
  
          }
  
  
      //oVideoWriter.write(frame_capture);
          imshow("video",frame_capture);
          waitKey(25);
      }    
      }
      }
      destroyAllWindows();
      return 0;
  
  }
  </code></pre>
  
  <p>I got such a result this image <a href="https://i.stack.imgur.com/MeC79.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MeC79.png" alt="detecte person"></a>.What can I do to detect all the persons present in the scene using this approach?Can anyone have an idea how to fix this problem?</p>