perf_reg.cpp 8.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/*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.
// Copyright (C) 2013, Alfonso Sanchez-Beato, 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 "perf_precomp.hpp"

46 47 48
namespace opencv_test { namespace {

using namespace perf;
49 50 51 52 53 54 55 56 57 58 59

Vec<double, 2> perfShift(const Mat& img1)
{
    Mat img2;

    // Warp original image
    Vec<double, 2> shift(5., 5.);
    MapShift mapTest(shift);
    mapTest.warp(img1, img2);

    // Register
60
    Ptr<MapperGradShift> mapper = makePtr<MapperGradShift>();
61
    MapperPyramid mappPyr(mapper);
62
    Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

    MapShift* mapShift = dynamic_cast<MapShift*>(mapPtr.get());
    return mapShift->getShift();
}

Matx<double, 2, 6> perfEuclidean(const Mat& img1)
{
    Mat img2;
    Matx<double, 2, 6> transf;

    // Warp original image
    double theta = 3*CV_PI/180;
    double cosT = cos(theta);
    double sinT = sin(theta);
    Matx<double, 2, 2> linTr(cosT, -sinT, sinT, cosT);
    Vec<double, 2> shift(5., 5.);
    MapAffine mapTest(linTr, shift);
    mapTest.warp(img1, img2);

    // Register
83
    Ptr<MapperGradEuclid> mapper = makePtr<MapperGradEuclid>();
84
    MapperPyramid mappPyr(mapper);
85
    Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

    MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
    Matx<double, 2, 2> resLinTr = mapAff->getLinTr();
    transf(0, 0) = resLinTr(0, 0), transf(0, 1) = resLinTr(0, 1);
    transf(1, 0) = resLinTr(1, 0), transf(1, 1) = resLinTr(1, 1);
    Vec<double, 2> resShift = mapAff->getShift();
    transf(0, 2) = resShift(0);
    transf(1, 2) = resShift(1);
    return transf;
}

Matx<double, 2, 6> perfSimilarity(const Mat& img1)
{
    Mat img2;
    Matx<double, 2, 6> transf;

    // Warp original image
    double theta = 3*CV_PI/180;
    double scale = 0.95;
    double a = scale*cos(theta);
    double b = scale*sin(theta);
    Matx<double, 2, 2> linTr(a, -b, b, a);
    Vec<double, 2> shift(5., 5.);
    MapAffine mapTest(linTr, shift);
    mapTest.warp(img1, img2);

    // Register
113
    Ptr<MapperGradSimilar> mapper = makePtr<MapperGradSimilar>();
114
    MapperPyramid mappPyr(mapper);
115
    Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

    MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
    Matx<double, 2, 2> resLinTr = mapAff->getLinTr();
    transf(0, 0) = resLinTr(0, 0), transf(0, 1) = resLinTr(0, 1);
    transf(1, 0) = resLinTr(1, 0), transf(1, 1) = resLinTr(1, 1);
    Vec<double, 2> resShift = mapAff->getShift();
    transf(0, 2) = resShift(0);
    transf(1, 2) = resShift(1);
    return transf;
}

Matx<double, 2, 6> perfAffine(const Mat& img1)
{
    Mat img2;
    Matx<double, 2, 6> transf;

    // Warp original image
    Matx<double, 2, 2> linTr(1., 0.1, -0.01, 1.);
    Vec<double, 2> shift(1., 1.);
    MapAffine mapTest(linTr, shift);
    mapTest.warp(img1, img2);

    // Register
139
    Ptr<MapperGradAffine> mapper = makePtr<MapperGradAffine>();
140
    MapperPyramid mappPyr(mapper);
141
    Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

    MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());
    Matx<double, 2, 2> resLinTr = mapAff->getLinTr();
    transf(0, 0) = resLinTr(0, 0), transf(0, 1) = resLinTr(0, 1);
    transf(1, 0) = resLinTr(1, 0), transf(1, 1) = resLinTr(1, 1);
    Vec<double, 2> resShift = mapAff->getShift();
    transf(0, 2) = resShift(0);
    transf(1, 2) = resShift(1);
    return transf;
}

Matx<double, 3, 3> perfProjective(const Mat& img1)
{
    Mat img2;

    // Warp original image
    Matx<double, 3, 3> projTr(1., 0., 0., 0., 1., 0., 0.0001, 0.0001, 1);
    MapProjec mapTest(projTr);
    mapTest.warp(img1, img2);

    // Register
163
    Ptr<MapperGradProj> mapper = makePtr<MapperGradProj>();
164
    MapperPyramid mappPyr(mapper);
165
    Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

    MapProjec* mapProj = dynamic_cast<MapProjec*>(mapPtr.get());
    mapProj->normalize();
    return mapProj->getProjTr();
}


PERF_TEST_P(Size_MatType, Registration_Shift,
            Combine(Values(szSmall64, szSmall128),
                    Values(MatType(CV_64FC1), MatType(CV_64FC3))))
{
    declare.time(60);

    const Size size = get<0>(GetParam());
    const int type = get<1>(GetParam());

    Mat frame(size, type);
    Vec<double, 2> shift;
    declare.in(frame, WARMUP_RNG).out(shift);

    TEST_CYCLE() shift = perfShift(frame);

188
    SANITY_CHECK_NOTHING();
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
}

PERF_TEST_P(Size_MatType, Registration_Euclidean,
            Combine(Values(szSmall64, szSmall128),
                    Values(MatType(CV_64FC1), MatType(CV_64FC3))))
{
    declare.time(60);

    const Size size = get<0>(GetParam());
    const int type = get<1>(GetParam());

    Mat frame(size, type);
    Matx<double, 2, 6> result;
    declare.in(frame, WARMUP_RNG).out(result);

    TEST_CYCLE() result = perfEuclidean(frame);

206
    SANITY_CHECK_NOTHING();
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
}

PERF_TEST_P(Size_MatType, Registration_Similarity,
            Combine(Values(szSmall64, szSmall128),
                    Values(MatType(CV_64FC1), MatType(CV_64FC3))))
{
    declare.time(60);

    const Size size = get<0>(GetParam());
    const int type = get<1>(GetParam());

    Mat frame(size, type);
    Matx<double, 2, 6> result;
    declare.in(frame, WARMUP_RNG).out(result);

    TEST_CYCLE() result = perfSimilarity(frame);

224
    SANITY_CHECK_NOTHING();
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
}

PERF_TEST_P(Size_MatType, Registration_Affine,
            Combine(Values(szSmall64, szSmall128),
                    Values(MatType(CV_64FC1), MatType(CV_64FC3))))
{
    declare.time(60);

    const Size size = get<0>(GetParam());
    const int type = get<1>(GetParam());

    Mat frame(size, type);
    Matx<double, 2, 6> result;
    declare.in(frame, WARMUP_RNG).out(result);

    TEST_CYCLE() result = perfAffine(frame);

242
    SANITY_CHECK_NOTHING();
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
}

PERF_TEST_P(Size_MatType, Registration_Projective,
            Combine(Values(szSmall64, szSmall128),
                    Values(MatType(CV_64FC1), MatType(CV_64FC3))))
{
    declare.time(60);

    const Size size = get<0>(GetParam());
    const int type = get<1>(GetParam());

    Mat frame(size, type);
    Matx<double, 3, 3> result;
    declare.in(frame, WARMUP_RNG).out(result);

    TEST_CYCLE() result = perfProjective(frame);

260
    SANITY_CHECK_NOTHING();
261
}
262 263

}} // namespace