CLM研究

CLM

FACETRACKER::Tracker model(ftFile);
int Tracker::Track(cv::Mat im,vector<int> &wSize, const int  fpd,
           const int  nIter, const double clamp,const double fTol,
           const bool fcheck)
{ 
  assert(im.type() == CV_8U);
  //转换成灰度图
  if(im.channels() == 1)
      gray_ = im;
  else
  {
    if((gray_.rows != im.rows) || (gray_.cols != im.cols))
      gray_.create(im.rows,im.cols,CV_8U);
    cv::cvtColor(im,gray_,CV_BGR2GRAY);
  }

  //检测人脸,返回人脸矩阵
  bool gen,rsize=true; 
  cv::Rect R;
  if((_frame < 0) || (fpd >= 0 && fpd < _frame))
  {
    _frame = 0; 
    R = _fdet.Detect(gray_);                
    gen = true;
  }
  else
  {
      R = this->ReDetect(gray_); 
      gen = false;
  }
  if((R.width == 0) || (R.height == 0))
  {
      _frame = -1; 
      return -1;
  }
  _frame++;

  if(gen)
  {
    this->InitShape(R,_shape);//通过rect赋值人脸形状
    _clm._pdm.CalcParams(_shape,_clm._plocal,_clm._pglobl);
  }
  else
  {
    double tx = R.x - _rect.x,ty = R.y - _rect.y;
    _clm._pglobl.db(4,0) += tx;    
    _clm._pglobl.db(5,0) += ty; 
    rsize = false;
  }
  _clm.Fit(gray_,wSize,nIter,clamp,fTol);
  _clm._pdm.CalcShape2D(_shape,_clm._plocal,_clm._pglobl);

  for(int ss=0;ss<66;ss++)
  {
      cv::circle(gray_,cv::Point(_shape.at<double>(ss,0),_shape.at<double>(ss+66,0)),1,CV_RGB(255,255,255),2);
  }
  imshow("Face Tracker",gray_); 
  cvWaitKey(1);

  if(fcheck)
  {
      if(!_fcheck.Check(_clm.GetViewIdx(),gray_,_shape))
          return -1;
  }
  _rect = this->UpdateTemplate(gray_,_shape,rsize); 
  if((_rect.width == 0) || (_rect.height == 0))
      return -1;
  else
      return 0;
}

你可能感兴趣的:(ASM,clm,AAM)