Skip to content

Commit

Permalink
ts: refactor OpenCV tests
Browse files Browse the repository at this point in the history
- removed tr1 usage (dropped in C++17)
- moved includes of vector/map/iostream/limits into ts.hpp
- require opencv_test + anonymous namespace (added compile check)
- fixed norm() usage (must be from cvtest::norm for checks) and other conflict functions
- added missing license headers
  • Loading branch information
alalek committed Feb 3, 2018
1 parent f1e50ec commit 4a297a2
Show file tree
Hide file tree
Showing 435 changed files with 2,010 additions and 2,379 deletions.
4 changes: 2 additions & 2 deletions modules/calib3d/perf/opencl/perf_stereobm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@

#ifdef HAVE_OPENCL

namespace cvtest {
namespace opencv_test {
namespace ocl {

typedef std::tr1::tuple<int, int> StereoBMFixture_t;
typedef tuple<int, int> StereoBMFixture_t;
typedef TestBaseWithParam<StereoBMFixture_t> StereoBMFixture;

OCL_PERF_TEST_P(StereoBMFixture, StereoBM, ::testing::Combine(OCL_PERF_ENUM(32, 64, 128), OCL_PERF_ENUM(11,21) ) )
Expand Down
9 changes: 2 additions & 7 deletions modules/calib3d/perf/perf_affine2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,9 @@
#include <algorithm>
#include <functional>

namespace cvtest
namespace opencv_test
{

using std::tr1::tuple;
using std::tr1::get;
using namespace perf;
using namespace testing;
using namespace cv;

CV_ENUM(Method, RANSAC, LMEDS)
typedef tuple<int, double, Method, size_t> AffineParams;
Expand Down Expand Up @@ -167,4 +162,4 @@ PERF_TEST_P( EstimateAffine, EstimateAffinePartial2D, ESTIMATE_PARAMS )
SANITY_CHECK_NOTHING();
}

} // namespace cvtest
} // namespace opencv_test
10 changes: 5 additions & 5 deletions modules/calib3d/perf/perf_cicrlesGrid.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include "perf_precomp.hpp"

using namespace std;
using namespace cv;
namespace opencv_test
{
using namespace perf;
using std::tr1::make_tuple;
using std::tr1::get;

typedef std::tr1::tuple<std::string, cv::Size> String_Size_t;
typedef 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(
Expand Down Expand Up @@ -40,3 +38,5 @@ PERF_TEST_P(String_Size, asymm_circles_grid, testing::Values(

SANITY_CHECK(ptvec, 2);
}

} // namespace
35 changes: 13 additions & 22 deletions modules/calib3d/perf/perf_pnp.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#include "perf_precomp.hpp"

#ifdef HAVE_TBB
#include "tbb/task_scheduler_init.h"
#endif

using namespace std;
using namespace cv;
namespace opencv_test
{
using namespace perf;
using std::tr1::make_tuple;
using std::tr1::get;

CV_ENUM(pnpAlgo, SOLVEPNP_ITERATIVE, SOLVEPNP_EPNP, SOLVEPNP_P3P, SOLVEPNP_DLS, SOLVEPNP_UPNP)

typedef std::tr1::tuple<int, pnpAlgo> PointsNum_Algo_t;
typedef tuple<int, pnpAlgo> PointsNum_Algo_t;
typedef perf::TestBaseWithParam<PointsNum_Algo_t> PointsNum_Algo;

typedef perf::TestBaseWithParam<int> PointsNum;
Expand Down Expand Up @@ -48,14 +42,14 @@ PERF_TEST_P(PointsNum_Algo, solvePnP,
//add noise
Mat noise(1, (int)points2d.size(), CV_32FC2);
randu(noise, 0, 0.01);
add(points2d, noise, points2d);
cv::add(points2d, noise, points2d);

declare.in(points3d, points2d);
declare.time(100);

TEST_CYCLE_N(1000)
{
solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, algo);
cv::solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, algo);
}

SANITY_CHECK(rvec, 1e-6);
Expand Down Expand Up @@ -92,22 +86,22 @@ PERF_TEST_P(PointsNum_Algo, solvePnPSmallPoints,

// normalize Rodrigues vector
Mat rvec_tmp = Mat::eye(3, 3, CV_32F);
Rodrigues(rvec, rvec_tmp);
Rodrigues(rvec_tmp, rvec);
cv::Rodrigues(rvec, rvec_tmp);
cv::Rodrigues(rvec_tmp, rvec);

projectPoints(points3d, rvec, tvec, intrinsics, distortion, points2d);
cv::projectPoints(points3d, rvec, tvec, intrinsics, distortion, points2d);

//add noise
Mat noise(1, (int)points2d.size(), CV_32FC2);
randu(noise, -0.001, 0.001);
add(points2d, noise, points2d);
cv::add(points2d, noise, points2d);

declare.in(points3d, points2d);
declare.time(100);

TEST_CYCLE_N(1000)
{
solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, algo);
cv::solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, algo);
}

SANITY_CHECK(rvec, 1e-1);
Expand Down Expand Up @@ -144,16 +138,13 @@ PERF_TEST_P(PointsNum, DISABLED_SolvePnPRansac, testing::Values(5, 3*9, 7*13))
Mat rvec;
Mat tvec;

#ifdef HAVE_TBB
// limit concurrency to get deterministic result
tbb::task_scheduler_init one_thread(1);
#endif

TEST_CYCLE()
{
solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec);
cv::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec);
}

SANITY_CHECK(rvec, 1e-6);
SANITY_CHECK(tvec, 1e-6);
}

} // namespace
17 changes: 3 additions & 14 deletions modules/calib3d/perf/perf_precomp.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wmissing-declarations"
# if defined __clang__ || defined __APPLE__
# pragma GCC diagnostic ignored "-Wmissing-prototypes"
# pragma GCC diagnostic ignored "-Wextra"
# endif
#endif

// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#ifndef __OPENCV_PERF_PRECOMP_HPP__
#define __OPENCV_PERF_PRECOMP_HPP__

#include "opencv2/ts.hpp"
#include "opencv2/calib3d.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"

#ifdef GTEST_CREATE_SHARED_LIBRARY
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
#endif

#endif
2 changes: 1 addition & 1 deletion modules/calib3d/perf/perf_stereosgbm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#include "perf_precomp.hpp"

namespace cvtest
namespace opencv_test
{
using namespace perf;
using namespace testing;
Expand Down
2 changes: 1 addition & 1 deletion modules/calib3d/test/opencl/test_stereobm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

#ifdef HAVE_OPENCL

namespace cvtest {
namespace opencv_test {
namespace ocl {

PARAM_TEST_CASE(StereoBMFixture, int, int)
Expand Down
9 changes: 3 additions & 6 deletions modules/calib3d/test/test_affine2d_estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@

#include "test_precomp.hpp"

using namespace cv;
using namespace std;
using namespace testing;

#include <vector>
#include <numeric>
namespace opencv_test { namespace {

CV_ENUM(Method, RANSAC, LMEDS)
typedef TestWithParam<Method> EstimateAffine2D;
Expand Down Expand Up @@ -156,3 +151,5 @@ TEST_P(EstimateAffine2D, testConversion)
}

INSTANTIATE_TEST_CASE_P(Calib3d, EstimateAffine2D, Method::all());

}} // namespace
6 changes: 4 additions & 2 deletions modules/calib3d/test/test_affine3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@

#include "test_precomp.hpp"
#include "opencv2/core/affine.hpp"
#include "opencv2/calib3d.hpp"
#include <iostream>

namespace opencv_test { namespace {

TEST(Calib3d_Affine3f, accuracy)
{
Expand Down Expand Up @@ -106,3 +106,5 @@ TEST(Calib3d_Affine3f, accuracy_rvec)
ASSERT_LT(cvtest::norm(va, vo, cv::NORM_L2), 1e-9);
}
}

}} // namespace
21 changes: 7 additions & 14 deletions modules/calib3d/test/test_affine3d_estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,7 @@

#include "test_precomp.hpp"

using namespace cv;
using namespace std;

#include <string>
#include <iostream>
#include <fstream>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
namespace opencv_test { namespace {

class CV_Affine3D_EstTest : public cvtest::BaseTest
{
Expand Down Expand Up @@ -101,7 +92,7 @@ bool CV_Affine3D_EstTest::test4Points()
fpts.ptr<Point3f>()[2] = Point3f( rngIn(1,2), rngIn(3,4), rngIn(5, 6) );
fpts.ptr<Point3f>()[3] = Point3f( rngIn(3,4), rngIn(1,2), rngIn(5, 6) );

transform(fpts.ptr<Point3f>(), fpts.ptr<Point3f>() + 4, tpts.ptr<Point3f>(), WrapAff(aff));
std::transform(fpts.ptr<Point3f>(), fpts.ptr<Point3f>() + 4, tpts.ptr<Point3f>(), WrapAff(aff));

Mat aff_est;
vector<uchar> outliers;
Expand Down Expand Up @@ -144,11 +135,11 @@ bool CV_Affine3D_EstTest::testNPoints()
Mat tpts(1, n, CV_32FC3);

randu(fpts, Scalar::all(0), Scalar::all(100));
transform(fpts.ptr<Point3f>(), fpts.ptr<Point3f>() + n, tpts.ptr<Point3f>(), WrapAff(aff));
std::transform(fpts.ptr<Point3f>(), fpts.ptr<Point3f>() + n, tpts.ptr<Point3f>(), WrapAff(aff));

/* adding noise*/
transform(tpts.ptr<Point3f>() + m, tpts.ptr<Point3f>() + n, tpts.ptr<Point3f>() + m, bind2nd(plus<Point3f>(), shift_outl));
transform(tpts.ptr<Point3f>() + m, tpts.ptr<Point3f>() + n, tpts.ptr<Point3f>() + m, Noise(noise_level));
std::transform(tpts.ptr<Point3f>() + m, tpts.ptr<Point3f>() + n, tpts.ptr<Point3f>() + m, std::bind2nd(std::plus<Point3f>(), shift_outl));
std::transform(tpts.ptr<Point3f>() + m, tpts.ptr<Point3f>() + n, tpts.ptr<Point3f>() + m, Noise(noise_level));

Mat aff_est;
vector<uchar> outl;
Expand Down Expand Up @@ -195,3 +186,5 @@ void CV_Affine3D_EstTest::run( int /* start_from */)
}

TEST(Calib3d_EstimateAffine3D, accuracy) { CV_Affine3D_EstTest test; test.safe_run(); }

}} // namespace
9 changes: 3 additions & 6 deletions modules/calib3d/test/test_affine_partial2d_estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@

#include "test_precomp.hpp"

using namespace cv;
using namespace std;
using namespace testing;

#include <vector>
#include <numeric>
namespace opencv_test { namespace {

CV_ENUM(Method, RANSAC, LMEDS)
typedef TestWithParam<Method> EstimateAffinePartial2D;
Expand Down Expand Up @@ -165,3 +160,5 @@ TEST_P(EstimateAffinePartial2D, testConversion)
}

INSTANTIATE_TEST_CASE_P(Calib3d, EstimateAffinePartial2D, Method::all());

}} // namespace
24 changes: 12 additions & 12 deletions modules/calib3d/test/test_cameracalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
#include "test_precomp.hpp"
#include "opencv2/calib3d/calib3d_c.h"

#include <limits>

using namespace std;
using namespace cv;
namespace opencv_test { namespace {

#if 0
class CV_ProjectPointsTest : public cvtest::ArrayTest
Expand Down Expand Up @@ -861,7 +858,7 @@ void CV_CameraCalibrationTest_CPP::calibrate(int imageCount, int* pointCounts,
for( int i = 0; i < imageCount; ++rvecsIt, ++tvecsIt, i++, rm+=9, tm+=3 )
{
Mat r9( 3, 3, CV_64FC1 );
Rodrigues( *rvecsIt, r9 );
cvtest::Rodrigues( *rvecsIt, r9 );
memcpy( rm, r9.ptr(), 9*sizeof(double) );
memcpy( tm, tvecsIt->ptr(), 3*sizeof(double) );
}
Expand All @@ -878,7 +875,7 @@ void CV_CameraCalibrationTest_CPP::project( int pointCount, CvPoint3D64f* _objec
Mat cameraMatrix( 3, 3, CV_64FC1, _cameraMatrix );
Mat distCoeffs( 1, 4, CV_64FC1, distortion );
vector<Point2f> imagePoints;
Rodrigues( rmat, rvec );
cvtest::Rodrigues( rmat, rvec );

objectPoints.convertTo( objectPoints, CV_32FC1 );
projectPoints( objectPoints, rvec, tvec,
Expand Down Expand Up @@ -982,7 +979,7 @@ void CV_CalibrationMatrixValuesTest::run(int)
code = cvtest::TS::FAIL_BAD_ACCURACY;
goto _exit_;
}
if( norm( principalPoint - goodPrincipalPoint ) > FLT_EPSILON )
if( cv::norm(principalPoint - goodPrincipalPoint) > FLT_EPSILON ) // Point2d
{
ts->printf( cvtest::TS::LOG, "bad principalPoint\n" );
code = cvtest::TS::FAIL_BAD_ACCURACY;
Expand Down Expand Up @@ -1117,7 +1114,8 @@ void CV_ProjectPointsTest::run(int)
rvec(0,0) = rng.uniform( rMinVal, rMaxVal );
rvec(0,1) = rng.uniform( rMinVal, rMaxVal );
rvec(0,2) = rng.uniform( rMinVal, rMaxVal );
Rodrigues( rvec, rmat );
rmat = cv::Mat_<float>::zeros(3, 3);
cvtest::Rodrigues( rvec, rmat );

tvec(0,0) = rng.uniform( tMinVal, tMaxVal );
tvec(0,1) = rng.uniform( tMinVal, tMaxVal );
Expand Down Expand Up @@ -2135,15 +2133,15 @@ TEST(Calib3d_Triangulate, accuracy)
Mat res_, res;

triangulatePoints(P1, P2, x1, x2, res_);
transpose(res_, res_);
cv::transpose(res_, res_); // TODO cvtest (transpose doesn't support inplace)
convertPointsFromHomogeneous(res_, res);
res = res.reshape(1, 1);

cout << "[1]:" << endl;
cout << "\tres0: " << res0 << endl;
cout << "\tres: " << res << endl;

ASSERT_LE(norm(res, res0, NORM_INF), 1e-1);
ASSERT_LE(cvtest::norm(res, res0, NORM_INF), 1e-1);
}

// another testcase http://code.opencv.org/issues/3461
Expand Down Expand Up @@ -2175,14 +2173,16 @@ TEST(Calib3d_Triangulate, accuracy)
Mat res_, res;

triangulatePoints(P1, P2, x1, x2, res_);
transpose(res_, res_);
cv::transpose(res_, res_); // TODO cvtest (transpose doesn't support inplace)
convertPointsFromHomogeneous(res_, res);
res = res.reshape(1, 1);

cout << "[2]:" << endl;
cout << "\tres0: " << res0 << endl;
cout << "\tres: " << res << endl;

ASSERT_LE(norm(res, res0, NORM_INF), 2);
ASSERT_LE(cvtest::norm(res, res0, NORM_INF), 2);
}
}

}} // namespace
Loading

0 comments on commit 4a297a2

Please sign in to comment.