diff c/feature-based-tracking.cpp @ 133:63dd4355b6d1

saving of feature positions in sqlite database
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 17 Aug 2011 22:26:01 -0400
parents 45c64e68053c
children a617d0808bbc
line wrap: on
line diff
--- a/c/feature-based-tracking.cpp	Wed Aug 17 19:03:25 2011 -0400
+++ b/c/feature-based-tracking.cpp	Wed Aug 17 22:26:01 2011 -0400
@@ -4,6 +4,7 @@
 #include "utils.hpp"
 
 #include "src/Trajectory.h"
+#include "src/TrajectoryDBAccessList.h"
 
 #include "opencv2/core/core.hpp"
 #include "opencv2/highgui/highgui.hpp"
@@ -60,7 +61,7 @@
 
   KLTFeatureTrackingParameters params;
   params.frame1 = 0;
-  params.nFrames = -1;
+  params.nFrames = 50;
   params.maxNFeatures = 1000;
   params.featureQuality = 0.1;
   params.minFeatureDistanceKLT = 3;
@@ -108,6 +109,11 @@
       return 1;
     }
   
+  // database
+  TrajectoryDBAccessList<Point2f> trajectoryDB;
+  trajectoryDB.connect("test.sqlite");
+  trajectoryDB.createTable();
+
   vector<KeyPoint> prevKpts, currKpts;
   vector<Point2f> prevPts, currPts, newPts;
   vector<uchar> status;
@@ -118,7 +124,8 @@
   vector<FeaturePointMatch> featurePointMatches;
     
   // TODO structure de donnee paires pointeur trajectory, numero de keypoint
-  int key = '?'; 
+  int key = '?';
+  unsigned int savedFeatureId=0;
   for (int frameNum = params.frame1; ((params.frame1+frameNum < params.nFrames) || (params.nFrames < 0)) && !::interruptionKey(key); frameNum++) {
       capture >> frame;
       cout << capture.get(CV_CAP_PROP_POS_FRAMES) << " " << prevPts.size() << endl;
@@ -144,7 +151,9 @@
 	    iter->pointNum = trackedPts.size()-1;
 	    iter++;
 	  } else {
-	    // save feature
+	    iter->feature->setId(savedFeatureId);
+	    savedFeatureId++;
+	    iter->feature->write(trajectoryDB);
 	    iter = featurePointMatches.erase(iter);
 	  }
 	}
@@ -185,9 +194,10 @@
       prevPts = currPts;
       //prevKpts = currKpts;
       //currDesc.copyTo(prevDesc);
-      key = waitKey(0);
+      key = waitKey(2);
     }  
   
+  trajectoryDB.disconnect();
   return 0;
 }