Added exhaustive perf test for cvtColor instead of several small tests

This commit is contained in:
Andrey Kamaev 2012-01-23 07:08:31 +00:00
parent 6c1de21a76
commit 347a7106ab

View File

@ -6,209 +6,257 @@ using namespace perf;
using std::tr1::make_tuple;
using std::tr1::get;
CV_ENUM(CvtMode, CV_YUV2BGR, CV_YUV2RGB, //YUV
CV_YUV420i2BGR, CV_YUV420i2RGB, CV_YUV420sp2BGR, CV_YUV420sp2RGB, //YUV420
CV_RGB2GRAY, CV_RGBA2GRAY, CV_BGR2GRAY, CV_BGRA2GRAY, //Gray
CV_GRAY2RGB, CV_GRAY2RGBA, /*CV_GRAY2BGR, CV_GRAY2BGRA*/ //Gray2
CV_BGR2HSV, CV_RGB2HSV, CV_BGR2HLS, CV_RGB2HLS, //H
CV_BGR2YCrCb, CV_RGB2YCrCb
)
//extra color conversions supported implicitly
enum
{
CX_BGRA2HLS = CV_COLORCVT_MAX + CV_BGR2HLS,
CX_BGRA2HLS_FULL = CV_COLORCVT_MAX + CV_BGR2HLS_FULL,
CX_BGRA2HSV = CV_COLORCVT_MAX + CV_BGR2HSV,
CX_BGRA2HSV_FULL = CV_COLORCVT_MAX + CV_BGR2HSV_FULL,
CX_BGRA2Lab = CV_COLORCVT_MAX + CV_BGR2Lab,
CX_BGRA2Luv = CV_COLORCVT_MAX + CV_BGR2Luv,
CX_BGRA2XYZ = CV_COLORCVT_MAX + CV_BGR2XYZ,
CX_BGRA2YCrCb = CV_COLORCVT_MAX + CV_BGR2YCrCb,
CX_BGRA2YUV = CV_COLORCVT_MAX + CV_BGR2YUV,
CX_HLS2BGRA = CV_COLORCVT_MAX + CV_HLS2BGR,
CX_HLS2BGRA_FULL = CV_COLORCVT_MAX + CV_HLS2BGR_FULL,
CX_HLS2RGBA = CV_COLORCVT_MAX + CV_HLS2RGB,
CX_HLS2RGBA_FULL = CV_COLORCVT_MAX + CV_HLS2RGB_FULL,
CX_HSV2BGRA = CV_COLORCVT_MAX + CV_HSV2BGR,
CX_HSV2BGRA_FULL = CV_COLORCVT_MAX + CV_HSV2BGR_FULL,
CX_HSV2RGBA = CV_COLORCVT_MAX + CV_HSV2RGB,
CX_HSV2RGBA_FULL = CV_COLORCVT_MAX + CV_HSV2RGB_FULL,
CX_Lab2BGRA = CV_COLORCVT_MAX + CV_Lab2BGR,
CX_Lab2LBGRA = CV_COLORCVT_MAX + CV_Lab2LBGR,
CX_Lab2LRGBA = CV_COLORCVT_MAX + CV_Lab2LRGB,
CX_Lab2RGBA = CV_COLORCVT_MAX + CV_Lab2RGB,
CX_LBGRA2Lab = CV_COLORCVT_MAX + CV_LBGR2Lab,
CX_LBGRA2Luv = CV_COLORCVT_MAX + CV_LBGR2Luv,
CX_LRGBA2Lab = CV_COLORCVT_MAX + CV_LRGB2Lab,
CX_LRGBA2Luv = CV_COLORCVT_MAX + CV_LRGB2Luv,
CX_Luv2BGRA = CV_COLORCVT_MAX + CV_Luv2BGR,
CX_Luv2LBGRA = CV_COLORCVT_MAX + CV_Luv2LBGR,
CX_Luv2LRGBA = CV_COLORCVT_MAX + CV_Luv2LRGB,
CX_Luv2RGBA = CV_COLORCVT_MAX + CV_Luv2RGB,
CX_RGBA2HLS = CV_COLORCVT_MAX + CV_RGB2HLS,
CX_RGBA2HLS_FULL = CV_COLORCVT_MAX + CV_RGB2HLS_FULL,
CX_RGBA2HSV = CV_COLORCVT_MAX + CV_RGB2HSV,
CX_RGBA2HSV_FULL = CV_COLORCVT_MAX + CV_RGB2HSV_FULL,
CX_RGBA2Lab = CV_COLORCVT_MAX + CV_RGB2Lab,
CX_RGBA2Luv = CV_COLORCVT_MAX + CV_RGB2Luv,
CX_RGBA2XYZ = CV_COLORCVT_MAX + CV_RGB2XYZ,
CX_RGBA2YCrCb = CV_COLORCVT_MAX + CV_RGB2YCrCb,
CX_RGBA2YUV = CV_COLORCVT_MAX + CV_RGB2YUV,
CX_XYZ2BGRA = CV_COLORCVT_MAX + CV_XYZ2BGR,
CX_XYZ2RGBA = CV_COLORCVT_MAX + CV_XYZ2RGB,
CX_YCrCb2BGRA = CV_COLORCVT_MAX + CV_YCrCb2BGR,
CX_YCrCb2RGBA = CV_COLORCVT_MAX + CV_YCrCb2RGB,
CX_YUV2BGRA = CV_COLORCVT_MAX + CV_YUV2BGR,
CX_YUV2RGBA = CV_COLORCVT_MAX + CV_YUV2RGB
};
CV_ENUM(CvtMode,
CV_BayerBG2BGR, CV_BayerBG2BGR_VNG, CV_BayerBG2GRAY,
CV_BayerGB2BGR, CV_BayerGB2BGR_VNG, CV_BayerGB2GRAY,
CV_BayerGR2BGR, CV_BayerGR2BGR_VNG, CV_BayerGR2GRAY,
CV_BayerRG2BGR, CV_BayerRG2BGR_VNG, CV_BayerRG2GRAY,
CV_BGR2BGR555, CV_BGR2BGR565, CV_BGR2BGRA, CV_BGR2GRAY,
CV_BGR2HLS, CV_BGR2HLS_FULL, CV_BGR2HSV, CV_BGR2HSV_FULL,
CV_BGR2Lab, CV_BGR2Luv, CV_BGR2RGB, CV_BGR2RGBA, CV_BGR2XYZ,
CV_BGR2YCrCb, CV_BGR2YUV, CV_BGR5552BGR, CV_BGR5552BGRA,
CV_BGR5552GRAY, CV_BGR5552RGB, CV_BGR5552RGBA, CV_BGR5652BGR,
CV_BGR5652BGRA, CV_BGR5652GRAY, CV_BGR5652RGB, CV_BGR5652RGBA,
CV_BGRA2BGR, CV_BGRA2BGR555, CV_BGRA2BGR565, CV_BGRA2GRAY, CV_BGRA2RGBA,
CX_BGRA2HLS, CX_BGRA2HLS_FULL, CX_BGRA2HSV, CX_BGRA2HSV_FULL,
CX_BGRA2Lab, CX_BGRA2Luv, CX_BGRA2XYZ,
CX_BGRA2YCrCb, CX_BGRA2YUV,
CV_GRAY2BGR, CV_GRAY2BGR555, CV_GRAY2BGR565, CV_GRAY2BGRA,
CV_HLS2BGR, CV_HLS2BGR_FULL, CV_HLS2RGB, CV_HLS2RGB_FULL,
CX_HLS2BGRA, CX_HLS2BGRA_FULL, CX_HLS2RGBA, CX_HLS2RGBA_F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{
ChPair(int _scn, int _dcn): scn(_scn), dcn(_dcn) {}
int scn, dcn;
};
ChPair getConversionInfo(int cvtMode)
{
switch(cvtMode)
{
case CV_BayerBG2GRAY: case CV_BayerGB2GRAY:
case CV_BayerGR2GRAY: case CV_BayerRG2GRAY:
return ChPair(1,1);
case CV_GRAY2BGR555: case CV_GRAY2BGR565:
return ChPair(1,2);
case CV_BayerBG2BGR: case CV_BayerBG2BGR_VNG:
case CV_BayerGB2BGR: case CV_BayerGB2BGR_VNG:
case CV_BayerGR2BGR: case CV_BayerGR2BGR_VNG:
case CV_BayerRG2BGR: case CV_BayerRG2BGR_VNG:
case CV_GRAY2BGR: case CV_YUV420i2BGR:
case CV_YUV420i2RGB: case CV_YUV420sp2BGR:
case CV_YUV420sp2RGB:
return ChPair(1,3);
case CV_GRAY2BGRA: case CV_YUV420i2BGRA:
case CV_YUV420i2RGBA: case CV_YUV420sp2BGRA:
case CV_YUV420sp2RGBA:
return ChPair(1,4);
case CV_BGR5552GRAY: case CV_BGR5652GRAY:
return ChPair(2,1);
case CV_BGR5552BGR: case CV_BGR5552RGB:
case CV_BGR5652BGR: case CV_BGR5652RGB:
return ChPair(2,3);
case CV_BGR5552BGRA: case CV_BGR5552RGBA:
case CV_BGR5652BGRA: case CV_BGR5652RGBA:
return ChPair(2,4);
case CV_BGR2GRAY: case CV_RGB2GRAY:
return ChPair(3,1);
case CV_BGR2BGR555: case CV_BGR2BGR565:
case CV_RGB2BGR555: case CV_RGB2BGR565:
return ChPair(3,2);
case CV_BGR2HLS: case CV_BGR2HLS_FULL:
case CV_BGR2HSV: case CV_BGR2HSV_FULL:
case CV_BGR2Lab: case CV_BGR2Luv:
case CV_BGR2RGB: case CV_BGR2XYZ:
case CV_BGR2YCrCb: case CV_BGR2YUV:
case CV_HLS2BGR: case CV_HLS2BGR_FULL:
case CV_HLS2RGB: case CV_HLS2RGB_FULL:
case CV_HSV2BGR: case CV_HSV2BGR_FULL:
case CV_HSV2RGB: case CV_HSV2RGB_FULL:
case CV_Lab2BGR: case CV_Lab2LBGR:
case CV_Lab2LRGB: case CV_Lab2RGB:
case CV_LBGR2Lab: case CV_LBGR2Luv:
case CV_LRGB2Lab: case CV_LRGB2Luv:
case CV_Luv2BGR: case CV_Luv2LBGR:
case CV_Luv2LRGB: case CV_Luv2RGB:
case CV_RGB2HLS: case CV_RGB2HLS_FULL:
case CV_RGB2HSV: case CV_RGB2HSV_FULL:
case CV_RGB2Lab: case CV_RGB2Luv:
case CV_RGB2XYZ: case CV_RGB2YCrCb:
case CV_RGB2YUV: case CV_XYZ2BGR:
case CV_XYZ2RGB: case CV_YCrCb2BGR:
case CV_YCrCb2RGB: case CV_YUV2BGR:
case CV_YUV2RGB:
return ChPair(3,3);
case CV_BGR2BGRA: case CV_BGR2RGBA:
case CX_HLS2BGRA: case CX_HLS2BGRA_FULL:
case CX_HLS2RGBA: case CX_HLS2RGBA_FULL:
case CX_HSV2BGRA: case CX_HSV2BGRA_FULL:
case CX_HSV2RGBA: case CX_HSV2RGBA_FULL:
case CX_Lab2BGRA: case CX_Lab2LBGRA:
case CX_Lab2LRGBA: case CX_Lab2RGBA:
case CX_Luv2BGRA: case CX_Luv2LBGRA:
case CX_Luv2LRGBA: case CX_Luv2RGBA:
case CX_XYZ2BGRA: case CX_XYZ2RGBA:
case CX_YCrCb2BGRA: case CX_YCrCb2RGBA:
case CX_YUV2BGRA: case CX_YUV2RGBA:
return ChPair(3,4);
case CV_BGRA2GRAY: case CV_RGBA2GRAY:
return ChPair(4,1);
case CV_BGRA2BGR555: case CV_BGRA2BGR565:
case CV_RGBA2BGR555: case CV_RGBA2BGR565:
return ChPair(4,2);
case CV_BGRA2BGR: case CX_BGRA2HLS:
case CX_BGRA2HLS_FULL: case CX_BGRA2HSV:
case CX_BGRA2HSV_FULL: case CX_BGRA2Lab:
case CX_BGRA2Luv: case CX_BGRA2XYZ:
case CX_BGRA2YCrCb: case CX_BGRA2YUV:
case CX_LBGRA2Lab: case CX_LBGRA2Luv:
case CX_LRGBA2Lab: case CX_LRGBA2Luv:
case CV_RGBA2BGR: case CX_RGBA2HLS:
case CX_RGBA2HLS_FULL: case CX_RGBA2HSV:
case CX_RGBA2HSV_FULL: case CX_RGBA2Lab:
case CX_RGBA2Luv: case CX_RGBA2XYZ:
case CX_RGBA2YCrCb: case CX_RGBA2YUV:
return ChPair(4,3);
case CV_BGRA2RGBA:
return ChPair(4,4);
default:
ADD_FAILURE() << "Unknown conversion type";
break;
};
return ChPair(0,0);
}
typedef std::tr1::tuple<Size, CvtMode> Size_CvtMode_t;
typedef perf::TestBaseWithParam<Size_CvtMode_t> Size_CvtMode;
typedef std::tr1::tuple<Size, CvtMode, int> Size_CvtMode_OutChNum_t;
typedef perf::TestBaseWithParam<Size_CvtMode_OutChNum_t> Size_CvtMode_OutChNum;
PERF_TEST_P(Size_CvtMode_OutChNum, cvtColorYUV,
PERF_TEST_P(Size_CvtMode, cvtColor8u,
testing::Combine(
testing::Values(TYPICAL_MAT_SIZES),
testing::Values((int)CV_YUV2BGR, (int)CV_YUV2RGB),
testing::Values(3, 4)
testing::ValuesIn(CvtMode::all())
)
)
{
Size sz = get<0>(GetParam());
int mode = get<1>(GetParam());
int ch = get<2>(GetParam());
Mat src(sz, CV_8UC3);
Mat dst(sz, CV_8UC(ch));
declare.in(src, WARMUP_RNG).out(dst);
Size sz = get<0>(GetParam());
int mode = get<1>(GetParam());
ChPair ch = getConversionInfo(mode);
mode %= CV_COLORCVT_MAX;
TEST_CYCLE() cvtColor(src, dst, mode, ch);
Mat src(sz, CV_8UC(ch.scn));
Mat dst(sz, CV_8UC(ch.dcn));
declare.in(src, WARMUP_RNG).out(dst);
TEST_CYCLE() cvtColor(src, dst, mode, ch.dcn);
SANITY_CHECK(dst, 1);
}
PERF_TEST_P(Size_CvtMode_OutChNum, cvtColorYUV420,
testing::Combine(
testing::Values(szVGA, sz720p, sz1080p, Size(130, 60)),
testing::Values((int)CV_YUV420i2BGR, (int)CV_YUV420i2RGB, (int)CV_YUV420sp2BGR, (int)CV_YUV420sp2RGB),
testing::Values(3, 4)
)
)
{
Size sz = get<0>(GetParam());
int mode = get<1>(GetParam());
int ch = get<2>(GetParam());
Mat src(sz.height + sz.height / 2, sz.width, CV_8UC1);
Mat dst(sz, CV_8UC(ch));
declare.in(src, WARMUP_RNG).out(dst);
TEST_CYCLE() cvtColor(src, dst, mode, ch);
SANITY_CHECK(dst, 1);
}
PERF_TEST_P(Size_CvtMode, cvtColorGray,
testing::Combine(
testing::Values(TYPICAL_MAT_SIZES),
testing::Values((int)CV_RGB2GRAY, (int)CV_RGBA2GRAY, (int)CV_BGR2GRAY, (int)CV_BGRA2GRAY)
)
)
{
Size sz = get<0>(GetParam());
int mode = get<1>(GetParam());
Mat src(sz, CV_8UC((mode==CV_RGBA2GRAY || mode==CV_BGRA2GRAY) ? 4 : 3));
Mat dst(sz, CV_8UC1);
declare.in(src, WARMUP_RNG).out(dst);
TEST_CYCLE() cvtColor(src, dst, mode);
SANITY_CHECK(dst, 1);
}
PERF_TEST_P(Size_CvtMode, cvtColorGray2,
testing::Combine(
testing::Values(TYPICAL_MAT_SIZES),
testing::Values((int)CV_GRAY2RGB, (int)CV_GRAY2RGBA)
)
)
{
Size sz = get<0>(GetParam());
int mode = get<1>(GetParam());
Mat src(sz, CV_8UC1);
Mat dst(sz, CV_8UC((mode==CV_GRAY2RGBA || mode==CV_GRAY2BGRA) ? 4 : 3));
declare.in(src, WARMUP_RNG).out(dst);
TEST_CYCLE() cvtColor(src, dst, mode);
SANITY_CHECK(dst);
}
PERF_TEST_P(Size_CvtMode, cvtColorH,
testing::Combine(
testing::Values(TYPICAL_MAT_SIZES),
testing::Values((int)CV_BGR2HSV, (int)CV_RGB2HSV, (int)CV_BGR2HLS, (int)CV_RGB2HLS)
)
)
{
Size sz = get<0>(GetParam());
int mode = get<1>(GetParam());
Mat src(sz, CV_8UC3);
Mat dst(sz, CV_8UC3);
declare.in(src, WARMUP_RNG).out(dst);
TEST_CYCLE() cvtColor(src, dst, mode);
SANITY_CHECK(dst, 1);
}
typedef std::tr1::tuple<Size, CvtMode, int> Size_CvtMode_Ch_t;
typedef perf::TestBaseWithParam<Size_CvtMode_Ch_t> Size_CvtMode_Ch;
PERF_TEST_P(Size_CvtMode_Ch, cvtColorYCrCb,
testing::Combine(
testing::Values(TYPICAL_MAT_SIZES),
testing::Values((int)CV_BGR2YCrCb, (int)CV_RGB2YCrCb),
testing::Values(3, 4)
)
)
{
Size sz = get<0>(GetParam());
int mode = get<1>(GetParam());
int ch = get<2>(GetParam());
Mat src(sz, CV_8UC(ch));
Mat dst(sz, CV_8UC3);
declare.in(src, WARMUP_RNG).out(dst);
TEST_CYCLE() cvtColor(src, dst, mode);
SANITY_CHECK(dst, 1);
}
CV_ENUM(CvtInBGR565Type, CV_RGB2BGR565, CV_RGBA2BGR565, CV_BGR2BGR565, CV_BGRA2BGR565)
typedef std::tr1::tuple<Size, CvtInBGR565Type> Size_CvtInBGR565Type_t;
typedef perf::TestBaseWithParam<Size_CvtInBGR565Type_t> Size_CvtInBGR565Type;
PERF_TEST_P( Size_CvtInBGR565Type, cvtColor_toBGR565,
testing::Combine
(
testing::Values(TYPICAL_MAT_SIZES),
testing::ValuesIn(CvtInBGR565Type::all())
)
)
{
Size sz = get<0>(GetParam());
CvtInBGR565Type code = get<1>(GetParam());
Mat src;
if ( code == CV_RGB2BGR565 || code == CV_BGR2BGR565 )
src.create(sz, CV_8UC3);
else
src.create(sz, CV_8UC4);
randu(src, 0, 255);
Mat dst;
TEST_CYCLE() cvtColor( src, dst, code );
SANITY_CHECK(dst);
}
CV_ENUM(CvtMode2, CV_RGB2BGR, CV_RGB2RGBA, CV_RGB2BGRA, CV_RGBA2RGB, CV_RGBA2BGR, CV_RGBA2BGRA)
typedef std::tr1::tuple<Size, CvtMode2> Size_CvtMode2_t;
typedef perf::TestBaseWithParam<Size_CvtMode2_t> Size_CvtMode2;
PERF_TEST_P( Size_CvtMode2, cvtColor_C3toC4_and_back,
testing::Combine
(
testing::Values(TYPICAL_MAT_SIZES),
testing::ValuesIn(CvtMode2::all())
)
)
PERF_TEST_P(Size_CvtMode2, cvtColorYUV420,
testing::Combine(
testing::Values(szVGA, sz720p, sz1080p, Size(130, 60)),
testing::ValuesIn(CvtMode2::all())
)
)
{
Size sz = get<0>(GetParam());
CvtMode2 code = get<1>(GetParam());
int mode = get<1>(GetParam());
ChPair ch = getConversionInfo(mode);
Mat src;
if ( code == CV_RGB2BGR || code == CV_RGB2RGBA || code == CV_RGB2BGRA )
src.create(sz, CV_8UC3);
else
src.create(sz, CV_8UC4);
Mat src(sz.height + sz.height / 2, sz.width, CV_8UC(ch.scn));
Mat dst(sz, CV_8UC(ch.dcn));
randu(src, 0, 255);
Mat dst;
TEST_CYCLE() cvtColor( src, dst, code );
SANITY_CHECK(dst);
declare.in(src, WARMUP_RNG).out(dst);
TEST_CYCLE() cvtColor(src, dst, mode, ch.dcn);
SANITY_CHECK(dst, 1);
}