예제 #1
0
void learndictionary::addResponsesForImage(const cv::Mat& img, cv::Mat& responses)
{
    cv::Mat* filterResponse = FilterBank::getInstance().apply(img);

    int currentRow = responses.rows;
    //responses.resize(img.rows * img.cols); //resize response matrix for new responses - not correct

    //TODO: done
    //calculate the responses for the image
    //for a mxn image you get m*n responses.

    // resize the image for m*n new ADDITIONAL responses, each row is one response
    responses.resize(responses.rows + img.rows * img.cols);

    for(int row = 0; row < img.rows; row++)
    {
    	for(int col = 0; col < img.cols; col++)
    	{
    		for(int i = 0; i < responses.cols; i++)
			{
    			int responseRow = currentRow + row * img.cols + col;
				responses.at<float>(responseRow, i) = filterResponse[i].at<double>(row, col);
			}
    	}
    }
}
void Mat::_removeRowsNonContinuous(cv::Mat &m, 
  const std::vector<unsigned int> &rows)
{
  // always preserve the order of the rest of rows
  
  // remove rows in descending order, grouping when possible
  int end_row = m.rows;
  int i_idx = (int)rows.size() - 1;
  while(i_idx >= 0)
  {
    int j_idx = i_idx - 1;
    while(j_idx >= 0 && ((int)(rows[i_idx] - rows[j_idx]) == i_idx - j_idx))
    {
      j_idx--;
    }
    //data.erase(data.begin() + indices[j_idx + 1], 
    //  data.begin() + indices[i_idx] + 1);
    // ==
    //std::copy( m.ptr<T>(rows[i_idx]+1), m.ptr<T>(end_row),
    //  m.ptr<T>(rows[j_idx + 1]) );
        
    m.rowRange(rows[j_idx+1], rows[j_idx+1] + end_row-rows[i_idx]-1) = 
      m.rowRange(rows[i_idx]+1, end_row) * 1;
    
    end_row -= rows[i_idx] - rows[j_idx+1] + 1;
    
    i_idx = j_idx;
  }
  
  // remove last rows
  m.resize(end_row);
}