Mercurial Hosting > traffic-intelligence
diff c/feature-based-tracking.cpp @ 1002:6c5ce3ec497e
improved handling of path for feature based tracking
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 01 Jun 2018 17:19:24 -0400 |
parents | 8ac7f61c6e4f |
children | 9fb82fe0156f |
line wrap: on
line diff
--- a/c/feature-based-tracking.cpp Wed May 30 14:44:08 2018 -0400 +++ b/c/feature-based-tracking.cpp Fri Jun 01 17:19:24 2018 -0400 @@ -16,6 +16,7 @@ #include "opencv2/calib3d/calib3d.hpp" #include <boost/foreach.hpp> +#include <boost/filesystem.hpp> #include <iostream> #include <vector> @@ -24,6 +25,8 @@ #include <memory> #include <limits> +namespace fs = boost::filesystem; // soon std + using namespace std; using namespace cv; @@ -63,7 +66,8 @@ } void trackFeatures(const KLTFeatureTrackingParameters& params) { - Mat homography = ::loadMat(params.homographyFilename, " "); + Mat homography = ::loadMat(::getRelativeFilename(params.parentDirname, params.homographyFilename), " "); + Mat invHomography; if (params.display && !homography.empty()) invHomography = homography.inv(); @@ -90,8 +94,8 @@ cout << "Empty video filename. Exiting." << endl; exit(0); } - - VideoCapture capture(params.videoFilename); + + VideoCapture capture(::getRelativeFilename(params.parentDirname, params.videoFilename)); if(!capture.isOpened()) { cout << "Video filename " << params.videoFilename << " could not be opened. Exiting." << endl; exit(0); @@ -113,7 +117,7 @@ Mat map1, map2; Mat intrinsicCameraMatrix, newIntrinsicCameraMatrix; if (params.undistort) { - intrinsicCameraMatrix = ::loadMat(params.intrinsicCameraFilename, " "); + intrinsicCameraMatrix = ::loadMat(::getRelativeFilename(params.parentDirname, params.intrinsicCameraFilename), " "); Size undistortedVideoSize = Size(static_cast<int>(round(videoSize.width*params.undistortedImageMultiplication)), static_cast<int>(round(videoSize.height*params.undistortedImageMultiplication))); newIntrinsicCameraMatrix = getDefaultNewCameraMatrix(intrinsicCameraMatrix, undistortedVideoSize, true);// for some reason, it's double type //getOptimalNewCameraMatrix(intrinsicCameraMatrix, params.distortionCoefficients, videoSize, 1, undistortedVideoSize);//, 0, true); initUndistortRectifyMap(intrinsicCameraMatrix, params.distortionCoefficients, Mat::eye(3,3, CV_32FC1) /* 0 ?*/, newIntrinsicCameraMatrix, undistortedVideoSize, CV_32FC1, map1, map2); @@ -122,14 +126,14 @@ ", height=" << undistortedVideoSize.height << endl; } - Mat mask = imread(params.maskFilename, 0); + Mat mask = imread(::getRelativeFilename(params.parentDirname, params.maskFilename), 0); if (mask.empty()) { cout << "Mask filename " << params.maskFilename << " could not be opened." << endl; mask = Mat::ones(videoSize, CV_8UC1); } std::shared_ptr<TrajectoryDBAccess<Point2f> > trajectoryDB = std::shared_ptr<TrajectoryDBAccess<Point2f> >(new TrajectoryDBAccessList<Point2f>()); - trajectoryDB->connect(params.databaseFilename.c_str()); + trajectoryDB->connect(::getRelativeFilename(params.parentDirname, params.databaseFilename).c_str()); trajectoryDB->createTable("positions"); trajectoryDB->createTable("velocities"); trajectoryDB->beginTransaction(); @@ -264,7 +268,7 @@ void groupFeatures(const KLTFeatureTrackingParameters& params) { std::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = std::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>()); - bool success = trajectoryDB->connect(params.databaseFilename.c_str()); + bool success = trajectoryDB->connect(::getRelativeFilename(params.parentDirname, params.databaseFilename).c_str()); trajectoryDB->createObjectTable("objects", "objects_features"); unsigned int savedObjectId=0; @@ -339,7 +343,7 @@ void loadingTimes(const KLTFeatureTrackingParameters& params) { std::shared_ptr<TrajectoryDBAccessList<Point2f> > trajectoryDB = std::shared_ptr<TrajectoryDBAccessList<Point2f> >(new TrajectoryDBAccessList<Point2f>()); - bool success = trajectoryDB->connect(params.databaseFilename.c_str()); + bool success = trajectoryDB->connect(::getRelativeFilename(params.parentDirname, params.databaseFilename).c_str()); vector<std::shared_ptr<Trajectory<Point2f> > > trajectories; //cout << trajectories.size() << endl;