VLTIF
CS426FinalProject
|
Class used to track and monitor the keypoints. More...
#include <PointTracker.h>
Public Member Functions | |
PointTracker () | |
default constructor | |
vector< Tuple > | update_points (vector< KeyPoint >const &list) |
update the point positions | |
int | point_match (Point2f const &pt) |
Point Match. | |
void | set_point_max_life (const int max_life) |
Set the max lifespan of the frame. | |
void | build_background (string const &filename, SIFT::CommonParams const &cparams, SIFT::DescriptorParams const &dparams, SIFT::DetectorParams const &detparams) |
create the history | |
Private Attributes | |
string | video_filename |
background video file | |
std::set< Point, PointComp > | background_list |
set of background points | |
vector< Tuple > | point_list |
set of current points | |
double | MIN_DISTANCE |
Minimum distance for valid point match. | |
size_t | num_frames |
Current number of frames. | |
size_t | MAX_NUM_FRAMES |
Max number of possible frames. |
Class used to track and monitor the keypoints.
Definition at line 68 of file PointTracker.h.
PointTracker::PointTracker | ( | ) |
default constructor
Default constructor for the point tracking structure
Definition at line 40 of file PointTracker.cpp.
References MAX_NUM_FRAMES, MIN_DISTANCE, and num_frames.
{ MIN_DISTANCE = 2.5; num_frames = 0; MAX_NUM_FRAMES = 50; }
void PointTracker::build_background | ( | string const & | filename, |
SIFT::CommonParams const & | cparams, | ||
SIFT::DescriptorParams const & | dparams, | ||
SIFT::DetectorParams const & | detparams | ||
) |
create the history
Build the background keypoints using the same sift features which are used by the algorithm.
filename | name of video file |
cparams | SIFT common parameters |
dparams | SIFT Descriptor parameters |
detparams | SIFT Detector parameters |
Definition at line 120 of file PointTracker.cpp.
References COLOR_GREEN, DescriptorDistanceL2(), median_frame(), PointDistanceL1(), and video_filename.
Referenced by init().
{ namedWindow("A"); video_filename = filename; size_t numImg = 2; size_t startA = 5; size_t startB = 9; size_t step = 10; size_t max = 100; size_t count = 0; //create median frames Mat imgA = median_frame(filename, startA, step, max); Mat imgB = median_frame(filename, startB, step, max); //compute the sift keypoints for frame SIFT sift(cparams, detparams, dparams); vector<KeyPoint> kpA, kpB; Mat descA, descB; sift(imgA, Mat(), kpA, descA); sift(imgB, Mat(), kpB, descB); cout << descA.cols << endl; double minDist = 0.5; double actDist; //check and compare keypoints for (size_t i = 0; i < kpA.size(); i++) { actDist = PointDistanceL1(kpA[i].pt, kpB[i].pt); if (actDist <= minDist) { cout << i+1 << " of " << kpA.size() << " -> " << DescriptorDistanceL2(descA.row(i), descB.row(i)) << endl; //cin.get(); if( DescriptorDistanceL2(descA.row(i), descB.row(i)) < 10 ){ cout << "done" << endl; circle(imgA, kpA[i].pt, 1, COLOR_GREEN, 2); } } } Mat AA = imgA.clone(); imshow("A", AA); waitKey(0); exit(0); }
int PointTracker::point_match | ( | Point2f const & | pt | ) |
Point Match.
Check if a match exists between a point and the point list. Return the match index if found.
pt | point to verify |
Definition at line 97 of file PointTracker.cpp.
References MIN_DISTANCE, point_list, and PointDistanceL2().
Referenced by update_points().
{ double dist; for (size_t i = 0; i < point_list.size(); i++) { dist = PointDistanceL2(pt, point_list[i].centroid); if (dist < MIN_DISTANCE) return i; } return -1; }
void PointTracker::set_point_max_life | ( | const int | max_life | ) |
Set the max lifespan of the frame.
Definition at line 173 of file PointTracker.cpp.
References MAX_NUM_FRAMES.
Referenced by init().
{ MAX_NUM_FRAMES = max_life; }
vector< Tuple > PointTracker::update_points | ( | vector< KeyPoint >const & | list | ) |
update the point positions
Update the points, adding new points and removing redundant ones.
list | of keypoints |
Definition at line 52 of file PointTracker.cpp.
References MAX_NUM_FRAMES, num_frames, point_list, and point_match().
Referenced by main().
{ int idx; //take the input list and check for collisions for (size_t i = 0; i < list.size(); i++) { //check to see if a point matches idx = point_match(list[i].pt); if (idx >= 0) { point_list[idx].found = true; point_list[idx].centroid.x = ((num_frames) / (double) (num_frames + 1)) * point_list[idx].centroid.x + (1 / (double) (num_frames + 1)) * list[i].pt.x; point_list[idx].centroid.y = ((num_frames) / (double) (num_frames + 1)) * point_list[idx].centroid.y + (1 / (double) (num_frames + 1)) * list[i].pt.y; continue; }//otherwise, add it to the list else { point_list.push_back(Tuple(list[i].pt)); } } //iterate through point list, updating the strength of each point for (int i = 0; i < (int) point_list.size(); i++) { point_list[i].strength = (point_list[i].span * point_list[i].strength + point_list[i].found) / (double) (point_list[i].span + 1); point_list[i].found = 0; point_list[i].span = min(point_list[i].span + 1, MAX_NUM_FRAMES); if (point_list[i].strength < 0.3) point_list.erase(point_list.begin() + i--); } num_frames++; if (num_frames > MAX_NUM_FRAMES) num_frames = MAX_NUM_FRAMES; return point_list; }
std::set<Point, PointComp> PointTracker::background_list [private] |
set of background points
Definition at line 95 of file PointTracker.h.
size_t PointTracker::MAX_NUM_FRAMES [private] |
Max number of possible frames.
Definition at line 107 of file PointTracker.h.
Referenced by PointTracker(), set_point_max_life(), and update_points().
double PointTracker::MIN_DISTANCE [private] |
Minimum distance for valid point match.
Definition at line 101 of file PointTracker.h.
Referenced by point_match(), and PointTracker().
size_t PointTracker::num_frames [private] |
Current number of frames.
Definition at line 104 of file PointTracker.h.
Referenced by PointTracker(), and update_points().
vector<Tuple> PointTracker::point_list [private] |
set of current points
Definition at line 98 of file PointTracker.h.
Referenced by point_match(), and update_points().
string PointTracker::video_filename [private] |
background video file
Definition at line 92 of file PointTracker.h.
Referenced by build_background().