📄 integralfeatures.cpp
字号:
if (leftcol==m_template_width-1) { return false; } rightcol=leftcol+1; } toprect_toprow=-1; } centerrow=toprect_toprow+1; } bottomrect_bottomrow=centerrow+1; } SetNonOverlap(); return true;}CIntegralFeature* CUpDownIF::Copy() const{ return new CUpDownIF(*this);}void CUpDownIF::MakePartialFromCurrentForNumIncarnations( featnum num){ m_is_partial=true; m_num_incarnations=num+1; start_toprect_toprow=toprect_toprow; start_centerrow=centerrow; start_bottomrect_bottomrow=bottomrect_bottomrow; start_leftcol=leftcol; start_rightcol=rightcol; m_remaining_incarnations=m_stop_after_num_incarnations=num;}#ifdef USE_MFCvoid CUpDownIF::Draw(CDC* pDC, int x_off, int y_off, int zoomfactor) const{ int lc = x_off + zoomfactor + leftcol*zoomfactor; int tt = y_off + zoomfactor + toprect_toprow*zoomfactor; int rc = x_off + zoomfactor + rightcol*zoomfactor; int cr = y_off + zoomfactor + centerrow*zoomfactor; int bb = y_off + zoomfactor + bottomrect_bottomrow*zoomfactor; pDC->FillRect(CRect(lc, tt, rc, cr), g_pBlackbrush); pDC->Rectangle(lc, cr, rc, bb);}#endif // USE_MFCostream& CUpDownIF::output(ostream& os) const{ os << "UpDown " << toprect_toprow << "," << centerrow << "," << bottomrect_bottomrow << " x " << leftcol << "," << rightcol; return os;}///////////////////////////////////////////////////////////////////////////////// CLeftCenterRightIF classes implementation///////////////////////////////////////////////////////////////////////////////CLeftCenterRightIF::CLeftCenterRightIF(int templateWidth, int templateHeight) : CIntegralFeature(templateWidth, templateHeight, IT_INVALID_FEATURE, false, 8*COST_GET+10*COST_ADD) {}CLeftCenterRightIF::CLeftCenterRightIF(int templateWidth, int templateHeight, int _toprow, int _bottomrow, int _leftrect_leftcol, int _leftrect_rightcol, int _rightrect_leftcol, int _rightrect_rightcol) : CIntegralFeature(templateWidth, templateHeight, IT_INVALID_FEATURE, false, 8*COST_GET+10*COST_ADD) { toprow = _toprow; bottomrow = _bottomrow; leftrect_leftcol = _leftrect_leftcol; leftrect_rightcol = _leftrect_rightcol; rightrect_leftcol = _rightrect_leftcol; rightrect_rightcol = _rightrect_rightcol; SetNonOverlap();}CLeftCenterRightIF::CLeftCenterRightIF(const CLeftCenterRightIF& frm) : CIntegralFeature(frm.m_template_width, frm.m_template_height, frm.m_num_incarnations, frm.m_is_partial, 8*COST_GET+10*COST_ADD) { toprow=frm.toprow; bottomrow=frm.bottomrow; leftrect_leftcol=frm.leftrect_leftcol; leftrect_rightcol=frm.leftrect_rightcol; rightrect_leftcol=frm.rightrect_leftcol; rightrect_rightcol=frm.rightrect_rightcol; if (m_is_partial) { start_toprow=frm.start_toprow; start_bottomrow=frm.start_bottomrow; start_leftrect_leftcol=frm.start_leftrect_leftcol; start_leftrect_rightcol=frm.start_leftrect_rightcol; start_rightrect_leftcol=frm.start_rightrect_leftcol; start_rightrect_rightcol=frm.start_rightrect_rightcol; m_remaining_incarnations = frm.m_remaining_incarnations; m_stop_after_num_incarnations = frm.m_stop_after_num_incarnations; } SetNonOverlap();}CLeftCenterRightIF::CLeftCenterRightIF(istream& is, int templateWidth, int templateHeight) : CIntegralFeature(templateWidth, templateHeight, IT_INVALID_FEATURE, false, 8*COST_GET+10*COST_ADD) { char a, b, c; string strx, strslash; is >> toprow >> a >> bottomrow >> strx >> leftrect_leftcol >> b >> leftrect_rightcol >> strslash >> rightrect_leftcol >> c >> rightrect_rightcol; if (a!=',' || b!=',' || c!=',' || strx!="x" || strslash!="/") { char* buf = (char*) alloca((256+strx.length()+strslash.length())*sizeof(char)); sprintf(buf, "error during construction of LeftCenterRightIF (%c|%c|%c|%s|%s)\n", a, b, c, strx.c_str(), strslash.c_str()); throw ITException(buf); } SetNonOverlap();}bool CLeftCenterRightIF::Equals(const CLeftCenterRightIF& frm) const{ bool equal = (toprow == frm.toprow && bottomrow == frm.bottomrow && leftrect_leftcol == frm.leftrect_leftcol && leftrect_rightcol == frm.leftrect_rightcol && rightrect_leftcol == frm.rightrect_leftcol && rightrect_rightcol == frm.rightrect_rightcol); return equal;}void CLeftCenterRightIF::SetNonOverlap() { m_non_overlap = ((leftrect_rightcol-leftrect_leftcol) - (rightrect_leftcol-leftrect_rightcol) + (rightrect_rightcol-rightrect_leftcol)) * (bottomrow-toprow);}II_TYPE CLeftCenterRightIF::Compute(const CIntegralImage& image) const{ II_TYPE botleri = image.GetElement(leftrect_rightcol, bottomrow); II_TYPE topleri = image.GetElement(leftrect_rightcol, toprow); II_TYPE botrile = image.GetElement(rightrect_leftcol, bottomrow); II_TYPE toprile = image.GetElement(rightrect_leftcol, toprow); II_TYPE val_leftrect = botleri - image.GetElement(leftrect_leftcol, bottomrow) - topleri + image.GetElement(leftrect_leftcol, toprow); II_TYPE val_centerrect = botrile - botleri - toprile + topleri; II_TYPE val_rightrect = image.GetElement(rightrect_rightcol, bottomrow) - botrile - image.GetElement(rightrect_rightcol, toprow) + toprile; return val_leftrect-val_centerrect+val_rightrect;}II_TYPE CLeftCenterRightIF::ComputeScaled(const CIntegralImage& image, II_TYPE mean, int left, int top) const{ int placed_leftrect_leftcol = left + scaled_leftrect_leftcol; int placed_leftrect_rightcol = left + scaled_leftrect_rightcol; int placed_rightrect_leftcol= left + scaled_rightrect_leftcol; int placed_rightrect_rightcol = left + scaled_rightrect_rightcol; int placed_toprow = top + scaled_toprow; int placed_bottomrow = top + scaled_bottomrow; II_TYPE botleri = image.GetElement(placed_leftrect_rightcol, placed_bottomrow); II_TYPE topleri = image.GetElement(placed_leftrect_rightcol, placed_toprow); II_TYPE botrile = image.GetElement(placed_rightrect_leftcol, placed_bottomrow); II_TYPE toprile = image.GetElement(placed_rightrect_leftcol, placed_toprow); II_TYPE val_leftrect = botleri - image.GetElement(placed_leftrect_leftcol, placed_bottomrow) - topleri + image.GetElement(placed_leftrect_leftcol, placed_toprow); II_TYPE val_centerrect = botrile - botleri - toprile + topleri; II_TYPE val_rightrect = image.GetElement(placed_rightrect_rightcol, placed_bottomrow) - botrile - image.GetElement(placed_rightrect_rightcol, placed_toprow) + toprile; II_TYPE val = val_leftrect-val_centerrect+val_rightrect; II_TYPE scaled_val = val/m_global_scale; II_TYPE mean_adjust = m_non_overlap*mean; return scaled_val-mean_adjust;}void CLeftCenterRightIF::Scale(II_TYPE scale_x, II_TYPE scale_y){ if (leftrect_leftcol==-1) { scaled_leftrect_leftcol = -1; scaled_leftrect_rightcol = (int)((II_TYPE)(leftrect_rightcol+1)*scale_x) -1; scaled_rightrect_leftcol= (int)((II_TYPE)(rightrect_leftcol-leftrect_rightcol)*scale_x) + scaled_leftrect_rightcol; scaled_rightrect_rightcol = (int)((II_TYPE)(rightrect_rightcol-rightrect_leftcol)*scale_x) + scaled_rightrect_leftcol; } else { scaled_leftrect_leftcol = (int)((II_TYPE)leftrect_leftcol*scale_x); scaled_leftrect_rightcol = (int)((II_TYPE)leftrect_rightcol*scale_x); scaled_rightrect_leftcol= (int)((II_TYPE)rightrect_leftcol*scale_x); scaled_rightrect_rightcol = (int)((II_TYPE)rightrect_rightcol*scale_x); } if (toprow==-1) { scaled_toprow = (int)((II_TYPE)(toprow+1)*scale_y) -1; scaled_bottomrow = (int)((II_TYPE)(bottomrow-toprow)*scale_y) + scaled_toprow; } else { scaled_toprow = (int)((II_TYPE)toprow*scale_y); scaled_bottomrow = (int)((II_TYPE)bottomrow*scale_y); } m_global_scale = scale_x*scale_y;}void CLeftCenterRightIF::EvenOutScales(II_TYPE* pScale_x, II_TYPE* pScale_y, int scaled_template_width, int /*scaled_template_height*/){ int leftrect = leftrect_rightcol-leftrect_leftcol; int midrect = rightrect_leftcol-leftrect_rightcol; int rightrect = rightrect_rightcol-rightrect_leftcol; II_TYPE ratio1 = (II_TYPE)leftrect/(II_TYPE)midrect; II_TYPE ratio2 = (II_TYPE)midrect/(II_TYPE)rightrect; int sleftrect = scaled_leftrect_rightcol-scaled_leftrect_leftcol; int smidrect = scaled_rightrect_leftcol-scaled_leftrect_rightcol; int srightrect = scaled_rightrect_rightcol-scaled_rightrect_leftcol; II_TYPE sratio1 = (II_TYPE)sleftrect/(II_TYPE)smidrect; II_TYPE sratio2 = (II_TYPE)smidrect/(II_TYPE)srightrect; int scaled_width = scaled_rightrect_rightcol-scaled_leftrect_leftcol; bool too_wide = scaled_width > scaled_template_width; while (!too_wide && (fabs(ratio1-sratio1)>=SCALE_DIFFERENCE_EPSILON || fabs(ratio2-sratio2)>=SCALE_DIFFERENCE_EPSILON)) { if (ratio1<sratio1) { scaled_rightrect_leftcol++; scaled_rightrect_rightcol++; smidrect++; } else if (ratio1>sratio1) { scaled_leftrect_rightcol++; scaled_rightrect_leftcol++; scaled_rightrect_rightcol++; sleftrect++; } else if (ratio2<sratio2) { scaled_rightrect_rightcol++; srightrect++; } else { ASSERT(ratio2>sratio2); scaled_rightrect_leftcol++; scaled_rightrect_rightcol++; smidrect++; } scaled_width = scaled_rightrect_rightcol-scaled_leftrect_leftcol; too_wide = scaled_width > scaled_template_width; sratio1 = (II_TYPE)sleftrect/(II_TYPE)smidrect; sratio2 = (II_TYPE)smidrect/(II_TYPE)srightrect; } ASSERT(too_wide || fabs((II_TYPE)leftrect/(II_TYPE)rightrect -(II_TYPE)sleftrect/(II_TYPE)srightrect)<SCALE_DIFFERENCE_EPSILON); 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_leftrect_rightcol -= overlap; scaled_rightrect_leftcol -= overlap; scaled_rightrect_rightcol -= overlap; *pScale_x = sratio1; } } else { *pScale_x = sratio1; }}void CLeftCenterRightIF::SetToFirstIncarnation(){ if (m_is_partial) { toprow=start_toprow; bottomrow=start_bottomrow; leftrect_leftcol=start_leftrect_leftcol; leftrect_rightcol=start_leftrect_rightcol; rightrect_leftcol=start_rightrect_leftcol; rightrect_rightcol=start_rightrect_rightcol; m_remaining_incarnations=m_stop_after_num_incarnations; } else { toprow=-1; bottomrow=0; leftrect_leftcol=-1; leftrect_rightcol=0; rightrect_leftcol=1; rightrect_rightcol=2; } SetNonOverlap();}bool CLeftCenterRightIF::SetToNextIncarnation(){ if (m_is_partial) { if (m_remaining_incarnations) { m_remaining_incarnations--; } else { return false; } } rightrect_rightcol++; if (rightrect_rightcol>=m_template_width) { rightrect_leftcol++; if (rightrect_leftcol>=m_template_width-1) { leftrect_rightcol++; if (leftrect_rightcol>=m_template_width-2) { leftrect_leftcol++; if (leftrect_leftcol==m_template_width-3) { bottomrow++; if (bottomrow==m_template_height) { toprow++; if (toprow==m_template_height-1) { return false; } bottomrow=toprow+1; } leftrect_leftcol=0; } leftrect_rightcol=leftrect_leftcol+1; } rightrect_leftcol=leftrect_rightcol+1; } rightrect_rightcol=rightrect_leftcol+1; } SetNonOverlap(); return true;}void CLeftCenterRightIF::MakePartialFromCurrentForNumIncarnations( featnum num){ m_is_partial=true; m_num_incarnations=num+1; start_toprow=toprow; start_bottomrow=bottomrow; start_leftrect_leftcol=leftrect_leftcol; start_leftrect_rightcol=leftrect_rightcol; start_rightrect_leftcol=rightrect_leftcol; start_rightrect_rightcol=rightrect_rightcol; m_remaining_incarnations=m_stop_after_num_incarnations=num;}CIntegralFeature* CLeftCenterRightIF::Copy() const { return new CLeftCenterRightIF(*this);}#ifdef USE_MFCvoid CLeftCenterRightIF::Draw(CDC* pDC, int x_off, int y_off, int zoomfactor) const{ int tr = y_off + zoomfactor + toprow*zoomfactor; int br = y_off + zoomfactor + bottomrow*zoomfactor; int ll = x_off + zoomfactor + leftrect_leftcol*zoomfactor; int lr = x_off + zoomfactor + leftrect_rightcol*zoomfactor; int rl = x_off + zoomfactor + rightrect_leftcol*zoomfactor; int rr = x_off + zoomfactor + rightrect_rightcol*zoomfactor; pDC->FillRect(CRect(ll, tr, lr, br), g_pBlackbrush); pDC->Rectangle(lr, tr, rl, br);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -