コード例 #1
0
// imageROI == outerbound, validROI == whole frame, patchSize == inner region 
void PatchesRegularScan::calculatePatches(Rect imageROI, Rect validROI, Size patchSize, float relOverlap)
{
	if ((validROI == imageROI))
		ROI = imageROI;
	else
		setCheckedROI(imageROI, validROI);

	stepCol = floor((1-relOverlap) * patchSize.width+0.5);
	stepRow = floor((1-relOverlap) * patchSize.height+0.5);
	if (stepCol <= 0) stepCol = 1;
	if (stepRow <= 0) stepRow = 1;
	// Setup the grid of regions (divide regions into patches)
	m_patchGrid.height = ((int)((float)(ROI.height-patchSize.height)/stepRow)+1);
	m_patchGrid.width = ((int)((float)(ROI.width-patchSize.width)/stepCol)+1);

	num = m_patchGrid.width * m_patchGrid.height;
	patches = new Rect[num]; // Build random patches
	int curPatch = 0;
	// Set up special patches
	m_rectUpperLeft = m_rectUpperRight = m_rectLowerLeft = m_rectLowerRight = m_rectUpperMiddle = m_rectLowerMiddle = m_rectMiddleLeft = m_rectMiddleRight = patchSize;

	m_rectUpperLeft.upper = ROI.upper;
	m_rectUpperLeft.left = ROI.left;
	m_rectUpperRight.upper = ROI.upper;
	m_rectUpperRight.left = ROI.left+ROI.width-patchSize.width;
	m_rectLowerLeft.upper = ROI.upper+ROI.height-patchSize.height;
	m_rectLowerLeft.left = ROI.left;
	m_rectLowerRight.upper = ROI.upper+ROI.height-patchSize.height;
	m_rectLowerRight.left = ROI.left+ROI.width-patchSize.width;

	m_rectUpperMiddle.upper = ROI.upper;
	m_rectUpperMiddle.left = ROI.left + ROI.width/2 - patchSize.width/2;
	m_rectLowerMiddle.upper = ROI.upper+ROI.height-patchSize.height;
	m_rectLowerMiddle.left = ROI.left + ROI.width/2 - patchSize.width/2;
	m_rectMiddleLeft.left = ROI.left;
	m_rectMiddleLeft.upper = ROI.upper + ROI.height/2 - patchSize.height/2;
	m_rectMiddleRight.left = ROI.left+ROI.width-patchSize.width;
	m_rectMiddleRight.upper = ROI.upper + ROI.height/2 - patchSize.height/2;

	// Build special patches
	numPatchesX=0; numPatchesY=0;
	for (int curRow=0; curRow< ROI.height-patchSize.height+1; curRow+=stepRow)
	{
		numPatchesY++;

		for (int curCol=0; curCol< ROI.width-patchSize.width+1; curCol+=stepCol)
		{
			if(curRow == 0)
				numPatchesX++;

			patches[curPatch].width = patchSize.width;
			patches[curPatch].height = patchSize.height;
			patches[curPatch].upper = curRow+ROI.upper;
			patches[curPatch].left = curCol+ROI.left;
			curPatch++;
		}
	}

	assert (curPatch==num);
}
コード例 #2
0
void PatchesRegularScaleScan::calculatePatches(Rect imageROI, Rect validROI, Size patchSize, float relOverlap, float scaleStart, float scaleEnd, float scaleFactor)
{

	if ((validROI == imageROI))
		ROI = imageROI;
	else
		setCheckedROI(imageROI, validROI);

	int numScales = (int)(log(scaleEnd/scaleStart)/log(scaleFactor));
	if (numScales < 0) numScales = 0;
	float curScaleFactor = 1;
	Size curPatchSize;
	int stepCol, stepRow;

	num = 0;
	for (int curScale = 0; curScale <= numScales; curScale++)
	{   
		curPatchSize = patchSize * (scaleStart*curScaleFactor);
		if (curPatchSize.height > ROI.height || curPatchSize.width > ROI.width)
		{
			numScales = curScale-1;
			break;
		}
		curScaleFactor *= scaleFactor;

		stepCol = floor((1-relOverlap) * curPatchSize.width+0.5);
		stepRow = floor((1-relOverlap) * curPatchSize.height+0.5);
		if (stepCol <= 0) stepCol = 1;
		if (stepRow <= 0) stepRow = 1;

		num += ((int)((float)(ROI.width-curPatchSize.width)/stepCol)+1)*((int)((float)(ROI.height-curPatchSize.height)/stepRow)+1);
	}
	patches = new Rect[num];

	int curPatch = 0;
	curScaleFactor = 1;
	for (int curScale = 0; curScale <= numScales; curScale++)
	{   
		curPatchSize = patchSize * (scaleStart*curScaleFactor);
		curScaleFactor *= scaleFactor;

		stepCol = floor((1-relOverlap) * curPatchSize.width+0.5);
		stepRow = floor((1-relOverlap) * curPatchSize.height+0.5);
		if (stepCol <= 0) stepCol = 1;
		if (stepRow <= 0) stepRow = 1;




		for (int curRow=0; curRow< ROI.height-curPatchSize.height+1; curRow+=stepRow)
		{
			for (int curCol=0; curCol<ROI.width-curPatchSize.width+1; curCol+=stepCol)
			{
				patches[curPatch].width = curPatchSize.width;
				patches[curPatch].height = curPatchSize.height;
				patches[curPatch].upper = curRow+ROI.upper;
				patches[curPatch].left = curCol+ROI.left;

				curPatch++;
			}
		}
	}
	assert (curPatch==num);

}
コード例 #3
0
void PatchesRegularScan::calculatePatches(Rect imageROI, Rect validROI, Size patchSize, float relOverlap)
{
	//std::cout << "Patches: 1 " << std::endl;	
	if ((validROI == imageROI))
		ROI = imageROI;
	else
		setCheckedROI(imageROI, validROI);
	
	//std::cout << "Patches: 2 " << std::endl;
	//std::cout << "ROI width " << ROI.width << std::endl;
	//std::cout << "patchSize width " << patchSize.width << std::endl;
	//std::cout << "patchSize height " << patchSize.height << std::endl;

	int stepCol = floor((1-relOverlap) * patchSize.width+0.5);
	int stepRow = floor((1-relOverlap) * patchSize.height+0.5);
	if (stepCol <= 0) stepCol = 1;
	if (stepRow <= 0) stepRow = 1;
	
	//std::cout << "stepCOL " << stepCol << " stepRow "<< stepRow << std::endl;
	
	//std::cout << "Patches: 3 " << std::endl;
	m_patchGrid.height = ((int)((float)(ROI.height-patchSize.height)/stepRow)+1);
	m_patchGrid.width = ((int)((float)(ROI.width-patchSize.width)/stepCol)+1);

	//std::cout << "width " << m_patchGrid.width << " height: "<< m_patchGrid.height << std::endl;
	num = m_patchGrid.width * m_patchGrid.height;
	//std::cout << "Patches: 4 " << num << std::endl;
	patches = new Rect[num];
	//std::cout << "Patches: 4.5 " << std::endl;
	int curPatch = 0;

	//std::cout << "Patches: 5 " << std::endl;
	m_rectUpperLeft = m_rectUpperRight = m_rectLowerLeft = m_rectLowerRight = patchSize;
	m_rectUpperLeft.upper = ROI.upper;
	m_rectUpperLeft.left = ROI.left;
	m_rectUpperRight.upper = ROI.upper;
	m_rectUpperRight.left = ROI.left+ROI.width-patchSize.width;
	m_rectLowerLeft.upper = ROI.upper+ROI.height-patchSize.height;
	m_rectLowerLeft.left = ROI.left;
	m_rectLowerRight.upper = ROI.upper+ROI.height-patchSize.height;
	m_rectLowerRight.left = ROI.left+ROI.width-patchSize.width;

  //std::cout << "Patches: 6 " << std::endl;
	numPatchesX=0; numPatchesY=0;
	for (int curRow=0; curRow< ROI.height-patchSize.height+1; curRow+=stepRow)
	{
		numPatchesY++;

		for (int curCol=0; curCol< ROI.width-patchSize.width+1; curCol+=stepCol)
		{
			if(curRow == 0)
				numPatchesX++;

			patches[curPatch].width = patchSize.width;
			patches[curPatch].height = patchSize.height;
			patches[curPatch].upper = curRow+ROI.upper;
			patches[curPatch].left = curCol+ROI.left;
			curPatch++;
		}
	}
	//std::cout << "Patches: 7 " << std::endl;
	assert (curPatch==num);
	//std::cout << "Patches: 8 " << std::endl;
}
コード例 #4
0
std::vector<Mat> TrackerSamplerCS::patchesRegularScan( const Mat& image, Rect trackingROI, Size patchSize )
{
  std::vector<Mat> sample;
  if( ( validROI == trackingROI ) )
    ROI = trackingROI;
  else
    setCheckedROI( trackingROI );

  if( mode == MODE_POSITIVE )
  {
    int num = 4;
    sample.resize( num );
    Mat singleSample = image( trackedPatch );
    for ( int i = 0; i < num; i++ )
      sample[i] = singleSample;
    return sample;
  }

  int stepCol = (int) floor( ( 1.0f - params.overlap ) * (float) patchSize.width + 0.5f );
  int stepRow = (int) floor( ( 1.0f - params.overlap ) * (float) patchSize.height + 0.5f );
  if( stepCol <= 0 )
    stepCol = 1;
  if( stepRow <= 0 )
    stepRow = 1;

  Size m_patchGrid;
  Rect m_rectUpperLeft;
  Rect m_rectUpperRight;
  Rect m_rectLowerLeft;
  Rect m_rectLowerRight;
  int num;

  m_patchGrid.height = ( (int) ( (float) ( ROI.height - patchSize.height ) / stepRow ) + 1 );
  m_patchGrid.width = ( (int) ( (float) ( ROI.width - patchSize.width ) / stepCol ) + 1 );

  num = m_patchGrid.width * m_patchGrid.height;
  sample.resize( num );
  int curPatch = 0;

  m_rectUpperLeft = m_rectUpperRight = m_rectLowerLeft = m_rectLowerRight = cv::Rect( 0, 0, patchSize.width, patchSize.height );
  m_rectUpperLeft.y = ROI.y;
  m_rectUpperLeft.x = ROI.x;
  m_rectUpperRight.y = ROI.y;
  m_rectUpperRight.x = ROI.x + ROI.width - patchSize.width;
  m_rectLowerLeft.y = ROI.y + ROI.height - patchSize.height;
  m_rectLowerLeft.x = ROI.x;
  m_rectLowerRight.y = ROI.y + ROI.height - patchSize.height;
  m_rectLowerRight.x = ROI.x + ROI.width - patchSize.width;

  if( mode == MODE_NEGATIVE )
  {
    int numSamples = 4;
    sample.resize( numSamples );
    sample[0] = image( m_rectUpperLeft );
    sample[1] = image( m_rectUpperRight );
    sample[2] = image( m_rectLowerLeft );
    sample[3] = image( m_rectLowerRight );
    return sample;
  }

  int numPatchesX;
  int numPatchesY;

  numPatchesX = 0;
  numPatchesY = 0;
  for ( int curRow = 0; curRow < ROI.height - patchSize.height + 1; curRow += stepRow )
  {
    numPatchesY++;

    for ( int curCol = 0; curCol < ROI.width - patchSize.width + 1; curCol += stepCol )
    {
      if( curRow == 0 )
        numPatchesX++;

      Mat singleSample = image( Rect( curCol + ROI.x, curRow + ROI.y, patchSize.width, patchSize.height ) );
      sample[curPatch] = singleSample;
      curPatch++;
    }
  }

  CV_Assert( curPatch == num );

  return sample;
}