diff 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
line wrap: on
line diff
--- a/c/track-features.cpp	Fri Nov 27 19:16:12 2009 -0500
+++ b/c/track-features.cpp	Sat Nov 28 01:56:46 2009 -0500
@@ -142,25 +142,36 @@
   fnameout = "features.txt";//"features-"%s"-"%d"-"%d"-"%d".txt", sequenceFile, nFeatures, tc->mindist, tc->window_width);
   //KLTWriteFeatureTable(ft, fnameout, "%5.1f");
 
-  out = fopen(fnameout.c_str(),"w");
-  if(out!=NULL){
-    fprintf(out,"%%StartFrame: 0\n");
-    fprintf(out,"%%NumFrames: %d\n",nFrames);
+  int precision = 2;
+  ofstream out;
+  openWriteScientific(out, fnameout, precision);//out = fopen(fnameout.c_str(),"w");
+
+  //fprintf(out,"%%StartFrame: 0\n");
+  //fprintf(out,"%%NumFrames: %d\n",nFrames);
     
-    // 1 feature / line
-    // x1 y1 val1 x2 y2 val2 ... (1 2... frame numbers)
-    for (j = 0 ; j < ft->nFeatures ; j++)  {
-      fprintf(out, "\n");
-      for (i = 0 ; i < ft->nFrames ; i++){
-        feature = ft->feature[j][i];
-	fprintf(out,"%.2f %.2f %d ",(float)feature->x,(float)feature->y,FEAT_VAL(feature->val));
-      }
-    }      
+  // 1 feature / line
+  // x1 y1 val1 x2 y2 val2 ... (1 2... frame numbers)
+  for (j = 0 ; j < ft->nFeatures ; j++)  {
+    int firstFrameNum = startFrame;
+    stringstream lx, ly;
+    for (i = 0 ; i < ft->nFrames ; i++){
+      feature = ft->feature[j][i];
+      //fprintf(out,"%.2f %.2f %d ",(float)feature->x,(float)feature->y,FEAT_VAL(feature->val));
+      lx << feature->x << " ";
+      ly << feature->y << " ";
+      if (feature->val <= 0) {
+	// print the feature
+	out << firstFrameNum <<  " " << startFrame+i << endl;
+	out << lx << endl;
+	out << ly << endl;
+	// velocity
+	out << "%" << endl;
+	firstFrameNum = i+1;
+	lx.clear();
+	ly.clear();
+    }
     
-    fclose(out);
-  }        
-  else
-    printf("\nError opening feature file\n");
+    //fclose(out);
 
   cvReleaseCapture(&sequence);