void parserV (FILE * xmlf, int /*p*/, CvLSVMFilterObject * model){ int st = 0; int tag; int tagVal; char ch; int i,j; char buf[1024]; char tagBuf[1024]; //printf(" <V>\n"); i = 0; j = 0; st = 0; tag = 0; while(!feof(xmlf)){ ch = (char)fgetc( xmlf ); if(ch == '<'){ tag = 1; j = 1; tagBuf[j - 1] = ch; }else { if(ch == '>'){ tagBuf[j ] = ch; tagBuf[j + 1] = '\0'; tagVal = getTeg(tagBuf); if(tagVal == ETAGV){ //printf(" </V>\n"); return; } if(tagVal == Vx){ st = 1; i = 0; } if(tagVal == EVx){ st = 0; buf[i] = '\0'; model->V.x = atoi(buf); //printf(" <Vx>%d</Vx>\n", model->V.x); } if(tagVal == Vy){ st = 1; i = 0; } if(tagVal == EVy){ st = 0; buf[i] = '\0'; model->V.y = atoi(buf); //printf(" <Vy>%d</Vy>\n", model->V.y); } tag = 0; i = 0; }else{ if((tag == 0)&& (st == 1)){ buf[i] = ch; i++; }else{ tagBuf[j] = ch; j++; } } } } }
void parserD (FILE * xmlf, int /*p*/, CvLSVMFilterObject * model){ int st = 0; int tag; int tagVal; char ch; int i,j; char buf[1024]; char tagBuf[1024]; //printf(" <D>\n"); i = 0; j = 0; st = 0; tag = 0; while(!feof(xmlf)){ ch = (char)fgetc( xmlf ); if(ch == '<'){ tag = 1; j = 1; tagBuf[j - 1] = ch; }else { if(ch == '>'){ tagBuf[j ] = ch; tagBuf[j + 1] = '\0'; tagVal = getTeg(tagBuf); if(tagVal == ETAGD){ //printf(" </D>\n"); return; } if(tagVal == Dx){ st = 1; i = 0; } if(tagVal == EDx){ st = 0; buf[i] = '\0'; model->fineFunction[0] = (float)atof(buf); //printf(" <Dx>%f</Dx>\n", model->fineFunction[0]); } if(tagVal == Dy){ st = 1; i = 0; } if(tagVal == EDy){ st = 0; buf[i] = '\0'; model->fineFunction[1] = (float)atof(buf); //printf(" <Dy>%f</Dy>\n", model->fineFunction[1]); } if(tagVal == Dxx){ st = 1; i = 0; } if(tagVal == EDxx){ st = 0; buf[i] = '\0'; model->fineFunction[2] = (float)atof(buf); //printf(" <Dxx>%f</Dxx>\n", model->fineFunction[2]); } if(tagVal == Dyy){ st = 1; i = 0; } if(tagVal == EDyy){ st = 0; buf[i] = '\0'; model->fineFunction[3] = (float)atof(buf); //printf(" <Dyy>%f</Dyy>\n", model->fineFunction[3]); } tag = 0; i = 0; }else{ if((tag == 0)&& (st == 1)){ buf[i] = ch; i++; }else{ tagBuf[j] = ch; j++; } } } } }
void parserRFilter (FILE * xmlf, int p, CvLSVMFilterObject * model, float *b){ int st = 0; int sizeX=0, sizeY=0; int tag; int tagVal; char ch; int i,j,ii; char buf[1024]; char tagBuf[1024]; double *data; //printf("<RootFilter>\n"); model->V.x = 0; model->V.y = 0; model->V.l = 0; model->fineFunction[0] = 0.0; model->fineFunction[1] = 0.0; model->fineFunction[2] = 0.0; model->fineFunction[3] = 0.0; i = 0; j = 0; st = 0; tag = 0; while(!feof(xmlf)){ ch = (char)fgetc( xmlf ); if(ch == '<'){ tag = 1; j = 1; tagBuf[j - 1] = ch; }else { if(ch == '>'){ tagBuf[j ] = ch; tagBuf[j + 1] = '\0'; tagVal = getTeg(tagBuf); if(tagVal == ERFILTER){ //printf("</RootFilter>\n"); return; } if(tagVal == SIZEX){ st = 1; i = 0; } if(tagVal == ESIZEX){ st = 0; buf[i] = '\0'; sizeX = atoi(buf); model->sizeX = sizeX; //printf("<sizeX>%d</sizeX>\n", sizeX); } if(tagVal == SIZEY){ st = 1; i = 0; } if(tagVal == ESIZEY){ st = 0; buf[i] = '\0'; sizeY = atoi(buf); model->sizeY = sizeY; //printf("<sizeY>%d</sizeY>\n", sizeY); } if(tagVal == WEIGHTS){ data = (double *)malloc( sizeof(double) * p * sizeX * sizeY); fread(data, sizeof(double), p * sizeX * sizeY, xmlf); model->H = (float *)malloc(sizeof(float)* p * sizeX * sizeY); for(ii = 0; ii < p * sizeX * sizeY; ii++){ model->H[ii] = (float)data[ii]; } free(data); } if(tagVal == EWEIGHTS){ //printf("WEIGHTS OK\n"); } if(tagVal == BTAG){ st = 1; i = 0; } if(tagVal == EBTAG){ st = 0; buf[i] = '\0'; *b =(float) atof(buf); //printf("<B>%f</B>\n", *b); } tag = 0; i = 0; }else{ if((tag == 0)&& (st == 1)){ buf[i] = ch; i++; }else{ tagBuf[j] = ch; j++; } } } } }
void parserModel(FILE * xmlf, CvLSVMFilterObjectCascade *** model, int *last, int *max, int **comp, float **b, int *count, float * score, float** PCAcoeff){ int p = 0, pca = 0; int N_comp = 0; int * cmp; float *bb; int st = 0; int tag; int tagVal; char ch; int i,j, ii = 0, jj; char buf[1024]; char tagBuf[1024]; double *data; //printf("<Model>\n"); i = 0; j = 0; st = 0; tag = 0; while(!feof(xmlf)){ ch = (char)fgetc( xmlf ); if(ch == '<'){ tag = 1; j = 1; tagBuf[j - 1] = ch; }else { if(ch == '>'){ tagBuf[j ] = ch; tagBuf[j + 1] = '\0'; tagVal = getTeg(tagBuf); if(tagVal == EMODEL){ //printf("</Model>\n"); for(ii = 0; ii <= *last; ii++){ (*model)[ii]->numFeatures = p; } * count = N_comp; return; } if(tagVal == COMP){ if(N_comp == 0){ cmp = (int *)malloc(sizeof(int)); bb = (float *)malloc(sizeof(float)); * comp = cmp; * b = bb; * count = N_comp + 1; } else { cmp = (int *)malloc(sizeof(int) * (N_comp + 1)); bb = (float *)malloc(sizeof(float) * (N_comp + 1)); for(ii = 0; ii < N_comp; ii++){ cmp[ii] = (* comp)[ii]; bb [ii] = (* b )[ii]; } free(* comp); free(* b ); * comp = cmp; * b = bb; * count = N_comp + 1; } parserComp(xmlf, p, pca, &N_comp, model, &((*b)[N_comp]), last, max); cmp[N_comp - 1] = *last; } if(tagVal == P){ st = 1; i = 0; } if(tagVal == EP){ st = 0; buf[i] = '\0'; p = atoi(buf); //printf("<P>%d</P>\n", p); } if(tagVal == PCA){ st = 1; i = 0; } if(tagVal == EPCA){ st = 0; buf[i] = '\0'; pca = atoi(buf); //printf("<PCA>%d</PCA>\n", p); } if(tagVal == SCORE){ st = 1; i = 0; } if(tagVal == PCACOEFF){ st = 0; i = 0; p--; data = (double *)malloc( sizeof(double) * p * p); (*PCAcoeff) = (float *)malloc( sizeof(float) * p * p); CV_Assert(fread(data, sizeof(double), p * p, xmlf)); for(jj = 0; jj < p * p; jj++){ (*PCAcoeff)[jj] = (float)data[jj]; } free(data); p++; } if(tagVal == EPCACOEFF){ st = 0; //printf("<PCA>%d</PCA>\n", p); } if(tagVal == SCORE){ st = 1; i = 0; } if(tagVal == ESCORE){ st = 0; buf[i] = '\0'; *score = (float)atof(buf); //printf("<ScoreThreshold>%f</ScoreThreshold>\n", score); } tag = 0; i = 0; }else{ if((tag == 0)&& (st == 1)){ buf[i] = ch; i++; }else{ tagBuf[j] = ch; j++; } } } } }
void parserPFilter (FILE * xmlf, int p, int pca, int /*N_path*/, CvLSVMFilterObjectCascade * model){ int st = 0; int sizeX = 0, sizeY = 0; int tag; int tagVal; char ch; int i,j, ii; char buf[1024]; char tagBuf[1024]; double *data; //printf("<PathFilter> (%d)\n", N_path); model->V.x = 0; model->V.y = 0; model->V.l = 0; model->fineFunction[0] = 0.0f; model->fineFunction[1] = 0.0f; model->fineFunction[2] = 0.0f; model->fineFunction[3] = 0.0f; i = 0; j = 0; st = 0; tag = 0; while(!feof(xmlf)){ ch = (char)fgetc( xmlf ); if(ch == '<'){ tag = 1; j = 1; tagBuf[j - 1] = ch; }else { if(ch == '>'){ tagBuf[j ] = ch; tagBuf[j + 1] = '\0'; tagVal = getTeg(tagBuf); if(tagVal == EPFILTER){ //printf("</PathFilter>\n"); return; } if(tagVal == TAGV){ parserV(xmlf, p, model); } if(tagVal == TAGD){ parserD(xmlf, p, model); } if(tagVal == SIZEX){ st = 1; i = 0; } if(tagVal == ESIZEX){ st = 0; buf[i] = '\0'; sizeX = atoi(buf); model->sizeX = sizeX; //printf("<sizeX>%d</sizeX>\n", sizeX); } if(tagVal == SIZEY){ st = 1; i = 0; } if(tagVal == ESIZEY){ st = 0; buf[i] = '\0'; sizeY = atoi(buf); model->sizeY = sizeY; //printf("<sizeY>%d</sizeY>\n", sizeY); } if(tagVal == WEIGHTS){ data = (double *)malloc( sizeof(double) * p * sizeX * sizeY); CV_Assert(fread(data, sizeof(double), p * sizeX * sizeY, xmlf)); model->H = (float *)malloc(sizeof(float)* p * sizeX * sizeY); for(ii = 0; ii < p * sizeX * sizeY; ii++){ model->H[ii] = (float)data[ii]; } free(data); } if(tagVal == WEIGHTSPCA){ data = (double *)malloc( sizeof(double) * pca * sizeX * sizeY); CV_Assert(fread(data, sizeof(double), pca * sizeX * sizeY, xmlf)); model->H_PCA = (float *)malloc(sizeof(float)* pca * sizeX * sizeY); for(ii = 0; ii < pca * sizeX * sizeY; ii++){ model->H_PCA[ii] = (float)data[ii]; } free(data); } if(tagVal == CASCADE_Th){ parserCascadeThresholds (xmlf, model); } if(tagVal == EWEIGHTS){ //printf("WEIGHTS OK\n"); } tag = 0; i = 0; }else{ if((tag == 0)&& (st == 1)){ buf[i] = ch; i++; }else{ tagBuf[j] = ch; j++; } } } } }
//############################################## void parserCascadeThresholds (FILE * xmlf, CvLSVMFilterObjectCascade * model){ int st = 0; int tag; int tagVal; char ch; int i,j; char buf[1024]; char tagBuf[1024]; i = 0; j = 0; st = 0; tag = 0; while(!feof(xmlf)){ ch = (char) fgetc( xmlf ); if(ch == '<'){ tag = 1; j = 1; tagBuf[j - 1] = ch; }else { if(ch == '>'){ tagBuf[j ] = ch; tagBuf[j + 1] = '\0'; tagVal = getTeg(tagBuf); if(tagVal == ECASCADE_Th){ return; } if(tagVal == HYPOTHES_PCA){ st = 1; i = 0; } if(tagVal == EHYPOTHES_PCA){ st = 0; buf[i] = '\0'; model->Hypothesis_PCA =(float) atof(buf); } if(tagVal == DEFORM_PCA){ st = 1; i = 0; } if(tagVal == EDEFORM_PCA){ st = 0; buf[i] = '\0'; model->Deformation_PCA =(float) atof(buf); } if(tagVal == HYPOTHES){ st = 1; i = 0; } if(tagVal == EHYPOTHES){ st = 0; buf[i] = '\0'; model->Hypothesis = (float)atof(buf); } if(tagVal == DEFORM){ st = 1; i = 0; } if(tagVal == EDEFORM){ st = 0; buf[i] = '\0'; model->Deformation = (float)atof(buf); } tag = 0; i = 0; }else{ if((tag == 0)&& (st == 1)){ buf[i] = ch; i++; }else{ tagBuf[j] = ch; j++; } } } } }
void parserModel(FILE * xmlf, CvLSVMFilterObject *** model, int *last, int *max, int **comp, float **b, int *count, float * score){ int p = 0; int N_comp = 0; int * cmp; float *bb; int st = 0; int tag; int tagVal; char ch; int i,j, ii = 0; char buf[1024]; char tagBuf[1024]; //printf("<Model>\n"); i = 0; j = 0; st = 0; tag = 0; while(!feof(xmlf)){ ch = (char)fgetc( xmlf ); if(ch == '<'){ tag = 1; j = 1; tagBuf[j - 1] = ch; }else { if(ch == '>'){ tagBuf[j ] = ch; tagBuf[j + 1] = '\0'; tagVal = getTeg(tagBuf); if(tagVal == EMODEL){ //printf("</Model>\n"); for(ii = 0; ii <= *last; ii++){ (*model)[ii]->numFeatures = p; } * count = N_comp; return; } if(tagVal == COMP){ if(N_comp == 0){ cmp = (int *)malloc(sizeof(int)); bb = (float *)malloc(sizeof(float)); * comp = cmp; * b = bb; * count = N_comp + 1; } else { cmp = (int *)malloc(sizeof(int) * (N_comp + 1)); bb = (float *)malloc(sizeof(float) * (N_comp + 1)); for(ii = 0; ii < N_comp; ii++){ cmp[ii] = (* comp)[ii]; bb [ii] = (* b )[ii]; } free(* comp); free(* b ); * comp = cmp; * b = bb; * count = N_comp + 1; } parserComp(xmlf, p, &N_comp, model, &((*b)[N_comp]), last, max); cmp[N_comp - 1] = *last; } if(tagVal == P){ st = 1; i = 0; } if(tagVal == EP){ st = 0; buf[i] = '\0'; p = atoi(buf); //printf("<P>%d</P>\n", p); } if(tagVal == SCORE){ st = 1; i = 0; } if(tagVal == ESCORE){ st = 0; buf[i] = '\0'; *score = (float)atof(buf); //printf("<ScoreThreshold>%f</ScoreThreshold>\n", score); } tag = 0; i = 0; }else{ if((tag == 0)&& (st == 1)){ buf[i] = ch; i++; }else{ tagBuf[j] = ch; j++; } } } } }