Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GenSynthMatches.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include "GenSynthMatches.hh"
26 #include <Base/ImageUtils/ImageDraw.hh>
27 #include <Geometry/PMatrix.hh>
28 #include <Utils/ThreeDOut.hh>
29 
30 using namespace BIAS;
31 using namespace std;
32 
33 
34 
35 
36 ostream& BIAS::operator<<(ostream& os, const GenSynthMatches& m)
37 {
38 
39  HomgPoint3D p3d(0.0, 0.0, 0.0, 0.0);
40  os << "true matches (0-"<<*m._NumStaticPoints-1<<"), outliers ("
42  <<") and moving objs ("<<*m._NumStaticPoints+*m._NumOutliers<<"-"
44  *m._NumMovingPoints* *m._NumMovingObjects-1<<"): \n";
45  for (int i=0; i<*m._NumStaticPoints; i++){
46  os << setw(3)<<i<<" : "<< m._StaticPoints[i] << " : ";
47  for (int k=0; k<*m._NumImages; k++){
48  os << k<<":"<<m._GT_Points[k][i]<<" ";
49  }
50  os << endl;
51  }
52  for (int i=*m._NumStaticPoints; i<*m._NumStaticPoints+*m._NumOutliers; i++){
53  os << setw(3) << i << " : " << p3d << " : ";
54  for (int k=0; k<*m._NumImages; k++){
55  os << k<<":"<<m._GT_Points[k][i]<<" ";
56  }
57  os << endl;
58  }
59  for (int i=*m._NumStaticPoints+*m._NumOutliers;
61  *m._NumMovingPoints * *m._NumMovingObjects; i++){
62  os << setw(3)<<i<<" : "<<
63  m._MovingPoints[i-*m._NumStaticPoints-*m._NumOutliers] << " : ";
64  for (int k=0; k<*m._NumImages; k++){
65  os << k<<":"<<m._GT_Points[k][i]<<" ";
66  }
67  os << endl;
68  }
69 
70  //////////////////////////////////////////////////
71 
72  os << "noisy matches (0-"<<*m._NumStaticPoints-1<<"), outliers ("
74  <<") and moving objs ("<<*m._NumStaticPoints+*m._NumOutliers<<"-"
76  *m._NumMovingPoints * *m._NumMovingObjects-1<<"): \n";
77  for (int i=0; i<*m._NumStaticPoints; i++){
78  os << setw(3)<<i<<" : "<< m._StaticPoints[i] << " : ";
79  for (int k=0; k<*m._NumImages; k++){
80  os << k<<":"<<m._Points[k][i]<<" ";
81  }
82  os << endl;
83  }
84  for (int i=*m._NumStaticPoints; i<*m._NumStaticPoints+*m._NumOutliers; i++){
85  os << setw(3) << i << " : " << p3d << " : ";
86  for (int k=0; k<*m._NumImages; k++){
87  os << k<<":"<<m._Points[k][i]<<" ";
88  }
89  os << endl;
90  }
91  for (int i=*m._NumStaticPoints+*m._NumOutliers;
93  *m._NumMovingPoints * *m._NumMovingObjects; i++){
94  os << setw(3)<<i<<" : "<<
95  m._MovingPoints[i-*m._NumStaticPoints-*m._NumOutliers] << " : ";
96  for (int k=0; k<*m._NumImages; k++){
97  os << k<<":"<<m._Points[k][i]<<" ";
98  }
99  os << endl;
100  }
101 
102  /*
103  //////////////////////////////////////////////////
104 
105  os << "normalized true matches (0-"<<*m._NumStaticPoints-1<<"), outliers ("
106  <<*m._NumStaticPoints<<"-"<<*m._NumStaticPoints+*m._NumOutliers-1
107  <<") and moving objs ("<<*m._NumStaticPoints+*m._NumOutliers<<"-"
108  <<*m._NumStaticPoints+*m._NumOutliers+
109  *m._NumMovingPoints * *m._NumMovingObjects-1<<"): \n";
110  for (int i=0; i<*m._NumStaticPoints; i++){
111  os << setw(3)<<i<<" : "<< m._StaticPoints[i] << " : ";
112  for (int k=0; k<*m._NumImages; k++){
113  os << k<<":"<<m._GT_NormalizedPoints[k][i]<<" ";
114  }
115  os << endl;
116  }
117  for (int i=*m._NumStaticPoints; i<*m._NumStaticPoints+*m._NumOutliers; i++){
118  os << setw(3) << i << " : " << p3d << " : ";
119  for (int k=0; k<*m._NumImages; k++){
120  os << k<<":"<<m._GT_NormalizedPoints[k][i]<<" ";
121  }
122  os << endl;
123  }
124  for (int i=*m._NumStaticPoints+*m._NumOutliers;
125  i<*m._NumStaticPoints+*m._NumOutliers+
126  *m._NumMovingPoints * *m._NumMovingObjects; i++){
127  os << setw(3)<<i<<" : "<<
128  m._MovingPoints[i-*m._NumStaticPoints-*m._NumOutliers] << " : ";
129  for (int k=0; k<*m._NumImages; k++){
130  os << k<<":"<<m._GT_NormalizedPoints[k][i]<<" ";
131  }
132  os << endl;
133  }
134 
135  //////////////////////////////////////////////////
136 
137  os << "normalized noisy matches (0-"<<*m._NumStaticPoints-1<<"), outliers ("
138  <<*m._NumStaticPoints<<"-"<<*m._NumStaticPoints+*m._NumOutliers-1
139  <<") and moving objs ("<<*m._NumStaticPoints+*m._NumOutliers<<"-"
140  <<*m._NumStaticPoints+*m._NumOutliers+
141  *m._NumMovingPoints * *m._NumMovingObjects-1<<"): \n";
142  for (int i=0; i<*m._NumStaticPoints; i++){
143  os << setw(3)<<i<<" : "<< m._StaticPoints[i] << " : ";
144  for (int k=0; k<*m._NumImages; k++){
145  os << k<<":"<<m._NormalizedPoints[k][i]<<" ";
146  }
147  os << endl;
148  }
149  for (int i=*m._NumStaticPoints; i<*m._NumStaticPoints+*m._NumOutliers; i++){
150  os << setw(3) << i << " : " << p3d << " : ";
151  for (int k=0; k<*m._NumImages; k++){
152  os << k<<":"<<m._NormalizedPoints[k][i]<<" ";
153  }
154  os << endl;
155  }
156  for (int i=*m._NumStaticPoints+*m._NumOutliers;
157  i<*m._NumStaticPoints+*m._NumOutliers+*m._NumMovingPoints *
158  *m._NumMovingObjects; i++){
159  os << setw(3)<<i<<" : "<<
160  m._MovingPoints[i-*m._NumStaticPoints-*m._NumOutliers] << " : ";
161  for (int k=0; k<*m._NumImages; k++){
162  os << k<<":"<<m._NormalizedPoints[k][i]<<" ";
163  }
164  os << endl;
165  }
166  */
167  return os;
168 }
169 
170 //////////////////////////////////////////////////////////////////////////
171 //
172 //////////////////////////////////////////////////////////////////////////
173 
174 
177  : MatchDataBase(para)
178 {
179  _para=&para;
180 
181  //AddDebugLevel(GSM_MOVIN_3D_POINTS);
182 
190  _UserGivenP=NULL;
195  Reset();
196 }
197 
200 {}
201 
203 CreateMatches(bool points3D_set_by_user, const bool fixed_errors) {
204  if (!points3D_set_by_user) {
205  Reset();
206 
207  _CheckParams();
208 
209  int res = Create3DPoints(fixed_errors);
210  if (res != 0) {
211  return res;
212  }
213 
214  } //if !points3D_set_by_user
215 
216  int index = 0;
217  return CreateMatches(index);
218 }
219 
221 CreateMatches(int &index)
222 {
223  //_para->ShowData();
224 
225  //cout << "DebugLevel is ";
226  //PrintDebugLevel();
227 
228  _CheckParams();
229 
230  if (_StaticPoints.size() == 0 && *_NumStaticPoints != 0) {
231  BIASERR("user error: no 3D points set. Use SetStatic3DPoints() "
232  "or Create3DPoints() before creating matches.");
233  return GSM_RETURN_NO_STATIC_3D_POINTS;
234  }
235  if ((_MovingPoints.size() == 0) &&
236  (*_NumMovingPoints * *_NumMovingObjects!= 0) ) {
237  BIASERR("user error: no moving 3D points set. Use Set3DPoints() "
238  "or Create3DPoints() before creating matches.");
239  return GSM_RETURN_NO_MOVING_3D_POINTS;
240  }
241 
242  int idx = -1;
243  int res = _CreateStatic2DPoints(idx);
244  if (res < 0) {
245  index = idx;
246  return GSM_RETURN_ERROR_HANDLING_STATIC_POINT;
247  }
249  res = _CreateMoving2DPoints(idx);
250  //cout << idx << " " << res << endl;
251  if (res < 0 && (*_NumMovingPoints * *_NumMovingObjects!= 0)) {
252  index = idx;
253  //cout << "Creation of moving 2D point did not succeed " << index << endl;
254  return GSM_RETURN_ERROR_HANDLING_MOVING_POINT;
255  }
256 
257  return GSM_RETURN_OK;
258 }
259 
261 Create3DPoints(const bool fixed_error)
262 {
263  _CreateCamMovement(fixed_error);
265 
266  if (*_NumStaticPoints != 0) {
267  //cout << "trying to create static points" << endl;
268  if (_CreateStatic3DPoints() != GSM_RETURN_OK) {
269  BIASERR("user error: maybe no common viewing volume");
270  return GSM_RETURN_STATIC_OBJECT_NOT_VISIBLE;
271  }
272  }
273 
274  if (*_NumMovingPoints * *_NumMovingObjects != 0) {
275  //cout << "trying to create moving points" << endl;
276  if (_CreateMoving3DPoints() != GSM_RETURN_OK) {
277  BIASERR("user error: moving object not visible");
278  return GSM_RETURN_MOVING_OBJECT_NOT_VISIBLE;
279  }
280  }
281  return GSM_RETURN_OK;
282 }
283 
285 DrawTrue(Image<unsigned char>& im, int minindex, int maxindex) const
286 { _Draw(im, minindex, maxindex, &_GT_Points); }
287 
289 DrawNoisy(Image<unsigned char>& im, int minindex, int maxindex) const
290 { _Draw(im, minindex, maxindex, &_Points); }
291 
292 
294 _Draw(Image<unsigned char>& im, int minindex, int maxindex,
295  const std::vector<std::vector<HomgPoint2D> >* p) const
296 {
297  int line_width = 1;
298  double mag=1.0;
299  int imag=(int)rint(mag);
300  if (!im.IsEmpty()) im.Release();
301  im.Init(*_ImWidth*imag, *_ImHeight*imag, 3);
302  unsigned char background = 255;
303  im.FillImageWithConstValue(background);
304 
305  _DrawPoints(im, maxindex, p);
306  if (minindex==maxindex){
307  return;
308  }
309 
310  if (minindex<0 || minindex>=*_NumImages ||
311  maxindex<=0 || maxindex>=*_NumImages){
312  BIASERR("invalid image to draw: "<<minindex<<" "<<maxindex<<" "
313  <<*_NumImages);
314  BIASABORT;
315  }
316 
317  unsigned char red[3]={255, 0, 0};
318  //unsigned char hred[3]={128, 0, 0};
319 #ifndef BIAS_HAVE_OPENCV
320  unsigned char hred[3]={200, 0, 0};
321 #endif
322  unsigned char green[3]={0, 255, 0};
323  //unsigned char hgreen[3]={0, 128, 0};
324 #ifndef BIAS_HAVE_OPENCV
325  unsigned char hgreen[3]={0, 200, 0};
326 #endif
327  unsigned char blue[3]={0, 0, 255};
328 #ifndef BIAS_HAVE_OPENCV
329  unsigned char hblue[3]={0, 0, 128};
330 #endif
331  unsigned int start[2], end[2];
332  for (int k=minindex+1; k<maxindex+1; k++){
333  // draw inliers green
334  for (int i=0; i<*_NumStaticPoints; i++){
335  for (int l=-line_width;l<=line_width; l++){
336  start[0]=(unsigned int)rint((*p)[k-1][i][0]*mag);
337  start[1]=(unsigned int)rint((*p)[k-1][i][1]*mag+(double)l);
338  end[0]=(unsigned int)rint((*p)[k][i][0]*mag);
339  end[1]=(unsigned int)rint((*p)[k][i][1]*mag+(double)l);
340 #ifndef BIAS_HAVE_OPENCV
341  ImageDraw<unsigned char>::Line(im, start, end, hgreen);
342  ImageDraw<unsigned char>::Line(im, start, start, green);
343 #else
345  Arrow(im, start[0], start[1], end[0], end[1],
346  ColourRGB<unsigned char>(green[0], green[1], green[2]), 2);
347 #endif
348  }
349  }
350  // draw outliers blue
351  for (int i=*_NumStaticPoints; i<*_NumStaticPoints+*_NumOutliers; i++){
352  for (int l=-line_width;l<=line_width; l++){
353  start[0]=(unsigned int)rint((*p)[k-1][i][0]*mag);
354  start[1]=(unsigned int)rint((*p)[k-1][i][1]*mag+(double)l);
355  end[0]=(unsigned int)rint((*p)[k][i][0]*mag);
356  end[1]=(unsigned int)rint((*p)[k][i][1]*mag+(double)l);
357 #ifndef BIAS_HAVE_OPENCV
358  ImageDraw<unsigned char>::Line(im, start, end, hblue);
359  ImageDraw<unsigned char>::Line(im, start, start, blue);
360 #else
362  Arrow(im, start[0], start[1], end[0], end[1],
363  ColourRGB<unsigned char>(blue[0], blue[1], blue[2]), 2);
364 #endif
365  }
366  }
367  // draw moving objects red
368  for (int i=*_NumStaticPoints+*_NumOutliers;
369  i<*_NumStaticPoints+*_NumOutliers+
371  for (int l=-line_width;l<=line_width; l++){
372  start[0]=(unsigned int)rint((*p)[k-1][i][0]*mag);
373  start[1]=(unsigned int)rint((*p)[k-1][i][1]*mag+(double)l);
374  end[0]=(unsigned int)rint((*p)[k][i][0]*mag);
375  end[1]=(unsigned int)rint((*p)[k][i][1]*mag+(double)l);
376 #ifndef BIAS_HAVE_OPENCV
377  ImageDraw<unsigned char>::Line(im, start, end, hred);
378  ImageDraw<unsigned char>::Line(im, start, start, red);
379 #else
381  Arrow(im, start[0], start[1], end[0], end[1],
382  ColourRGB<unsigned char>(red[0], red[1], red[2]), 2);
383 #endif
384  }
385  }
386  }
387 }
388 
389 
392  const std::vector<std::vector<HomgPoint2D> >* p) const
393 {
394  if (index<0 || index>=*_NumImages ){
395  BIASERR("invalid image to draw: "<<index<<" "<<*_NumImages);
396  BIASABORT;
397  }
398  unsigned char red[3]={255, 0, 0};
399  unsigned char green[3]={0, 255, 0};
400  unsigned char blue[3]={0, 0, 255};
401  double mag=1.0;
402  int k = index, imag=(int)rint(mag);
403  unsigned int radius=1, end[2];
404  // draw inliers green
405  for (int i=0; i<*_NumStaticPoints; i++){
406  end[0]=(unsigned int)rint((*p)[k][i][0]*mag);
407  end[1]=(unsigned int)rint((*p)[k][i][1]*mag);
408  if (end[0]>=radius && end[1]>=radius &&
409  end[0]<=*_ImWidth*imag-radius-1 &&
410  end[1]<=*_ImHeight*imag-radius-1)
412  radius, green);
413  }
414  // draw outliers blue
415  for (int i=*_NumStaticPoints; i<*_NumStaticPoints+*_NumOutliers; i++){
416  end[0]=(unsigned int)rint((*p)[k][i][0]*mag);
417  end[1]=(unsigned int)rint((*p)[k][i][1]*mag);
418  if (end[0]>=radius && end[1]>=radius &&
419  end[0]<=*_ImWidth-radius-1 && end[1]<=*_ImHeight-radius-1)
421  radius, blue);
422  }
423  // draw moving objects red
424  for (int i=*_NumStaticPoints+*_NumOutliers;
425  i<*_NumStaticPoints+*_NumOutliers+*_NumMovingPoints * *_NumMovingObjects; i++){
426  end[0]=(unsigned int)rint((*p)[k][i][0]*mag);
427  end[1]=(unsigned int)rint((*p)[k][i][1]*mag);
428  if (end[0]>=radius && end[1]>=radius &&
429  end[0]<=*_ImWidth-radius-1 && end[1]<=*_ImHeight-radius-1)
431  radius, red);
432  }
433 
434 }
435 
437 WriteData(string file) const
438 {
439  ofstream of(file.c_str());
440  if (!of){
441  BIASERR("error opening "<<file);
442  return -1;
443  }
444  of << *this;
445  if (!of){
446  BIASERR("error writing to "<<file);
447  return -1;
448  }
449  of.close();
450  return 0;
451 }
452 
453 // hack to disabled unreachabel warning
454 #if defined(WIN32)
455 # pragma warning(push)
456 # pragma warning(disable : 4702)
457 #endif
459 {
460  ifstream of(file.c_str());
461  if (!of){
462  BIASERR("error opening "<<file);
463  return -1;
464  }
465  BIASERR("unfinished");
466 
467  //// of >> *this;
468  //if (!of){
469  // BIASERR("error reading from "<<file);
470  // return -1;
471  //}
472  //of.close();
473 
474  BIASABORT;
475  return -1;
476 }
477 #if defined(WIN32)
478 # pragma warning(pop)
479 #endif
480 
481 
484 {
486  _rand.Reset();
487 
488  // clear K, R, C and P
489  //_K.SetZero();
490  //_Ki.SetZero();
491  _GT_R.clear();
492  //_R.clear();
493  _GT_C.clear();
494  //_C.clear();
495  _GT_P.clear();
496  //_P.clear();
497 
498  // now clear the 3D data points
499  _StaticPoints.clear();
500  _MovingPoints.clear();
501 
502  // transformation for moving points
503  _MovingTransform.clear();
504 
505  // now clear 2D points
506  _GT_Points.clear();
507  //_Points.clear();
508  _GT_NormalizedPoints.clear();
509  //_NormalizedPoints.clear();
510 
511 }
512 
514 GetGTR(int imNo, RMatrixBase& R) const
515 { R = _GT_R[imNo]; }
517 GetGTR(std::vector<RMatrixBase>& R) const
518 { R = _GT_R; }
519 
521 GetGTC(int imNo, HomgPoint3D& C) const
522 { C = _GT_C[imNo]; }
524 GetGTC(std::vector<HomgPoint3D>& C) const
525 { C = _GT_C; }
526 
528 GetGTP(int imNo, PMatrixBase& P) const
529 { P = _GT_P[imNo]; }
531 GetGTP(std::vector<PMatrixBase>& P) const
532 { P = _GT_P; }
533 
535 GetGTPoints(int imNo, std::vector<HomgPoint2D>& p) const
536 { p = _GT_Points[imNo]; }
538 GetGTPoints(std::vector<std::vector<HomgPoint2D> >& p) const
539 { p = _GT_Points; }
540 
542 GetGTNormalizedPoints(int imNo, std::vector<HomgPoint2D>& p) const
543 { p = _GT_NormalizedPoints[imNo]; }
545 GetGTNormalizedPoints(std::vector<std::vector<HomgPoint2D> >& p) const
546 { p = _GT_NormalizedPoints; }
547 
549 Get3DPoints(std::vector<HomgPoint3D>& p) const
550 { p = _StaticPoints; }
551 
553 Get3DMovingPoints(std::vector<HomgPoint3D>& p, const int frame) const
554 {
555  if (_MovingPoints.size()==0) { p.clear(); return; }
556  if ((int)_MovingTransform.size()<=frame){
557  BIASERR("invalid frame number");
558  p.clear();
559  return;
560  }
561  p = _MovingPoints;
563  for (unsigned i=0; i<p.size(); i++)
564  p[i] = T * p[i];
565 }
566 
568 GetInliers(std::vector<bool>& inl) const
569 {
570  inl.resize(*_NumPoints);
571  for (int i=0; i<*_NumStaticPoints; i++) inl[i]=true;
572  for (int i=*_NumStaticPoints; i<*_NumPoints; i++) inl[i]=false;
573 }
574 
575 /** A moving 3D point X_i is generated for image i from 3D Point X using the
576  euclidean transform E_i=[R_i | T_i]:
577  X_i = E_i * X
578  It projects into the image point x_i with the according projection matrix
579  P_i=[r_i'|-r_i'C_i] (where ' denotes transposition):
580  x_i = P_i * X_i
581 
582  Finding a projection matrix P_x where each 3D point from image i-1
583  projects onto the same 2D points goes as follows:
584  x_i = P_x X_{i-1}
585 
586  First take the 3D point and move it to ist new poition in image i. This is
587  done by first applying the inverse E_{i-1} and then E_i:
588  X_i = E_i * E_{i-1}^{-1} * X_{i-1}
589  Now use the old projection matrix P_i.
590  x_i = P_i * E_i * E_{i-1}^{-1} * X_{i-1}
591 
592  The new projection matrix P_x is composed as follows:
593  P_x = P_i * E_i * E_{i-1}^{-1}
594  = [r_i'|-r_i'C_i] * [R_i | T_i] * [R_{i-1} | T_{i-1}]^{-1}
595  = [r_i'|-r_i'C_i] * [R_i | T_i] * [R_{i-1}' | -R_{i-1}'T_{i-1}]
596  = [r_i'|-r_i'C_i] * [R_i R_{i-1}' | T_i - R_i R_{i-1}'T_{i-1}]
597  = [r_i' R_i R_{i-1}' | -r_i'C_i + r_i'(T_i - R_i R_{i-1}'T_{i-1})]
598  = [r_i' R_i R_{i-1}' | -r_i'C_i + r_i'T_i - r_i'R_i R_{i-1}'T_{i-1}]
599  = [r_i'R_iR_{i-1}' | -r_i'R_iR_{i-1}'R_{i-1}R_i'C_i + r_i'R_iR_{i-1}'R_{i-1}R_i'T_i - r_i'R_i R_{i-1}'T_{i-1}]
600  = [r_i'R_iR_{i-1}' | -r_i'R_iR_{i-1}'(T_{i-1}+R_{i-1}R_i'(C_i-T_i))]
601  setting R_x' = r_i'R_iR_{i-1}' is aequivalent to R_x = R_{i-1} R_i' r_i
602  setting C_x = T_{i-1} + R_{i-1} R_i' (C_i - T_i)
603  and leads to
604  = [ R_x' | -R_x' C_x ]
605  @author woelk 08/2004 */
606 void
607 GenSynthMatches::GetGTNormalizedF(std::vector<std::vector<FMatrixBase> >& F) const
608 {
609  Vector3<double> C1, C2, cc1, cc2;
610  RMatrixBase R1, R2, R, r1, r2;
611  int idx;
612 
613  //cerr << "resizing F with newsize "<<*_NumMovingObjects+1<<endl;
614  F.resize(*_NumImages-1);
615  for (int i=1; i<*_NumImages; i++){
616  //cerr << "resizing F["<<i<<"] with newsize "<<*_NumMovingObjects+1<<endl;
617  F[i-1].resize(*_NumMovingObjects+1);
618 
619  _GT_C[i-1].GetEuclidean(C1);
620  _GT_C[i].GetEuclidean(C2);
621  BIASCDOUT(GSM_FMATRIX, "\n------------------------------------------\n\n");
622  BIASCDOUT(GSM_FMATRIX, "C1: "<<C1<<"R1: "<<_GT_R[i-1]<<endl);
623  BIASCDOUT(GSM_FMATRIX, "C2: "<<C2<<"R2: "<<_GT_R[i]<<endl);
624  F[i-1][0].Compose(_GT_R[i-1], C1, _GT_R[i], C2);
625  BIASCDOUT(GSM_FMATRIX, "F from image "<<i-1<<" to "<<i
626  <<" for static objects is "<<F[i-1][0]<<endl);
627 #ifdef BIAS_DEBUG
628  if (DebugLevelIsSet(GSM_FMATRIX)){
629  for (int k=0; k<*_NumStaticPoints; k++){
630  BIASCDOUT(GSM_FMATRIX, setw(5)<<k<<" p2^T * F * p1 = "
631  <<(F[i-1][0]*_GT_NormalizedPoints[i-1][k]).
632  ScalarProduct(_GT_NormalizedPoints[i][k])
633  <<"\t"<<_GT_NormalizedPoints[i-1][k]<<" "
634  <<_GT_NormalizedPoints[i][k]<<endl);
635  }
636  }
637 #endif
638 
639  for (int l=0; l<*_NumMovingObjects; l++){
640  _GT_C[i-1].GetEuclidean(C1);
641  R1=_GT_R[i-1];
642  BIASCDOUT(GSM_FMATRIX, "\n------\n\nC1: "<<C1<<"R1: "<<R1<<endl);
643 
644  idx=l * *_NumMovingObjects + i-1;
645  cc1.Set((*_MovingObjMotionVecX)[idx], (*_MovingObjMotionVecY)[idx],
646  (*_MovingObjMotionVecZ)[idx]);
647  r1.SetXYZ((*_MovingObjRotVecX)[idx], (*_MovingObjRotVecY)[idx],
648  (*_MovingObjRotVecZ)[idx]);
649 
650  idx=l * *_NumMovingObjects + i;
651  cc2.Set((*_MovingObjMotionVecX)[idx], (*_MovingObjMotionVecY)[idx],
652  (*_MovingObjMotionVecZ)[idx]);
653  _GT_C[i].GetEuclidean(C2);
654  r2.SetXYZ((*_MovingObjRotVecX)[idx], (*_MovingObjRotVecY)[idx],
655  (*_MovingObjRotVecZ)[idx]);
656  r1.Mult(r2.Transpose(), R);
657  R.Mult((C2-cc2), C2);
658  C2+=cc1;
659  // C2=cc1+r1*r2.Transpose()*(C2-cc2);
660  R=_GT_R[i];
661  R2=r1*r2.Transpose()*R;
662 
663  BIASCDOUT(GSM_FMATRIX, "C2: "<<C2<<"R2: "<<R2<<endl);
664 
665  F[i-1][l+1].Compose(R1, C1, R2, C2);
666  BIASCDOUT(GSM_FMATRIX, "F from image "<<i-1<<" to "<<i<<" for "<<l
667  <<"th objects is "<<F[i-1][l+1]<<endl);
668 #ifdef BIAS_DEBUG
669  if (DebugLevelIsSet(GSM_FMATRIX)){
670  for (int k=*_NumStaticPoints + *_NumOutliers + l * *_NumMovingPoints;
672  k++){
673  BIASCDOUT(GSM_FMATRIX, setw(5)<<k<<" p2^T * F * p1 = "
674  <<(F[i-1][l+1]*_GT_NormalizedPoints[i-1][k]).
675  ScalarProduct(_GT_NormalizedPoints[i][k])
676  <<"\t"<<_GT_NormalizedPoints[i-1][k]<<" "
677  <<_GT_NormalizedPoints[i][k]<<endl);
678  }
679  }
680 #endif
681  }
682  }
683 }
684 
685 int GenSynthMatches::Write(const std::string& fname) const
686 {
687  return MatchDataBase::Write(fname);
688 }
689 
690 int GenSynthMatches::Write(ostream& os) const
691 {
692  BIASCDOUT(D_MD_IO, "using GenSynthMatches::Write(ostream)\n");
693  int res=MatchDataBase::Write(os);
694  if (res==0){
695  os.write((char*)_NumStaticPoints, sizeof(int));
696  os.write((char*)_NumOutliers, sizeof(int));
697  os.write((char*)_ImWidth, sizeof(int));
698  os.write((char*)_ImHeight, sizeof(int));
699  os.write((char*)_FocalLength, sizeof(double));
700  os.write((char*)_PrinciplePointX, sizeof(double));
701  os.write((char*)_PrinciplePointY, sizeof(double));
702  os.write((char*)_SigmaImagePoints, sizeof(double));
703  os.write((char*)_MaxDispOutliers, sizeof(double));
704  os.write((char*)_OutlDirChange, sizeof(double));
705  os.write((char*)_OutlLengthChange, sizeof(double));
706  os.write((char*)_SigmaCamCenterX, sizeof(double));
707  os.write((char*)_SigmaCamCenterY, sizeof(double));
708  os.write((char*)_SigmaCamCenterZ, sizeof(double));
709  os.write((char*)_SigmaCamRotX, sizeof(double));
710  os.write((char*)_SigmaCamRotY, sizeof(double));
711  os.write((char*)_SigmaCamRotZ, sizeof(double));
712  os.write((char*)_MinCamDistance, sizeof(double));
713  os.write((char*)_MaxCamDistance, sizeof(double));
714  os.write((char*)_UserGivenP, sizeof(bool));
715  os.write((char*)_NumMovingPoints, sizeof(int));
716  os.write((char*)_NumMovingObjects, sizeof(int));
717 
718  for (int i=0; i<*_NumMovingObjects; i++){
719  os.write((char*)&(*_SizeMovingObjX)[i], sizeof(double));
720  os.write((char*)&(*_SizeMovingObjY)[i], sizeof(double));
721  os.write((char*)&(*_SizeMovingObjZ)[i], sizeof(double));
722  }
723 
724  for (int i=0; i<*_NumStaticPoints; i++){
725  os.write((char*)_StaticPoints[i].GetData(), sizeof(HOMGPOINT3D_TYPE)*4);
726  }
727  for (int i=0; i<*_NumMovingPoints * *_NumMovingObjects; i++){
728  os.write((char*)_MovingPoints[i].GetData(), sizeof(HOMGPOINT3D_TYPE)*4);
729  }
730 
731  for (int i=0; i<*_NumImages; i++){
732  os.write((char*)&(*_MotionVecX)[i], sizeof(double));
733  os.write((char*)&(*_MotionVecY)[i], sizeof(double));
734  os.write((char*)&(*_MotionVecZ)[i], sizeof(double));
735  os.write((char*)&(*_RotVecX)[i], sizeof(double));
736  os.write((char*)&(*_RotVecY)[i], sizeof(double));
737  os.write((char*)&(*_RotVecZ)[i], sizeof(double));
738  for (int k=0; k<*_NumMovingObjects; k++){
739  int idx=k * *_NumImages + i;
740  os.write((char*)&(*_MovingObjMotionVecX)[idx], sizeof(double));
741  os.write((char*)&(*_MovingObjMotionVecY)[idx], sizeof(double));
742  os.write((char*)&(*_MovingObjMotionVecZ)[idx], sizeof(double));
743  os.write((char*)&(*_MovingObjRotVecX)[idx], sizeof(double));
744  os.write((char*)&(*_MovingObjRotVecY)[idx], sizeof(double));
745  os.write((char*)&(*_MovingObjRotVecZ)[idx], sizeof(double));
746  }
747  os.write((char*)_GT_R[i].GetData(), sizeof(ROTATION_MATRIX_TYPE)*9);
748  os.write((char*)_GT_C[i].GetData(), sizeof(HOMGPOINT3D_TYPE)*4);
749  for (int k=0; k<*_NumMovingObjects; k++){
750  int idx=k * *_NumImages + i;
751  os.write((char*)_MovingTransform[idx].GetData(), sizeof(double)*16);
752  }
753 
754  }
755  // write outlier
756  for (int i=0; i<*_NumImages; i++){
757  for (int k=*_NumStaticPoints; k<*_NumStaticPoints+*_NumOutliers; k++){
758  os.write((char*)_GT_Points[i][k].GetData(),sizeof(HOMGPOINT2D_TYPE)*3);
759  }
760  }
761 
762  if (!os) res=-3;
763  }
764  return res;
765 }
766 
767 int GenSynthMatches::Read(const string& fname)
768 {
769  return MatchDataBase::Read(fname);
770 }
771 
772 int GenSynthMatches::Read(istream & is)
773 {
774  BIASCDOUT(D_MD_IO, "using GenSynthMatches::Read(ostream)\n");
775  int res = MatchDataBase::Read(is);
776  if (res==0){
777  is.read((char*)_NumStaticPoints, sizeof(int));
778  is.read((char*)_NumOutliers, sizeof(int));
779  is.read((char*)_ImWidth, sizeof(int));
780  is.read((char*)_ImHeight, sizeof(int));
781  is.read((char*)_FocalLength, sizeof(double));
782  is.read((char*)_PrinciplePointX, sizeof(double));
783  is.read((char*)_PrinciplePointY, sizeof(double));
784  is.read((char*)_SigmaImagePoints, sizeof(double));
785  is.read((char*)_MaxDispOutliers, sizeof(double));
786  is.read((char*)_OutlDirChange, sizeof(double));
787  is.read((char*)_OutlLengthChange, sizeof(double));
788  is.read((char*)_SigmaCamCenterX, sizeof(double));
789  is.read((char*)_SigmaCamCenterY, sizeof(double));
790  is.read((char*)_SigmaCamCenterZ, sizeof(double));
791  is.read((char*)_SigmaCamRotX, sizeof(double));
792  is.read((char*)_SigmaCamRotY, sizeof(double));
793  is.read((char*)_SigmaCamRotZ, sizeof(double));
794  is.read((char*)_MinCamDistance, sizeof(double));
795  is.read((char*)_MaxCamDistance, sizeof(double));
796  is.read((char*)_UserGivenP, sizeof(bool));
797  is.read((char*)_NumMovingPoints, sizeof(int));
798  is.read((char*)_NumMovingObjects, sizeof(int));
802  for (int i=0; i<*_NumMovingObjects; i++){
803  is.read((char*)&(*_SizeMovingObjX)[i], sizeof(double));
804  is.read((char*)&(*_SizeMovingObjY)[i], sizeof(double));
805  is.read((char*)&(*_SizeMovingObjZ)[i], sizeof(double));
806  }
807 
809  for (int i=0; i<*_NumStaticPoints; i++){
810  is.read((char*)_StaticPoints[i].GetData(), sizeof(HOMGPOINT3D_TYPE)*4);
811  }
812  _MovingPoints.resize(*_NumMovingPoints * *_NumMovingObjects);
813  for (int i=0; i<*_NumMovingPoints * *_NumMovingObjects; i++){
814  is.read((char*)_MovingPoints[i].GetData(), sizeof(HOMGPOINT3D_TYPE)*4);
815  }
816 
823  _MovingObjMotionVecX->newsize(*_NumImages * *_NumMovingObjects);
824  _MovingObjMotionVecY->newsize(*_NumImages * *_NumMovingObjects);
825  _MovingObjMotionVecZ->newsize(*_NumImages * *_NumMovingObjects);
826  _MovingObjRotVecX->newsize(*_NumImages * *_NumMovingObjects);
827  _MovingObjRotVecY->newsize(*_NumImages * *_NumMovingObjects);
828  _MovingObjRotVecZ->newsize(*_NumImages * *_NumMovingObjects);
829  _GT_R.resize(*_NumImages);
830  _GT_C.resize(*_NumImages);
831  _GT_P.resize(*_NumImages);
832  _GT_Points.resize(*_NumImages);
834  _MovingTransform.resize(*_NumImages * *_NumMovingObjects);
835 
836  for (int i=0; i<*_NumImages; i++){
837  is.read((char*)&(*_MotionVecX)[i], sizeof(double));
838  is.read((char*)&(*_MotionVecY)[i], sizeof(double));
839  is.read((char*)&(*_MotionVecZ)[i], sizeof(double));
840  is.read((char*)&(*_RotVecX)[i], sizeof(double));
841  is.read((char*)&(*_RotVecY)[i], sizeof(double));
842  is.read((char*)&(*_RotVecZ)[i], sizeof(double));
843  for (int k=0; k<*_NumMovingObjects; k++){
844  int idx=k * *_NumImages + i;
845  is.read((char*)&(*_MovingObjMotionVecX)[idx], sizeof(double));
846  is.read((char*)&(*_MovingObjMotionVecY)[idx], sizeof(double));
847  is.read((char*)&(*_MovingObjMotionVecZ)[idx], sizeof(double));
848  is.read((char*)&(*_MovingObjRotVecX)[idx], sizeof(double));
849  is.read((char*)&(*_MovingObjRotVecY)[idx], sizeof(double));
850  is.read((char*)&(*_MovingObjRotVecZ)[idx], sizeof(double));
851  }
852 
853  is.read((char*)_GT_R[i].GetData(), sizeof(ROTATION_MATRIX_TYPE)*9);
854  is.read((char*)_GT_C[i].GetData(), sizeof(HOMGPOINT3D_TYPE)*4);
855  _GT_P[i].Compose(_K, _GT_R[i], _GT_C[i]);
856  for (int k=0; k<*_NumMovingObjects; k++){
857  int idx=k * *_NumImages + i;
858  is.read((char*)_MovingTransform[idx].GetData(), sizeof(double)*16);
859  }
860  }
861  int index;
864  // read outlier
865  for (int i=0; i<*_NumImages; i++){
866  for (int k=*_NumStaticPoints; k<*_NumStaticPoints+*_NumOutliers; k++){
867  is.read((char*)_GT_Points[i][k].GetData(),sizeof(HOMGPOINT2D_TYPE)*3);
868  _GT_NormalizedPoints[i][k]=_Ki*_GT_Points[i][k];
869  }
870  }
871  if (!is) res=-3;
872  }
873  return res;
874 }
875 
877 _CreateCamMovement(const bool fixed_error)
878 {
879  _K[0][0]=_K[1][1]=*_FocalLength;
880  _K[2][2]=1.0;
881  _K[0][2]=*_PrinciplePointX;
882  _K[1][2]=*_PrinciplePointY;
883 
884  _Ki=_K.Invert();
885 
886  _GT_R.resize(*_NumImages);
887  _R.resize(*_NumImages);
888  _GT_C.resize(*_NumImages);
889  _C.resize(*_NumImages);
890  _GT_P.resize(*_NumImages);
891  _P.resize(*_NumImages);
892 
893  HomgPoint3D C, nC;
894  RMatrixBase R, nR;
895  for (int i=0; i<*_NumImages; i++){
896  if (*_UserGivenP){
897  BIASASSERT((int)_MotionVecX->Size()>=*_NumImages);
898  BIASASSERT((int)_MotionVecY->Size()>=*_NumImages);
899  BIASASSERT((int)_MotionVecZ->Size()>=*_NumImages);
900  BIASASSERT((int)_RotVecX->Size()>=*_NumImages);
901  BIASASSERT((int)_RotVecY->Size()>=*_NumImages);
902  BIASASSERT((int)_RotVecZ->Size()>=*_NumImages);
903  C.Set((*_MotionVecX)[i], (*_MotionVecY)[i], (*_MotionVecZ)[i], 1.0);
904  R.SetXYZ((*_RotVecX)[i], (*_RotVecY)[i], (*_RotVecZ)[i]);
905  if (fixed_error){
906  if (i==0){
907  nC = C;
908  nR = R;
909  } else {
910  //generate random direction for rotation axis
911  Vector3<double> dC, dR, tmp(0.0, 0.0, 1.0), ep;
912  dC[0] = dR[0] = 1.0; // radius
913  dR[1] = _rand.GetUniformDistributed(0.0, M_PI*2.0); // phi
914  dR[2] = _rand.GetUniformDistributed(0.0, M_PI); // theta
915  dR = dR.CoordSphereToEuclidean();
916  double mR = *_SigmaCamRotX;
917  RMatrixBase tmpR, tmpdR(dR, mR);
918  tmpR.SetXYZ((*_RotVecX)[i], (*_RotVecY)[i], (*_RotVecZ)[i]);
919  nR = tmpR * tmpdR;
920 
921  // generate direction perpendicular to motion
922  Vector4<double> C4(C[0], C[1], C[2], 1.0);
923  ep = _GT_P[i-1] * C4;
924  ep /= ep.NormL2();
925  if (fabs(tmp.ScalarProduct(ep))>0.8){
926  tmp.Set(1.0, 0.0, 0.0);
927  }
928  // create dC which is perpendicual to ep
929  dC = ep.CrossProduct(tmp);
930  dC /= dC.NormL2();
931  // create a random rotation around old epipole direction
932  RMatrixBase CR(ep, _rand.GetUniformDistributed(0.0, M_PI*2.0));
933  dC = CR * dC;
934  // now compute the length for the diplacement vectro dC
935  double ang = *_SigmaCamCenterX;
936  double scale = tan(ang) * (_GT_C[i-1] - C).NormL2();
937  dC *= scale;
938  nC.Set(C[0]+dC[0], C[1]+dC[1], C[2]+dC[2], 1.0);
939  }
940  } else {
944  1.0);
945  nR.SetXYZ((*_RotVecX)[i]+
947  (*_RotVecY)[i]+
949  (*_RotVecZ)[i]+
951  }
952  } else { // if (*_UserGivenP){
953  BIASERR("unfinished");
954  } // if (*_UserGivenP){
955 
956  _GT_R[i]=R;
957  _R[i]=nR;
958  _GT_C[i]=C;
959  _C[i]=nC;
960  _GT_P[i].Compose(_K, _GT_R[i], _GT_C[i]);
961  _P[i].Compose(_K, _R[i], _C[i]);
962 
963 #ifdef BIAS_DEBUG
964  BIASCDOUT(GSM_CAM_MOTION, "_K: "<<_K<<endl);
965  BIASCDOUT(GSM_CAM_MOTION, "_Ki: "<<_Ki<<endl);
966  if (DebugLevelIsSet(GSM_CAM_MOTION)){
967  Vector3<double> r, nr;
968  _GT_R[i].GetRotationAnglesXYZ(r[0], r[1], r[2]);
969  _R[i].GetRotationAnglesXYZ(nr[0], nr[1], nr[2]);
970  BIASCDOUT(GSM_CAM_MOTION, "_GT_R["<<i<<"] = "<<r<<endl);
971  BIASCDOUT(GSM_CAM_MOTION, "_R["<<i<<"] = "<<nr<<endl);
972  BIASCDOUT(GSM_CAM_MOTION, "_GT_C["<<i<<"] = "<<_GT_C[i]<<endl);
973  BIASCDOUT(GSM_CAM_MOTION, "_C["<<i<<"] = "<<_C[i]<<endl);
974  BIASCDOUT(GSM_CAM_MOTION, "_GT_P["<<i<<"] = "<<_GT_P[i]<<endl);
975  BIASCDOUT(GSM_CAM_MOTION, "_P["<<i<<"] = "<<_P[i]<<endl);
976  }
977 #endif
978  }
979 }
980 
982 {
983  BIASASSERT((*_MovingObjMotionVecX).size() >= *_NumImages
984  || *_NumMovingObjects == 0);
985  BIASASSERT((*_MovingObjMotionVecY).size() >= *_NumImages
986  || *_NumMovingObjects == 0);
987  BIASASSERT((*_MovingObjMotionVecZ).size() >= *_NumImages
988  || *_NumMovingObjects == 0);
989  BIASASSERT((*_MovingObjRotVecX).size() >= *_NumImages
990  || *_NumMovingObjects == 0);
991  BIASASSERT((*_MovingObjRotVecY).size() >= *_NumImages
992  || *_NumMovingObjects == 0);
993  BIASASSERT((*_MovingObjRotVecZ).size() >= *_NumImages
994  || *_NumMovingObjects == 0);
995 
997  if (*_NumMovingObjects>0 && *_NumMovingPoints>0){
998  Vector3<double> r, t;
999  const int ni=*_NumImages;
1000  int ofs, idx;
1001  for (int n=0; n<*_NumMovingObjects; n++){
1002  BIASCDOUT(GSM_MOVIN_TRANSF, n<<"th moving object\n");
1003  ofs = ni*n;
1004  for (int k=0; k<ni; k++){
1005  idx=ofs+k;
1006  t[0]=(*_MovingObjMotionVecX)[idx];
1007  t[1]=(*_MovingObjMotionVecY)[idx];
1008  t[2]=(*_MovingObjMotionVecZ)[idx];
1009  r[0]=(*_MovingObjRotVecX)[idx];
1010  r[1]=(*_MovingObjRotVecY)[idx];
1011  r[2]=(*_MovingObjRotVecZ)[idx];
1012  _MovingTransform[idx].SetXYZ(r, t);
1013  BIASCDOUT(GSM_MOVIN_TRANSF, idx<<"th moving transf: "
1014  <<_MovingTransform[idx]<<endl);
1015  }
1016  }
1017  }
1018 }
1019 
1021  BIASASSERT(index >= 0);
1022  BIASASSERT(index < (int)_StaticPoints.size());
1023  double minx, maxx, miny, maxy, minz, maxz;
1024  // explanation of var names
1025  // 1. character: f/l - belonging first/last P Matrix
1026  // 2. character: n/f - near/far clippingplane
1027  // 3. character: u/l - upper/lower image corner
1028  // 4. character: r/l - left/right image corner
1029  // points in array are stored in this order
1030  // p3d[0]=fnul, p3d[1]=fnur, p3d[2]=fnll, p3d[3]=fnlr, p3d[4]=fful,
1031  // p3d[5]=ffur, p3d[6]=ffll, p3d[7]=fflr, p3d[8]=lnul, p3d[9]=lnur,
1032  // p3d[10]=lnll, p3d[11]=lnlr, p3d[12]=lful, p3d[13]=lfur, p3d[14]=lfll,
1033  // p3d[15]=lflr;
1034  HomgPoint3D p3d[16];
1035  HomgPoint3D fC, lC;
1036  fC=_GT_C[0];
1037  lC=_GT_C[*_NumImages-1];
1038  PMatrix fP, lP;
1039  fP=_GT_P[0];
1040  lP=_GT_P[*_NumImages-1];
1041 
1042  // now calculate the volume seen by at minimum one camera
1043  // backproject the image corners into space and apply min/max depth
1044  Vector3<double> ray;
1045  HomgPoint2D ul(0.0, 0.0), ur(*_ImWidth-1.0, 0.0),
1046  ll(0.0, *_ImHeight-1.0), lr(*_ImWidth-1.0, *_ImHeight-1.0);
1047 
1048  fP.BackprojectWorldCoo(ul, *_MinCamDistance, p3d[0]);
1049  fP.BackprojectWorldCoo(ur, *_MinCamDistance, p3d[1]);
1050  fP.BackprojectWorldCoo(ll, *_MinCamDistance, p3d[2]);
1051  fP.BackprojectWorldCoo(lr, *_MinCamDistance, p3d[3]);
1052  fP.BackprojectWorldCoo(ul, *_MaxCamDistance, p3d[4]);
1053  fP.BackprojectWorldCoo(ur, *_MaxCamDistance, p3d[5]);
1054  fP.BackprojectWorldCoo(ll, *_MaxCamDistance, p3d[6]);
1055  fP.BackprojectWorldCoo(lr, *_MaxCamDistance, p3d[7]);
1056 
1057  lP.BackprojectWorldCoo(ul, *_MinCamDistance, p3d[8]);
1058  lP.BackprojectWorldCoo(ur, *_MinCamDistance, p3d[9]);
1059  lP.BackprojectWorldCoo(ll, *_MinCamDistance, p3d[10]);
1060  lP.BackprojectWorldCoo(lr, *_MinCamDistance, p3d[11]);
1061  lP.BackprojectWorldCoo(ul, *_MaxCamDistance, p3d[12]);
1062  lP.BackprojectWorldCoo(ur, *_MaxCamDistance, p3d[13]);
1063  lP.BackprojectWorldCoo(ll, *_MaxCamDistance, p3d[14]);
1064  lP.BackprojectWorldCoo(lr, *_MaxCamDistance, p3d[15]);
1065 
1066  minx=miny=minz=DBL_MAX;
1067  maxx=maxy=maxz=-DBL_MAX;
1068  for (int j=0; j<16; j++){
1069  BIASCDOUT(GSM_VIEWINGVOL, "p3d["<<j<<"] = "<<p3d[j]<<endl);
1070  if (p3d[j][0]<minx) minx=p3d[j][0];
1071  if (p3d[j][0]>maxx) maxx=p3d[j][0];
1072  if (p3d[j][1]<miny) miny=p3d[j][1];
1073  if (p3d[j][1]>maxy) maxy=p3d[j][1];
1074  if (p3d[j][2]<minz) minz=p3d[j][2];
1075  if (p3d[j][2]>maxz) maxz=p3d[j][2];
1076  }
1077  BIASCDOUT(GSM_VIEWINGVOL, "Generating 3D point between ["<<minx<<", "
1078  <<miny<<", "<<minz<<"] and ["<<maxx<<", "<<maxy<<", "<<maxz
1079  <<"]\n");
1080 
1081  // generate static points
1082  HomgPoint3D p;
1083  HomgPoint2D p2d, np2d;
1084  int mtry;
1085  bool is_seen=true, seen_in_k=false;
1086  mtry=0;
1087  do {
1088  is_seen=true;
1089  p.Set(_rand.GetUniformDistributed(minx, maxx),
1090  _rand.GetUniformDistributed(miny, maxy),
1091  _rand.GetUniformDistributed(minz, maxz));
1092  for (int k=0; k<*_NumImages; k++){
1093  p2d=_GT_P[k]*p;
1094  np2d=_P[k]*p;
1095  // 99 % of all noisy points lie with *_SigmaImagePoints * 2.6 distance
1096  // of true image points
1097  seen_in_k = (_IsSeen(p2d, *_SigmaImagePoints * 2.6) &&
1098  _IsSeen(np2d, *_SigmaImagePoints * 2.6));
1099  is_seen=is_seen && seen_in_k;
1100  if (!seen_in_k) {
1101  BIASCDOUT(GSM_3D_POINTS, p<<" not seen in P["<<k<<"] : "<<p2d
1102  <<"/"<<np2d<<"\n");
1103  break;
1104  }
1105  }
1106  if (mtry>1000){
1107  for (int k=0; k<*_NumImages; k++){
1108  cerr << "_P["<<k<<"]: "<<_P[k]<<endl;
1109  cerr << "_GT_P["<<k<<"]: "<<_GT_P[k]<<endl;
1110  }
1111  cerr << "tried to generate 3D points between ["<<minx<<", "<<miny
1112  <<", "<<minz<<"] and ["<<maxx<<", "<<maxy<<", "<<maxz<<"]\n";
1113  BIASERR("more than 1000 tries for one 3D point, maybe no common "
1114  <<"viewing volume present");
1115  return GSM_RETURN_STATIC_OBJECT_NOT_VISIBLE;
1116  }
1117  mtry++;
1118  } while (!is_seen);
1119  _StaticPoints[index]=p;
1120  BIASCDOUT(GSM_3D_POINTS, index<<"th true 3D point: "
1121  <<_StaticPoints[index]<<endl);
1122 
1123  return GSM_RETURN_OK;
1124 }
1125 
1126 
1128 {
1129  double minx, maxx, miny, maxy, minz, maxz;
1130  // explanation of var names
1131  // 1. character: f/l - belonging first/last P Matrix
1132  // 2. character: n/f - near/far clippingplane
1133  // 3. character: u/l - upper/lower image corner
1134  // 4. character: r/l - left/right image corner
1135  // points in array are stored in this order
1136  // p3d[0]=fnul, p3d[1]=fnur, p3d[2]=fnll, p3d[3]=fnlr, p3d[4]=fful,
1137  // p3d[5]=ffur, p3d[6]=ffll, p3d[7]=fflr, p3d[8]=lnul, p3d[9]=lnur,
1138  // p3d[10]=lnll, p3d[11]=lnlr, p3d[12]=lful, p3d[13]=lfur, p3d[14]=lfll,
1139  // p3d[15]=lflr;
1140  HomgPoint3D p3d[16];
1141  HomgPoint3D fC, lC;
1142  fC=_GT_C[0];
1143  lC=_GT_C[*_NumImages-1];
1144  PMatrix fP, lP;
1145  fP=_GT_P[0];
1146  lP=_GT_P[*_NumImages-1];
1147 
1148  // now calculate the volume seen by at minimum one camera
1149  // backproject the image corners into space and apply min/max depth
1150  Vector3<double> ray;
1151  HomgPoint2D ul(0.0, 0.0), ur(*_ImWidth-1.0, 0.0),
1152  ll(0.0, *_ImHeight-1.0), lr(*_ImWidth-1.0, *_ImHeight-1.0);
1153 
1154  fP.BackprojectWorldCoo(ul, *_MinCamDistance, p3d[0]);
1155  fP.BackprojectWorldCoo(ur, *_MinCamDistance, p3d[1]);
1156  fP.BackprojectWorldCoo(ll, *_MinCamDistance, p3d[2]);
1157  fP.BackprojectWorldCoo(lr, *_MinCamDistance, p3d[3]);
1158  fP.BackprojectWorldCoo(ul, *_MaxCamDistance, p3d[4]);
1159  fP.BackprojectWorldCoo(ur, *_MaxCamDistance, p3d[5]);
1160  fP.BackprojectWorldCoo(ll, *_MaxCamDistance, p3d[6]);
1161  fP.BackprojectWorldCoo(lr, *_MaxCamDistance, p3d[7]);
1162 
1163  lP.BackprojectWorldCoo(ul, *_MinCamDistance, p3d[8]);
1164  lP.BackprojectWorldCoo(ur, *_MinCamDistance, p3d[9]);
1165  lP.BackprojectWorldCoo(ll, *_MinCamDistance, p3d[10]);
1166  lP.BackprojectWorldCoo(lr, *_MinCamDistance, p3d[11]);
1167  lP.BackprojectWorldCoo(ul, *_MaxCamDistance, p3d[12]);
1168  lP.BackprojectWorldCoo(ur, *_MaxCamDistance, p3d[13]);
1169  lP.BackprojectWorldCoo(ll, *_MaxCamDistance, p3d[14]);
1170  lP.BackprojectWorldCoo(lr, *_MaxCamDistance, p3d[15]);
1171 
1172  minx=miny=minz=DBL_MAX;
1173  maxx=maxy=maxz=-DBL_MAX;
1174  for (int j=0; j<16; j++){
1175  BIASCDOUT(GSM_VIEWINGVOL, "p3d["<<j<<"] = "<<p3d[j]<<endl);
1176  if (p3d[j][0]<minx) minx=p3d[j][0];
1177  if (p3d[j][0]>maxx) maxx=p3d[j][0];
1178  if (p3d[j][1]<miny) miny=p3d[j][1];
1179  if (p3d[j][1]>maxy) maxy=p3d[j][1];
1180  if (p3d[j][2]<minz) minz=p3d[j][2];
1181  if (p3d[j][2]>maxz) maxz=p3d[j][2];
1182  }
1183  BIASCDOUT(GSM_VIEWINGVOL, "Generating 3D point between ["<<minx<<", "
1184  <<miny<<", "<<minz<<"] and ["<<maxx<<", "<<maxy<<", "<<maxz
1185  <<"]\n");
1186 
1187  // generate static points
1188  HomgPoint3D p;
1189  HomgPoint2D p2d, np2d;
1190  int i=0, mtry;
1191  bool is_seen=true, seen_in_k=false;
1193  while(i<*_NumStaticPoints){
1194  mtry=0;
1195  do {
1196  is_seen=true;
1197  p.Set(_rand.GetUniformDistributed(minx, maxx),
1198  _rand.GetUniformDistributed(miny, maxy),
1199  _rand.GetUniformDistributed(minz, maxz));
1200  for (int k=0; k<*_NumImages; k++){
1201  p2d=_GT_P[k]*p;
1202  np2d=_P[k]*p;
1203  // 99 % of all noisy points lie with *_SigmaImagePoints * 2.6 distance
1204  // of true image points
1205  seen_in_k = (_IsSeen(p2d, *_SigmaImagePoints * 2.6) &&
1206  _IsSeen(np2d, *_SigmaImagePoints * 2.6));
1207  is_seen=is_seen && seen_in_k;
1208  if (!seen_in_k) {
1209  BIASCDOUT(GSM_3D_POINTS, p<<" not seen in P["<<k<<"] : "<<p2d
1210  <<"/"<<np2d<<"\n");
1211  break;
1212  }
1213  }
1214  if (mtry>1000){
1215  for (int k=0; k<*_NumImages; k++){
1216  cerr << "_P["<<k<<"]: "<<_P[k]<<endl;
1217  cerr << "_GT_P["<<k<<"]: "<<_GT_P[k]<<endl;
1218  }
1219  cerr << "tried to generate 3D points between ["<<minx<<", "<<miny
1220  <<", "<<minz<<"] and ["<<maxx<<", "<<maxy<<", "<<maxz<<"]\n";
1221  BIASERR("more than 1000 tries for one 3D point, maybe no common "
1222  <<"viewing volume present");
1223  return -1;
1224  }
1225  mtry++;
1226  } while (!is_seen);
1227  _StaticPoints[i]=p;
1228  BIASCDOUT(GSM_3D_POINTS, i<<"th true 3D point: "<<_StaticPoints[i]<<endl);
1229  i++;
1230  }
1231  return 0;
1232 }
1233 
1235 {
1236  if (*_NumMovingPoints>0 && *_NumMovingObjects>0){
1237  HomgPoint3D corner[8], p3d;
1238  HomgPoint2D p2d, np2d;
1239  bool seen_in_k=true, any_seen_in_k=false;
1240  double r1, r2, r3;
1241 
1242  for (int i=0; i<*_NumMovingObjects; i++){
1243  corner[0][3]=corner[1][3]=corner[2][3]=corner[3][3]=1.0;
1244  corner[4][3]=corner[5][3]=corner[6][3]=corner[7][3]=1.0;
1245 
1246  corner[0][2]=corner[1][2]=corner[2][2]=corner[3][2]=
1247  (*_SizeMovingObjZ)[i]/2.0;
1248  corner[4][2]=corner[5][2]=corner[6][2]=corner[7][2]=
1249  -(*_SizeMovingObjZ)[i]/2.0;
1250 
1251  corner[0][1]=corner[1][1]=corner[4][1]=corner[5][1]=
1252  (*_SizeMovingObjY)[i]/2.0;
1253  corner[2][1]=corner[3][1]=corner[6][1]=corner[7][1]=
1254  -(*_SizeMovingObjY)[i]/2.0;
1255 
1256  corner[0][0]=corner[3][0]=corner[4][0]=corner[7][0]=
1257  (*_SizeMovingObjX)[i]/2.0;
1258  corner[1][0]=corner[2][0]=corner[5][0]=corner[6][0]=
1259  -(*_SizeMovingObjX)[i]/2.0;
1260 
1261  for (int k=0; k<*_NumImages; k++){
1262  int idx = i * *_NumImages + k;
1263  // check if center of moving object is visible
1264  for (int l=0; l<8; l++){
1265  //cerr <<setw(3)<<l<<" "<<corner[l]<<endl;
1266  p3d=_MovingTransform[idx]*corner[l];
1267  p2d=_GT_P[k]*p3d;
1268  np2d=_P[k]*p3d;
1269  seen_in_k = _IsSeen(p2d) && _IsSeen(np2d);
1270  any_seen_in_k = any_seen_in_k || seen_in_k;
1271  }
1272  if (!any_seen_in_k){
1273  cerr << "_MovingTransform["<<idx<<"]: "<<_MovingTransform[idx]
1274  <<endl;
1275  cerr << "_P["<<k<<"]: "<<_P[k]<<endl;
1276  cerr << "_GT_P["<<k<<"]: "<<_GT_P[k]<<endl;
1277  cerr << "_R["<<k<<"]: "<<_R[k]<<endl;
1278  _R[k].GetRotationAnglesXYZ(r1, r2, r3);
1279  cerr <<"rotation angles of _R["<<k<<"]: "<<r1<<"\t"<< r2<<"\t"
1280  <<r3<<endl;
1281  cerr << "_GT_R["<<k<<"]: "<<_GT_R[k]<<endl;
1282  cerr << "_C["<<k<<"]: "<<_C[k]<<endl;
1283  cerr << "_GT_C["<<k<<"]: "<<_GT_C[k]<<endl;
1284  cerr << "corners: "<<endl;
1285  for (int l=0; l<8; l++){
1286  p3d=_MovingTransform[idx]*corner[l];
1287  p2d=_GT_P[k]*p3d;
1288  np2d=_P[k]*p3d;
1289  cerr <<setw(3)<<l<<" corn: "<<corner[l]<<"\tp3d: "<<p3d<<"\tp2d: "
1290  <<p2d<<"\tnp2d: "<<np2d<<endl;
1291  }
1292  BIASERR("no corner of moving object not seen in image "<<k);
1293  return -1;
1294  }
1295  // check if center is visible
1296  p3d.Set(0.0, 0.0, 0.0);
1297  p3d=_MovingTransform[idx]*p3d;
1298  p2d=_GT_P[k]*p3d;
1299  np2d=_P[k]*p3d;
1300  seen_in_k = _IsSeen(p2d) && _IsSeen(np2d);
1301  if (!seen_in_k){
1302  cerr << "_MovingTransform["<<idx<<"]: "<<_MovingTransform[idx]<<endl;
1303  cerr << "_P["<<k<<"]: "<<_P[k]<<endl;
1304  cerr << "_GT_P["<<k<<"]: "<<_GT_P[k]<<endl;
1305  cerr << "_R["<<k<<"]: "<<_R[k]<<endl;
1306  _R[k].GetRotationAnglesXYZ(r1, r2, r3);
1307  cerr <<"rotation angles of _R["<<k<<"]: "<<r1<<"\t"<< r2<<"\t"
1308  <<r3<<endl;
1309  cerr << "_GT_R["<<k<<"]: "<<_GT_R[k]<<endl;
1310  cerr << "_C["<<k<<"]: "<<_C[k]<<endl;
1311  cerr << "_GT_C["<<k<<"]: "<<_GT_C[k]<<endl;
1312  BIASERR("center of moving object not seen in image "<<k<<" center "
1313  <<p3d<<" p2d: "<<p2d<<" np2d: "<<np2d);
1314  return -2;
1315  }
1316  }
1317  }
1318  }
1319  return 0;
1320 
1321 }
1322 
1323 
1325 {
1326 
1327  int offset=*_NumStaticPoints + *_NumOutliers;
1328  int movingPointIndex = index - offset;
1329 
1330  BIASASSERT(*_NumMovingPoints > 0);
1331  int l = (int)(movingPointIndex / *_NumMovingPoints);
1332 
1333  BIASASSERT(movingPointIndex >= 0);
1334  BIASASSERT(movingPointIndex < (int)_MovingPoints.size());
1335 
1336  // _MovingPoints.resize(*_NumMovingPoints * *_NumMovingObjects);
1337  double x2, y2, z2;
1338 
1339  HomgPoint2D p2d, np2d;
1340  HomgPoint3D p3d;
1341  bool seen_in_all=true, seen_in_k=true;
1342 
1343  x2=(*_SizeMovingObjX)[l]/2.0;
1344  y2=(*_SizeMovingObjY)[l]/2.0;
1345  z2=(*_SizeMovingObjZ)[l]/2.0;
1346 
1347  int mytry = 0;
1348  do {
1349  seen_in_all=true;
1350  _MovingPoints[movingPointIndex].Set(_rand.GetUniformDistributed(-x2, x2),
1351  _rand.GetUniformDistributed(-y2, y2),
1352  _rand.GetUniformDistributed(-z2, z2),
1353  1.0);
1354  for (int k=0; k<*_NumImages; k++) {
1355  p3d=_MovingTransform[l* *_NumImages + k]*_MovingPoints[movingPointIndex];
1356  p2d=_GT_P[k]*p3d;
1357  np2d=_P[k]*p3d;
1358  seen_in_k = _IsSeen(p2d) && _IsSeen(np2d);
1359  if (!seen_in_k){
1360  BIASCDOUT(GSM_3D_POINTS, p3d<<" moving point not seen in k "
1361  <<p2d<<"/"<<np2d<<endl);
1362  break;
1363  }
1364  }
1365  seen_in_all = seen_in_k && seen_in_all;
1366  mytry++;
1367  } while (!seen_in_all && mytry < 1000);
1368  BIASCDOUT(GSM_3D_POINTS, movingPointIndex<<"th moving 3D point : "
1369  <<_MovingPoints[movingPointIndex]<<endl);
1370 
1371  return GSM_RETURN_OK;
1372 }
1373 
1376 {
1378  double x2, y2, z2;
1379 
1380  HomgPoint2D p2d, np2d;
1381  HomgPoint3D p3d;
1382  bool seen_in_all=true, seen_in_k=true;
1383  int mpi;
1384 
1385  if (_AreMovingObjectsVisible()!=0) return -1;
1386 
1387  for (int l=0; l<*_NumMovingObjects; l++){
1388  x2=(*_SizeMovingObjX)[l]/2.0;
1389  y2=(*_SizeMovingObjY)[l]/2.0;
1390  z2=(*_SizeMovingObjZ)[l]/2.0;
1391  for (int i=0; i<*_NumMovingPoints; i++){
1392  mpi=i + l* *_NumMovingPoints;
1393  do {
1394  seen_in_all=true;
1395  _MovingPoints[mpi].Set(_rand.GetUniformDistributed(-x2, x2),
1396  _rand.GetUniformDistributed(-y2, y2),
1397  _rand.GetUniformDistributed(-z2, z2), 1.0);
1398  for (int k=0; k<*_NumImages; k++){
1399  p3d=_MovingTransform[l* *_NumImages + k]*_MovingPoints[mpi];
1400  p2d=_GT_P[k]*p3d;
1401  np2d=_P[k]*p3d;
1402  seen_in_k = _IsSeen(p2d) && _IsSeen(np2d);
1403  if (!seen_in_k){
1404  BIASCDOUT(GSM_3D_POINTS, p3d<<" moving point not seen in k "
1405  <<p2d<<"/"<<np2d<<endl);
1406  break;
1407  }
1408  }
1409  seen_in_all = seen_in_k && seen_in_all;
1410  } while (!seen_in_all);
1411  BIASCDOUT(GSM_3D_POINTS, mpi<<"th moving 3D point : "
1412  <<_MovingPoints[mpi]<<endl);
1413  }
1414  }
1415  return 0;
1416 }
1417 
1418 
1419 
1420 
1421 
1422 
1423 
1424 
1425 
1426 
1427 
1428 
1429 
1430 
1432 {
1433  int idx;
1434  int res = _CreateStaticGT2DPoints(idx);
1435  if (res != GSM_RETURN_OK) {
1436  index = idx;
1437  return res;
1438  }
1439  std::vector<HomgPoint2D> empty(*_NumStaticPoints +
1441  + *_NumOutliers);
1442  _Points.assign(*_NumImages, empty);
1443  _NormalizedPoints.assign(*_NumImages, empty);
1444 
1445  BIASCDOUT(GSM_NOISE, "Static2D: "<<*_SigmaImagePoints<<endl);
1446 
1447  HomgPoint2D noise;
1448  for (int k=0; k<*_NumImages; k++){
1449  for (int i=0; i<*_NumStaticPoints; i++){
1450  _Points[k][i]=_P[k]*_StaticPoints[i];
1451  _Points[k][i].Homogenize();
1454  BIASCDOUT(GSM_NOISE, "s2d: "<<noise << endl);
1455  _Points[k][i]+=noise;
1456  _NormalizedPoints[k][i]=_Ki*_Points[k][i];
1457  if (!_IsSeen(_Points[k][i])){
1458  BIASERR("static point "<<i<<"<< not seen in image "<<k<<" : "
1459  <<_Points[k][i]);
1460  index = i;
1461  return GSM_RETURN_STATIC_OBJECT_NOT_VISIBLE;
1462  }
1463  }
1464  }
1465 #ifdef BIASDEBUG
1466  if (DebugLevelIsSet(GSM_2D_MATCHES)){
1467  for (int i=0; i<*_NumStaticPoints; i++){
1468  BIASCDOUT(GSM_2D_MATCHES, "match "<<i<<" : ");
1469  for (int k=0; k<*_NumImages; k++){
1470  BIASCDOUT(GSM_2D_MATCHES, k<<":"<<_GT_Points[k][i]<<"/"
1471  <<_Points[k][i]<<"/"<<_GT_NormalizedPoints[k][i]<<"/"
1472  <<_NormalizedPoints[k][i]<<" ");
1473  }
1474  BIASCDOUT(GSM_2D_MATCHES, endl);
1475  }
1476  }
1477 #endif
1478  return GSM_RETURN_OK;
1479 }
1480 
1482 {
1483  std::vector<HomgPoint2D> empty(*_NumStaticPoints
1485  *_NumOutliers);
1486  _GT_Points.assign(*_NumImages, empty);
1487  _GT_NormalizedPoints.assign(*_NumImages, empty);
1488 
1489  for (int k=0; k<*_NumImages; k++){
1490  for (int i=0; i<*_NumStaticPoints; i++){
1491  _GT_Points[k][i]=_GT_P[k]*_StaticPoints[i];
1492  _GT_Points[k][i].Homogenize();
1493  _GT_NormalizedPoints[k][i]=_Ki*_GT_Points[k][i];
1494  if (!_IsSeen(_GT_Points[k][i])) {
1495  BIASERR("static GT point "<<i<<"<< not seen in image "<<k<<" : "
1496  <<_GT_Points[k][i]);
1497  index = i;
1498  return GSM_RETURN_STATIC_OBJECT_NOT_VISIBLE;
1499  }
1500  }
1501  }
1502  return GSM_RETURN_OK;
1503 }
1504 
1506 {
1507  BIASCDOUT(GSM_NOISE, "AddOutlier: "<<*_SigmaImagePoints<<endl);
1508  HomgPoint2D noise, outldisp;
1509  bool seen_from_all=true, seen_in_k=true;
1510  RMatrixBase R;
1511  for (int i=*_NumStaticPoints; i<*_NumStaticPoints+*_NumOutliers; i++){
1512  do {
1513  seen_from_all=true;
1514  _GT_Points[0][i].Set(_rand.GetUniformDistributed(0.0, *_ImWidth-1.0),
1515  _rand.GetUniformDistributed(0.0, *_ImHeight-1.0), 1.0);
1518  BIASCDOUT(GSM_NOISE, "outl: "<<noise << endl);
1519  _Points[0][i]=_GT_Points[0][i]+noise;
1520  _GT_NormalizedPoints[0][i]=_Ki*_GT_Points[0][i];
1521  _NormalizedPoints[0][i]=_Ki*_Points[0][i];
1522  seen_in_k = _IsSeen(_GT_Points[0][i]) && _IsSeen(_Points[0][i]);
1523  seen_from_all = seen_from_all && seen_in_k;
1524  // first match determines direction
1526  *_MaxDispOutliers),
1528  *_MaxDispOutliers), 0.0);
1529  _GT_Points[1][i]=_GT_Points[0][i]+outldisp;
1532  BIASCDOUT(GSM_NOISE, "outl: "<<noise << endl);
1533  _Points[1][i]=_GT_Points[1][i]+noise;
1534  _GT_NormalizedPoints[1][i]=_Ki*_GT_Points[1][i];
1535  _NormalizedPoints[1][i]=_Ki*_Points[1][i];
1536  seen_in_k = _IsSeen(_GT_Points[1][i]) && _IsSeen(_Points[1][i]);
1537  seen_from_all = seen_from_all && seen_in_k;
1538  // direction is taken from last match
1539  for (int k=2; k<*_NumImages; k++){
1540  R.SetXYZ(0.0, 0.0, _rand.GetNormalDistributed(0.0,*_OutlDirChange));
1541  outldisp=R*outldisp;
1543  _GT_Points[k][i]=_GT_Points[k-1][i]+outldisp;
1544  noise.Set(_rand.GetNormalDistributed(0.0, *_SigmaImagePoints),
1546  BIASCDOUT(GSM_NOISE, "outl: "<<noise << endl);
1547  _Points[k][i]=_GT_Points[k][i]+noise;
1548  _GT_NormalizedPoints[k][i]=_Ki*_GT_Points[k][i];
1549  _NormalizedPoints[k][i]=_Ki*_Points[k][i];
1550  seen_in_k = _IsSeen(_GT_Points[k][i]) && _IsSeen(_Points[k][i]);
1551  seen_from_all = seen_from_all && seen_in_k;
1552  if (!seen_from_all) break;
1553  }
1554  } while (!seen_from_all);
1555  }
1556 
1557 #ifdef BIASDEBUG
1558  if (DebugLevelIsSet(GSM_2D_MATCHES)){
1559  for (int i=*_NumStaticPoints; i<*_NumStaticPoints+*_NumOutliers; i++){
1560  BIASCDOUT(GSM_2D_MATCHES, "match "<<i<<" : ");
1561  for (int k=0; k<*_NumImages; k++){
1562  BIASCDOUT(GSM_2D_MATCHES, k<<":"<<_GT_Points[k][i]<<"/"
1563  <<_Points[k][i]<<"/"<<_GT_NormalizedPoints[k][i]<<"/"
1564  <<_NormalizedPoints[k][i]<<" ");
1565  }
1566  BIASCDOUT(GSM_2D_MATCHES, endl);
1567  }
1568  }
1569 #endif
1570 }
1571 
1572 
1574 {
1575  index = -1;
1576  if ((int)_GT_Points.size()!=*_NumImages ||
1577  (int)_GT_Points[0].size()!=*_NumStaticPoints+*_NumOutliers+
1579  BIASERR("internal data structs not allocated call "
1580  <<"_CreateStatic2DPoints() first ");
1581  BIASABORT;
1582  }
1583 
1584  int idx = -1;
1585  int res = _CreateMovingGT2DPoints(idx);
1586  if (res != GSM_RETURN_OK) {
1587  index = idx;
1588  return res;
1589  }
1590 
1591  BIASCDOUT(GSM_NOISE, "Moving2D: "<<*_SigmaImagePoints<<endl);
1592 
1593  HomgPoint2D noise;
1594  HomgPoint3D p3d;
1595  for (int l=0; l<*_NumMovingObjects; l++){
1596  int offset=*_NumStaticPoints+*_NumOutliers + l * *_NumMovingPoints;
1597  BIASCDOUT(GSM_MOVIN_3D_POINTS, "object "<<l<<endl);
1598  for (int k=0; k<*_NumImages; k++){
1599  int idx=l* *_NumImages + k;
1600  for (int i=offset; i<offset+*_NumMovingPoints; i++){
1601  p3d=_MovingTransform[idx]*_MovingPoints[i-offset+l* *_NumMovingPoints];
1602  BIASCDOUT(GSM_MOVIN_3D_POINTS, "using moving transf "<<idx
1603  <<" and _MovingPoints["<<i-offset+l * *_NumMovingPoints
1604  <<"] to create point in image "<<k<<"\n");
1605  _Points[k][i]=_P[k]*p3d;
1606  _Points[k][i].Homogenize();
1609  BIASCDOUT(GSM_NOISE, "m2d: "<<noise << endl);
1610  _Points[k][i]+=noise;
1611  BIASCDOUT(GSM_MOVIN_3D_POINTS, "moving 3d point "<<i<<" "<<p3d
1612  <<"\t "<<_Points[k][i]<<endl);
1613  _NormalizedPoints[k][i]=_Ki*_Points[k][i];
1614  if (!_IsSeen(_Points[k][i])){
1615  BIASERR("moving point "<<i<<"<< not seen in image "<<k<<" : "
1616  <<_Points[k][i]);
1617  index = i;
1618  return GSM_RETURN_ERROR_HANDLING_MOVING_POINT;
1619  }
1620  }
1621  }
1622  }
1623  return GSM_RETURN_OK;
1624 }
1625 
1627 {
1628  index = -1;
1629  if ((int)_GT_Points.size()!=*_NumImages ||
1630  (int)_GT_Points[0].size()!=*_NumStaticPoints+*_NumOutliers+
1632  BIASERR("internal data structs not allocated call "
1633  <<"_CreateStatic2DPoints() first ");
1634  BIASABORT;
1635  }
1636 
1637  HomgPoint3D p3d;
1638  for (int l=0; l<*_NumMovingObjects; l++){
1639  int offset=*_NumStaticPoints + *_NumOutliers + l * *_NumMovingPoints;
1640  BIASCDOUT(GSM_MOVIN_3D_POINTS, "object "<<l<<endl);
1641  for (int k=0; k<*_NumImages; k++){
1642  int idx=l * *_NumImages + k;
1643  for (int i=offset; i<offset+*_NumMovingPoints; i++) {
1644  p3d=_MovingTransform[idx]*_MovingPoints[i-offset+l* *_NumMovingPoints];
1645  BIASCDOUT(GSM_MOVIN_3D_POINTS, "using moving transf "<< idx << _MovingTransform[idx]
1646  <<" and _MovingPoints["<<i-offset+l * *_NumMovingPoints
1647  <<"] to create point in image "<<k<<"\n");
1648  _GT_Points[k][i]=_GT_P[k]*p3d;
1649  _GT_Points[k][i].Homogenize();
1650 
1651  BIASCDOUT(GSM_MOVIN_3D_POINTS, "moving 3d point "<<i<<" "<<p3d
1652  <<"\t "<<_GT_Points[k][i]<<endl);
1653 
1654  _GT_NormalizedPoints[k][i]=_Ki*_GT_Points[k][i];
1655  if (!_IsSeen(_GT_Points[k][i])) {
1656  BIASERR("moving point "<<i<<"<< not seen in image "<<k<<" : "
1657  <<_GT_Points[k][i]);
1658  index = i;
1659  return GSM_RETURN_ERROR_HANDLING_MOVING_POINT;
1660  }
1661  }
1662  }
1663  }
1664  BIASCDOUT(GSM_MOVIN_3D_POINTS, endl);
1665  return GSM_RETURN_OK;
1666 }
1667 
1668 
1670 {
1671  ////////////////////////////////////////////////////////////
1672  // PGNum
1673  ///////////////////////////////////////////////////////////
1674 
1675  int grp;
1676  // para.ShowData();
1677  if (para.CheckParam("NumImages")){
1678  grp=para.GetGroupID("NumImages");
1679  } else {
1680  grp=para.GetFreeGroupID();
1681  }
1682  // cerr << "GenSynthMatches: using ID "<<grp<<" for group num\n";
1683 
1684  if (para.CheckParam("NumStaticPoints")){
1685  _NumStaticPoints=para.GetParamInt("NumStaticPoints");
1686  } else {
1687  _NumStaticPoints=para.AddParamInt("NumStaticPoints", "number of true matches", 15, 0, INT_MAX, 0, grp);
1688  }
1689 
1690  if (para.CheckParam("NumOutliers")){
1691  _NumOutliers=para.GetParamInt("NumOutliers");
1692  } else {
1693  _NumOutliers=para.AddParamInt("NumOutliers", "number of outliers", 5, 0, INT_MAX, 0, grp);
1694  }
1695 
1696  if (para.CheckParam("ImWidth")){
1697  _ImWidth=para.GetParamInt("ImWidth");
1698  } else {
1699  _ImWidth=para.AddParamInt("ImWidth", "image width", 640, 0, INT_MAX, 0, grp);
1700  }
1701 
1702  if (para.CheckParam("ImHeight")){
1703  _ImHeight=para.GetParamInt("ImHeight");
1704  } else {
1705  _ImHeight=para.AddParamInt("ImHeight", "image height", 480, 0, INT_MAX, 0, grp);
1706  }
1707 
1708  if (para.CheckParam("NumMovingPoints")){
1709  _NumMovingPoints=para.GetParamInt("NumMovingPoints");
1710  } else {
1711  _NumMovingPoints=para.AddParamInt("NumMovingPoints", "number of moving points", 10, 0, INT_MAX, 0, grp);
1712  }
1713 
1714  if (para.CheckParam("NumMovingObjects")){
1715  _NumMovingObjects=para.GetParamInt("NumMovingObjects");
1716  } else {
1717  _NumMovingObjects=para.AddParamInt("NumMovingObjects", "number of moving objects", 1, 0, INT_MAX, 0, grp);
1718  }
1719 
1720  if (para.IsUsedGroupID(grp))
1721  para.SetGroupName(grp, "numbers");
1722 
1723  ////////////////////////////////////////////////////////////
1724  // PGMotion
1725  ///////////////////////////////////////////////////////////
1726 
1727  grp=para.GetFreeGroupID();
1728  //cerr << "using ID "<<grp<<" for group motion\n";
1729 
1730  if (para.CheckParam("FocalLength")){
1731  _FocalLength=para.GetParamDouble("FocalLength");
1732  } else {
1733  _FocalLength=para.AddParamDouble("FocalLength", "focal length in pixel", 840.0, 0.0, DBL_MAX, 0, grp);
1734  }
1735 
1736  if (para.CheckParam("PrinciplePointX")){
1737  _PrinciplePointX=para.GetParamDouble("PrinciplePointX");
1738  } else {
1739  _PrinciplePointX=para.AddParamDouble("PrinciplePointX", "x component of principle point", 320.0, 0.0, DBL_MAX, 0, grp);
1740  }
1741 
1742  if (para.CheckParam("PrinciplePointY")){
1743  _PrinciplePointY=para.GetParamDouble("PrinciplePointY");
1744  } else {
1745  _PrinciplePointY=para.AddParamDouble("PrinciplePointY", "y component of principle point", 240.0, 0.0, DBL_MAX, 0, grp);
1746  }
1747 
1748  if (para.CheckParam("UserGivenP")){
1749  _UserGivenP=para.GetParamBool("UserGivenP");
1750  } else {
1751  _UserGivenP=para.AddParamBool("UserGivenP", "if true use MotionVec? and RotVec?, if false use Overall? ", true, 0, grp);
1752  }
1753 
1754  Vector<double> dflt;
1755  dflt.newsize(2);
1756  dflt[0]=0.0; dflt[1]=-0.1;
1757  if (para.CheckParam("MotionVecX")){
1758  _MotionVecX=para.GetParamVecDbl("MotionVecX");
1759  } else {
1760  _MotionVecX=para.AddParamVecDbl("MotionVecX", "vector of x components of camera centers", dflt, 0, grp);
1761  }
1762 
1763  dflt[0]=0.0; dflt[1]=0.0;
1764  if (para.CheckParam("MotionVecY")){
1765  _MotionVecY=para.GetParamVecDbl("MotionVecY");
1766  } else {
1767  _MotionVecY=para.AddParamVecDbl("MotionVecY", "vector of y components of camera centers", dflt, 0, grp);
1768  }
1769 
1770  dflt[0]=0.0; dflt[1]=1.0;
1771  if (para.CheckParam("MotionVecZ")){
1772  _MotionVecZ=para.GetParamVecDbl("MotionVecZ");
1773  } else {
1774  _MotionVecZ=para.AddParamVecDbl("MotionVecZ", "vector of z components of camera centers", dflt, 0, grp);
1775  }
1776 
1777  dflt[0]=0.0; dflt[1]=0.0;
1778  if (para.CheckParam("RotVecX")){
1779  _RotVecX=para.GetParamVecDbl("RotVecX");
1780  } else {
1781  _RotVecX=para.AddParamVecDbl("RotVecX", "vector of rotation around x-axis", dflt, 0, grp);
1782  }
1783 
1784  dflt[0]=0.0; dflt[1]=-0.1;
1785  if (para.CheckParam("RotVecY")){
1786  _RotVecY=para.GetParamVecDbl("RotVecY");
1787  } else {
1788  _RotVecY=para.AddParamVecDbl("RotVecY", "vector of rotation around y-axis", dflt, 0, grp);
1789  }
1790 
1791  dflt[0]=0.0; dflt[1]=0.0;
1792  if (para.CheckParam("RotVecZ")){
1793  _RotVecZ=para.GetParamVecDbl("RotVecZ");
1794  } else {
1795  _RotVecZ=para.AddParamVecDbl("RotVecZ", "vector of rotation around z-axis", dflt, 0, grp);
1796  }
1797 
1798  if (para.IsUsedGroupID(grp))
1799  para.SetGroupName(grp, "cam motion");
1800 
1801  ////////////////////////////////////////////////////////////
1802  // PGNoise
1803  ///////////////////////////////////////////////////////////
1804 
1805  grp=para.GetFreeGroupID();
1806  //cerr << "using ID "<<grp<<" for group noise\n";
1807 
1808  if (para.CheckParam("SigmaImagePoints")){
1809  _SigmaImagePoints=para.GetParamDouble("SigmaImagePoints");
1810  } else {
1811  _SigmaImagePoints=para.AddParamDouble("SigmaImagePoints", "sigma of normal distribution in image", 1.0, 0.0, DBL_MAX, 0, grp);
1812  }
1813 
1814  if (para.CheckParam("MaxDispOutliers")){
1815  _MaxDispOutliers=para.GetParamDouble("MaxDispOutliers");
1816  } else {
1817  _MaxDispOutliers=para.AddParamDouble("MaxDispOutliers", "max allowed flow for outliers", 25.0, 0.0, DBL_MAX, 0, grp);
1818  }
1819 
1820  if (para.CheckParam("SigmaCamCenterX")){
1821  _SigmaCamCenterX=para.GetParamDouble("SigmaCamCenterX");
1822  } else {
1823  _SigmaCamCenterX=para.AddParamDouble("SigmaCamCenterX", "sigma of normal distributed noise of cam centers", 0.1, 0.0, DBL_MAX, 0, grp);
1824  }
1825 
1826  if (para.CheckParam("SigmaCamCenterY")){
1827  _SigmaCamCenterY=para.GetParamDouble("SigmaCamCenterY");
1828  } else {
1829  _SigmaCamCenterY=para.AddParamDouble("SigmaCamCenterY", "sigma of normal distributed noise of cam centers", 0.1, 0.0, DBL_MAX, 0, grp);
1830  }
1831 
1832  if (para.CheckParam("SigmaCamCenterZ")){
1833  _SigmaCamCenterZ=para.GetParamDouble("SigmaCamCenterZ");
1834  } else {
1835  _SigmaCamCenterZ=para.AddParamDouble("SigmaCamCenterZ", "sigma of normal distributed noise of cam centers", 0.1, 0.0, DBL_MAX, 0, grp);
1836  }
1837 
1838  if (para.CheckParam("SigmaCamRotX")){
1839  _SigmaCamRotX=para.GetParamDouble("SigmaCamRotX");
1840  } else {
1841  _SigmaCamRotX=para.AddParamDouble("SigmaCamRotX", "sigma of normal distributed noise of cam rotation", 0.01, 0.0, DBL_MAX, 0, grp);
1842  }
1843 
1844  if (para.CheckParam("SigmaCamRotY")){
1845  _SigmaCamRotY=para.GetParamDouble("SigmaCamRotY");
1846  } else {
1847  _SigmaCamRotY=para.AddParamDouble("SigmaCamRotY", "sigma of normal distributed noise of cam rotation", 0.01, 0.0, DBL_MAX, 0, grp);
1848  }
1849 
1850  if (para.CheckParam("SigmaCamRotZ")){
1851  _SigmaCamRotZ=para.GetParamDouble("SigmaCamRotZ");
1852  } else {
1853  _SigmaCamRotZ=para.AddParamDouble("SigmaCamRotZ", "sigma of normal distributed noise of cam rotation", 0.01, 0.0, DBL_MAX, 0, grp);
1854  }
1855 
1856  if (para.CheckParam("MinCamDistance")){
1857  _MinCamDistance=para.GetParamDouble("MinCamDistance");
1858  } else {
1859  _MinCamDistance=para.AddParamDouble("MinCamDistance", "minimal distance a point must have to every camera", 1.0, 0.0, DBL_MAX, 0, grp);
1860  }
1861 
1862  if (para.CheckParam("MaxCamDistance")){
1863  _MaxCamDistance=para.GetParamDouble("MaxCamDistance");
1864  } else {
1865  _MaxCamDistance=para.AddParamDouble("MaxCamDistance", "maximal distance a point can have to every camera", 50.0, 0.0, DBL_MAX, 0, grp);
1866  }
1867 
1868  if (para.CheckParam("OutlDirChange")){
1869  _OutlDirChange=para.GetParamDouble("OutlDirChange");
1870  } else {
1871  _OutlDirChange=para.AddParamDouble("OutlDirChange", "maximal change of direction for outlying matches (RAD)", 0.05, -M_PI, M_PI, 0, grp);
1872  }
1873 
1874  if (para.CheckParam("OutlLengthChange")){
1875  _OutlLengthChange=para.GetParamDouble("OutlLengthChange");
1876  } else {
1877  _OutlLengthChange=para.AddParamDouble("OutlLengthChange", "maximal change of length for outlying matches", 0.05, -1.0, 1.0, 0, grp);
1878  }
1879 
1880  if (para.IsUsedGroupID(grp))
1881  para.SetGroupName(grp, "noise");
1882 
1883  ////////////////////////////////////////////////////////////
1884  // PGMovObj
1885  ///////////////////////////////////////////////////////////
1886 
1887  grp=para.GetFreeGroupID();
1888  //cerr << "using ID "<<grp<<" for group moving objects\n";
1889  Vector<double> sizedflt;
1890  sizedflt.newsize(2);
1891  sizedflt[0]=5.0; sizedflt[1]=5.0;
1892  if (para.CheckParam("SizeMovingObjX")){
1893  _SizeMovingObjX=para.GetParamVecDbl("SizeMovingObjX");
1894  } else {
1895  _SizeMovingObjX=para.AddParamVecDbl("SizeMovingObjX", "x size of moving object", sizedflt, 0, grp);
1896  }
1897  sizedflt[0]=1.5; sizedflt[1]=1.5;
1898  if (para.CheckParam("SizeMovingObjY")){
1899  _SizeMovingObjY=para.GetParamVecDbl("SizeMovingObjY");
1900  } else {
1901  _SizeMovingObjY=para.AddParamVecDbl("SizeMovingObjY", "y size of moving object", sizedflt, 0, grp);
1902  }
1903  sizedflt[0]=2.0; sizedflt[1]=2.0;
1904  if (para.CheckParam("SizeMovingObjZ")){
1905  _SizeMovingObjZ=para.GetParamVecDbl("SizeMovingObjZ");
1906  } else {
1907  _SizeMovingObjZ=para.AddParamVecDbl("SizeMovingObjZ", "z size of moving object", sizedflt, 0, grp);
1908  }
1909 
1910  dflt.newsize(4);
1911  dflt[0]=5.0; dflt[1]=5.5; dflt[2]=0.0; dflt[3]=-1.0;
1912  if (para.CheckParam("MovingObjMotionVecX")){
1913  _MovingObjMotionVecX=para.GetParamVecDbl("MovingObjMotionVecX");
1914  } else {
1915  _MovingObjMotionVecX=para.AddParamVecDbl("MovingObjMotionVecX", "vector of x components of moving object centers", dflt, 0, grp);
1916  }
1917 
1918  dflt[0]=0.0; dflt[1]=0.0; dflt[2]=1.5; dflt[3]=1.5;
1919  if (para.CheckParam("MovingObjMotionVecY")){
1920  _MovingObjMotionVecY=para.GetParamVecDbl("MovingObjMotionVecY");
1921  } else {
1922  _MovingObjMotionVecY=para.AddParamVecDbl("MovingObjMotionVecY", "vector of y components of moving object centers", dflt, 0, grp);
1923  }
1924 
1925  dflt[0]=30.0; dflt[1]=30.0; dflt[2]=18.0; dflt[3]=18.0;
1926  if (para.CheckParam("MovingObjMotionVecZ")){
1927  _MovingObjMotionVecZ=para.GetParamVecDbl("MovingObjMotionVecZ");
1928  } else {
1929  _MovingObjMotionVecZ=para.AddParamVecDbl("MovingObjMotionVecZ", "vector of z components of moving object centers", dflt, 0, grp);
1930  }
1931 
1932  dflt[0]=0.0; dflt[1]=0.0; dflt[2]=0.0; dflt[3]=0.0;
1933  if (para.CheckParam("MovingObjRotVecX")){
1934  _MovingObjRotVecX=para.GetParamVecDbl("MovingObjRotVecX");
1935  } else {
1936  _MovingObjRotVecX=para.AddParamVecDbl("MovingObjRotVecX", "vector of rotation of moving object around x-axis", dflt, 0, grp);
1937  }
1938 
1939  dflt[0]=0.0; dflt[1]=-0.1; dflt[2]=0.0; dflt[3]=0.1;
1940  if (para.CheckParam("MovingObjRotVecY")){
1941  _MovingObjRotVecY=para.GetParamVecDbl("MovingObjRotVecY");
1942  } else {
1943  _MovingObjRotVecY=para.AddParamVecDbl("MovingObjRotVecY", "vector of rotation of moving object around y-axis", dflt, 0, grp);
1944  }
1945 
1946  dflt[0]=0.0; dflt[1]=0.0; dflt[2]=0.0; dflt[3]=0.0;
1947  if (para.CheckParam("MovingObjRotVecZ")){
1948  _MovingObjRotVecZ=para.GetParamVecDbl("MovingObjRotVecZ");
1949  } else {
1950  _MovingObjRotVecZ=para.AddParamVecDbl("MovingObjRotVecZ", "vector of rotation of moving object around z-axis", dflt, 0, grp);
1951  }
1952 
1953  if (para.IsUsedGroupID(grp))
1954  para.SetGroupName(grp, "moving objects");
1955 
1956 }
1957 
1959 {
1962  BIASERR("inconsistent parameter (number of points), correcting");
1965  // BIASABORT;
1966  return false;
1967  }
1968  if (*_NumMovingObjects>_SizeMovingObjX->size() ||
1969  *_NumMovingObjects>_SizeMovingObjY->size() ||
1970  *_NumMovingObjects>_SizeMovingObjZ->size()){
1971  BIASERR("inconsistent parameter (NumMovingObjects and SizeMovingObj?)"
1972  <<*_NumMovingObjects<<" "<<_SizeMovingObjX->size()
1973  <<" "<<_SizeMovingObjY->size()<<" "<<_SizeMovingObjZ->size());
1974  BIASABORT;
1975  //return false;
1976  }
1977  int n=*_NumMovingObjects**_NumImages;
1978  if (n>_MovingObjMotionVecX->size() ||
1979  n>_MovingObjMotionVecY->size() ||
1980  n>_MovingObjMotionVecZ->size() ||
1981  n>_MovingObjRotVecX->size() ||
1982  n>_MovingObjRotVecY->size() ||
1983  n>_MovingObjRotVecZ->size()){
1984  BIASERR("inconsistent parameter (NumMovingObjects, NumImages and MovingObj*Vec?)");
1985  BIASABORT;
1986  //return false;
1987  }
1988  if ((int)_MotionVecX->Size()<*_NumImages ||
1989  (int)_MotionVecY->Size()<*_NumImages ||
1990  (int)_MotionVecZ->Size()<*_NumImages ||
1991  (int)_RotVecX->Size()<*_NumImages ||
1992  (int)_RotVecY->Size()<*_NumImages ||
1993  (int)_RotVecZ->Size()<*_NumImages){
1994  BIASERR("MotionVec? and RotVec? must be of size NumImages");
1995  BIASABORT;
1996  //return false;
1997  }
1998 
1999  return true;
2000 }
2001 
2002 
2004 {
2005  ((MatchDataBase)(*this))=mdb;
2006 
2007  _GT_R=_R;
2008  _GT_C=_C;
2009  _GT_P=_P;
2010  _MovingTransform.resize(0);
2011  _StaticPoints.resize(0);
2012  _MovingPoints.resize(0);
2015 
2017 
2018  *_UserGivenP=true;
2019 
2020  _MotionVecX->newsize(0);
2021  _MotionVecY->newsize(0);
2022  _MotionVecZ->newsize(0);
2023  _RotVecX->newsize(0);
2024  _RotVecY->newsize(0);
2025  _RotVecZ->newsize(0);
2032 
2033 
2038 
2039  _Points.resize(0);
2040  _NormalizedPoints.resize(0);
2041 
2042  return *this;
2043 }
2044 
2046 CreateGTVRML(const string& file_name) const
2047 {
2048  KMatrix K;
2049  vector<HomgPoint3D> C;
2050  vector<RMatrixBase> R;
2051  GetGTC(C);
2052  GetGTR(R);
2053  GetK(K);
2054  vector<PMatrix> P(R.size());
2055  //cout << "adding "<<P.size()<<" P matrices\n";
2056  for (unsigned i=0; i< P.size(); i++){
2057  P[i].Compose(K, R[i], C[i]);
2058  }
2059  vector<HomgPoint3D> p, mp;
2060  Get3DPoints(p);
2061  Get3DMovingPoints(mp);
2062  for (unsigned i=0; i<mp.size(); i++) p.push_back(mp[i]);
2063  return CreateVRML_(file_name, P, p);
2064 }
2065 
2066 
2068 CreateVRML_(const string& file_name, const vector<PMatrix> & P,
2069  const vector<HomgPoint3D>& p) const
2070 {
2071  ThreeDOut tdo;
2072  RGBAuc color;
2073  RGBAuc green(0,255,0,255), red(255,0,0,255), blue(0,0,255,255);
2074  PMatrix tmpP;
2075  const double fac = (P.size()>1)?((double)P.size()-1.0):(1.0);
2076  const int width = *_ImWidth, height = *_ImHeight;
2077  for (unsigned i=0; i<P.size(); i++){
2078  double f = (double)i/fac;
2079  color = RGBAuc((unsigned char)rint(f*255),
2080  (unsigned char)rint((1.0-f)*255),0,255);
2081  tmpP = P[i];
2082  //tdo.AddPMatrix(tmpP, width, height, color);
2083  tdo.AddPMatrix(tmpP, width, height, blue);
2084  }
2085 
2086  int max_inlier, max_outlier, max_mov_obj, num_mov, num_pt;
2087  GetPointSourceBorders(max_inlier, max_outlier, max_mov_obj);
2088  BIASASSERT(max_outlier>=0 && max_outlier<max_mov_obj);
2089  num_mov = max_mov_obj - max_outlier;
2090  num_pt = num_mov + max_inlier;
2091  cout << p.size() << " "<<num_pt<<endl;
2092  BIASASSERT((int)p.size()==num_pt);
2093  //RGBAuc green(255,255,255,255), red(255,255,255,255);
2094  for (int i=0; i<max_inlier; i++){
2095  tdo.AddPoint(p[i], green);
2096  }
2097  for (int i=max_inlier; i<num_pt; i++){
2098  tdo.AddPoint(p[i], red);
2099  }
2100 
2101  // add coordinate system
2103  tdo.AddPose(pp);
2104 
2107  tdo.SetParamsPointSize(0.5);
2108 
2109  if (tdo.VRMLOut(file_name)!=0){
2110  BIASERR("error creating vrml file \""<<file_name<<"\"\n");
2111  return -1;
2112  } else {
2113  cout << "wrote \""<<file_name<<"\"\n";
2114  }
2115  return 0;
2116 }
void Release()
reimplemented from ImageBase
Definition: Image.cpp:1579
std::vector< std::vector< HomgPoint2D > > _NormalizedPoints
unsigned int AddPose(const PoseParametrization &p, const RGBAuc &colorSelection=RGBAuc_WHITE_OPAQUE, const double radius=0.1, const double scale=1.0, const int camera_type=-1)
Definition: ThreeDOut.cpp:1407
std::vector< BIAS::HomgPoint3D > _MovingPoints
int Read(const std::string &fname)
binary read
double * GetParamDouble(const std::string &name) const
Definition: Param.cpp:665
static int Arrow(Image< StorageType > &im, const unsigned start[2], const unsigned end[2], const unsigned length, const unsigned width, const StorageType value[])
draws an arrow from start to end, the tips of the head are length pixel back on the line and width pi...
Definition: ImageDraw.cpp:1127
BIAS::Vector< double > * _MovingObjRotVecZ
void Set(const T *pv)
copy the array of vectorsize beginning at *T to this-&gt;data_
Definition: Vector3.hh:532
BIAS::Vector< double > * _RotVecX
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
void SetXYZ(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order XYZ.
int _AreMovingObjectsVisible()
returns -1 if no corner of moving object boundary is seen in images
int VRMLOut(const std::string &sFilename)
flush all 3d objects to a vrml file with name sFilename, this is the function most users would call ...
Definition: ThreeDOut.cpp:3670
void GetInliers(std::vector< bool > &inl) const
inl[i] indicates if Get(GT)Points()[i] is outlier
int WriteData(std::string file) const
write in ascii file format
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
bool _IsSeen(HomgPoint2D &p, double border=0.0)
void SetParamsCameraStyle(CameraDrawingStyle cameraStyle)
Definition: ThreeDOut.cpp:231
std::vector< PMatrixBase > _P
int _CreateStatic2DPoints(int &index)
fills *_NumStaticPoints first entries of _GT_Points, _Points, _GT_NormalizedPoints, _NormalizedPoints also resizes the above vectors to [*_NumImages][*_NumStaticPoints+*_NumMovingObjects+*_NumOutliers]
BIAS::Vector< double > * _SizeMovingObjZ
void SetParamsPointDrawingStyle(const PointDrawingStyle pointStyle)
Definition: ThreeDOut.cpp:261
int _CreateMoving3DPoints()
fills _MovingPoints returns -1 if no corner of moving object boundary is seen in images or the center...
void Set(const HOMGPOINT3D_TYPE &x, const HOMGPOINT3D_TYPE &y, const HOMGPOINT3D_TYPE &z)
set elementwise with given 3 euclidean scalar values.
Definition: HomgPoint3D.hh:321
Unified output of 3D entities via OpenGL or VRML.
Definition: ThreeDOut.hh:349
void GetK(KMatrix &K) const
MatchDataBase(Param &para)
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:305
BIAS::Vector< double > * _MovingObjRotVecY
double * AddParamDouble(const std::string &name, const std::string &help, double deflt=0.0, double min=-DBL_MAX, double max=DBL_MAX, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:351
GenSynthMatches & operator=(const MatchDataBase &mdb)
static int CircleCenterFilled(Image< StorageType > &im, unsigned int CenterX, unsigned int CenterY, unsigned int Radius, const StorageType Value[])
draws a filled circle using Value
Definition: ImageDraw.cpp:1023
void DrawTrue(Image< unsigned char > &im, int minindex=0, int maxindex=1) const
std::vector< BIAS::RMatrixBase > _GT_R
Slim class bundeling pose parametrization and associated covariance matrix.
unsigned int Size() const
length of the vector
Definition: Vector.hh:143
int CreateGTVRML(const std::string &file_name) const
std::vector< std::vector< HomgPoint2D > > _GT_Points
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Definition: Random.hh:84
void Get3DPoints(std::vector< HomgPoint3D > &p) const
p = _StaticPoints;
BIAS::Vector< double > * _MovingObjRotVecX
int _CreateStaticGT2DPoints(int &index)
fills *_NumStaticPoints first entries of _GT_Points and _GT_NormalizedPoints also resizes the above v...
std::vector< BIAS::HomgPoint3D > _StaticPoints
class for generating synthetic matches
int Read(const std::string &fname)
binary read
bool * GetParamBool(const std::string &name) const
Definition: Param.cpp:633
void GetPointSourceBorders(int &max_inlier, int &max_outlier, int &max_mov_obj) const
when getting point list for an image, inidices 0 - max_inlier-1 are true matches generated by static ...
std::vector< RMatrixBase > _R
void _Draw(Image< unsigned char > &im, int minindex, int maxindex, const std::vector< std::vector< HomgPoint2D > > *p) const
helper function used for visualizing the matches
bool DebugLevelIsSet(const long int lv) const
Definition: Debug.hh:341
int CreateMoving3DPoint(int index)
Replace the moving 3D point at index by a newly generated one.
class Vector4 contains a Vector of dim.
Definition: Vector4.hh:65
Vector< T > & newsize(Subscript N)
Definition: vec.h:220
int CreateStatic3DPoint(int index)
Replace the static 3D point at index by a newly generated one.
bool IsUsedGroupID(const int group_id)
returns if the group id is used
Definition: Param.cpp:1496
int Write(const std::string &fname) const
binary write
void CrossProduct(const Vector3< T > &argvec, Vector3< T > &destvec) const
cross product of two vectors destvec = this x argvec
Definition: Vector3.hh:594
virtual void _AddParameter(Param &para)
fills all protected pointer values
static int Line(Image< StorageType > &im, const unsigned int start[2], const unsigned int end[2], const StorageType value[])
lines
Definition: ImageDraw.cpp:404
void Mult(const Vector3< T > &argvec, Vector3< T > &destvec) const
matrix - vector multiplicate this matrix with Vector3, storing the result in destvec calculates: dest...
Definition: Matrix3x3.hh:302
bool CheckParam(const std::string &name)
Check if parameter has already been added.
Definition: Param.cpp:527
int ReadData(std::string file)
read in ascii file format
BIAS::Vector< double > * GetParamVecDbl(const std::string &name) const
Definition: Param.cpp:680
int CreateMatches(bool points3D_set_by_user=false, bool fixed_errors=false)
returns negative value, if error occurs, 0 on success see _CreateCamMovement for explanation of param...
class for representing matches, used in GenSynthMatches and biasshowsm
BIAS::Vector< double > * _MovingObjMotionVecX
int * GetParamInt(const std::string &name) const
Definition: Param.cpp:618
void GetGTR(int imNo, RMatrixBase &R) const
R = _GT_R[imNo];.
int GetFreeGroupID()
returns unused group id
Definition: Param.cpp:1421
void SetParamsPointSize(const double pointSize)
Definition: ThreeDOut.cpp:214
void FillImageWithConstValue(StorageType Value)
fill grey images
Definition: Image.cpp:456
BIAS::Vector< double > * _MotionVecY
BIAS::Vector4< unsigned char > RGBAuc
Definition: RGBA.hh:47
void GetGTNormalizedPoints(int imNo, std::vector< HomgPoint2D > &p) const
p = _GT_NormalizedPoints[imNo];
BIAS::Vector< double > * _MovingObjMotionVecZ
BIAS::Vector< double > * _RotVecY
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrixBase.hh:74
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
Definition: Array2D.hh:260
BIAS::Vector< double > * AddParamVecDbl(const std::string &name, const std::string &help, const BIAS::Vector< double > &deflt, char cmdshort=0, int Group=GRP_NOSHOW)
Add a parameter that expects a string on command line like &quot;&lt;value0&gt; &lt;value1&gt; &lt;value2&gt; ...
Definition: Param.cpp:378
void _AddUniformDistributedOutliers()
fills _GT_Points, _Points, _GT_NormalizedPoints, _NormalizedPoints from entries [*_NumStaticPoints] t...
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
int _CreateMovingGT2DPoints(int &index)
fills _GT_Points, _GT_NormalizedPoints from entries [*_NumStaticPoints+_*NumOutliers] to [*_NumStatic...
int _CreateMoving2DPoints(int &index)
fills _GT_Points, _Points, _GT_NormalizedPoints, _NormalizedPoints from entries [*_NumStaticPoints+_*...
BIAS::Vector< double > * _MovingObjMotionVecY
BIAS::Vector< double > * _SizeMovingObjY
BIAS::Vector3< T > CoordSphereToEuclidean() const
coordinate transfrom.
Definition: Vector3.cpp:78
This class Param provides generic support for parameters.
Definition: Param.hh:231
int SetGroupName(const int group_id, const std::string &name)
sets the name for a group
Definition: Param.cpp:1448
Matrix3x3< T > Transpose() const
returns transposed matrix tested 12.06.2002
Definition: Matrix3x3.cpp:167
std::vector< BIAS::EuclideanTransf3D > _MovingTransform
int CreateVRML_(const std::string &file_name, const std::vector< PMatrix > &P, const std::vector< HomgPoint3D > &p) const
void Reset()
calls srand() with a seed generated from system call time, also initializes some other variables ...
Definition: Random.cpp:113
void GetGTPoints(int imNo, std::vector< HomgPoint2D > &p) const
p = _GT_Points[imNo];
std::vector< HomgPoint3D > _C
void GetGTP(int imNo, PMatrixBase &P) const
P = _GT_P[imNo];.
std::vector< std::vector< HomgPoint2D > > _Points
int _CreateStatic3DPoints()
fills _StaticPoints returns -1 if no common viewing volume of all cameras is present ...
void _CreateCamMovement(const bool fixed_error)
fills _k, _Ki, _GT_R, _R, GT_C, _C, _GT_P and _P
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
int Create3DPoints(bool fixed_errors=false)
Create static and moving 3D points see _CreateCamMovement for explanation of parameter.
BIAS::Vector< double > * _SizeMovingObjX
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
Definition: Param.cpp:276
void BackprojectWorldCoo(const HomgPoint2D &point, double depth, HomgPoint3D &res)
returns a 3D point res which is located depth away from center of projection in direction given by po...
Definition: PMatrix.cpp:468
Implements a 3D rotation matrix.
Definition: RMatrixBase.hh:44
unsigned int AddPMatrix(BIAS::PMatrix &P, const unsigned int &width, const unsigned int &height, const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE, const double &dScale=DEF_P_SCALE, const std::string &name="")
decompose P and add to internal data structures.
Definition: ThreeDOut.cpp:1029
int Write(const std::string &fname) const
binary write
BIAS::Vector< double > * _RotVecZ
double GetNormalDistributed(const double mean, const double sigma)
on succesive calls return normal distributed random variable with mean and standard deviation sigma ...
Definition: Random.hh:71
std::vector< BIAS::PMatrixBase > _GT_P
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrix.hh:88
void _DrawPoints(Image< unsigned char > &im, int index, const std::vector< std::vector< HomgPoint2D > > *p) const
helper function used for visualizing the matches
unsigned int AddPoint(const BIAS::Vector3< double > &v, const BIAS::RGBAuc &Color=RGBAuc_WHITE_OPAQUE)
Definition: ThreeDOut.cpp:719
void DrawNoisy(Image< unsigned char > &im, int minindex=0, int maxindex=1) const
void _CreateMovingTransforms()
fills _MovinTransforms
void GetGTNormalizedF(std::vector< std::vector< FMatrixBase > > &F) const
A moving 3D point X_i is generated for image i from 3D Point X using the euclidean transform E_i=[R_i...
KMatrix Invert() const
returns analyticaly inverted matrix
Definition: KMatrix.cpp:31
BIAS::Vector< double > * _MotionVecX
void Set(const HOMGPOINT2D_TYPE &x, const HOMGPOINT2D_TYPE &y)
set elementwise with given 2 euclidean scalar values.
Definition: HomgPoint2D.hh:174
std::vector< BIAS::HomgPoint3D > _GT_C
void GetGTC(int imNo, HomgPoint3D &C) const
C = _GT_C[imNo];.
Euclidean transformation for 3D points.
int GetGroupID(const std::string &name)
returns group id of parameter with name
Definition: Param.cpp:1430
Subscript size() const
Definition: vec.h:262
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)
Definition: Vector3.hh:633
void Get3DMovingPoints(std::vector< HomgPoint3D > &p, const int frame=0) const
p = _MovingTransform[frame] * _MovingPoints;
BIAS::Vector< double > * _MotionVecZ
std::vector< std::vector< HomgPoint2D > > _GT_NormalizedPoints