28 # pragma warning(disable: 4251) // DLL interface
33 #include "TrackerSynth.hh"
34 #include <Base/Math/Random.hh>
35 #include <Base/Common/BIASpragma.hh>
43 template <
class StorageType,
class CalculationType>
50 template <
class StorageType,
class CalculationType>
56 template <
class StorageType,
class CalculationType>
63 if (Points_.size()>0){
64 for (
int i=0; i<5; i++)
65 BIASCDOUT(D_TS_REPLACE,
"Points_[PyIndex_]["<<i<<
"] = "
66 <<Points_[PyIndex_][i]<<endl);
78 template <
class StorageType,
class CalculationType>
83 const std::vector<HomgPoint2D>& prediction,
87 if (Points_.size()>0){
88 for (
int i=0; i<5; i++)
89 BIASCDOUT(D_TS_REPLACE,
"Points_[*PyIndex_]["<<i<<
"] = "
90 <<Points_[PyIndex_][i]<<endl);
93 Track(pim, gradx, grady, prediction, affineprediction);
101 template <
class StorageType,
class CalculationType>
106 const int pyindex = PyIndex_;
109 if ((
int)Points_.size()>pyindex){
110 const int num = Points_[pyindex].size();
112 cout <<
"correction : ";
113 for (
int i=0; i<num; i++){
114 if (!Points_[pyindex][i].IsAtInfinity()){
115 index = FindNearest_(Points_[pyindex][i], Frame_);
116 diff = Points_[pyindex][i].Distance(Tracks_[Frame_][index]);
117 BIASCDOUT(D_TS_REPLACE,
"old point "<< Tracks_[Frame_-1][index] <<
" "
118 <<
"correcting: "<<Points_[pyindex][i]<<
" --> "
119 <<Tracks_[Frame_][index]<<
" = "<<diff<<endl);
120 cout << setprecision(3) << setw(8) << diff ;
122 Points_[pyindex][i] = Tracks_[Frame_][index];
132 template <
class StorageType,
class CalculationType>
137 const double Sigma = 0.05;
138 const int pyindex = PyIndex_;
139 if ((
int)Points_.size()>pyindex){
140 const int num = (int)Points_[pyindex].size();
141 cout <<
"adding noise: "<<endl;
142 for (
int i=0; i<num; i++){
143 if (!Points_[pyindex][i].IsAtInfinity()){
144 cout << setw(4) << i <<
" "<<Points_[pyindex][i]<<
" --> ";
147 cout << Points_[pyindex][i] << endl;
153 template <
class StorageType,
class CalculationType>
158 const double fraction = 0.025;
159 const double offs = 5.0;
160 const int pyindex = PyIndex_;
163 if ((
int)Points_.size()>pyindex){
164 const int num = (int)Points_[pyindex].size();
165 cout <<
"adding outlier: "<<endl;
166 for (
int i=0; i<num; i++){
167 if (!Points_[pyindex][i].IsAtInfinity()){
172 int num_outl = (int)rint(fraction * (
double)act_num);
173 vector<unsigned> outl;
174 for (
int i=0; i<num_outl; i++)
178 for (
unsigned j=0; j<outl.size(); j++){
179 index = used[outl[j]];
180 assert(!Points_[pyindex][index].IsAtInfinity());
181 cout << setw(4)<<index<<
" "<<Points_[pyindex][index] <<
" --> ";
182 Points_[pyindex][index][0] +=
184 Points_[pyindex][index][1] +=
186 cout << Points_[pyindex][index] << endl;
193 template <
class StorageType,
class CalculationType>
198 ifstream is(filename.c_str());
200 BIASERR(
"error opening \""<<filename<<
"\"");
205 int frame, num_tracks=0, num_frames=0;
206 is >> tmp >> num_tracks >> tmp >> num_frames >> tmp;
207 BIASCDOUT(D_TS_READ,
"found "<<num_tracks<<
" in "<<num_frames<<
" frames\n");
208 const int num_c = 2048;
209 char *ttt =
new char[num_c];
210 is.getline(ttt, num_c);
214 Tracks_.resize(num_frames);
215 for (
int f=0; f<num_frames; f++){
219 BIASERR(
"error reading \""<<filename<<
"\"");
222 BIASCDOUT(D_TS_READ, setw(4)<< frame<<
" ");
223 Tracks_[f].resize(num_tracks);
224 for (
int t=0; t<num_tracks; t++){
225 is >> Tracks_[f][t][0] >> Tracks_[f][t][1];
226 BIASCDOUT(D_TS_READ, setw(7)<<Tracks_[f][t][0] <<
" "
227 << setw(7)<<Tracks_[f][t][1]<<
" ");
228 Tracks_[f][t][2] = 1.0;
230 BIASERR(
"error reading \""<<filename<<
"\"");
239 template <
class StorageType,
class CalculationType>
242 int &nearest_track_index)
244 const int num_frames = (int)Tracks_.size();
246 double nearest_dist = numeric_limits<double>::max();
249 nearest_frame_index = -1;
250 nearest_track_index = -1;
251 for (
int f=0; f<num_frames; f++){
252 t = FindNearest_(p, f);
254 if (dist <= nearest_dist){
256 nearest_frame_index = f;
257 nearest_track_index = t;
260 BIASASSERT(nearest_frame_index>0);
261 BIASASSERT(nearest_dist<0.1);
264 template <
class StorageType,
class CalculationType>
268 int nearest_track_index = -1;
270 double nearest_dist = numeric_limits<double>::max();
271 const int num_tracks = (int)Tracks_[frame].size();
272 for (
int t=0; t<num_tracks; t++){
273 dist = p.
Distance(Tracks_[frame][t]);
274 if (dist <= nearest_dist){
276 nearest_track_index = t;
279 BIASASSERT(nearest_track_index>=0);
280 return nearest_track_index;
virtual int Track(PyramidImageInterface< CalculationType > &pim, PyramidImageInterface< CalculationType > &gradx, PyramidImageInterface< CalculationType > &grady)
Tracks all points from the internal data structure Points_ and afterwards replaces them by the neares...
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
returns ground truth tracks read from file, for debugging
HOMGPOINT2D_TYPE Distance(const HomgPoint2D &point) const
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
int GetUniformDistributedInt(const int min, const int max)
get uniform distributed random variable including min/max
void AddGaussianNoise_()
adds spatial gaussian noise to Points_[*PyIndex_]
virtual int Track(PyramidImageInterface< CalculationType > &pim, PyramidImageInterface< CalculationType > &gradx, PyramidImageInterface< CalculationType > &grady)
Tracks all points from the internal data structure Points_.
void Track_()
for all succesfully tracked points p in Points_[*PyIndex] it calls FindNearest_(p, Frame_) and replaces Points_[*PyIndex] by the so found track.
double GetNormalDistributed(const double mean, const double sigma)
on succesive calls return normal distributed random variable with mean and standard deviation sigma ...
void AddOutlier_()
adds outliers to Points_[*PyIndex_]
void FindNearest_(HomgPoint2D &p, int &nearest_frame_index, int &nearest_track_index)
finds the nearest point to p in all frames in Tracks_.
class for producing random numbers from different distributions
void ReadTracks_(const std::string &filename)
reads tracks from file and stores them in Tracks_