Path: blob/master/modules/calib3d/perf/perf_affine2d.cpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// By downloading, copying, installing or using the software you agree to this license.3// If you do not agree to this license, do not download, install,4// copy or use the software.5//6//7// License Agreement8// For Open Source Computer Vision Library9// (3-clause BSD License)10//11// Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.12// Third party copyrights are property of their respective owners.13//14// Redistribution and use in source and binary forms, with or without modification,15// are permitted provided that the following conditions are met:16//17// * Redistributions of source code must retain the above copyright notice,18// this list of conditions and the following disclaimer.19//20// * Redistributions in binary form must reproduce the above copyright notice,21// this list of conditions and the following disclaimer in the documentation22// and/or other materials provided with the distribution.23//24// * Neither the names of the copyright holders nor the names of the contributors25// may be used to endorse or promote products derived from this software26// without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall copyright holders or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/4041#include "perf_precomp.hpp"42#include <algorithm>43#include <functional>4445namespace opencv_test46{47using namespace perf;4849CV_ENUM(Method, RANSAC, LMEDS)50typedef tuple<int, double, Method, size_t> AffineParams;51typedef TestBaseWithParam<AffineParams> EstimateAffine;52#define ESTIMATE_PARAMS Combine(Values(100000, 5000, 100), Values(0.99, 0.95, 0.9), Method::all(), Values(10, 0))5354static float rngIn(float from, float to) { return from + (to-from) * (float)theRNG(); }5556static Mat rngPartialAffMat() {57double theta = rngIn(0, (float)CV_PI*2.f);58double scale = rngIn(0, 3);59double tx = rngIn(-2, 2);60double ty = rngIn(-2, 2);61double aff[2*3] = { std::cos(theta) * scale, -std::sin(theta) * scale, tx,62std::sin(theta) * scale, std::cos(theta) * scale, ty };63return Mat(2, 3, CV_64F, aff).clone();64}6566PERF_TEST_P( EstimateAffine, EstimateAffine2D, ESTIMATE_PARAMS )67{68AffineParams params = GetParam();69const int n = get<0>(params);70const double confidence = get<1>(params);71const int method = get<2>(params);72const size_t refining = get<3>(params);7374Mat aff(2, 3, CV_64F);75cv::randu(aff, -2., 2.);7677// LMEDS can't handle more than 50% outliers (by design)78int m;79if (method == LMEDS)80m = 3*n/5;81else82m = 2*n/5;83const float shift_outl = 15.f;84const float noise_level = 20.f;8586Mat fpts(1, n, CV_32FC2);87Mat tpts(1, n, CV_32FC2);8889randu(fpts, 0., 100.);90transform(fpts, tpts, aff);9192/* adding noise to some points */93Mat outliers = tpts.colRange(m, n);94outliers.reshape(1) += shift_outl;9596Mat noise (outliers.size(), outliers.type());97randu(noise, 0., noise_level);98outliers += noise;99100Mat aff_est;101vector<uchar> inliers (n);102103warmup(inliers, WARMUP_WRITE);104warmup(fpts, WARMUP_READ);105warmup(tpts, WARMUP_READ);106107TEST_CYCLE()108{109aff_est = estimateAffine2D(fpts, tpts, inliers, method, 3, 2000, confidence, refining);110}111112// we already have accuracy tests113SANITY_CHECK_NOTHING();114}115116PERF_TEST_P( EstimateAffine, EstimateAffinePartial2D, ESTIMATE_PARAMS )117{118AffineParams params = GetParam();119const int n = get<0>(params);120const double confidence = get<1>(params);121const int method = get<2>(params);122const size_t refining = get<3>(params);123124Mat aff = rngPartialAffMat();125126int m;127// LMEDS can't handle more than 50% outliers (by design)128if (method == LMEDS)129m = 3*n/5;130else131m = 2*n/5;132const float shift_outl = 15.f; const float noise_level = 20.f;133134Mat fpts(1, n, CV_32FC2);135Mat tpts(1, n, CV_32FC2);136137randu(fpts, 0., 100.);138transform(fpts, tpts, aff);139140/* adding noise*/141Mat outliers = tpts.colRange(m, n);142outliers.reshape(1) += shift_outl;143144Mat noise (outliers.size(), outliers.type());145randu(noise, 0., noise_level);146outliers += noise;147148Mat aff_est;149vector<uchar> inliers (n);150151warmup(inliers, WARMUP_WRITE);152warmup(fpts, WARMUP_READ);153warmup(tpts, WARMUP_READ);154155TEST_CYCLE()156{157aff_est = estimateAffinePartial2D(fpts, tpts, inliers, method, 3, 2000, confidence, refining);158}159160// we already have accuracy tests161SANITY_CHECK_NOTHING();162}163164} // namespace opencv_test165166167