mirror of
https://github.com/opencv/opencv.git
synced 2024-12-02 07:39:57 +08:00
95a55453df
Conflicts: modules/calib3d/perf/perf_pnp.cpp modules/contrib/src/imagelogpolprojection.cpp modules/contrib/src/templatebuffer.hpp modules/core/perf/opencl/perf_gemm.cpp modules/cudafeatures2d/doc/feature_detection_and_description.rst modules/cudafeatures2d/perf/perf_features2d.cpp modules/cudafeatures2d/src/fast.cpp modules/cudafeatures2d/test/test_features2d.cpp modules/features2d/doc/feature_detection_and_description.rst modules/features2d/include/opencv2/features2d/features2d.hpp modules/features2d/perf/opencl/perf_brute_force_matcher.cpp modules/gpu/include/opencv2/gpu/gpu.hpp modules/gpu/perf/perf_imgproc.cpp modules/gpu/perf4au/main.cpp modules/imgproc/perf/opencl/perf_blend.cpp modules/imgproc/perf/opencl/perf_color.cpp modules/imgproc/perf/opencl/perf_moments.cpp modules/imgproc/perf/opencl/perf_pyramid.cpp modules/objdetect/perf/opencl/perf_hogdetect.cpp modules/ocl/perf/perf_arithm.cpp modules/ocl/perf/perf_bgfg.cpp modules/ocl/perf/perf_blend.cpp modules/ocl/perf/perf_brute_force_matcher.cpp modules/ocl/perf/perf_canny.cpp modules/ocl/perf/perf_filters.cpp modules/ocl/perf/perf_gftt.cpp modules/ocl/perf/perf_haar.cpp modules/ocl/perf/perf_imgproc.cpp modules/ocl/perf/perf_imgwarp.cpp modules/ocl/perf/perf_match_template.cpp modules/ocl/perf/perf_matrix_operation.cpp modules/ocl/perf/perf_ml.cpp modules/ocl/perf/perf_moments.cpp modules/ocl/perf/perf_opticalflow.cpp modules/ocl/perf/perf_precomp.hpp modules/ocl/src/cl_context.cpp modules/ocl/src/opencl/haarobjectdetect.cl modules/video/src/lkpyramid.cpp modules/video/src/precomp.hpp samples/gpu/morphology.cpp
144 lines
3.7 KiB
C++
144 lines
3.7 KiB
C++
#include "perf_precomp.hpp"
|
|
|
|
#ifdef HAVE_TBB
|
|
#include "tbb/task_scheduler_init.h"
|
|
#endif
|
|
|
|
using namespace std;
|
|
using namespace cv;
|
|
using namespace perf;
|
|
using std::tr1::make_tuple;
|
|
using std::tr1::get;
|
|
|
|
CV_ENUM(pnpAlgo, ITERATIVE, EPNP /*, P3P*/)
|
|
|
|
typedef std::tr1::tuple<int, pnpAlgo> PointsNum_Algo_t;
|
|
typedef perf::TestBaseWithParam<PointsNum_Algo_t> PointsNum_Algo;
|
|
|
|
typedef perf::TestBaseWithParam<int> PointsNum;
|
|
|
|
PERF_TEST_P(PointsNum_Algo, solvePnP,
|
|
testing::Combine(
|
|
testing::Values(/*4,*/ 3*9, 7*13), //TODO: find why results on 4 points are too unstable
|
|
testing::Values((int)ITERATIVE, (int)EPNP)
|
|
)
|
|
)
|
|
{
|
|
int pointsNum = get<0>(GetParam());
|
|
pnpAlgo algo = get<1>(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, (int)points2d.size(), CV_32FC2);
|
|
randu(noise, 0, 0.01);
|
|
add(points2d, noise, points2d);
|
|
|
|
declare.in(points3d, points2d);
|
|
|
|
TEST_CYCLE_N(1000)
|
|
{
|
|
solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, algo);
|
|
}
|
|
|
|
SANITY_CHECK(rvec, 1e-6);
|
|
SANITY_CHECK(tvec, 1e-3);
|
|
}
|
|
|
|
PERF_TEST(PointsNum_Algo, solveP3P)
|
|
{
|
|
int pointsNum = 4;
|
|
|
|
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, (int)points2d.size(), CV_32FC2);
|
|
randu(noise, 0, 0.01);
|
|
add(points2d, noise, points2d);
|
|
|
|
declare.in(points3d, points2d);
|
|
declare.time(100);
|
|
|
|
TEST_CYCLE_N(1000)
|
|
{
|
|
solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, P3P);
|
|
}
|
|
|
|
SANITY_CHECK(rvec, 1e-6);
|
|
SANITY_CHECK(tvec, 1e-6);
|
|
}
|
|
|
|
PERF_TEST_P(PointsNum, DISABLED_SolvePnPRansac, testing::Values(4, 3*9, 7*13))
|
|
{
|
|
int count = GetParam();
|
|
|
|
Mat object(1, count, CV_32FC3);
|
|
randu(object, -100, 100);
|
|
|
|
Mat camera_mat(3, 3, CV_32FC1);
|
|
randu(camera_mat, 0.5, 1);
|
|
camera_mat.at<float>(0, 1) = 0.f;
|
|
camera_mat.at<float>(1, 0) = 0.f;
|
|
camera_mat.at<float>(2, 0) = 0.f;
|
|
camera_mat.at<float>(2, 1) = 0.f;
|
|
|
|
Mat dist_coef(1, 8, CV_32F, cv::Scalar::all(0));
|
|
|
|
vector<cv::Point2f> image_vec;
|
|
Mat rvec_gold(1, 3, CV_32FC1);
|
|
randu(rvec_gold, 0, 1);
|
|
Mat tvec_gold(1, 3, CV_32FC1);
|
|
randu(tvec_gold, 0, 1);
|
|
projectPoints(object, rvec_gold, tvec_gold, camera_mat, dist_coef, image_vec);
|
|
|
|
Mat image(1, count, CV_32FC2, &image_vec[0]);
|
|
|
|
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);
|
|
}
|
|
|
|
SANITY_CHECK(rvec, 1e-6);
|
|
SANITY_CHECK(tvec, 1e-6);
|
|
}
|