⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 integralfeatures.cpp

📁 tracciatore di mani con webcam
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  II_TYPE sratio = (II_TYPE)sleftrect/(II_TYPE)srightrect;  int scaled_width = scaled_rightrect_rightcol-scaled_leftrect_leftcol;  bool too_wide = scaled_width > scaled_template_width;  while (!too_wide && fabs(ratio-sratio)>=SCALE_DIFFERENCE_EPSILON) {    if (ratio<sratio) {      scaled_rightrect_rightcol++;      srightrect++;    } else {      scaled_centercol++;      scaled_rightrect_rightcol++;      sleftrect++;    }    scaled_width = scaled_rightrect_rightcol-scaled_leftrect_leftcol;    too_wide = scaled_width > scaled_template_width;    sratio = (II_TYPE)sleftrect/(II_TYPE)srightrect;  }  int overlap = scaled_rightrect_rightcol-scaled_template_width+1;  // overlap: by how much is rightmost too far to the right?   // it must not be larger than scaled_template_width-1  if (overlap>0) {    // went outside template boundaries    if (too_wide) {      // feature too big, use int scale      *pScale_x = floor(*pScale_x);      Scale(*pScale_x, *pScale_y);    } else {      // shift feature by overlap      scaled_leftrect_leftcol -= overlap;      scaled_centercol -= overlap;      scaled_rightrect_rightcol -= overlap;      *pScale_x = sratio;    }  } else {    *pScale_x = sratio;  }}void CLeftRightIF::SetToFirstIncarnation(){  if (m_is_partial) {    toprow=start_toprow;    bottomrow=start_bottomrow;    leftrect_leftcol=start_leftrect_leftcol;    centercol=start_centercol;    rightrect_rightcol=start_rightrect_rightcol;    m_remaining_incarnations=m_stop_after_num_incarnations;  } else {    toprow=-1;    bottomrow=0;    leftrect_leftcol=-1;    centercol=0;    rightrect_rightcol=1;  }  SetNonOverlap();}bool CLeftRightIF::SetToNextIncarnation(){  if (m_is_partial) {    if (m_remaining_incarnations) {      m_remaining_incarnations--;    } else {      return false;    }  }  rightrect_rightcol++;  if (rightrect_rightcol>=m_template_width) {    centercol++;    if (centercol>=m_template_width-1) {      leftrect_leftcol++;      if (leftrect_leftcol==m_template_width-2) {	bottomrow++;	if (bottomrow==m_template_height) {	  toprow++;	  if (toprow==m_template_height-1) {	    return false;	  }	  bottomrow=toprow+1;	}	leftrect_leftcol=-1;      }      centercol=leftrect_leftcol+1;    }    rightrect_rightcol=centercol+1;  }  SetNonOverlap();  return true;}CIntegralFeature* CLeftRightIF::Copy() const{  return new CLeftRightIF(*this);}void CLeftRightIF::MakePartialFromCurrentForNumIncarnations(  featnum num){  m_is_partial=true;  m_num_incarnations=num+1;  start_toprow=toprow;  start_bottomrow=bottomrow;  start_leftrect_leftcol=leftrect_leftcol;  start_centercol=centercol;  start_rightrect_rightcol=rightrect_rightcol;  m_remaining_incarnations=m_stop_after_num_incarnations=num;}/*void CLeftRightIF::Transform(const CFeatureTransformer& transformer){  ASSERT(!m_is_partial);  transformer.TransformWidthHeight(&m_template_width, &m_template_height);  transformer.TransformCoordinate();  transformer.FeatureDone();  toprow=start_toprow;  bottomrow=start_bottomrow;  leftrect_leftcol=start_leftrect_leftcol;  centercol=start_centercol;  rightrect_rightcol=start_rightrect_rightcol;}*/#ifdef USE_MFCvoid CLeftRightIF::Draw(CDC* pDC, int x_off, int y_off, int zoomfactor) const{  int ll = x_off + zoomfactor + leftrect_leftcol*zoomfactor;  int tr = y_off + zoomfactor + toprow*zoomfactor;  int cl = x_off + zoomfactor + centercol*zoomfactor;  int br = y_off + zoomfactor + bottomrow*zoomfactor;  int rr = x_off + zoomfactor + rightrect_rightcol*zoomfactor;  pDC->FillRect(CRect(ll, tr, cl, br), g_pBlackbrush);  pDC->Rectangle(cl, tr, rr, br);}#endif // USE_MFCostream& CLeftRightIF::output(ostream& os) const{  os << "LeftRight " << toprow << "," << bottomrow << " x "     << leftrect_leftcol << "," << centercol << "," << rightrect_rightcol;  return os;}///////////////////////////////////////////////////////////////////////////////// CUpDownIF classes implementation///////////////////////////////////////////////////////////////////////////////CUpDownIF::CUpDownIF(int templateWidth, int templateHeight)  : CIntegralFeature(templateWidth, templateHeight, IT_INVALID_FEATURE, false, 		     6*COST_GET+7*COST_ADD) {}CUpDownIF::CUpDownIF(int templateWidth, int templateHeight,                     int _toprect_toprow, int _centerrow,                     int _bottomrect_bottomrow,                     int _leftcol, int _rightcol)  : CIntegralFeature(templateWidth, templateHeight, IT_INVALID_FEATURE, false,		     6*COST_GET+7*COST_ADD) {  toprect_toprow = _toprect_toprow;  centerrow = _centerrow;  bottomrect_bottomrow = _bottomrect_bottomrow;  leftcol = _leftcol;  rightcol = _rightcol;  SetNonOverlap();}CUpDownIF::CUpDownIF(const CUpDownIF& frm)  : CIntegralFeature(frm.m_template_width, frm.m_template_height,		     frm.m_num_incarnations, frm.m_is_partial, 		     6*COST_GET+7*COST_ADD) {  toprect_toprow=frm.toprect_toprow;  centerrow=frm.centerrow;  bottomrect_bottomrow=frm.bottomrect_bottomrow;  leftcol=frm.leftcol;  rightcol=frm.rightcol;  if (m_is_partial) {    start_toprect_toprow=frm.start_toprect_toprow;    start_centerrow=frm.start_centerrow;    start_bottomrect_bottomrow=frm.start_bottomrect_bottomrow;    start_leftcol=frm.start_leftcol;    start_rightcol=frm.start_rightcol;    m_remaining_incarnations = frm.m_remaining_incarnations;    m_stop_after_num_incarnations = frm.m_stop_after_num_incarnations;  }  SetNonOverlap();}CUpDownIF::CUpDownIF(istream& is, int templateWidth, int templateHeight)  : CIntegralFeature(templateWidth, templateHeight, IT_INVALID_FEATURE, false, 		     6*COST_GET+7*COST_ADD) {  char a, b, c;  string str;  is >> toprect_toprow >> a >> centerrow >> b     >> bottomrect_bottomrow >> str >> leftcol >> c >> rightcol;  if (a!=',' || b!=',' || c!=',' || str!="x") {    char* buf = (char*) alloca((256+str.length())*sizeof(char));    sprintf(buf, "error during construction of UpDownIF (%c|%c|%c|%s)\n",	   a, b, c, str.c_str());    throw ITException(buf);  }  SetNonOverlap();}bool CUpDownIF::Equals(const CUpDownIF& frm) const{  bool equal =     (toprect_toprow == frm.toprect_toprow &&     centerrow == frm.centerrow &&     bottomrect_bottomrow == frm.bottomrect_bottomrow &&     leftcol == frm.leftcol &&     rightcol == frm.rightcol);  return equal;}void CUpDownIF::SetNonOverlap() {  m_non_overlap =    ((centerrow-toprect_toprow) - (bottomrect_bottomrow-centerrow))    * (rightcol-leftcol);}II_TYPE CUpDownIF::Compute(const CIntegralImage& image) const{	II_TYPE ceri = image.GetElement(rightcol, centerrow);	II_TYPE cele = image.GetElement(leftcol, centerrow);	II_TYPE val_toprect = 		ceri		- cele		- image.GetElement(rightcol, toprect_toprow)		+ image.GetElement(leftcol, toprect_toprow);	II_TYPE val_bottomrect = 		image.GetElement(rightcol, bottomrect_bottomrow)		- image.GetElement(leftcol, bottomrect_bottomrow)		- ceri		+ cele;	return val_toprect-val_bottomrect;}II_TYPE CUpDownIF::ComputeScaled(const CIntegralImage& image, II_TYPE mean, int left, int top) const{	int placed_leftcol = left + scaled_leftcol;	int placed_rightcol = left + scaled_rightcol;	int placed_toprect_toprow = top + scaled_toprect_toprow;	int placed_centerrow = top + scaled_centerrow;	int placed_bottomrect_bottomrow = top + scaled_bottomrect_bottomrow;	II_TYPE ceri = image.GetElement(placed_rightcol, placed_centerrow);	II_TYPE cele = image.GetElement(placed_leftcol, placed_centerrow);	II_TYPE val_toprect = 		ceri		- cele		- image.GetElement(placed_rightcol, placed_toprect_toprow)		+ image.GetElement(placed_leftcol, placed_toprect_toprow);	II_TYPE val_bottomrect = 		image.GetElement(placed_rightcol, placed_bottomrect_bottomrow)		- image.GetElement(placed_leftcol, placed_bottomrect_bottomrow)		- ceri		+ cele;	II_TYPE val = val_toprect-val_bottomrect;	II_TYPE scaled_val = val/m_global_scale;	II_TYPE mean_adjust = m_non_overlap*mean;	return scaled_val-mean_adjust;}void CUpDownIF::Scale(II_TYPE scale_x, II_TYPE scale_y){	if (leftcol==-1) {		scaled_leftcol = -1;		scaled_rightcol = (int)((II_TYPE)(rightcol+1)*scale_x) - 1;	} else {		scaled_leftcol = (int)((II_TYPE)leftcol*scale_x);		scaled_rightcol = (int)((II_TYPE)rightcol*scale_x);	}	if (toprect_toprow==-1) {		scaled_toprect_toprow = -1;		scaled_centerrow = (int)((II_TYPE)(centerrow+1)*scale_y) - 1;		scaled_bottomrect_bottomrow = (int)((II_TYPE)(bottomrect_bottomrow-centerrow)*scale_y) + scaled_centerrow;	} else {		scaled_toprect_toprow = (int)((II_TYPE)toprect_toprow*scale_y);		scaled_centerrow = (int)((II_TYPE)centerrow*scale_y);		scaled_bottomrect_bottomrow = (int)((II_TYPE)bottomrect_bottomrow*scale_y);	}  m_global_scale = scale_x*scale_y;}void CUpDownIF::EvenOutScales(II_TYPE* pScale_x, II_TYPE* pScale_y,        int /*scaled_template_width*/, int scaled_template_height){  int toprect = centerrow-toprect_toprow;  int bottomrect = bottomrect_bottomrow-centerrow;  II_TYPE ratio = (II_TYPE)toprect/(II_TYPE)bottomrect;  int stoprect = scaled_centerrow-scaled_toprect_toprow;  int sbottomrect = scaled_bottomrect_bottomrow-scaled_centerrow;  II_TYPE sratio = (II_TYPE)stoprect/(II_TYPE)sbottomrect;  int scaled_height = scaled_bottomrect_bottomrow-toprect_toprow;  bool too_high = scaled_height > scaled_template_height;  while (!too_high && fabs(ratio-sratio)>=SCALE_DIFFERENCE_EPSILON) {    if (ratio<sratio) {      scaled_bottomrect_bottomrow++;      sbottomrect++;    } else {      scaled_centerrow++;      scaled_bottomrect_bottomrow++;      stoprect++;    }    scaled_height = scaled_bottomrect_bottomrow-toprect_toprow;    too_high = scaled_height > scaled_template_height;    sratio = (II_TYPE)stoprect/(II_TYPE)sbottomrect;  }  int overlap = scaled_bottomrect_bottomrow-scaled_template_height+1;  // overlap: by how much is bottommost too far down?   // it must not be larger than scaled_template_height-1  if (overlap>0) {    // went outside template boundaries    if (too_high) {      // feature too big, use int scale      *pScale_y = floor(*pScale_y);      Scale(*pScale_x, *pScale_y);    } else {      // shift feature by overlap      scaled_toprect_toprow -= overlap;      scaled_centerrow -= overlap;      scaled_bottomrect_bottomrow -= overlap;      *pScale_y = sratio;    }  } else {    *pScale_y = sratio;  }}void CUpDownIF::SetToFirstIncarnation(){  if (m_is_partial) {    toprect_toprow=start_toprect_toprow;    centerrow=start_centerrow;    bottomrect_bottomrow=start_bottomrect_bottomrow;    leftcol=start_leftcol;    rightcol=start_rightcol;    m_remaining_incarnations=m_stop_after_num_incarnations;  } else {    toprect_toprow=-1;    centerrow=0;    bottomrect_bottomrow=1;    leftcol=-1;    rightcol=0;  }  SetNonOverlap();}bool CUpDownIF::SetToNextIncarnation(){	if (m_is_partial) {		if (m_remaining_incarnations) {			m_remaining_incarnations--;		} else {			return false;		}	}	bottomrect_bottomrow++;	if (bottomrect_bottomrow>=m_template_height) {		centerrow++;		if (centerrow>=m_template_height-1) {			toprect_toprow++;			if (toprect_toprow==m_template_height-2) {				rightcol++;				if (rightcol==m_template_width) {					leftcol++;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -