perf_ecc.cpp 2.28 KB
Newer Older
Georgios Evangelidis's avatar
Georgios Evangelidis committed
1 2
#include "perf_precomp.hpp"

3 4
namespace opencv_test
{
Georgios Evangelidis's avatar
Georgios Evangelidis committed
5 6 7 8
using namespace perf;

CV_ENUM(MotionType, MOTION_TRANSLATION, MOTION_EUCLIDEAN, MOTION_AFFINE, MOTION_HOMOGRAPHY)

9
typedef tuple<MotionType> MotionType_t;
Georgios Evangelidis's avatar
Georgios Evangelidis committed
10 11 12 13 14 15 16 17
typedef perf::TestBaseWithParam<MotionType_t> TransformationType;


PERF_TEST_P(TransformationType, findTransformECC, /*testing::ValuesIn(MotionType::all())*/
            testing::Values((int) MOTION_TRANSLATION, (int) MOTION_EUCLIDEAN,
            (int) MOTION_AFFINE, (int) MOTION_HOMOGRAPHY)
            )
{
18
    Mat img = imread(getDataPath("cv/shared/fruits_ecc.png"),0);
Georgios Evangelidis's avatar
Georgios Evangelidis committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32
    Mat templateImage;

    int transform_type = get<0>(GetParam());

    Mat warpMat;
    Mat warpGround;

    double angle;
    switch (transform_type) {
        case MOTION_TRANSLATION:
            warpGround = (Mat_<float>(2,3) << 1.f, 0.f, 7.234f,
                0.f, 1.f, 11.839f);

            warpAffine(img, templateImage, warpGround,
33
                Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
Georgios Evangelidis's avatar
Georgios Evangelidis committed
34 35 36 37 38 39 40
            break;
        case MOTION_EUCLIDEAN:
            angle = CV_PI/30;

            warpGround = (Mat_<float>(2,3) << (float)cos(angle), (float)-sin(angle), 12.123f,
                (float)sin(angle), (float)cos(angle), 14.789f);
            warpAffine(img, templateImage, warpGround,
41
                Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
Georgios Evangelidis's avatar
Georgios Evangelidis committed
42 43 44 45 46
            break;
        case MOTION_AFFINE:
            warpGround = (Mat_<float>(2,3) << 0.98f, 0.03f, 15.523f,
                -0.02f, 0.95f, 10.456f);
            warpAffine(img, templateImage, warpGround,
47
                Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
Georgios Evangelidis's avatar
Georgios Evangelidis committed
48 49 50 51 52 53
            break;
        case MOTION_HOMOGRAPHY:
            warpGround = (Mat_<float>(3,3) << 0.98f, 0.03f, 15.523f,
                -0.02f, 0.95f, 10.456f,
                0.0002f, 0.0003f, 1.f);
            warpPerspective(img, templateImage, warpGround,
54
                Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
Georgios Evangelidis's avatar
Georgios Evangelidis committed
55 56 57 58 59 60 61 62 63 64 65 66 67
            break;
    }

    TEST_CYCLE()
    {
        if (transform_type<3)
            warpMat = Mat::eye(2,3, CV_32F);
        else
            warpMat = Mat::eye(3,3, CV_32F);

        findTransformECC(templateImage, img, warpMat, transform_type,
            TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 5, -1));
    }
68
    SANITY_CHECK(warpMat, 3e-3);
Georgios Evangelidis's avatar
Georgios Evangelidis committed
69
}
70 71

} // namespace