Exemple #1
0
static void FindEyesGivenVjFace1 (DET_PARAMS *pDet,     // io: eye fields updated
                                  int nEyeScale,
                                  double DetWidth,
                                  const Image &Img)
{
double EyeScale12 = POW12(nEyeScale);
Image ReducedImg(Img);
ReduceImage(ReducedImg, EyeScale12, IM_BILINEAR);
double ScaledDetWidth = DetWidth / EyeScale12;

// cartesian coords
double x = pDet->x / EyeScale12;
double y = pDet->y / EyeScale12;
// opencv coords
x += ReducedImg.width / 2;
y = ReducedImg.height / 2 - y;
// move x.y from center of face box to top right corner of face box
x -= ScaledDetWidth/2;
y -= ScaledDetWidth/2;

// Adjust viola jones y up the image, to correspond to rowley y.
// The conversion factor was discovered by measuring on the training data.
// See regress-vj-to-rowley-width.R. The exact value is not critical.

const double CONF_VjWidthScale = 0.13;
y += CONF_VjWidthScale * ScaledDetWidth;

ZapEyes(*pDet);                     // assume won't find eyes
FindEyes(&pDet->lex, &pDet->ley, &pDet->rex, &pDet->rey,
         iround(x), iround(y), ScaledDetWidth,
         ReducedImg, gEyeMask, 3);  // 3 is iNet i.e. eye.net

if (pDet->lex != INVALID)
    {
    pDet->lex = iround(pDet->lex * EyeScale12 - Img.width/2);
    pDet->ley = iround(Img.height/2 - pDet->ley * EyeScale12);
    }
if (pDet->rex != INVALID)
    {
    pDet->rex = iround(pDet->rex * EyeScale12 - Img.width/2);
    pDet->rey = iround(Img.height/2 - pDet->rey * EyeScale12);
    }
}
Exemple #2
0
//------------------------------------------------------------------------------------------------
// multi-grid belie propagation
//------------------------------------------------------------------------------------------------
void BPFlow::generateCoarserLevel(BPFlow &bp)
{
	//------------------------------------------------------------------------------------------------
	// set the dimensions and parameters
	//------------------------------------------------------------------------------------------------
	bp.Width=Width/2;
	if(Width%2==1)
		bp.Width++;

	bp.Height=Height/2;
	if(Height%2==1)
		bp.Height++;

	bp.Area=bp.Width*bp.Height;
	bp.s=s;
	bp.d=d;

	DImage foo;
	Im_s.smoothing(foo);
	foo.imresize(bp.Im_s,bp.Width,bp.Height);
	Im_d.smoothing(foo);
	foo.imresize(bp.Im_d,bp.Width,bp.Height);

	bp.IsDisplay=IsDisplay;
	bp.nNeighbors=nNeighbors;

	//------------------------------------------------------------------------------------------------
	// allocate buffers
	//------------------------------------------------------------------------------------------------
	for(int i=0;i<2;i++)
	{
		bp.pOffset[i]=new int[bp.Area];
		bp.pWinSize[i]=new int[bp.Area];
		ReduceImage(bp.pOffset[i],Width,Height,pOffset[i]);
		ReduceImage(bp.pWinSize[i],Width,Height,pWinSize[i]);
		for(int j = 0;j<bp.Area;j++)
			bp.pWinSize[i][j] = __max(bp.pWinSize[i][j],1);
	}
	//------------------------------------------------------------------------------------------------
	// generate data term
	//------------------------------------------------------------------------------------------------
	bp.nTotalMatches=bp.AllocateBuffer(bp.pDataTerm,bp.ptrDataTerm,bp.pWinSize[0],bp.pWinSize[1]);
	for(int i=0;i<bp.Height;i++)
		for(int j=0;j<bp.Width;j++)
		{
			int offset=i*bp.Width+j;
			for(int ii=0;ii<2;ii++)
				for(int jj=0;jj<2;jj++)
				{
					int y=i*2+ii;
					int x=j*2+jj;
					if(y<Height && x<Width)
					{
						int nStates=(bp.pWinSize[0][offset]*2+1)*(bp.pWinSize[1][offset]*2+1);
						for(int k=0;k<nStates;k++)
							bp.pDataTerm[offset].data()[k]+=pDataTerm[y*Width+x].data()[k];
					}
				}
		}
	//------------------------------------------------------------------------------------------------
	// generate range term
	//------------------------------------------------------------------------------------------------
	bp.ComputeRangeTerm(gamma/2);
}
Exemple #3
0
//------------------------------------------------------------------------------------------------
// multi-grid belief propagation
//------------------------------------------------------------------------------------------------
void BPFlow::generateCoarserLevel(BPFlow &bp)
{
	//------------------------------------------------------------------------------------------------
	// set the dimensions and parameters
	//------------------------------------------------------------------------------------------------
	bp.Width = Width / 2;
    
	if(Width % 2 == 1) bp.Width++;

	bp.Height = Height / 2;
	if(Height % 2 == 1) bp.Height++;

    bp.WinSize = WinSize;
	bp.Area = bp.Width * bp.Height;
	bp.s = s;
	bp.d = d;

//	DImage foo;
//	Im_s.smoothing(foo);
//	foo.imresize(bp.Im_s,bp.Width,bp.Height);
//	Im_d.smoothing(foo);
//	foo.imresize(bp.Im_d,bp.Width,bp.Height);

	bp.IsDisplay = IsDisplay;
	bp.nNeighbors = nNeighbors;
    bp.setPenalty(4 * alphaD, alphaV);
    
	//------------------------------------------------------------------------------------------------
	// allocate buffers
	//------------------------------------------------------------------------------------------------
	for(int i = 0; i < 2; i++)
	{
		bp.pOffset[i] = new int[bp.Area];
		ReduceImage(bp.pOffset[i], Width, Height, pOffset[i]);
	}

    // generate mask
    bp.pMask1 = new bool[bp.Area];
    bp.pMask2 = new bool[bp.Area];
    
	memset(bp.pMask1, 0, sizeof(bool) * bp.Area);
    memset(bp.pMask2, 0, sizeof(bool) * bp.Area);
    
	int sum1 = 0;
    int sum2 = 0;
	for (int i = 0; i < bp.Width; i++)
    {
		for (int j = 0; j < bp.Height; j++)
		{
			int offset = i + j * bp.Width;
			sum1 = 0;
            sum2 = 0;
            
			for(int ii = 0; ii < 2; ii++)
				for(int jj = 0; jj < 2; jj++)
				{
					int x = j * 2 + jj;
					int y = i * 2 + ii;
                    
					if(y < Height && x < Width)
					{
                        int index = x + y * Width;
                        if (pMask1[index]) sum1++;
                        if (pMask2[index]) sum2++;
					}
				}
            
            if (sum1 > 0) bp.pMask1[offset] = true;
            if (sum2 > 0) bp.pMask2[offset] = true;
		}
    }

    // allocate buffer
	for(int i=0;i<2;i++)
	{
		bp.pOffset[i] = new int[bp.Area];
		ReduceImage(bp.pOffset[i], Width, Height, pOffset[i]);
	}
    
	//------------------------------------------------------------------------------------------------
	// generate data term
	//------------------------------------------------------------------------------------------------
	bp.nTotalMatches = bp.AllocateBuffer(bp.pDataTerm, bp.ptrDataTerm, bp.WinSize);
    int nStates = (bp.WinSize * 2 + 1) * (bp.WinSize * 2 + 1);

	for(int i = 0; i < bp.Height; i++)
		for(int j = 0; j < bp.Width; j++)
		{
			int offset = i * bp.Width + j;
            
			for(int ii = 0; ii < 2; ii++)
            {
                for(int jj = 0; jj < 2; jj++)
				{
					int y = i * 2 + ii;
					int x = j * 2 + jj;

					if(y < Height && x < Width)
					{
                        for(int k = 0; k < nStates; k++)
							bp.pDataTerm[offset].data()[k] += pDataTerm[y * Width + x].data()[k];
					}
				}
            }
		}

	//------------------------------------------------------------------------------------------------
	// generate range term
	//------------------------------------------------------------------------------------------------
	bp.ComputeRangeTerm(gamma / 2);
}