資源簡介
該代碼實現了boosting算法的每一條步驟,用C++語言實現,比較完整。
代碼片段和文件信息
//?Boosting.cpp:?implementation?of?the?Boosting?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“BoostingLbp.h“
#include?“Boosting.h“
#include?“math.h“
#include?“stdio.h“
#include?“Define.h“
#include?“HarrFeature.h“
#ifdef?_DEBUG
#undef?THIS_FILE
static?char?THIS_FILE[]=__FILE__;
#define?new?DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
Boosting::Boosting(DWORD?posNum?DWORD?negNum)
{
????????PositiveNum?=?posNum;
????????NegativeNum?=?negNum;
????????TotalNegativeNum?=?negNum;
????????TotalSampleNum?=?PositiveNum?+?NegativeNum;
????????unsigned?char?*pFlag?=?new?unsigned?char[TOTAL_FEATURE_NUM];
????????// FILE?*fFlag?=?fopen(SAVEPATH?+?“flag“?“rb“);
????????// fread(pFlag?sizeof(unsigned?char)?TOTAL_FEATURE_NUM?fFlag);
????????// fclose(fFlag);
????????memset(pFlag?1?TOTAL_FEATURE_NUM);
????????usedFeaCount?=?0;
????????for?(int?c=0;?c ????????{
????????????????if?(pFlag[c]?==?1)?usedFeaCount++;
????????}
????????delete?[]pFlag;
????????BinMin?=?NULL;
????????BinWidth?=?NULL;
????????FeaValue?=?NULL;
????????subWinInfo?=?new?FeatureInfo[usedFeaCount];
????????Weight?=?new?double[TotalSampleNum];
????????VotedValue?=?new?double[TotalSampleNum];
????????Label?=?new?unsigned?char[TotalSampleNum];
????????memset(Label?1??PositiveNum);
????????memset(Label?+?PositiveNum?0?NegativeNum);
}
Boosting::~Boosting()
{
????????delete?[]BinMin;
????????BinMin?=?NULL;
????????delete?[]BinWidth;
????????BinWidth?=?NULL;
????????delete?[]Weight;
????????Weight?=?NULL;
????????delete?[]VotedValue;
????????VotedValue?=?NULL;
????????delete?[]Label;
????????Label?=?NULL;
????????if?(NULL?!=?FeaValue)
????????{
????????????????for(int?i=0;?i ????????????????{
????????????????????????if(FeaValue[i]?!=?NULL)?
????????????????????????{
????????????????????????????????delete?[]?FeaValue[i];
????????????????????????????????FeaValue[i]?=?NULL;
????????????????????????}
????????????????}
????????????????FeaValue?=?NULL;
????????}
????????if?(subWinInfo?!=?NULL)?delete?[]subWinInfo;
????????return;
}
//Quantize?and?the?LBP?bin?distance.
void?Boosting::Init(CString?szPosName?CString?szNegName)
{
????????GetAllSubWinInfo();
????????printf(“\n“);
????????printf(“Total?Weak?Learner:?%d\n“?usedFeaCount);
????????printf(“Positive?Sample?Number:?%d\n“?PositiveNum);
????????printf(“Negative?Sample?Number:?%d\n“?NegativeNum);
????????printf(“\n“);
????????CString?szPosPath?=?szPosName;
????????CString?szNegPath?=?szNegName;
????????FILE?*PosFile?=?fopen(szPosPath?“rb“);
????????FILE?*NegFile?=?fopen(szNegPath?“rb“);
????????//Quantize?the?distance?to?be?between?0?and?99.
????????BinMin???=?new?doubl
- 上一篇:C語言課設之校級運動會管理系統
- 下一篇:三次樣條插值算法C++實現
評論
共有 條評論