Пример #1
0
CvRect combi_track(IplImage * pImg,KalmanFilter &kfilter)
{
	CvRect predrect=kfilter.predictionReport(prevHandRect);	
	//if((predrect.x<0)||(predrect.y<0)||((predrect.x+predrect.width)>pImg->width)||((predrect.y+predrect.height)>pImg->height))
	//	return NULL;	
	CvConnectedComp components;

	// Create a new hue image
	updateHueImage(pImg);

	// Create a probability image based on the hand histogram
	cvCalcBackProject( &pHueImg, pProbImg, pHist );
    cvAnd( pProbImg, pMask, pProbImg, 0 );
	//cvSetImageROI(pProbImg,predrect);
	
	// Use CamShift to find the center of the new hand probability
    if(!((predrect.x<0)||(predrect.y<0)||((predrect.x+predrect.width)>pImg->width)||((predrect.y+predrect.height)>pImg->height))) {
        cvCamShift( pProbImg, predrect, cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),&components, handBox );
	// Update hand location and angle
    prevHandRect = components.rect;

    }
    else
        //cvCamShift( pProbImg, prevHandRect, cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),&components, handBox );
		prevHandRect.x=-1;
	
    //if(!pImg->origin)	
	//	handBox->angle = -handBox->angle;
	//cvResetImageROI(pProbImg);
	
	return prevHandRect;

}
Пример #2
0
// startTracking()
//
void startTracking(IplImage * pImg, CvRect pHandRect,KalmanFilter &kfilter)
{
	float maxVal = 0.f;

	// Make sure internal data structures have been allocated
	if( !pHist ) createTracker(pImg);

	// Create a new hue image
	updateHueImage(pImg);

    if(!((pHandRect.x<0)||(pHandRect.y<0)||((pHandRect.x+pHandRect.width)>pImg->width)||((pHandRect.y+pHandRect.height)>pImg->height))) {

	// Create a histogram representation for the hand
    cvSetImageROI( pHueImg, pHandRect );
    cvSetImageROI( pMask,   pHandRect );
    cvCalcHist( &pHueImg, pHist, 0, pMask );
    cvGetMinMaxHistValue( pHist, 0, &maxVal, 0, 0 );
    cvConvertScale( pHist->bins, pHist->bins, maxVal? 255.0/maxVal : 0, 0 );
    cvResetImageROI( pHueImg );
    cvResetImageROI( pMask );

	}
	// Store the previous hand location
	prevHandRect =pHandRect;
	prevHandRect2 =pHandRect;

	//Pass the hand location to kalman initializer
	kfilter.predictionBegin(prevHandRect);
	
}
Пример #3
0
int track(camshift * cs, IplImage * img, CvBox2D * fBox)
{
  CvConnectedComp components;

  updateHueImage(cs, img);

  cvCalcBackProject( &cs->hueImg, cs->probImg, cs->hist );
  cvAnd( cs->probImg, cs->mask, cs->probImg, 0 );

  CvSize size = cvGetSize(cs->probImg);
//  printf("%d %d %d %d\n", cs->prevFaceRect.x, cs->prevFaceRect.y, cs->prevFaceRect.width, cs->prevFaceRect.height);
  if (cs->prevFaceRect.x <= 0) {
    return 0;
  }
  if (cs->prevFaceRect.x > size.width) {
    return 0;
  }
  if (cs->prevFaceRect.y <= 0) {
    return 0;
  }
  if (cs->prevFaceRect.y > size.height) {
    return 0;
  }

  if (cs->prevFaceRect.x + cs->prevFaceRect.width > size.width) {
    return 0;
  }
  if (cs->prevFaceRect.y + cs->prevFaceRect.height > size.height) {
    return 0;
  }
  if (cs->prevFaceRect.width <= 0) {
    return 0;
  }
  if (cs->prevFaceRect.height <= 0) {
    return 0;
  }


  cvCamShift( cs->probImg, cs->prevFaceRect,
      cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),
      &components, &cs->faceBox );

  cs->prevFaceRect = components.rect;
  cs->faceBox.angle = -cs->faceBox.angle;

  *fBox = cs->faceBox;
  return 1;
}
Пример #4
0
void initTracking(camshift * cs, IplImage * img, CvRect * faceRect)
{
  float maxVal = 0.f;

  updateHueImage(cs, img);

  cvSetImageROI( cs->hueImg, *faceRect );
  cvSetImageROI( cs->mask,   *faceRect );
  cvCalcHist( &cs->hueImg, cs->hist, 0, cs->mask );
  cvGetMinMaxHistValue( cs->hist, 0, &maxVal, 0, 0 );
  cvConvertScale( cs->hist->bins, cs->hist->bins,
      maxVal? 255.0/maxVal : 0, 0 );
  cvResetImageROI( cs->hueImg );
  cvResetImageROI( cs->mask );

  cs->prevFaceRect = *faceRect;
}
Пример #5
0
//////////////////////////////////
// track()
//
CvBox2D track(camshift * cs, IplImage * pImg)
{
	CvConnectedComp components;

	// Create a new hue image
	updateHueImage(cs, pImg);

	// Create a probability image based on the face histogram
	cvCalcBackProject( &cs->pHueImg, cs->pProbImg, cs->pHist );
    cvAnd( cs->pProbImg, cs->pMask, cs->pProbImg, 0 );

	// Use CamShift to find the center of the new face probability
    CvSize size = cvGetSize(cs->pProbImg);
    if (cs->prevFaceRect.x < 0) {
      cs->prevFaceRect.x = 0;
    }
    if (cs->prevFaceRect.x >= size.width) {
      cs->prevFaceRect.x = size.width - 1;
    }
    if (cs->prevFaceRect.y < 0) {
      cs->prevFaceRect.y = 0;
    }
    if (cs->prevFaceRect.y >= size.height) {
      cs->prevFaceRect.y = size.height - 1;
    }

    if (cs->prevFaceRect.x + cs->prevFaceRect.width > size.width) {
      cs->prevFaceRect.width = size.width - cs->prevFaceRect.x;
    }
    if (cs->prevFaceRect.y + cs->prevFaceRect.height > size.height) {
      cs->prevFaceRect.height = size.height - cs->prevFaceRect.y;
    }


    cvCamShift( cs->pProbImg, cs->prevFaceRect,
                cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),
                &components, &cs->faceBox );

	// Update face location and angle
    cs->prevFaceRect = components.rect;
	cs->faceBox.angle = -cs->faceBox.angle;

	return cs->faceBox;
}
Пример #6
0
//////////////////////////////////
// track()
//
CvRect camshift_track(IplImage * pImg)
{
	CvConnectedComp components;

	// Create a new hue image
	updateHueImage(pImg);

	// Create a probability image based on the hand histogram
	cvCalcBackProject( &pHueImg, pProbImg, pHist );
    cvAnd( pProbImg, pMask, pProbImg, 0 );
	//cvSetImageROI(pProbImg,predrect);
	
	// Use CamShift to find the center of the new hand probability
    cvCamShift( pProbImg, prevHandRect2, cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),&components, handBox );

	// Update hand location and angle
    prevHandRect2 = components.rect;
	//if(!pImg->origin)	
	//	handBox->angle = -handBox->angle;
	//cvResetImageROI(pProbImg);
	return prevHandRect2;
}
Пример #7
0
//////////////////////////////////
// track()
//
CvBox2D track(IplImage * pImg)
{
	CvConnectedComp components;

	// Create a new hue image
	updateHueImage(pImg);

	// Create a probability image based on the face histogram
	cvCalcBackProject( &pHueImg, pProbImg, pHist );
    cvAnd( pProbImg, pMask, pProbImg, 0 );

	// Use CamShift to find the center of the new face probability
    cvCamShift( pProbImg, prevFaceRect,
                cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),
                &components, &faceBox );

	// Update face location and angle
    prevFaceRect = components.rect;
	faceBox.angle = -faceBox.angle;

	return faceBox;
}
Пример #8
0
//////////////////////////////////
// startTracking()
//
void startTracking(IplImage * pImg, CvRect * pFaceRect)
{
	float maxVal = 0.f;

	// Make sure internal data structures have been allocated
	if( !pHist ) createTracker(pImg);

	// Create a new hue image
	updateHueImage(pImg);

	// Create a histogram representation for the face
    cvSetImageROI( pHueImg, *pFaceRect );
    cvSetImageROI( pMask,   *pFaceRect );
    cvCalcHist( &pHueImg, pHist, 0, pMask );
    cvGetMinMaxHistValue( pHist, 0, &maxVal, 0, 0 );
    cvConvertScale( pHist->bins, pHist->bins, maxVal? 255.0/maxVal : 0, 0 );
    cvResetImageROI( pHueImg );
    cvResetImageROI( pMask );

	// Store the previous face location
	prevFaceRect = *pFaceRect;
}