Added performance tests for findCirclesGrid and solvePnP
authorAndrey Kamaev <no@email>
Tue, 13 Sep 2011 07:54:19 +0000 (07:54 +0000)
committerAndrey Kamaev <no@email>
Tue, 13 Sep 2011 07:54:19 +0000 (07:54 +0000)
modules/calib3d/perf/perf_cicrlesGrid.cpp [new file with mode: 0644]
modules/calib3d/perf/perf_main.cpp [new file with mode: 0644]
modules/calib3d/perf/perf_pnp.cpp [new file with mode: 0644]
modules/calib3d/perf/perf_precomp.cpp [new file with mode: 0644]
modules/calib3d/perf/perf_precomp.hpp [new file with mode: 0644]
modules/ts/include/opencv2/ts/ts_perf.hpp
modules/ts/src/ts_perf.cpp

diff --git a/modules/calib3d/perf/perf_cicrlesGrid.cpp b/modules/calib3d/perf/perf_cicrlesGrid.cpp
new file mode 100644 (file)
index 0000000..5e3dd31
--- /dev/null
@@ -0,0 +1,41 @@
+#include "perf_precomp.hpp"
+
+using namespace std;
+using namespace cv;
+using namespace perf;
+
+
+typedef std::tr1::tuple<std::string, cv::Size> String_Size_t;
+typedef perf::TestBaseWithParam<String_Size_t> String_Size;
+
+PERF_TEST_P(String_Size, asymm_circles_grid, testing::Values(
+                 String_Size_t("cv/cameracalibration/asymmetric_circles/acircles1.jpg", Size(7,13)),
+                 String_Size_t("cv/cameracalibration/asymmetric_circles/acircles2.jpg", Size(7,13)),
+                 String_Size_t("cv/cameracalibration/asymmetric_circles/acircles3.jpg", Size(7,13)),
+                 String_Size_t("cv/cameracalibration/asymmetric_circles/acircles4.jpg", Size(5,5)),
+                 String_Size_t("cv/cameracalibration/asymmetric_circles/acircles5.jpg", Size(5,5)),
+                 String_Size_t("cv/cameracalibration/asymmetric_circles/acircles6.jpg", Size(5,5)),
+                 String_Size_t("cv/cameracalibration/asymmetric_circles/acircles7.jpg", Size(3,9)),
+                 String_Size_t("cv/cameracalibration/asymmetric_circles/acircles8.jpg", Size(3,9)),
+                 String_Size_t("cv/cameracalibration/asymmetric_circles/acircles9.jpg", Size(3,9))
+                 )
+             )
+{
+    String filename = getDataPath(std::tr1::get<0>(GetParam()));
+    Size gridSize = std::tr1::get<1>(GetParam());
+
+    Mat frame = imread(filename);
+    if (frame.empty())
+        FAIL() << "Unable to load source image " << filename;
+    vector<Point2f> ptvec;
+    ptvec.resize(gridSize.area());
+
+    cvtColor(frame, frame, COLOR_BGR2GRAY);
+
+    declare.in(frame).out(ptvec);
+
+    TEST_CYCLE(100)
+    {
+        ASSERT_TRUE(findCirclesGrid(frame, gridSize, ptvec, CALIB_CB_CLUSTERING | CALIB_CB_ASYMMETRIC_GRID));
+    }
+}
diff --git a/modules/calib3d/perf/perf_main.cpp b/modules/calib3d/perf/perf_main.cpp
new file mode 100644 (file)
index 0000000..a8dddb8
--- /dev/null
@@ -0,0 +1,3 @@
+#include "perf_precomp.hpp"
+
+CV_PERF_TEST_MAIN(calib3d)
diff --git a/modules/calib3d/perf/perf_pnp.cpp b/modules/calib3d/perf/perf_pnp.cpp
new file mode 100644 (file)
index 0000000..1fbe8f0
--- /dev/null
@@ -0,0 +1,48 @@
+#include "perf_precomp.hpp"
+
+using namespace std;
+using namespace cv;
+using namespace perf;
+
+
+typedef std::tr1::tuple<std::string, cv::Size> String_Size_t;
+typedef perf::TestBaseWithParam<int> PointsNumber;
+
+PERF_TEST_P(PointsNumber, solvePnP, testing::Values(4, 3*9, 7*13)
+             )
+{
+    int pointsNum = GetParam();
+
+    vector<Point2f> points2d(pointsNum);
+    vector<Point3f> points3d(pointsNum);
+    Mat rvec = Mat::zeros(3, 1, CV_32FC1);
+    Mat tvec = Mat::zeros(3, 1, CV_32FC1);
+
+    Mat distortion = Mat::zeros(5, 1, CV_32FC1);
+    Mat intrinsics = Mat::eye(3, 3, CV_32FC1);
+    intrinsics.at<float> (0, 0) = 400.0;
+    intrinsics.at<float> (1, 1) = 400.0;
+    intrinsics.at<float> (0, 2) = 640 / 2;
+    intrinsics.at<float> (1, 2) = 480 / 2;
+
+    warmup(points3d, WARMUP_RNG);
+    warmup(rvec, WARMUP_RNG);
+    warmup(tvec, WARMUP_RNG);
+
+    projectPoints(points3d, rvec, tvec, intrinsics, distortion, points2d);
+
+    //add noise
+    Mat noise(1, points2d.size(), CV_32FC2);
+    randu(noise, 0, 0.01);
+    add(points2d, noise, points2d);
+
+    declare.in(points3d, points2d);
+
+    TEST_CYCLE(1000)
+    {
+        solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false);
+    }
+
+    SANITY_CHECK(rvec);
+    SANITY_CHECK(tvec);
+}
diff --git a/modules/calib3d/perf/perf_precomp.cpp b/modules/calib3d/perf/perf_precomp.cpp
new file mode 100644 (file)
index 0000000..8552ac3
--- /dev/null
@@ -0,0 +1 @@
+#include "perf_precomp.hpp"
diff --git a/modules/calib3d/perf/perf_precomp.hpp b/modules/calib3d/perf/perf_precomp.hpp
new file mode 100644 (file)
index 0000000..ccadd24
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef __OPENCV_PERF_PRECOMP_HPP__
+#define __OPENCV_PERF_PRECOMP_HPP__
+
+#include "opencv2/ts/ts.hpp"
+#include "opencv2/calib3d/calib3d.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+
+#if GTEST_CREATE_SHARED_LIBRARY
+#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
+#endif
+
+#endif
index a20de1b..d342aad 100644 (file)
@@ -255,7 +255,7 @@ private:
     static int64 _timeadjustment;\r
     static int64 _calibrate();\r
 \r
-    static void warmup(cv::Mat m, int wtype);\r
+    static void warmup_impl(cv::Mat m, int wtype);\r
     static int getSizeInBytes(cv::InputArray a);\r
     static cv::Size getSize(cv::InputArray a);\r
     static void declareArray(SizeVector& sizes, cv::InputOutputArray a, int wtype = 0);\r
index 02e8254..91456c0 100644 (file)
@@ -472,12 +472,12 @@ void TestBase::warmup(cv::InputOutputArray a, int wtype)
 {\r
     if (a.empty()) return;\r
     if (a.kind() != cv::_InputArray::STD_VECTOR_MAT && a.kind() != cv::_InputArray::STD_VECTOR_VECTOR)\r
-        warmup(a.getMat(), wtype);\r
+        warmup_impl(a.getMat(), wtype);\r
     else\r
     {\r
         size_t total = a.total();\r
         for (size_t i = 0; i < total; ++i)\r
-            warmup(a.getMat(i), wtype);\r
+            warmup_impl(a.getMat(i), wtype);\r
     }\r
 }\r
 \r
@@ -507,7 +507,7 @@ bool TestBase::next()
     return ++currentIter < nIters && totalTime < timeLimit;\r
 }\r
 \r
-void TestBase::warmup(cv::Mat m, int wtype)\r
+void TestBase::warmup_impl(cv::Mat m, int wtype)\r
 {\r
     switch(wtype)\r
     {\r