📄 integralfeatures.cpp
字号:
} else { return false; } } col7_right++; if (col7_right>=m_template_width) { col7_left++; if (col7_left>=m_template_width-1) { col6_left++; if (col6_left>=m_template_width-2) { col5_left++; if (col5_left>=m_template_width-3) { col4_left++; if (col4_left>=m_template_width-4) { col3_left++; if (col3_left>=m_template_width-5) { col2_left++; if (col2_left>=m_template_width-6) { col1_left++; if (col1_left>=m_template_width-7) { bottomrow++; if (bottomrow==m_template_height) { toprow++; if (toprow==m_template_height-1) { return false; } bottomrow = toprow+1; } col1_left = -1; } col2_left = col1_left+1; } col3_left = col2_left+1; } col4_left = col3_left+1; } col5_left = col4_left+1; } col6_left = col5_left+1; } col7_left = col6_left+1; } col7_right = col7_left+1; } SetNonOverlap(); return true;}CIntegralFeature* CSevenColumnsIF::Copy() const{ return new CSevenColumnsIF(*this);}void CSevenColumnsIF::MakePartialFromCurrentForNumIncarnations( featnum num){ m_is_partial = true; m_num_incarnations=num+1; start_toprow = toprow; start_bottomrow = bottomrow; start_col1_left = col1_left; start_col2_left = col2_left; start_col3_left = col3_left; start_col4_left = col4_left; start_col5_left = col5_left; start_col6_left = col6_left; start_col7_left = col7_left; start_col7_right= col7_right; m_remaining_incarnations = m_stop_after_num_incarnations=num;}#ifdef USE_MFCvoid CSevenColumnsIF::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 c1 = x_off + zoomfactor + col1_left*zoomfactor; int c2 = x_off + zoomfactor + col2_left*zoomfactor; int c3 = x_off + zoomfactor + col3_left*zoomfactor; int c4 = x_off + zoomfactor + col4_left*zoomfactor; int c5 = x_off + zoomfactor + col5_left*zoomfactor; int c6 = x_off + zoomfactor + col6_left*zoomfactor; int c7 = x_off + zoomfactor + col7_left*zoomfactor; int cr = x_off + zoomfactor + col7_right*zoomfactor; pDC->FillRect(CRect(c1, tr, c2, br), g_pBlackbrush); pDC->Rectangle(c2, tr, c3, br); pDC->FillRect(CRect(c3, tr, c4, br), g_pBlackbrush); pDC->Rectangle(c4, tr, c5, br); pDC->FillRect(CRect(c5, tr, c6, br), g_pBlackbrush); pDC->Rectangle(c6, tr, c7, br); pDC->FillRect(CRect(c7, tr, cr, br), g_pBlackbrush);}#endif // USE_MFCostream& CSevenColumnsIF::output(ostream& os) const{ os << "SevenColumns " << toprow << "," << bottomrow << " x " << col1_left << "," << col2_left << "," << col3_left << "," << col4_left << "," << col5_left << "," << col6_left << "," << col7_left << "," << col7_right; return os;}///////////////////////////////////////////////////////////////////////////////// CDiagIF classes implementation///////////////////////////////////////////////////////////////////////////////CDiagIF::CDiagIF(int templateWidth, int templateHeight) : CIntegralFeature(templateWidth, templateHeight, IT_INVALID_FEATURE, false, 9*COST_GET+15*COST_ADD) {}CDiagIF::CDiagIF(int templateWidth, int templateHeight, int _toprect_toprow, int _centerrow, int _bottomrect_bottomrow, int _leftrect_leftcol, int _centercol, int _rightrect_rightcol) : CIntegralFeature(templateWidth, templateHeight, IT_INVALID_FEATURE, false, 9*COST_GET+15*COST_ADD) { toprect_toprow = _toprect_toprow; centerrow = _centerrow; bottomrect_bottomrow = _bottomrect_bottomrow; leftrect_leftcol = _leftrect_leftcol; centercol = _centercol; rightrect_rightcol = _rightrect_rightcol; SetNonOverlap();}CDiagIF::CDiagIF(const CDiagIF& frm) : CIntegralFeature(frm.m_template_width, frm.m_template_height, frm.m_num_incarnations, frm.m_is_partial, 9*COST_GET+15*COST_ADD) { toprect_toprow=frm.toprect_toprow; centerrow=frm.centerrow; bottomrect_bottomrow=frm.bottomrect_bottomrow; leftrect_leftcol = frm.leftrect_leftcol; centercol = frm.centercol; rightrect_rightcol = frm.rightrect_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_leftrect_leftcol = frm.start_leftrect_leftcol; start_centercol = frm.start_centercol; 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();}CDiagIF::CDiagIF(istream& is, int templateWidth, int templateHeight) : CIntegralFeature(templateWidth, templateHeight, IT_INVALID_FEATURE, false, 9*COST_GET+15*COST_ADD) { char a, b, c, d; string str; is >> toprect_toprow >> a >> centerrow >> b >> bottomrect_bottomrow >> str >> leftrect_leftcol >> c >> centercol >> d >> rightrect_rightcol; if (a!=',' || b!=',' || str!="x" || c!=',' || d!=',') { char* buf = (char*) alloca((256+str.length())*sizeof(char)); sprintf(buf, "error during construction of DiagIF (%c|%c|%s|%c|%c)\n", a, b, str.c_str(), c, d); throw ITException(buf); } SetNonOverlap();}bool CDiagIF::Equals(const CDiagIF& frm) const{ bool equal = (toprect_toprow == frm.toprect_toprow && centerrow == frm.centerrow && bottomrect_bottomrow == frm.bottomrect_bottomrow && leftrect_leftcol == frm.leftrect_leftcol && centercol == frm.centercol && rightrect_rightcol == frm.rightrect_rightcol); return equal;}void CDiagIF::SetNonOverlap() { // left_upper - right_upper - left_lower + right_lower m_non_overlap = (centercol-leftrect_leftcol)*(centerrow-toprect_toprow) - (rightrect_rightcol-centercol)*(centerrow-toprect_toprow) - (centercol-leftrect_leftcol)*(bottomrect_bottomrow-centerrow) + (rightrect_rightcol-centercol)*(bottomrect_bottomrow-centerrow);}II_TYPE CDiagIF::Compute(const CIntegralImage& image) const{ II_TYPE ceri = image.GetElement(rightrect_rightcol, centerrow); II_TYPE cele = image.GetElement(leftrect_leftcol, centerrow); II_TYPE cecen = image.GetElement(centercol, centerrow); II_TYPE topcen = image.GetElement(centercol, toprect_toprow); II_TYPE botcen = image.GetElement(centercol, bottomrect_bottomrow); II_TYPE val_topleft = cecen - cele - topcen + image.GetElement(leftrect_leftcol, toprect_toprow); II_TYPE val_topright = ceri - cecen - image.GetElement(rightrect_rightcol, toprect_toprow) + topcen; II_TYPE val_bottomleft = botcen - image.GetElement(leftrect_leftcol, bottomrect_bottomrow) - cecen + cele; II_TYPE val_bottomright = image.GetElement(rightrect_rightcol, bottomrect_bottomrow) - botcen - ceri + cecen; return val_topleft-val_topright-val_bottomleft+val_bottomright;}II_TYPE CDiagIF::ComputeScaled(const CIntegralImage& image, II_TYPE mean, int left, int top) const{ int placed_leftrect_leftcol = left + scaled_leftrect_leftcol; int placed_centercol = left + scaled_centercol; int placed_rightrect_rightcol = left + scaled_rightrect_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_rightrect_rightcol, placed_centerrow); II_TYPE cele = image.GetElement(placed_leftrect_leftcol, placed_centerrow); II_TYPE cecen = image.GetElement(placed_centercol, placed_centerrow); II_TYPE topcen = image.GetElement(placed_centercol, placed_toprect_toprow); II_TYPE botcen = image.GetElement(placed_centercol, placed_bottomrect_bottomrow); II_TYPE val_topleft = cecen - cele - topcen + image.GetElement(placed_leftrect_leftcol, placed_toprect_toprow); II_TYPE val_topright = ceri - cecen - image.GetElement(placed_rightrect_rightcol, placed_toprect_toprow) + topcen; II_TYPE val_bottomleft = botcen - image.GetElement(placed_leftrect_leftcol, placed_bottomrect_bottomrow) - cecen + cele; II_TYPE val_bottomright = image.GetElement(placed_rightrect_rightcol, placed_bottomrect_bottomrow) - botcen - ceri + cecen; II_TYPE val = val_topleft-val_topright-val_bottomleft+val_bottomright; II_TYPE scaled_val = val/m_global_scale; II_TYPE mean_adjust = m_non_overlap*mean; return scaled_val-mean_adjust;}void CDiagIF::ScaleX(II_TYPE scale_x){ if (leftrect_leftcol==-1) { scaled_leftrect_leftcol = -1; scaled_centercol = (int)((II_TYPE)(centercol+1)*scale_x) - 1; scaled_rightrect_rightcol = (int)((II_TYPE)(rightrect_rightcol-centercol)*scale_x) + scaled_centercol; } else { scaled_leftrect_leftcol = (int)((II_TYPE)leftrect_leftcol*scale_x); scaled_centercol = (int)((II_TYPE)centercol*scale_x); scaled_rightrect_rightcol = (int)((II_TYPE)rightrect_rightcol*scale_x); }}void CDiagIF::ScaleY(II_TYPE scale_y){ 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); }}void CDiagIF::Scale(II_TYPE scale_x, II_TYPE scale_y){ ScaleX(scale_x); ScaleY(scale_y); m_global_scale = scale_x*scale_y;}void CDiagIF::EvenOutScales(II_TYPE* pScale_x, II_TYPE* pScale_y, int scaled_template_width, int scaled_template_height){ int leftrect = centercol-leftrect_leftcol; int rightrect = rightrect_rightcol-centercol; II_TYPE ratio = (II_TYPE)leftrect/(II_TYPE)rightrect; int sleftrect = scaled_centercol-scaled_leftrect_leftcol; int srightrect = scaled_rightrect_rightcol-scaled_centercol; 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); ScaleX(*pScale_x); } else { // shift feature by overlap scaled_leftrect_leftcol -= overlap; scaled_centercol -= overlap; scaled_rightrect_rightcol -= overlap; *pScale_x = sratio; } } else { *pScale_x = sratio; } int toprect = centerrow-toprect_toprow; int bottomrect = bottomrect_bottomrow-centerrow; ratio = (II_TYPE)toprect/(II_TYPE)bottomrect; int stoprect = scaled_centerrow-scaled_toprect_toprow; int sbottomrect = scaled_bottomrect_bottomrow-scaled_centerrow; 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; } 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -