2011-02-10 04:55:11 +08:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
|
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of the copyright holders may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
2017-11-05 21:48:40 +08:00
|
|
|
namespace opencv_test { namespace {
|
2011-02-10 04:55:11 +08:00
|
|
|
|
|
|
|
class CV_RigidTransform_Test : public cvtest::BaseTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CV_RigidTransform_Test();
|
2012-10-17 15:12:04 +08:00
|
|
|
~CV_RigidTransform_Test();
|
2011-02-10 04:55:11 +08:00
|
|
|
protected:
|
2012-10-17 15:12:04 +08:00
|
|
|
void run(int);
|
2011-02-10 04:55:11 +08:00
|
|
|
|
|
|
|
bool testNPoints(int);
|
2012-10-17 15:12:04 +08:00
|
|
|
bool testImage();
|
2011-02-10 04:55:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CV_RigidTransform_Test::CV_RigidTransform_Test()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
CV_RigidTransform_Test::~CV_RigidTransform_Test() {}
|
|
|
|
|
|
|
|
struct WrapAff2D
|
|
|
|
{
|
|
|
|
const double *F;
|
|
|
|
WrapAff2D(const Mat& aff) : F(aff.ptr<double>()) {}
|
|
|
|
Point2f operator()(const Point2f& p)
|
|
|
|
{
|
2014-10-16 02:40:04 +08:00
|
|
|
return Point2f( (float)(p.x * F[0] + p.y * F[1] + F[2]),
|
|
|
|
(float)(p.x * F[3] + p.y * F[4] + F[5]) );
|
2011-02-10 04:55:11 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool CV_RigidTransform_Test::testNPoints(int from)
|
|
|
|
{
|
|
|
|
cv::RNG rng = ts->get_rng();
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
int progress = 0;
|
|
|
|
int k, ntests = 10000;
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
for( k = from; k < ntests; k++ )
|
|
|
|
{
|
|
|
|
ts->update_context( this, k, true );
|
|
|
|
progress = update_progress(progress, k, ntests, 0);
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
Mat aff(2, 3, CV_64F);
|
2013-04-11 21:38:33 +08:00
|
|
|
rng.fill(aff, RNG::UNIFORM, Scalar(-2), Scalar(2));
|
2011-02-10 04:55:11 +08:00
|
|
|
|
|
|
|
int n = (unsigned)rng % 100 + 10;
|
|
|
|
|
|
|
|
Mat fpts(1, n, CV_32FC2);
|
|
|
|
Mat tpts(1, n, CV_32FC2);
|
|
|
|
|
2013-04-11 21:38:33 +08:00
|
|
|
rng.fill(fpts, RNG::UNIFORM, Scalar(0,0), Scalar(10,10));
|
2017-11-05 21:48:40 +08:00
|
|
|
std::transform(fpts.ptr<Point2f>(), fpts.ptr<Point2f>() + n, tpts.ptr<Point2f>(), WrapAff2D(aff));
|
2011-02-10 04:55:11 +08:00
|
|
|
|
|
|
|
Mat noise(1, n, CV_32FC2);
|
2013-04-11 21:38:33 +08:00
|
|
|
rng.fill(noise, RNG::NORMAL, Scalar::all(0), Scalar::all(0.001*(n<=7 ? 0 : n <= 30 ? 1 : 10)));
|
2011-02-10 04:55:11 +08:00
|
|
|
tpts += noise;
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
Mat aff_est = estimateRigidTransform(fpts, tpts, true);
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2014-04-09 04:00:13 +08:00
|
|
|
double thres = 0.1*cvtest::norm(aff, NORM_L2);
|
|
|
|
double d = cvtest::norm(aff_est, aff, NORM_L2);
|
2011-02-10 04:55:11 +08:00
|
|
|
if (d > thres)
|
|
|
|
{
|
|
|
|
double dB=0, nB=0;
|
|
|
|
if (n <= 4)
|
|
|
|
{
|
|
|
|
Mat A = fpts.reshape(1, 3);
|
|
|
|
Mat B = A - repeat(A.row(0), 3, 1), Bt = B.t();
|
2012-10-17 15:12:04 +08:00
|
|
|
B = Bt*B;
|
2011-02-10 04:55:11 +08:00
|
|
|
dB = cv::determinant(B);
|
2014-04-09 04:00:13 +08:00
|
|
|
nB = cvtest::norm(B, NORM_L2);
|
2011-02-10 04:55:11 +08:00
|
|
|
if( fabs(dB) < 0.01*nB )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
|
|
|
ts->printf( cvtest::TS::LOG, "Threshold = %f, norm of difference = %f", thres, d );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CV_RigidTransform_Test::testImage()
|
|
|
|
{
|
|
|
|
Mat img;
|
2011-06-03 15:57:07 +08:00
|
|
|
Mat testImg = imread( string(ts->get_data_path()) + "shared/graffiti.png", 1);
|
|
|
|
if (testImg.empty())
|
|
|
|
{
|
|
|
|
ts->printf( ts->LOG, "test image can not be read");
|
|
|
|
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pyrDown(testImg, img);
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
Mat aff = cv::getRotationMatrix2D(Point(img.cols/2, img.rows/2), 1, 0.99);
|
|
|
|
aff.ptr<double>()[2]+=3;
|
|
|
|
aff.ptr<double>()[5]+=3;
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
Mat rotated;
|
|
|
|
warpAffine(img, rotated, aff, img.size());
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2011-02-10 04:55:11 +08:00
|
|
|
Mat aff_est = estimateRigidTransform(img, rotated, true);
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2013-03-20 23:51:49 +08:00
|
|
|
const double thres = 0.033;
|
2014-04-09 04:00:13 +08:00
|
|
|
if (cvtest::norm(aff_est, aff, NORM_INF) > thres)
|
2012-10-17 15:12:04 +08:00
|
|
|
{
|
2011-02-10 04:55:11 +08:00
|
|
|
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
2012-10-17 15:12:04 +08:00
|
|
|
ts->printf( cvtest::TS::LOG, "Threshold = %f, norm of difference = %f", thres,
|
2014-04-09 04:00:13 +08:00
|
|
|
cvtest::norm(aff_est, aff, NORM_INF) );
|
2011-02-10 04:55:11 +08:00
|
|
|
return false;
|
2012-10-17 15:12:04 +08:00
|
|
|
}
|
2011-02-10 04:55:11 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CV_RigidTransform_Test::run( int start_from )
|
2012-10-17 15:12:04 +08:00
|
|
|
{
|
2011-02-10 04:55:11 +08:00
|
|
|
cvtest::DefaultRngAuto dra;
|
|
|
|
|
|
|
|
if (!testNPoints(start_from))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!testImage())
|
|
|
|
return;
|
|
|
|
|
|
|
|
ts->set_failed_test_info(cvtest::TS::OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Video_RigidFlow, accuracy) { CV_RigidTransform_Test test; test.safe_run(); }
|
2017-11-05 21:48:40 +08:00
|
|
|
|
|
|
|
}} // namespace
|