c 语言 文本处理范例

c 语言 文本处理范例

 

从一个文件列表中读入各个文件名,然后依次打开各个文件进行处理。

  1 void load_ann_res_files(char *dir_ann, char *dir_res,char *fn_list,char *score_pos)
  2 {
  3 
  4     FILE *F_A;
  5     char fname_a[1024];
  6     float ratio=0;
  7     FILE * LogFile;
  8 
  9     char strFileName[1024];
 10 
 11     //F_A =fopen("D:\\vc2008\\people_detect\\people_detect\\AnnotationData\\file_a.lst", "rt");
 12     F_A =fopen(fn_list, "rt");
 13     LogFile =fopen("D:\\vc2008\\people_detect\\people_detect\\Log.txt","wb+");
 14     if(F_A==NULL)
 15         return;
 16     FILE *SCORE_POS =fopen(score_pos,"wb+");
 17     float tmp_score =0.5;
 18     while(!feof(F_A))
 19     {
 20         int i=0;
 21         int j=0;
 22         fscanf(F_A,"%s\n",&fname_a);
 23         fprintf(LogFile,"%s\n",fname_a);
 24         
 25         char str_a[1024];
 26         //sprintf(str_a, "D:\\vc2008\\people_detect\\people_detect\\AnnotationData\\");
 27         //strcat(str_a,fname_a);
 28         strcpy(str_a,dir_ann);
 29         strcat(str_a,fname_a);
 30         char str_r[1024];
 31         //sprintf(str_r, "D:\\vc2008\\people_detect\\people_detect\\ResultData\\");
 32         //strcat(str_r,fname_a);
 33         strcpy(str_r,dir_res);
 34         strcat(str_r,fname_a);
 35 
 36         FILE *ANN;
 37         ANN =fopen(str_a, "rt");        
 38         if(ANN==NULL)
 39             continue;
 40 
 41         FILE *RES;
 42         RES =fopen(str_r, "rt");        
 43         if(RES==NULL)
 44             continue;
 45 
 46         //char picname[1024];
 47         //fscanf(ANN,"%s\n",&picname);
 48 
 49         //Load annotation data
 50         fprintf(LogFile,"****************annotation data***************\n");
 51         int num_a;
 52         fscanf(ANN,"%d\n",&num_a);
 53         fprintf(LogFile,"%d\n",num_a);
 54 
 55         struct points *P_A;
 56         P_A =(struct points *)malloc(sizeof(struct points)*num_a);
 57 
 58 
 59         for(i=0;i<num_a;i++)
 60         {
 61             fscanf(ANN,"%d %d %d %d\n",&((P_A+i)->lt_x), &((P_A+i)->lt_y), &((P_A+i)->rb_x), &((P_A+i)->rb_y));
 62             fprintf(LogFile,"%d %d %d %d\n",(P_A+i)->lt_x, (P_A+i)->lt_y, (P_A+i)->rb_x, (P_A+i)->rb_y);
 63         }
 64         
 65 
 66         // Load result data
 67         fprintf(LogFile,"****************result data*******************\n");
 68         int num_r;
 69         fscanf(RES,"%d\n",&num_r);
 70         fprintf(LogFile,"%d\n",num_r);
 71 
 72         struct points *P_R;
 73         P_R =(struct points *)malloc(sizeof(struct points)*num_r);
 74 
 75 
 76         for(i=0;i<num_r;i++)
 77         {
 78             fscanf(RES,"%d %d %d %d\n",&((P_R+i)->lt_x), &((P_R+i)->lt_y), &((P_R+i)->rb_x), &((P_R+i)->rb_y));
 79             fprintf(LogFile,"%d %d %d %d\n",(P_R+i)->lt_x, (P_R+i)->lt_y, (P_R+i)->rb_x, (P_R+i)->rb_y);
 80         }
 81 
 82 
 83         //Compare result with annotation data
 84         //float calculate_area(int x_lf,int y_lf,int x_rb,int y_rb, int x_lf_a, int y_lf_a, int x_rb_a, int y_rb_a)
 85         fprintf(LogFile,"****************compare result*******************\n");
 86         for(i=0;i<num_r;i++)
 87         {
 88             for(j=0;j<num_a;j++)
 89             {
 90                 ratio =calculate_area((P_R+i)->lt_x, (P_R+i)->lt_y, (P_R+i)->rb_x, (P_R+i)->rb_y,
 91                                         (P_A+j)->lt_x, (P_A+j)->lt_y, (P_A+j)->rb_x, (P_A+j)->rb_y);
 92                 if(ratio>0.5)
 93                 {                
 94                     fprintf(LogFile,"overlapping area ratio between %dth result data and %dth annotation is: %f\n",i,j,ratio);
 95                     fprintf(SCORE_POS,"%f ",tmp_score);
 96                 }
 97             }
 98         }
 99         fprintf(LogFile,"\n \n");
100         free(P_A);
101         free(P_R);
102         fclose(ANN);
103         fclose(RES);
104     }
105     fclose(F_A);
106     fclose(SCORE_POS);
107 }

 

 

 

posted on 2010-12-30 18:13  Homography Matrix  阅读(887)  评论(0编辑  收藏  举报

导航