# HG changeset patch # User Nicolas Saunier # Date 1313622205 14400 # Node ID 45c64e68053cb3dd9a0a589e21240e882fb3de3a # Parent 3a11dba306552a5af0f5255b056b5f4dd912e43b added drawing function for features diff -r 3a11dba30655 -r 45c64e68053c c/Feature.cpp --- a/c/Feature.cpp Wed Aug 17 19:03:11 2011 -0400 +++ b/c/Feature.cpp Wed Aug 17 19:03:25 2011 -0400 @@ -1,15 +1,32 @@ #include "Feature.hpp" #include "opencv2/core/core.hpp" +#include "opencv2/highgui/highgui.hpp" using namespace std; using namespace cv; +FeatureTrajectory::FeatureTrajectory(const int& frameNum, const cv::Point2f& p) { + addPoint(frameNum, p); +} + void FeatureTrajectory::addPoint(const int& frameNum, const Point2f& p) { positions.add(frameNum, p); computeMotionData(frameNum); } +#ifdef USE_OPENCV +/// \todo add option for anti-aliased drawing, thickness +void FeatureTrajectory::draw(Mat& img, const Scalar& color) const { + Point2f p1 = positions[0]; + for (unsigned int i=1; i +#include #include //#include @@ -18,7 +19,6 @@ using namespace std; using namespace cv; -using namespace boost; void drawMatchesRelative(const vector& train, const vector& query, std::vector& matches, Mat& img) { for (int i = 0; i < (int)matches.size(); i++) @@ -42,11 +42,18 @@ } } +struct FeaturePointMatch { + FeatureTrajectoryPtr feature; + int pointNum; + + FeaturePointMatch(FeatureTrajectoryPtr _feature, const int& _pointNum): + feature(_feature), pointNum(_pointNum) {} +}; + int main(int argc, char *argv[]) { - BriefDescriptorExtractor brief(32); - const int DESIRED_FTRS = 500; - //shared_ptr detector = shared_ptr(new GridAdaptedFeatureDetector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4)); - //GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); + // BriefDescriptorExtractor brief(32); + // const int DESIRED_FTRS = 500; + // GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4); VideoCapture capture; Mat frame, currentFrameBW, previousFrameBW; @@ -107,7 +114,8 @@ vector errors; Mat prevDesc, currDesc; - vector features; + vector features; + vector featurePointMatches; // TODO structure de donnee paires pointeur trajectory, numero de keypoint int key = '?'; @@ -127,14 +135,26 @@ currPts.clear(); calcOpticalFlowPyrLK(previousFrameBW, currentFrameBW, prevPts, currPts, status, errors, window, params.pyramidLevel, TermCriteria(3 /*static_cast(TermCriteria::COUNT)+static_cast(TermCriteria::EPS)*/, params.maxNumberTrackingIterations, params.minTrackingError), params.derivLambda, 0); // OPTFLOW_USE_INITIAL_FLOW - drawOpticalFlow(prevPts, currPts, status, frame); - vector trackedPts; - for (unsigned int i=0; i::iterator iter = featurePointMatches.begin(); + while (iter != featurePointMatches.end()) { + if (status[iter->pointNum]) { + iter->feature->addPoint(frameNum, currPts[iter->pointNum]); + trackedPts.push_back(currPts[iter->pointNum]); + iter->pointNum = trackedPts.size()-1; + iter++; + } else { + // save feature + iter = featurePointMatches.erase(iter); + } + } currPts = trackedPts; - + assert(currPts.size() == featurePointMatches.size()); + + BOOST_FOREACH(FeaturePointMatch fp, featurePointMatches) + fp.feature->draw(frame, Colors::red()); + //drawOpticalFlow(prevPts, currPts, status, frame); + // cout << matches.size() << " matches" << endl; // descMatcher.match(currDesc, prevDesc, matches); // cout << matches.size() << " matches" << endl; @@ -148,7 +168,13 @@ for (int i=MAX(0, currPts[n].y-params.minFeatureDistanceKLT); i(i,j)=0; goodFeaturesToTrack(currentFrameBW, newPts, params.maxNFeatures, params.featureQuality, params.minFeatureDistanceKLT, featureMask, params.windowSize, params.useHarrisDetector, params.k); - currPts.insert(currPts.end(), newPts.begin(), newPts.end()); + BOOST_FOREACH(Point2f p, newPts) { //for (unsigned int i=0; i + +/** Class for feature data + positions, velocities and other statistics to evaluate their quality + before saving. */ class FeatureTrajectory { +public: + FeatureTrajectory(const int& frameNum, const cv::Point2f& p); void addPoint(const int& frameNum, const cv::Point2f& p); +#ifdef USE_OPENCV + void draw(cv::Mat& img, const cv::Scalar& color) const; +#endif + protected: Trajectory positions; Trajectory velocities; @@ -19,4 +28,6 @@ }; +typedef boost::shared_ptr FeatureTrajectoryPtr; + #endif