<commit_before>#include "perf_precomp.hpp"

using namespace std;
using namespace cv;
using namespace perf;
using namespace testing;
using std::tr1::make_tuple;
using std::tr1::get;

enum{HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH};

CV_ENUM(BorderMode, BORDER_CONSTANT, BORDER_REPLICATE)
CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR)
CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH)

typedef TestBaseWithParam< tr1::tuple<Size, InterType, BorderMode> > TestWarpAffine;
typedef TestBaseWithParam< tr1::tuple<Size, InterType, BorderMode> > TestWarpPerspective;
typedef TestBaseWithParam< tr1::tuple<MatType, Size, InterType, BorderMode, RemapMode> > TestRemap;

void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode );

PERF_TEST_P( TestWarpAffine, WarpAffine,
             Combine(
                Values( szVGA, sz720p, sz1080p ),
                ValuesIn( InterType::all() ),
                ValuesIn( BorderMode::all() )
             )
)
{
    Size sz;
    int borderMode, interType;
    sz         = get<0>(GetParam());
    borderMode = get<1>(GetParam());
    interType  = get<2>(GetParam());

    Mat src, img = imread(getDataPath("cv/shared/fruits.png"));
    cvtColor(img, src, COLOR_BGR2RGBA, 4);
    Mat warpMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
    Mat dst(sz, CV_8UC4);

    declare.in(src).out(dst);

    TEST_CYCLE() warpAffine( src, dst, warpMat, sz, interType, borderMode, Scalar::all(150) );

    SANITY_CHECK(dst);

}

PERF_TEST_P( TestWarpPerspective, WarpPerspective,
             Combine(
                Values( szVGA, sz720p, sz1080p ),
                ValuesIn( InterType::all() ),
                ValuesIn( BorderMode::all() )
             )
)
{
    Size sz;
    int borderMode, interType;
    sz         = get<0>(GetParam());
    borderMode = get<1>(GetParam());
    interType  = get<2>(GetParam());


    Mat src, img = imread(getDataPath("cv/shared/fruits.png"));
    cvtColor(img, src, COLOR_BGR2RGBA, 4);
    Mat rotMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
    Mat warpMat(3, 3, CV_64FC1);
    for(int r=0; r<2; r++)
        for(int c=0; c<3; c++)
            warpMat.at<double>(r, c) = rotMat.at<double>(r, c);
    warpMat.at<double>(2, 0) = .3/sz.width;
    warpMat.at<double>(2, 1) = .3/sz.height;
    warpMat.at<double>(2, 2) = 1;
    Mat dst(sz, CV_8UC4);

    declare.in(src).out(dst);

    TEST_CYCLE() warpPerspective( src, dst, warpMat, sz, interType, borderMode, Scalar::all(150) );

    SANITY_CHECK(dst);
}

PERF_TEST_P( TestWarpPerspective, WarpPerspectiveLarge,
             Combine(
                Values( sz3MP, sz5MP ),
                ValuesIn( InterType::all() ),
                ValuesIn( BorderMode::all() )
             )
)
{
    Size sz;
    int borderMode, interType;
    sz         = get<0>(GetParam());
    borderMode = get<1>(GetParam());
    interType  = get<2>(GetParam());

    string resolution;
    if (sz == sz3MP)
        resolution = "3MP";
    else if (sz == sz5MP)
        resolution = "5MP";
    else
        FAIL();

    Mat src, img = imread(getDataPath("cv/shared/" + resolution + ".png"));
    cvtColor(img, src, COLOR_BGR2BGRA, 4);

    int shift = 103;
    Mat srcVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, 0), Vec2f(sz.width-1, 0),
                                            Vec2f(sz.width-1, sz.height-1), Vec2f(0, sz.height-1));
    Mat dstVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, shift), Vec2f(sz.width-shift/2, 0),
                                            Vec2f(sz.width-shift, sz.height-shift), Vec2f(shift/2, sz.height-1));
    Mat warpMat = getPerspectiveTransform(srcVertices, dstVertices);

    Mat dst(sz, CV_8UC4);

    declare.in(src).out(dst);

    TEST_CYCLE()
        warpPerspective( src, dst, warpMat, sz, interType, borderMode, Scalar::all(150) );

    SANITY_CHECK(dst);
}

PERF_TEST_P( TestRemap, remap,
             Combine(
                 Values( TYPICAL_MAT_TYPES ),
                 Values( szVGA, sz720p, sz1080p ),
                 ValuesIn( InterType::all() ),
                 ValuesIn( BorderMode::all() ),
                 ValuesIn( RemapMode::all() )
                 )
             )
{
    int type = get<0>(GetParam());
    Size size = get<1>(GetParam());
    int interpolationType = get<2>(GetParam());
    int borderMode = get<3>(GetParam());
    int remapMode = get<4>(GetParam());<commit_msg>extended perf test warpPerspectiveLarge<commit_after>#include "perf_precomp.hpp"

using namespace std;
using namespace cv;
using namespace perf;
using namespace testing;
using std::tr1::make_tuple;
using std::tr1::get;

enum{HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH};

CV_ENUM(BorderMode, BORDER_CONSTANT, BORDER_REPLICATE)
CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR)
CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH)

typedef TestBaseWithParam< tr1::tuple<Size, InterType, BorderMode> > TestWarpAffine;
typedef TestBaseWithParam< tr1::tuple<Size, InterType, BorderMode> > TestWarpPerspective;
typedef TestBaseWithParam< tr1::tuple<Size, InterType, BorderMode, MatType> > TestWarpPerspectiveNear_t;
typedef TestBaseWithParam< tr1::tuple<MatType, Size, InterType, BorderMode, RemapMode> > TestRemap;

void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode );

PERF_TEST_P( TestWarpAffine, WarpAffine,
             Combine(
                Values( szVGA, sz720p, sz1080p ),
                ValuesIn( InterType::all() ),
                ValuesIn( BorderMode::all() )
             )
)
{
    Size sz;
    int borderMode, interType;
    sz         = get<0>(GetParam());
    borderMode = get<1>(GetParam());
    interType  = get<2>(GetParam());

    Mat src, img = imread(getDataPath("cv/shared/fruits.png"));
    cvtColor(img, src, COLOR_BGR2RGBA, 4);
    Mat warpMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
    Mat dst(sz, CV_8UC4);

    declare.in(src).out(dst);

    TEST_CYCLE() warpAffine( src, dst, warpMat, sz, interType, borderMode, Scalar::all(150) );

    SANITY_CHECK(dst);

}

PERF_TEST_P( TestWarpPerspective, WarpPerspective,
             Combine(
                Values( szVGA, sz720p, sz1080p ),
                ValuesIn( InterType::all() ),
                ValuesIn( BorderMode::all() )
             )
)
{
    Size sz;
    int borderMode, interType;
    sz         = get<0>(GetParam());
    borderMode = get<1>(GetParam());
    interType  = get<2>(GetParam());


    Mat src, img = imread(getDataPath("cv/shared/fruits.png"));
    cvtColor(img, src, COLOR_BGR2RGBA, 4);
    Mat rotMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
    Mat warpMat(3, 3, CV_64FC1);
    for(int r=0; r<2; r++)
        for(int c=0; c<3; c++)
            warpMat.at<double>(r, c) = rotMat.at<double>(r, c);
    warpMat.at<double>(2, 0) = .3/sz.width;
    warpMat.at<double>(2, 1) = .3/sz.height;
    warpMat.at<double>(2, 2) = 1;
    Mat dst(sz, CV_8UC4);

    declare.in(src).out(dst);

    TEST_CYCLE() warpPerspective( src, dst, warpMat, sz, interType, borderMode, Scalar::all(150) );

    SANITY_CHECK(dst);
}

PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear,
             Combine(
                 Values( Size(176,144), Size(320,240), Size(352,288), Size(480,480),
                         Size(640,480), Size(704,576), Size(720,408), Size(720,480),
                         Size(720,576), Size(768,432), Size(800,448), Size(960,720),
                         Size(1024,768), Size(1280,720), Size(1280,960), Size(1360,720),
                         Size(1600,1200), Size(1920,1080), Size(2048,1536), Size(2592,1920),
                         Size(2592,1944), Size(3264,2448), Size(4096,3072), Size(4208,3120) ),
                 ValuesIn( InterType::all() ),
                 ValuesIn( BorderMode::all() ),
                 Values( CV_8UC1, CV_8UC4 )
                 )
             )
{
    Size size;
    int borderMode, interType, type;
    size       = get<0>(GetParam());
    borderMode = get<1>(GetParam());
    interType  = get<2>(GetParam());
    type = get<3>(GetParam());

    Mat src, img = imread(getDataPath("cv/shared/5MP.png"));

    if( type == CV_8UC1 )
    {
        cvtColor(img, src, COLOR_BGR2GRAY, 1);
    }
    else if( type == CV_8UC4 )
    {
        cvtColor(img, src, COLOR_BGR2BGRA, 4);
    }
    else
    {
        FAIL();
    }

    resize(src, src, size);

    int shift = src.cols*0.04;
    Mat srcVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, 0), Vec2f(size.width-1, 0),
                                            Vec2f(size.width-1, size.height-1), Vec2f(0, size.height-1));
    Mat dstVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, shift), Vec2f(size.width-shift/2, 0),
                                            Vec2f(size.width-shift, size.height-shift), Vec2f(shift/2, size.height-1));
    Mat warpMat = getPerspectiveTransform(srcVertices, dstVertices);

    Mat dst(size, type);

    declare.in(src).out(dst);

    TEST_CYCLE()
    {
        warpPerspective( src, dst, warpMat, size, interType, borderMode, Scalar::all(150) );
    }

    SANITY_CHECK(dst);
}

PERF_TEST_P( TestRemap, remap,
             Combine(
                 Values( TYPICAL_MAT_TYPES ),
                 Values( szVGA, sz720p, sz1080p ),
                 ValuesIn( InterType::all() ),
                 ValuesIn( BorderMode::all() ),
                 ValuesIn( RemapMode::all() )
                 )
             )
{
    int type = get<0>(GetParam());
    Size size = get<1>(GetParam());
    int interpolationType = get<2>(GetParam());
    int borderMode = get<3>(GetParam());
    int remapMode = get<4>(GetParam());
{'fraction_non_alphanumeric': 0.14807930607187111, 'fraction_numerical': 0.04471292854192482, 'mean_word_length': 2.665783497350492, 'pattern_counts': {'":': 0, '<': 72, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3849021', 'n_tokens_mistral': 3759, 'n_tokens_neox': 3433, 'n_words': 664}