📄 integralfeaturessame.cpp
字号:
/** * cubicles * * This is an implementation of the Viola-Jones object detection * method and some extensions. The code is mostly platform- * independent and uses only standard C and C++ libraries. It * can make use of MPI for parallel training and a few Windows * MFC functions for classifier display. * * Mathias Kolsch, matz@cs.ucsb.edu * * $Id: IntegralFeaturesSame.cpp,v 1.29 2004/11/11 01:58:58 matz Exp $**/// IntegralFeatures describe the rectangular areas whose pixel// sums are compared to a weak classifier's threshold. There// are many different types of IntegralFeatures.// IntegralFeaturesSame are features just as IntegralFeatures, // but their rectangular regions observe more stringent constraints// during feature instance generation (see SetToNextIncarnation).// Functions for reading from files are flex/bison generated from// CascadeFileScanner.lex and CascadeFileParser.yy.////////////////////////////////////////////////////////////////////////// By downloading, copying, installing or using the software you // agree to this license. If you do not agree to this license, // do not download, install, copy or use the software.//// Copyright (C) 2004, Mathias Kolsch, all rights reserved.// Third party copyrights are property of their respective owners.//// Redistribution and use in binary form, with or without // modification, is permitted for non-commercial purposes only.// Redistribution in source, with or without modification, is // prohibited without prior written permission.// If granted in writing in another document, personal use and // modification are permitted provided that the following two// conditions are met://// 1.Any modification of source code must retain the above // copyright notice, this list of conditions and the following // disclaimer.//// 2.Redistribution's in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided// with the distribution.//// This software is provided by the copyright holders and // contributors "as is" and any express or implied warranties, // including, but not limited to, the implied warranties of // merchantability and fitness for a particular purpose are // disclaimed. In no event shall the copyright holder or // contributors be liable for any direct, indirect, incidental, // special, exemplary, or consequential damages (including, but not // limited to, procurement of substitute goods or services; loss of // use, data, or profits; or business interruption) however caused// and on any theory of liability, whether in contract, strict // liability, or tort (including negligence or otherwise) arising // in any way out of the use of this software, even if advised of // the possibility of such damage.//////////////////////////////////////////////////////////////////////#include "cubicles.hpp"#include "IntegralFeatures.h"#include "Exceptions.h"#include <iostream>#ifdef _DEBUG#ifdef USE_MFC#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif // USE_MFC#endif // _DEBUG#ifdef WIN32#include <malloc.h>#define alloca _alloca#endif///////////////////////////////////////////////////////////////////////////////// CLeftRightSameIF classes implementation///////////////////////////////////////////////////////////////////////////////CLeftRightSameIF::CLeftRightSameIF(int templateWidth, int templateHeight) : CLeftRightIF(templateWidth, templateHeight) {}CLeftRightSameIF::CLeftRightSameIF(const CLeftRightSameIF& frm) : CLeftRightIF(frm) {}CLeftRightSameIF::CLeftRightSameIF(int templateWidth, int templateHeight, int _toprow, int _bottomrow, int _leftrect_leftcol, int _centercol, int _rightrect_rightcol) : CLeftRightIF(templateWidth, templateHeight) { toprow = _toprow; bottomrow = _bottomrow; leftrect_leftcol = _leftrect_leftcol; centercol = _centercol; rightrect_rightcol = _rightrect_rightcol; SetNonOverlap();}CLeftRightSameIF::CLeftRightSameIF(istream& is, int template_width, int template_height) : CLeftRightIF(template_width, template_height){ char a, b, c; string str; is >> toprow >> a >> bottomrow >> str >> leftrect_leftcol >> b >> centercol >> c >> rightrect_rightcol; if (a!=',' || b!=',' || c!=',' || str!="x") { char* buf = (char*) alloca((256+str.length())*sizeof(char)); sprintf(buf, "error during construction of LeftRightSameIF (%c|%c|%c|%s)\n", a, b, c, str.c_str()); throw ITException(buf); } SetNonOverlap();}bool CLeftRightSameIF::SetToNextIncarnation(){ if (m_is_partial) { if (m_remaining_incarnations) { m_remaining_incarnations--; } else { return false; } } rightrect_rightcol+=2; centercol++; if (rightrect_rightcol>=m_template_width) { 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* CLeftRightSameIF::Copy() const{ return new CLeftRightSameIF(*this);}ostream& CLeftRightSameIF::output(ostream& os) const{ os << "LeftRightSame " << toprow << "," << bottomrow << " x "; os << leftrect_leftcol << "," << centercol << "," << rightrect_rightcol; return os;}///////////////////////////////////////////////////////////////////////////////// CUpDownSameIF classes implementation///////////////////////////////////////////////////////////////////////////////CUpDownSameIF::CUpDownSameIF(int templateWidth, int templateHeight) : CUpDownIF(templateWidth, templateHeight) {}CUpDownSameIF::CUpDownSameIF(const CUpDownSameIF& frm) : CUpDownIF(frm) {}CUpDownSameIF::CUpDownSameIF(int templateWidth, int templateHeight, int _toprect_toprow, int _centerrow, int _bottomrect_bottomrow, int _leftcol, int _rightcol) : CUpDownIF(templateWidth, templateHeight) { toprect_toprow = _toprect_toprow; centerrow = _centerrow; bottomrect_bottomrow = _bottomrect_bottomrow; leftcol = _leftcol; rightcol = _rightcol; SetNonOverlap();}CUpDownSameIF::CUpDownSameIF(istream& is, int templateWidth, int templateHeight) : CUpDownIF(templateWidth, templateHeight) { 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 UpDownSameIF (%c|%c|%c|%s)\n", a, b, c, str.c_str()); throw ITException(buf); } SetNonOverlap();}bool CUpDownSameIF::SetToNextIncarnation(){ if (m_is_partial) { if (m_remaining_incarnations) { m_remaining_incarnations--; } else { return false; } } bottomrect_bottomrow+=2; centerrow++; if (bottomrect_bottomrow>=m_template_height) { toprect_toprow++; if (toprect_toprow==m_template_height-2) { rightcol++; if (rightcol==m_template_width) { leftcol++; 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* CUpDownSameIF::Copy() const{ return new CUpDownSameIF(*this);}ostream& CUpDownSameIF::output(ostream& os) const{ os << "UpDownSame " << toprect_toprow << "," << centerrow << "," << bottomrect_bottomrow << " x "; os << leftcol << "," << rightcol; return os;}///////////////////////////////////////////////////////////////////////////////// CLeftCenterRightSameIF classes implementation///////////////////////////////////////////////////////////////////////////////CLeftCenterRightSameIF::CLeftCenterRightSameIF(int templateWidth, int templateHeight) : CLeftCenterRightIF(templateWidth, templateHeight) {}CLeftCenterRightSameIF::CLeftCenterRightSameIF(int templateWidth, int templateHeight, int _toprow, int _bottomrow, int _leftrect_leftcol, int _leftrect_rightcol, int _rightrect_leftcol, int _rightrect_rightcol) : CLeftCenterRightIF(templateWidth, templateHeight) { toprow = _toprow; bottomrow = _bottomrow; leftrect_leftcol = _leftrect_leftcol; leftrect_rightcol = _leftrect_rightcol; rightrect_leftcol = _rightrect_leftcol; rightrect_rightcol = _rightrect_rightcol; SetNonOverlap();}CLeftCenterRightSameIF::CLeftCenterRightSameIF(const CLeftCenterRightSameIF& frm) : CLeftCenterRightIF(frm) {}CLeftCenterRightSameIF::CLeftCenterRightSameIF(istream& is, int templateWidth, int templateHeight) : CLeftCenterRightIF(templateWidth, templateHeight) { 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 LeftCenterRightSameIF (%c|%c|%c|%s|%s)\n", a, b, c, strx.c_str(), strslash.c_str()); throw ITException(buf); } SetNonOverlap();}bool CLeftCenterRightSameIF::SetToNextIncarnation(){ if (m_is_partial) { if (m_remaining_incarnations) { m_remaining_incarnations--; } else { return false; } } rightrect_rightcol+=3; rightrect_leftcol+=2; leftrect_rightcol++; if (rightrect_rightcol>=m_template_width) { 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;}CIntegralFeature* CLeftCenterRightSameIF::Copy() const { return new CLeftCenterRightSameIF(*this);}ostream& CLeftCenterRightSameIF::output(ostream& os) const{ os << "LeftCenterRightSame " << toprow << "," << bottomrow << " x "; os << leftrect_leftcol << "," << leftrect_rightcol << " / "; os << rightrect_leftcol << "," << rightrect_rightcol; return os;}///////////////////////////////////////////////////////////////////////////////// CSevenColumnsSameIF classes implementation///////////////////////////////////////////////////////////////////////////////CSevenColumnsSameIF::CSevenColumnsSameIF(int templateWidth, int templateHeight) : CSevenColumnsIF(templateWidth, templateHeight) {}CSevenColumnsSameIF::CSevenColumnsSameIF(int templateWidth, int templateHeight, int _toprow, int _bottomrow, int _1, int _2, int _3, int _4, int _5, int _6, int _7, int _8) : CSevenColumnsIF(templateWidth, templateHeight) { toprow = _toprow; bottomrow = _bottomrow; col1_left = _1; col2_left = _2; col3_left = _3; col4_left = _4; col5_left = _5; col6_left = _6; col7_left = _7; col7_right = _8; SetNonOverlap();}CSevenColumnsSameIF::CSevenColumnsSameIF(const CSevenColumnsSameIF& frm) : CSevenColumnsIF(frm) {}CSevenColumnsSameIF::CSevenColumnsSameIF(istream& is, int template_width, int template_height) : CSevenColumnsIF(is, template_width, template_height){}bool CSevenColumnsSameIF::SetToNextIncarnation(){ if (m_is_partial) { if (m_remaining_incarnations) { m_remaining_incarnations--; } else { return false; } } col1_left += 1; col2_left += 2; col3_left += 3; col4_left += 4; col5_left += 5; col6_left += 6; col7_left += 7; col7_right += 8; if (col7_right>=m_template_width) { 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* CSevenColumnsSameIF::Copy() const{ return new CSevenColumnsSameIF(*this);}ostream& CSevenColumnsSameIF::output(ostream& os) const{ os << "SevenColumnsSame " << toprow << "," << bottomrow << " x "; os << col1_left << "," << col2_left << "," << col3_left << "," << col4_left << ","; os << col5_left << "," << col6_left << "," << col7_left << "," << col7_right; return os;}/////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -