Beispiel #1
0
void generateInitialWindows( 
      const cv::Mat  &input, 
      const cv::Size &minSize, 
      const cv::Size &maxSize,
      const int wsize,
      std::vector<std::pair<MatT, float> > &scaledimages, 
      std::vector<cv::Rect> &rects,
      std::vector<int> &scales)
{
   rects.clear();
   scales.clear();


   
	

   // How many pixels to move the window for each step
   // TODO : figure out if it makes sense to change this depending on
   // the size of the scaled input image - i.e. it is possible that
   // a small step size on an image scaled way larger than the input
   // will end up detecting too much stuff ... each step on the larger
   // image might not correspond to a step of 1 pixel on the
   // input image?
   const int step = 6;
   //int step = std::min(img.cols, img.rows) *0.05;

   double start = gtod_wrapper(); // grab start time

   // The net expects each pixel to be 3x 32-bit floating point
   // values. Convert it once here rather than later for every
   // individual input image.
   MatT f32Img;
   MatT(input).convertTo(f32Img, CV_32FC3);

   // Create array of scaled images
   scalefactor(f32Img, cv::Size(wsize,wsize), minSize, maxSize, 1.35, scaledimages);

   // Main loop.  Look at each scaled image in turn
   for (size_t scale = 0; scale < scaledimages.size(); ++scale)
   {
      // Start at the upper left corner.  Loop through the rows and cols until
      // the detection window falls off the edges of the scaled image
      for (int r = 0; (r + wsize) < scaledimages[scale].first.rows; r += step)
      {
	 for (int c = 0; (c + wsize) < scaledimages[scale].first.cols; c += step)
	 {
	    // Save location and image data for each sub-image
	    rects.push_back(cv::Rect(c, r, wsize, wsize));
	    scales.push_back(scale);

	 }
      }
      
   } 
   double end = gtod_wrapper();
   std::cout << "Elapsed time = " << (end - start) << std::endl;
}
dmatrix param_init_bounded_number_matrix::get_scalefactor() const
{
  dmatrix scalefactor;
  if (index_min < index_max)
  {
    scalefactor.allocate(index_min, index_max);
    for (int i = index_min; i <= index_max; i++)
    {
      param_init_bounded_number_vector& pibv = v[i];
      dvector dv = pibv.get_scalefactor();
      int indexmin = pibv.indexmin();
      int indexmax = pibv.indexmax();
      scalefactor.allocate(indexmin, indexmax);
      scalefactor(i) = dv;
    }
  }
  return scalefactor;
}
/**
 * Test for param_init_bounded_number_matrix.
 */
TEST_F(test_param_init_bounded_number_matrix, param_init_bounded_number_matrix_04)
{
  dmatrix b(1, 5, 1, 5);
  imatrix m(1, 5, 1, 5);
  param_init_bounded_number_matrix v;
  v.allocate(1, 5, 
             1, 5,
             b, b,
             m,
             "test");

  dmatrix scalefactor(1, 5, 1, 5);
  scalefactor = 2;
  v.set_scalefactor(scalefactor);
  dmatrix dm = v.get_scalefactor();
  if (dm.rowmin() != 1 && dm.rowmax() != 5)
  {
    FAIL();
    return;
  }
  for (int i = dm.rowmin(); i <= dm.rowmax(); i++)
  {
    dvector& dv = dm(i);
    int indexmin = dv.indexmin();
    int indexmax = dv.indexmax();
    if (indexmin != 1 && indexmax != 5)
    {
      FAIL();
      return;
    }
    for (int j = indexmin; j <= indexmax; j++)
    {
      double value = dv(j);
      if (!(1.9999 < value && value < 2.00001))
      {
        FAIL();
        return;
      }
    }
  } 
  SUCCEED();
}