반응형
중요 코드
//가중치 갱신, 및 약분류기 신뢰도 계산 함수
float icvBoostNextWeakClassifierGAB( CvMat* weakEvalVals, CvMat* trainClasses, CvMat* /*weakTrainVals*/, CvMat* weights, CvBoostTrainer* trainer ) { uchar* evaldata; int evalstep; int m; uchar* ydata; int ystep; int ynum; uchar* wdata; int wstep; int wnum; int i, idx; float sumw; CV_Assert( weakEvalVals != NULL ); CV_Assert( CV_MAT_TYPE( weakEvalVals->type ) == CV_32FC1 ); CV_Assert( trainClasses != NULL ); CV_Assert( CV_MAT_TYPE( trainClasses->type ) == CV_32FC1 ); CV_Assert( weights != NULL ); CV_Assert( CV_MAT_TYPE( weights->type ) == CV_32FC1 ); CV_MAT2VEC( *weakEvalVals, evaldata, evalstep, m ); CV_MAT2VEC( *trainClasses, ydata, ystep, ynum ); CV_MAT2VEC( *weights, wdata, wstep, wnum ); assert( m == ynum ); assert( m == wnum ); sumw = 0.0F; for( i = 0; i < trainer->count; i++ ) { idx = (trainer->idx) ? trainer->idx[i] : i; *((float*) (wdata + idx*wstep)) *= expf( -(*((float*) (evaldata + idx*evalstep))) * ( 2.0F * (*((float*) (ydata + idx*ystep))) - 1.0F ) ); sumw += *((float*) (wdata + idx*wstep)); } for( i = 0; i < trainer->count; i++ ) { idx = (trainer->idx) ? trainer->idx[i] : i; *((float*) (wdata + idx*wstep)) /= sumw; } return 1.0F; }
//평가 함수
float icvEvalCARTHaarClassifier( CvIntHaarClassifier* classifier, sum_type* sum, sum_type* tilted, float normfactor ) { int idx = 0; do { if( cvEvalFastHaarFeature( ((CvCARTHaarClassifier*) classifier)->fastfeature + idx, sum, tilted ) < (((CvCARTHaarClassifier*) classifier)->threshold[idx] * normfactor) ) { idx = ((CvCARTHaarClassifier*) classifier)->left[idx]; } else { idx = ((CvCARTHaarClassifier*) classifier)->right[idx]; } } while( idx > 0 ); return ((CvCARTHaarClassifier*) classifier)->val[-idx]; }
반응형
'Algorithm' 카테고리의 다른 글
OpenCV Adaboost 분석(3) (0) | 2013.05.12 |
---|---|
다양한 Boosting 알고리즘 (0) | 2013.05.08 |
OpenCV Adaboost 분석 (0) | 2013.05.03 |
OpenCV에서 사용하는 Labeling(레이블링, 라벨링) (0) | 2013.04.29 |
[AGAST] Adaptive and Generic Corner Detection Based on the Accelerated Segment Test (0) | 2013.04.23 |