static void CV_CDECL icvDefaultSplitIdx_R( int compidx, float threshold, CvMat* idx, CvMat** left, CvMat** right, void* userdata ) { CvMat* trainData = (CvMat*) userdata; int i = 0; *left = cvCreateMat( 1, trainData->rows, CV_32FC1 ); *right = cvCreateMat( 1, trainData->rows, CV_32FC1 ); (*left)->cols = (*right)->cols = 0; if( idx == NULL ) { for( i = 0; i < trainData->rows; i++ ) { if( CV_MAT_ELEM( *trainData, float, i, compidx ) < threshold ) { (*left)->data.fl[(*left)->cols++] = (float) i; } else { (*right)->data.fl[(*right)->cols++] = (float) i; } } } else { uchar* idxdata; int idxnum; int idxstep; int index; idxdata = idx->data.ptr; idxnum = (idx->rows == 1) ? idx->cols : idx->rows; idxstep = (idx->rows == 1) ? CV_ELEM_SIZE( idx->type ) : idx->step; for( i = 0; i < idxnum; i++ ) { index = (int) *((float*) (idxdata + i * idxstep)); if( CV_MAT_ELEM( *trainData, float, index, compidx ) < threshold ) { (*left)->data.fl[(*left)->cols++] = (float) index; } else { (*right)->data.fl[(*right)->cols++] = (float) index; } } } } static void CV_CDECL icvDefaultSplitIdx_C( int compidx, float threshold, CvMat* idx, CvMat** left, CvMat** right, void* userdata ) { CvMat* trainData = (CvMat*) userdata; int i = 0; *left = cvCreateMat( 1, trainData->cols, CV_32FC1 ); *right = cvCreateMat( 1, trainData->cols, CV_32FC1 ); (*left)->cols = (*right)->cols = 0; if( idx == NULL ) { for( i = 0; i < trainData->cols; i++ ) { if( CV_MAT_ELEM( *trainData, float, compidx, i ) < threshold ) { (*left)->data.fl[(*left)->cols++] = (float) i; } else { (*right)->data.fl[(*right)->cols++] = (float) i; } } } else { uchar* idxdata; int idxnum; int idxstep; int index; idxdata = idx->data.ptr; idxnum = (idx->rows == 1) ? idx->cols : idx->rows; idxstep = (idx->rows == 1) ? CV_ELEM_SIZE( idx->type ) : idx->step; for( i = 0; i < idxnum; i++ ) { index = (int) *((float*) (idxdata + i * idxstep)); if( CV_MAT_ELEM( *trainData, float, compidx, index ) < threshold ) { (*left)->data.fl[(*left)->cols++] = (float) index; } else { (*right)->data.fl[(*right)->cols++] = (float) index; } } } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-06 01:15:01