changeset 164:76610dcf3b8d

added test code to read trajectories
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 28 Sep 2011 13:27:20 -0400
parents cde87a07eb58
children 50964af05a80
files c/Parameters.cpp c/feature-based-tracking.cpp include/Parameters.hpp
diffstat 3 files changed, 39 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/c/Parameters.cpp	Tue Sep 27 01:38:05 2011 -0400
+++ b/c/Parameters.cpp	Wed Sep 28 13:27:20 2011 -0400
@@ -16,6 +16,8 @@
   // configuration filename
   onlyCmdLine.add_options()
     ("help,h", "displays this help message")
+    ("tf", "tracks features")
+    ("gf", "groups features")
     ("config-file", po::value<string>(&configurationFilename)->default_value("tracking.cfg"), "configuration file")
     ;
 
@@ -75,6 +77,9 @@
 
     parameterDescription = getParameterDescription(cmdLineAndFile, vm);
 
+    trackFeatures = vm.count("tf")>0;
+    groupFeatures = vm.count("gf")>0;
+
     if (vm.count("help")) {
       cout << cmdLine << endl;
       // cout << "Positional options:";
--- a/c/feature-based-tracking.cpp	Tue Sep 27 01:38:05 2011 -0400
+++ b/c/feature-based-tracking.cpp	Wed Sep 28 13:27:20 2011 -0400
@@ -60,17 +60,7 @@
   }
 }
 
-int main(int argc, char *argv[]) {
-  // BriefDescriptorExtractor brief(32);
-  // const int DESIRED_FTRS = 500;
-  // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4);
-
-  VideoCapture capture;
-  Mat frame, currentFrameBW, previousFrameBW;
-
-  KLTFeatureTrackingParameters params(argc, argv);
-  cout << params.parameterDescription << endl;
-
+void trackFeatures(const KLTFeatureTrackingParameters& params) {
   Mat homography = ::loadMat(params.homographyFilename, " ");
   Mat invHomography;
   if (params.display && !homography.empty())
@@ -104,6 +94,7 @@
   //       }
   //   }
 
+  VideoCapture capture;
   capture.open(params.videoFilename);
   if(capture.isOpened()) {
     videoSize = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT));
@@ -146,6 +137,7 @@
     
   int key = '?';
   unsigned int savedFeatureId=0;
+  Mat frame, currentFrameBW, previousFrameBW;
   for (int frameNum = params.frame1; ((frameNum-params.frame1 < params.nFrames) || (params.nFrames < 0)) && !::interruptionKey(key); frameNum++) {
       capture >> frame;
       cout << frameNum << " " << capture.get(CV_CAP_PROP_POS_FRAMES) << " " << prevPts.size() << endl;
@@ -243,10 +235,37 @@
   
   trajectoryDB->endTransaction();
   trajectoryDB->disconnect();
+}
+
+int main(int argc, char *argv[]) {
+  // BriefDescriptorExtractor brief(32);
+  // const int DESIRED_FTRS = 500;
+  // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4);
+
+  KLTFeatureTrackingParameters params(argc, argv);
+  cout << params.parameterDescription << endl;
+
+  if (params.trackFeatures)
+    trackFeatures(params);
+  else if (params.groupFeatures) {
+    cout << "group" << endl;
+    
+    boost::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = boost::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>());
+    //TODO write generic methods for blob and list versions TrajectoryDBAccess<Point2f>* trajectoryDB = new TrajectoryDBAccessBlob<Point2f>();
+    bool success = trajectoryDB->connect(params.databaseFilename.c_str());
+    vector<boost::shared_ptr<Trajectory<Point2f> > > trajectories;
+    cout << trajectories.size() << endl;
+    success = trajectoryDB->read(trajectories, "positions");
+    cout << trajectories.size() << endl;
+    cout << trajectories[0]->size() << endl;
+    //cout << trajectories[0]->getPoint(0) << endl;
+    trajectoryDB->endTransaction();
+    trajectoryDB->disconnect();
+  }
+
   return 0;
 }
 
-
 /* ------------------ DOCUMENTATION ------------------ */
 
 
--- a/include/Parameters.hpp	Tue Sep 27 01:38:05 2011 -0400
+++ b/include/Parameters.hpp	Wed Sep 28 13:27:20 2011 -0400
@@ -13,6 +13,9 @@
 }
 
 struct KLTFeatureTrackingParameters {
+  bool trackFeatures;
+  bool groupFeatures;
+
   std::string videoFilename;
   std::string databaseFilename;
   std::string homographyFilename;