From 5a5c477be643e6225625ccc00c861d57298b1ea1 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Tue, 9 Oct 2012 18:34:55 +0400 Subject: [PATCH] Make performance tests for solvePnPRansec more determenistic --- modules/calib3d/perf/perf_pnp.cpp | 18 +++++++++++++----- modules/calib3d/src/solvepnp.cpp | 2 ++ modules/ts/src/ts_perf.cpp | 3 ++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/calib3d/perf/perf_pnp.cpp b/modules/calib3d/perf/perf_pnp.cpp index 746f548e8..b32b96cae 100644 --- a/modules/calib3d/perf/perf_pnp.cpp +++ b/modules/calib3d/perf/perf_pnp.cpp @@ -1,4 +1,5 @@ #include "perf_precomp.hpp" +#include "opencv2/core/internal.hpp" using namespace std; using namespace cv; @@ -48,7 +49,10 @@ PERF_TEST_P(PointsNum_Algo, solvePnP, declare.in(points3d, points2d); - TEST_CYCLE_N(1000) solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, algo); + TEST_CYCLE_N(1000) + { + solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, algo); + } SANITY_CHECK(rvec, 1e-6); SANITY_CHECK(tvec, 1e-6); @@ -83,7 +87,10 @@ PERF_TEST(PointsNum_Algo, solveP3P) declare.in(points3d, points2d); - TEST_CYCLE_N(1000) solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, CV_P3P); + TEST_CYCLE_N(1000) + { + solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, CV_P3P); + } SANITY_CHECK(rvec, 1e-6); SANITY_CHECK(tvec, 1e-6); @@ -117,9 +124,10 @@ PERF_TEST_P(PointsNum, SolvePnPRansac, testing::Values(4, 3*9, 7*13)) Mat rvec; Mat tvec; - solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); - - declare.time(3.0); +#ifdef HAVE_TBB + // limit concurrency to get determenistic result + cv::Ptr one_thread = new tbb::task_scheduler_init(1); +#endif TEST_CYCLE() { diff --git a/modules/calib3d/src/solvepnp.cpp b/modules/calib3d/src/solvepnp.cpp index 125d7a9fa..25988be48 100644 --- a/modules/calib3d/src/solvepnp.cpp +++ b/modules/calib3d/src/solvepnp.cpp @@ -260,6 +260,8 @@ namespace cv { rvec.copyTo(initRvec); tvec.copyTo(initTvec); + + generator.state = theRNG().state; //to control it somehow... } private: PnPSolver& operator=(const PnPSolver&); diff --git a/modules/ts/src/ts_perf.cpp b/modules/ts/src/ts_perf.cpp index 5467d618d..a59880afd 100644 --- a/modules/ts/src/ts_perf.cpp +++ b/modules/ts/src/ts_perf.cpp @@ -674,6 +674,8 @@ cv::Size TestBase::getSize(cv::InputArray a) bool TestBase::next() { bool has_next = ++currentIter < nIters && totalTime < timeLimit; + cv::theRNG().state = param_seed; //this rng should generate same numbers for each run + #ifdef ANDROID if (log_power_checkpoints) { @@ -948,7 +950,6 @@ void TestBase::SetUp() currentIter = (unsigned int)-1; timeLimit = timeLimitDefault; times.clear(); - cv::theRNG().state = param_seed;//this rng should generate same numbers for each run } void TestBase::TearDown()