Mercurial > hg > nsaunier > traffic-intelligence
comparison c/track-features.cpp @ 20:ef0d7caf8e91
draft code for feature saving (UBC format)
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Sat, 28 Nov 2009 01:56:46 -0500 |
| parents | ef35d5f111e4 |
| children | a52653dca25d |
comparison
equal
deleted
inserted
replaced
| 19:5a21d2cfee44 | 20:ef0d7caf8e91 |
|---|---|
| 140 | 140 |
| 141 // writing feature file | 141 // writing feature file |
| 142 fnameout = "features.txt";//"features-"%s"-"%d"-"%d"-"%d".txt", sequenceFile, nFeatures, tc->mindist, tc->window_width); | 142 fnameout = "features.txt";//"features-"%s"-"%d"-"%d"-"%d".txt", sequenceFile, nFeatures, tc->mindist, tc->window_width); |
| 143 //KLTWriteFeatureTable(ft, fnameout, "%5.1f"); | 143 //KLTWriteFeatureTable(ft, fnameout, "%5.1f"); |
| 144 | 144 |
| 145 out = fopen(fnameout.c_str(),"w"); | 145 int precision = 2; |
| 146 if(out!=NULL){ | 146 ofstream out; |
| 147 fprintf(out,"%%StartFrame: 0\n"); | 147 openWriteScientific(out, fnameout, precision);//out = fopen(fnameout.c_str(),"w"); |
| 148 fprintf(out,"%%NumFrames: %d\n",nFrames); | 148 |
| 149 //fprintf(out,"%%StartFrame: 0\n"); | |
| 150 //fprintf(out,"%%NumFrames: %d\n",nFrames); | |
| 149 | 151 |
| 150 // 1 feature / line | 152 // 1 feature / line |
| 151 // x1 y1 val1 x2 y2 val2 ... (1 2... frame numbers) | 153 // x1 y1 val1 x2 y2 val2 ... (1 2... frame numbers) |
| 152 for (j = 0 ; j < ft->nFeatures ; j++) { | 154 for (j = 0 ; j < ft->nFeatures ; j++) { |
| 153 fprintf(out, "\n"); | 155 int firstFrameNum = startFrame; |
| 154 for (i = 0 ; i < ft->nFrames ; i++){ | 156 stringstream lx, ly; |
| 155 feature = ft->feature[j][i]; | 157 for (i = 0 ; i < ft->nFrames ; i++){ |
| 156 fprintf(out,"%.2f %.2f %d ",(float)feature->x,(float)feature->y,FEAT_VAL(feature->val)); | 158 feature = ft->feature[j][i]; |
| 157 } | 159 //fprintf(out,"%.2f %.2f %d ",(float)feature->x,(float)feature->y,FEAT_VAL(feature->val)); |
| 158 } | 160 lx << feature->x << " "; |
| 161 ly << feature->y << " "; | |
| 162 if (feature->val <= 0) { | |
| 163 // print the feature | |
| 164 out << firstFrameNum << " " << startFrame+i << endl; | |
| 165 out << lx << endl; | |
| 166 out << ly << endl; | |
| 167 // velocity | |
| 168 out << "%" << endl; | |
| 169 firstFrameNum = i+1; | |
| 170 lx.clear(); | |
| 171 ly.clear(); | |
| 172 } | |
| 159 | 173 |
| 160 fclose(out); | 174 //fclose(out); |
| 161 } | |
| 162 else | |
| 163 printf("\nError opening feature file\n"); | |
| 164 | 175 |
| 165 cvReleaseCapture(&sequence); | 176 cvReleaseCapture(&sequence); |
| 166 | 177 |
| 167 return 1; | 178 return 1; |
| 168 } | 179 } |
