timePinholeCamera.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* ----------------------------------------------------------------------------
  2. * GTSAM Copyright 2010, Georgia Tech Research Corporation,
  3. * Atlanta, Georgia 30332-0415
  4. * All Rights Reserved
  5. * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
  6. * See LICENSE for the license information
  7. * -------------------------------------------------------------------------- */
  8. /**
  9. * @file timePinholeCamera.cpp
  10. * @brief time PinholeCamera derivatives
  11. * @author Frank Dellaert
  12. */
  13. #include <time.h>
  14. #include <iostream>
  15. #include <gtsam/geometry/PinholeCamera.h>
  16. #include <gtsam/geometry/Cal3Bundler.h>
  17. using namespace std;
  18. using namespace gtsam;
  19. int main()
  20. {
  21. int n = 1e6;
  22. const Pose3 pose1(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5));
  23. static Cal3Bundler K(500, 1e-3, 2.0*1e-3);
  24. const PinholeCamera<Cal3Bundler> camera(pose1,K);
  25. const Point3 point1(-0.08,-0.08, 0.0);
  26. /**
  27. * NOTE: because we only have combined derivative functions now,
  28. * parts of this test are no longer useful.
  29. */
  30. // Oct 12 2013, iMac 3.06GHz Core i3
  31. // Original: 0.14737 musecs/call
  32. // After collapse: 0.11469 musecs/call
  33. // Cal3DS2: 0.14201 musecs/call
  34. // After Cal3DS2 fix: 0.12231 musecs/call
  35. // Cal3Bundler: 0.12000 musecs/call
  36. // Cal3Bundler fix: 0.14637 musecs/call
  37. // June 24 2014, Macbook Pro 2.3GHz Core i7
  38. // GTSAM 3.1: 0.04295 musecs/call
  39. // After project fix: 0.04193 musecs/call
  40. {
  41. long timeLog = clock();
  42. for(int i = 0; i < n; i++)
  43. camera.project(point1);
  44. long timeLog2 = clock();
  45. double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC;
  46. cout << ((double)seconds*1e9/n) << " nanosecs/call" << endl;
  47. }
  48. // Oct 12 2014, Macbook Air
  49. {
  50. long timeLog = clock();
  51. Point2 measurement(0,0);
  52. for(int i = 0; i < n; i++)
  53. camera.project(point1)-measurement;
  54. long timeLog2 = clock();
  55. double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC;
  56. cout << ((double)seconds*1e9/n) << " nanosecs/call" << endl;
  57. }
  58. // Oct 12 2013, iMac 3.06GHz Core i3
  59. // Original: 3.8720 musecs/call
  60. // After collapse: 2.6269 musecs/call
  61. // Cal3DS2: 4.3330 musecs/call
  62. // After Cal3DS2 fix: 3.2857 musecs/call
  63. // Cal3Bundler: 2.6556 musecs/call
  64. // Cal3Bundler fix: 2.1613 musecs/call
  65. // June 24 2014, Macbook Pro 2.3GHz Core i7
  66. // GTSAM 3.1: 0.2322 musecs/call
  67. // After project fix: 0.2094 musecs/call
  68. {
  69. Matrix Dpose, Dpoint;
  70. long timeLog = clock();
  71. for(int i = 0; i < n; i++)
  72. camera.project(point1, Dpose, Dpoint, boost::none);
  73. long timeLog2 = clock();
  74. double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC;
  75. cout << ((double)seconds*1e9/n) << " nanosecs/call" << endl;
  76. }
  77. // Oct 12 2013, iMac 3.06GHz Core i3
  78. // Original: 4.0119 musecs/call
  79. // After collapse: 2.5698 musecs/call
  80. // Cal3DS2: 4.8325 musecs/call
  81. // After Cal3DS2 fix: 3.4483 musecs/call
  82. // Cal3Bundler: 2.5112 musecs/call
  83. // Cal3Bundler fix: 2.0946 musecs/call
  84. // June 24 2014, Macbook Pro 2.3GHz Core i7
  85. // GTSAM 3.1: 0.2294 musecs/call
  86. // After project fix: 0.2093 nanosecs/call
  87. {
  88. Matrix Dpose, Dpoint, Dcal;
  89. long timeLog = clock();
  90. for(int i = 0; i < n; i++)
  91. camera.project(point1, Dpose, Dpoint, Dcal);
  92. long timeLog2 = clock();
  93. double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC;
  94. cout << ((double)seconds*1e9/n) << " nanosecs/call" << endl;
  95. }
  96. return 0;
  97. }