perf_calib3d.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #include "perf_precomp.hpp"
  43. #ifdef HAVE_OPENCV_CALIB3D
  44. #include "opencv2/calib3d.hpp"
  45. namespace opencv_test { namespace {
  46. DEF_PARAM_TEST_1(Count, int);
  47. //////////////////////////////////////////////////////////////////////
  48. // ProjectPoints
  49. PERF_TEST_P(Count, Calib3D_ProjectPoints,
  50. Values(5000, 10000, 20000))
  51. {
  52. const int count = GetParam();
  53. cv::Mat src(1, count, CV_32FC3);
  54. declare.in(src, WARMUP_RNG);
  55. const cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1);
  56. const cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1);
  57. const cv::Mat camera_mat = cv::Mat::ones(3, 3, CV_32FC1);
  58. if (PERF_RUN_CUDA())
  59. {
  60. const cv::cuda::GpuMat d_src(src);
  61. cv::cuda::GpuMat dst;
  62. TEST_CYCLE() cv::cuda::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), dst);
  63. CUDA_SANITY_CHECK(dst);
  64. }
  65. else
  66. {
  67. cv::Mat dst;
  68. TEST_CYCLE() cv::projectPoints(src, rvec, tvec, camera_mat, cv::noArray(), dst);
  69. CPU_SANITY_CHECK(dst);
  70. }
  71. }
  72. //////////////////////////////////////////////////////////////////////
  73. // SolvePnPRansac
  74. PERF_TEST_P(Count, Calib3D_SolvePnPRansac,
  75. Values(5000, 10000, 20000))
  76. {
  77. declare.time(10.0);
  78. const int count = GetParam();
  79. cv::Mat object(1, count, CV_32FC3);
  80. declare.in(object, WARMUP_RNG);
  81. cv::Mat camera_mat(3, 3, CV_32FC1);
  82. cv::randu(camera_mat, 0.5, 1);
  83. camera_mat.at<float>(0, 1) = 0.f;
  84. camera_mat.at<float>(1, 0) = 0.f;
  85. camera_mat.at<float>(2, 0) = 0.f;
  86. camera_mat.at<float>(2, 1) = 0.f;
  87. const cv::Mat dist_coef(1, 8, CV_32F, cv::Scalar::all(0));
  88. cv::Mat rvec_gold(1, 3, CV_32FC1);
  89. cv::randu(rvec_gold, 0, 1);
  90. cv::Mat tvec_gold(1, 3, CV_32FC1);
  91. cv::randu(tvec_gold, 0, 1);
  92. std::vector<cv::Point2f> image_vec;
  93. cv::projectPoints(object, rvec_gold, tvec_gold, camera_mat, dist_coef, image_vec);
  94. const cv::Mat image(1, count, CV_32FC2, &image_vec[0]);
  95. cv::Mat rvec;
  96. cv::Mat tvec;
  97. if (PERF_RUN_CUDA())
  98. {
  99. TEST_CYCLE() cv::cuda::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec);
  100. CUDA_SANITY_CHECK(rvec, 1e-3);
  101. CUDA_SANITY_CHECK(tvec, 1e-3);
  102. }
  103. else
  104. {
  105. TEST_CYCLE() cv::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec);
  106. CPU_SANITY_CHECK(rvec, 1e-6);
  107. CPU_SANITY_CHECK(tvec, 1e-6);
  108. }
  109. }
  110. }} // namespace
  111. #endif