#include "perf_precomp.hpp"
-int main(int argc, const char *argv[])
+static int old_main(int argc, const char *argv[])
{
const char *keys =
"{ h | help | false | print help message }"
// set this to overwrite binary cache every time the test starts
ocl::setBinaryDiskCache(ocl::CACHE_UPDATE);
-
+
if (cmd.get<bool>("verify"))
{
TestSystem::instance().setNumIters(1);
return 0;
}
+
+const char * impls[] =
+{
+ "ocl",
+ "plain",
+#ifdef HAVE_OPENCV_GPU
+ "gpu"
+#endif
+};
+
+int main(int argc, char **argv)
+{
+ // temp solution: if no '--gtest_' and '--perf_' args switch to old behavior
+ bool useGTest = false;
+
+ for(int i=1; i<argc; i++)
+ {
+ std::string arg( argv[i] );
+ if( arg.find("--gtest_")==0 || arg.find("--perf_")==0 )
+ useGTest = true;
+
+// if (arg == "--perf_verify_sanity")
+// argv[i] = (char*)"--perf_no_verify_sanity";
+ }
+
+ if( !useGTest )
+ return old_main(argc, (const char**)argv);
+
+ CV_PERF_TEST_MAIN_INTERNALS(ocl, impls)
+}
//M*/
#include "perf_precomp.hpp"
+
+using namespace perf;
+using std::tr1::get;
+using std::tr1::tuple;
+
///////////// Lut ////////////////////////
-PERFTEST(lut)
-{
- Mat src, lut, dst, ocl_dst;
- ocl::oclMat d_src, d_lut, d_dst;
- int all_type[] = {CV_8UC1, CV_8UC3};
- std::string type_name[] = {"CV_8UC1", "CV_8UC3"};
+CV_ENUM(LUTMatTypes, CV_8UC1, CV_8UC3)
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j];
+typedef tuple<Size, LUTMatTypes> LUTParams;
+typedef TestBaseWithParam<LUTParams> LUTFixture;
- gen(src, size, size, all_type[j], 0, 256);
- gen(lut, 1, 256, CV_8UC1, 0, 1);
+PERF_TEST_P(LUTFixture, LUT,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ LUTMatTypes::all()))
+{
+ // getting params
+ LUTParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
- LUT(src, lut, dst);
+ const std::string impl = getSelectedImpl();
- CPU_ON;
- LUT(src, lut, dst);
- CPU_OFF;
+ // creating src data
+ Mat src(srcSize, type), lut(1, 256, CV_8UC1);
+ int dstType = CV_MAKETYPE(lut.depth(), src.channels());
+ Mat dst(srcSize, dstType);
- d_src.upload(src);
- d_lut.upload(lut);
+ randu(lut, 0, 2);
+ declare.in(src, WARMUP_RNG).in(lut).out(dst);
- WARMUP_ON;
- ocl::LUT(d_src, d_lut, d_dst);
- WARMUP_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclLut(lut), oclDst(srcSize, dstType);
- GPU_ON;
- ocl::LUT(d_src, d_lut, d_dst);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::LUT(oclSrc, oclLut, oclDst);
- GPU_FULL_ON;
- d_src.upload(src);
- d_lut.upload(lut);
- ocl::LUT(d_src, d_lut, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::LUT(src, lut, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// Exp ////////////////////////
-PERFTEST(Exp)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- SUBTEST << size << 'x' << size << "; CV_32FC1";
+typedef TestBaseWithParam<Size> ExpFixture;
+
+PERF_TEST_P(ExpFixture, Exp, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
- gen(src, size, size, CV_32FC1, 5, 16);
+ const std::string impl = getSelectedImpl();
- exp(src, dst);
+ // creating src data
+ Mat src(srcSize, CV_32FC1), dst(srcSize, CV_32FC1);
+ declare.in(src).out(dst);
+ randu(src, 5, 16);
- CPU_ON;
- exp(src, dst);
- CPU_OFF;
- d_src.upload(src);
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, src.type());
- WARMUP_ON;
- ocl::exp(d_src, d_dst);
- WARMUP_OFF;
+ TEST_CYCLE() cv::ocl::exp(oclSrc, oclDst);
- GPU_ON;
- ocl::exp(d_src, d_dst);
- GPU_OFF;
+ oclDst.download(dst);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::exp(d_src, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ SANITY_CHECK(dst, 0.3);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::exp(src, dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 2);
+ SANITY_CHECK(dst, 0.3);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// LOG ////////////////////////
-PERFTEST(Log)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- SUBTEST << size << 'x' << size << "; 32F";
+typedef TestBaseWithParam<Size> LogFixture;
- gen(src, size, size, CV_32F, 1, 10);
+PERF_TEST_P(LogFixture, Log, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const std::string impl = getSelectedImpl();
- log(src, dst);
+ // creating src data
+ Mat src(srcSize, CV_32F), dst(srcSize, src.type());
+ randu(src, 1, 10);
+ declare.in(src).out(dst);
- CPU_ON;
- log(src, dst);
- CPU_OFF;
- d_src.upload(src);
+ if (srcSize == OCL_SIZE_4000)
+ declare.time(3.6);
- WARMUP_ON;
- ocl::log(d_src, d_dst);
- WARMUP_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, src.type());
- GPU_ON;
- ocl::log(d_src, d_dst);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::log(oclSrc, oclDst);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::log(d_src, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1);
+ SANITY_CHECK(dst);
}
-}
-
-///////////// Add ////////////////////////
-PERFTEST(Add)
-{
- Mat src1, src2, dst, ocl_dst;
- ocl::oclMat d_src1, d_src2, d_dst;
-
- int all_type[] = {CV_8UC1, CV_32FC1};
- std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ else if (impl == "plain")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j];
+ TEST_CYCLE() cv::log(src, dst);
- gen(src1, size, size, all_type[j], 0, 1);
- gen(src2, size, size, all_type[j], 0, 1);
+ SANITY_CHECK(dst);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
+}
- add(src1, src2, dst);
+///////////// Add ////////////////////////
- CPU_ON;
- add(src1, src2, dst);
- CPU_OFF;
+CV_ENUM(AddMatTypes, CV_8UC1, CV_32FC1)
- d_src1.upload(src1);
- d_src2.upload(src2);
+typedef tuple<Size, AddMatTypes> AddParams;
+typedef TestBaseWithParam<AddParams> AddFixture;
- WARMUP_ON;
- ocl::add(d_src1, d_src2, d_dst);
- WARMUP_OFF;
+PERF_TEST_P(AddFixture, Add,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ AddMatTypes::all()))
+{
+ // getting params
+ AddParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
+ randu(src1, 0, 1);
+ randu(src2, 0, 1);
+ declare.in(src1, src2).out(dst);
+
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst(srcSize, type);
- GPU_ON;
- ocl::add(d_src1, d_src2, d_dst);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::add(oclSrc1, oclSrc2, oclDst);
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::add(d_src1, d_src2, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 0.0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::add(src1, src2, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// Mul ////////////////////////
-PERFTEST(Mul)
-{
- Mat src1, src2, dst, ocl_dst;
- ocl::oclMat d_src1, d_src2, d_dst;
-
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src1, size, size, all_type[j], 0, 256);
- gen(src2, size, size, all_type[j], 0, 256);
- multiply(src1, src2, dst);
+CV_ENUM(MulMatTypes, CV_8UC1, CV_8UC4)
- CPU_ON;
- multiply(src1, src2, dst);
- CPU_OFF;
- d_src1.upload(src1);
- d_src2.upload(src2);
+typedef tuple<Size, MulMatTypes> MulParams;
+typedef TestBaseWithParam<MulParams> MulFixture;
- WARMUP_ON;
- ocl::multiply(d_src1, d_src2, d_dst);
- WARMUP_OFF;
+PERF_TEST_P(MulFixture, Mul, ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ MulMatTypes::all()))
+{
+ // getting params
+ MulParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
+ randu(src1, 0, 256);
+ randu(src2, 0, 256);
+ declare.in(src1, src2).out(dst);
+
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst(srcSize, type);
- GPU_ON;
- ocl::multiply(d_src1, d_src2, d_dst);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::multiply(oclSrc1, oclSrc2, oclDst);
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::multiply(d_src1, d_src2, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 0.0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::multiply(src1, src2, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// Div ////////////////////////
-PERFTEST(Div)
-{
- Mat src1, src2, dst, ocl_dst;
- ocl::oclMat d_src1, d_src2, d_dst;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j];
+typedef MulMatTypes DivMatTypes;
+typedef tuple<Size, DivMatTypes> DivParams;
+typedef TestBaseWithParam<DivParams> DivFixture;
- gen(src1, size, size, all_type[j], 0, 256);
- gen(src2, size, size, all_type[j], 0, 256);
-
- divide(src1, src2, dst);
-
- CPU_ON;
- divide(src1, src2, dst);
- CPU_OFF;
-
- d_src1.upload(src1);
- d_src2.upload(src2);
-
- WARMUP_ON;
- ocl::divide(d_src1, d_src2, d_dst);
- WARMUP_OFF;
+PERF_TEST_P(DivFixture, Div, ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ DivMatTypes::all()))
+{
+ // getting params
+ DivParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
+ declare.in(src1, src2).out(dst);
+ randu(src1, 0, 256);
+ randu(src2, 0, 256);
+
+ if ((srcSize == OCL_SIZE_4000 && type == CV_8UC1) ||
+ (srcSize == OCL_SIZE_2000 && type == CV_8UC4))
+ declare.time(4.2);
+ else if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
+ declare.time(16.6);
+
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst(srcSize, type);
- GPU_ON;
- ocl::divide(d_src1, d_src2, d_dst);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::divide(oclSrc1, oclSrc2, oclDst);
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::divide(d_src1, d_src2, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::divide(src1, src2, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// Absdiff ////////////////////////
-PERFTEST(Absdiff)
-{
- Mat src1, src2, dst, ocl_dst;
- ocl::oclMat d_src1, d_src2, d_dst;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
+typedef MulMatTypes AbsDiffMatTypes;
+typedef tuple<Size, AbsDiffMatTypes> AbsDiffParams;
+typedef TestBaseWithParam<AbsDiffParams> AbsDiffFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+PERF_TEST_P(AbsDiffFixture, Absdiff, ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ AbsDiffMatTypes::all()))
+{
+ // getting params
+ AbsDiffParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
+ declare.in(src1, src2).in(dst);
+ randu(src1, 0, 256);
+ randu(src2, 0, 256);
+
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src1, size, size, all_type[j], 0, 256);
- gen(src2, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
-
- absdiff(src1, src2, dst);
-
- CPU_ON;
- absdiff(src1, src2, dst);
- CPU_OFF;
-
- d_src1.upload(src1);
- d_src2.upload(src2);
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst(srcSize, type);
- WARMUP_ON;
- ocl::absdiff(d_src1, d_src2, d_dst);
- WARMUP_OFF;
+ TEST_CYCLE() cv::ocl::absdiff(oclSrc1, oclSrc2, oclDst);
- GPU_ON;
- ocl::absdiff(d_src1, d_src2, d_dst);
- GPU_OFF;
+ oclDst.download(dst);
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::absdiff(d_src1, d_src2, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 0.0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::absdiff(src1, src2, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// CartToPolar ////////////////////////
-PERFTEST(CartToPolar)
-{
- Mat src1, src2, dst, dst1, ocl_dst, ocl_dst1;
- ocl::oclMat d_src1, d_src2, d_dst, d_dst1;
- int all_type[] = {CV_32FC1};
- std::string type_name[] = {"CV_32FC1"};
+typedef TestBaseWithParam<Size> CartToPolarFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+PERF_TEST_P(CartToPolarFixture, CartToPolar, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1),
+ dst1(srcSize, CV_32FC1), dst2(srcSize, CV_32FC1);
+ declare.in(src1, src2).out(dst1, dst2);
+ randu(src1, 0, 256);
+ randu(src2, 0, 256);
+
+ if (srcSize == OCL_SIZE_4000)
+ declare.time(3.6);
+
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j];
-
- gen(src1, size, size, all_type[j], 0, 256);
- gen(src2, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
- gen(dst1, size, size, all_type[j], 0, 256);
-
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2),
+ oclDst1(srcSize, src1.type()), oclDst2(srcSize, src1.type());
- cartToPolar(src1, src2, dst, dst1, 1);
+ TEST_CYCLE() cv::ocl::cartToPolar(oclSrc1, oclSrc2, oclDst1, oclDst2);
- CPU_ON;
- cartToPolar(src1, src2, dst, dst1, 1);
- CPU_OFF;
+ oclDst1.download(dst1);
+ oclDst2.download(dst2);
- d_src1.upload(src1);
- d_src2.upload(src2);
-
- WARMUP_ON;
- ocl::cartToPolar(d_src1, d_src2, d_dst, d_dst1, 1);
- WARMUP_OFF;
-
- GPU_ON;
- ocl::cartToPolar(d_src1, d_src2, d_dst, d_dst1, 1);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::cartToPolar(d_src1, d_src2, d_dst, d_dst1, 1);
- d_dst.download(ocl_dst);
- d_dst1.download(ocl_dst1);
- GPU_FULL_OFF;
-
- double diff1 = checkNorm(ocl_dst1, dst1);
- double diff2 = checkNorm(ocl_dst, dst);
- double max_diff = max(diff1, diff2);
- TestSystem::instance().setAccurate(max_diff<=.5?1:0, max_diff);
-
- }
+ SANITY_CHECK(dst1, 5e-3);
+ SANITY_CHECK(dst2, 5e-3);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::cartToPolar(src1, src2, dst1, dst2);
+ SANITY_CHECK(dst1, 5e-3);
+ SANITY_CHECK(dst2, 5e-3);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// PolarToCart ////////////////////////
-PERFTEST(PolarToCart)
-{
- Mat src1, src2, dst, dst1, ocl_dst, ocl_dst1;
- ocl::oclMat d_src1, d_src2, d_dst, d_dst1;
- int all_type[] = {CV_32FC1};
- std::string type_name[] = {"CV_32FC1"};
+typedef TestBaseWithParam<Size> PolarToCartFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+PERF_TEST_P(PolarToCartFixture, PolarToCart, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1),
+ dst1(srcSize, CV_32FC1), dst2(srcSize, CV_32FC1);
+ declare.in(src1, src2).out(dst1, dst2);
+ randu(src1, 0, 256);
+ randu(src2, 0, 256);
+
+ if (srcSize == OCL_SIZE_4000)
+ declare.time(5.4);
+
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src1, size, size, all_type[j], 0, 256);
- gen(src2, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
- gen(dst1, size, size, all_type[j], 0, 256);
-
-
- polarToCart(src1, src2, dst, dst1, 1);
-
- CPU_ON;
- polarToCart(src1, src2, dst, dst1, 1);
- CPU_OFF;
- d_src1.upload(src1);
- d_src2.upload(src2);
-
- WARMUP_ON;
- ocl::polarToCart(d_src1, d_src2, d_dst, d_dst1, 1);
- WARMUP_OFF;
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2),
+ oclDst1(srcSize, src1.type()), oclDst2(srcSize, src1.type());
- GPU_ON;
- ocl::polarToCart(d_src1, d_src2, d_dst, d_dst1, 1);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::polarToCart(oclSrc1, oclSrc2, oclDst1, oclDst2);
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::polarToCart(d_src1, d_src2, d_dst, d_dst1, 1);
- d_dst.download(ocl_dst);
- d_dst1.download(ocl_dst1);
- GPU_FULL_OFF;
+ oclDst1.download(dst1);
+ oclDst2.download(dst2);
- double diff1 = checkNorm(ocl_dst1, dst1);
- double diff2 = checkNorm(ocl_dst, dst);
- double max_diff = max(diff1, diff2);
- TestSystem::instance().setAccurate(max_diff<=.5?1:0, max_diff);
-
- }
+ SANITY_CHECK(dst1, 5e-5);
+ SANITY_CHECK(dst2, 5e-5);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::polarToCart(src1, src2, dst1, dst2);
+ SANITY_CHECK(dst1, 5e-5);
+ SANITY_CHECK(dst2, 5e-5);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// Magnitude ////////////////////////
-PERFTEST(magnitude)
-{
- Mat x, y, mag, ocl_mag;
- ocl::oclMat d_x, d_y, d_mag;
- int all_type[] = {CV_32FC1};
- std::string type_name[] = {"CV_32FC1"};
+typedef TestBaseWithParam<Size> MagnitudeFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+PERF_TEST_P(MagnitudeFixture, Magnitude, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1),
+ dst(srcSize, CV_32FC1);
+ randu(src1, 0, 1);
+ randu(src2, 0, 1);
+ declare.in(src1, src2).out(dst);
+
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j];
-
- gen(x, size, size, all_type[j], 0, 1);
- gen(y, size, size, all_type[j], 0, 1);
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2),
+ oclDst(srcSize, src1.type());
- magnitude(x, y, mag);
+ TEST_CYCLE() cv::ocl::magnitude(oclSrc1, oclSrc2, oclDst);
- CPU_ON;
- magnitude(x, y, mag);
- CPU_OFF;
- d_x.upload(x);
- d_y.upload(y);
+ oclDst.download(dst);
- WARMUP_ON;
- ocl::magnitude(d_x, d_y, d_mag);
- WARMUP_OFF;
-
- GPU_ON;
- ocl::magnitude(d_x, d_y, d_mag);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_x.upload(x);
- d_y.upload(y);
- ocl::magnitude(d_x, d_y, d_mag);
- d_mag.download(ocl_mag);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(ocl_mag, mag, 1e-5);
- }
+ SANITY_CHECK(dst, 1e-6);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::magnitude(src1, src2, dst);
+ SANITY_CHECK(dst, 1e-6);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// Transpose ////////////////////////
-PERFTEST(Transpose)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
+typedef MulMatTypes TransposeMatTypes;
+typedef tuple<Size, TransposeMatTypes> TransposeParams;
+typedef TestBaseWithParam<TransposeParams> TransposeFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+PERF_TEST_P(TransposeFixture, Transpose,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ TransposeMatTypes::all()))
+{
+ // getting params
+ TransposeParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
+
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j];
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
- gen(src, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
+ TEST_CYCLE() cv::ocl::transpose(oclSrc, oclDst);
- transpose(src, dst);
+ oclDst.download(dst);
- CPU_ON;
- transpose(src, dst);
- CPU_OFF;
- d_src.upload(src);
-
- WARMUP_ON;
- ocl::transpose(d_src, d_dst);
- WARMUP_OFF;
-
- GPU_ON;
- ocl::transpose(d_src, d_dst);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::transpose(d_src, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::transpose(src, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// Flip ////////////////////////
-PERFTEST(Flip)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
+typedef MulMatTypes FlipMatTypes;
+typedef tuple<Size, FlipMatTypes> FlipParams;
+typedef TestBaseWithParam<FlipParams> FlipFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+PERF_TEST_P(FlipFixture, Flip,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ FlipMatTypes::all()))
+{
+ // getting params
+ TransposeParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
+
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] << " ; FLIP_BOTH";
-
- gen(src, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
-
- flip(src, dst, 0);
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
- CPU_ON;
- flip(src, dst, 0);
- CPU_OFF;
- d_src.upload(src);
+ TEST_CYCLE() cv::ocl::flip(oclSrc, oclDst, 0);
- WARMUP_ON;
- ocl::flip(d_src, d_dst, 0);
- WARMUP_OFF;
+ oclDst.download(dst);
- GPU_ON;
- ocl::flip(d_src, d_dst, 0);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::flip(d_src, d_dst, 0);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::flip(src, dst, 0);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// minMax ////////////////////////
-PERFTEST(minMax)
-{
- Mat src;
- ocl::oclMat d_src;
-
- double min_val = 0.0, max_val = 0.0;
- double min_val_ = 0.0, max_val_ = 0.0;
- Point min_loc, max_loc;
- int all_type[] = {CV_8UC1, CV_32FC1};
- std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j];
+typedef AddMatTypes minMaxMatTypes;
+typedef tuple<Size, minMaxMatTypes> minMaxParams;
+typedef TestBaseWithParam<minMaxParams> minMaxFixture;
- gen(src, size, size, all_type[j], 0, 256);
+PERF_TEST_P(minMaxFixture, minMax,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ minMaxMatTypes::all()))
+{
+ // getting params
+ minMaxParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
- CPU_ON;
- minMaxLoc(src, &min_val, &max_val, &min_loc, &max_loc);
- CPU_OFF;
- d_src.upload(src);
+ // creating src data
+ Mat src(srcSize, type);
+ declare.in(src, WARMUP_RNG);
- WARMUP_ON;
- ocl::minMax(d_src, &min_val_, &max_val_);
- WARMUP_OFF;
+ double min_val = 0.0, max_val = 0.0;
- if(EeceptDoubleEQ<double>(max_val_, max_val) && EeceptDoubleEQ<double>(min_val_, min_val))
- TestSystem::instance().setAccurate(1, max(fabs(max_val_-max_val), fabs(min_val_-min_val)));
- else
- TestSystem::instance().setAccurate(0, max(fabs(max_val_-max_val), fabs(min_val_-min_val)));
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src);
- GPU_ON;
- ocl::minMax(d_src, &min_val, &max_val);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::minMax(oclSrc, &min_val, &max_val);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::minMax(d_src, &min_val, &max_val);
- GPU_FULL_OFF;
+ ASSERT_GE(max_val, min_val);
+ SANITY_CHECK(min_val);
+ SANITY_CHECK(max_val);
+ }
+ else if (impl == "plain")
+ {
+ Point min_loc, max_loc;
- }
+ TEST_CYCLE() cv::minMaxLoc(src, &min_val, &max_val, &min_loc, &max_loc);
+ ASSERT_GE(max_val, min_val);
+ SANITY_CHECK(min_val);
+ SANITY_CHECK(max_val);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// minMaxLoc ////////////////////////
-PERFTEST(minMaxLoc)
+
+typedef AddMatTypes minMaxLocMatTypes;
+typedef tuple<Size, minMaxMatTypes> minMaxLocParams;
+typedef TestBaseWithParam<minMaxLocParams> minMaxLocFixture;
+
+PERF_TEST_P(minMaxLocFixture, minMaxLoc,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ minMaxLocMatTypes::all()))
{
- Mat src;
- ocl::oclMat d_src;
+ // getting params
+ minMaxLocParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src(srcSize, type);
+ randu(src, 0, 1);
+ declare.in(src);
double min_val = 0.0, max_val = 0.0;
- double min_val_ = 0.0, max_val_ = 0.0;
Point min_loc, max_loc;
- Point min_loc_, max_loc_;
- int all_type[] = {CV_8UC1, CV_32FC1};
- std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+ ocl::oclMat oclSrc(src);
- gen(src, size, size, all_type[j], 0, 1);
+ TEST_CYCLE() cv::ocl::minMaxLoc(oclSrc, &min_val, &max_val, &min_loc, &max_loc);
- CPU_ON;
- minMaxLoc(src, &min_val, &max_val, &min_loc, &max_loc);
- CPU_OFF;
- d_src.upload(src);
-
- WARMUP_ON;
- ocl::minMaxLoc(d_src, &min_val_, &max_val_, &min_loc_, &max_loc_);
- WARMUP_OFF;
-
- double error0 = 0., error1 = 0., minlocVal = 0., minlocVal_ = 0., maxlocVal = 0., maxlocVal_ = 0.;
- if(src.depth() == 0)
- {
- minlocVal = src.at<unsigned char>(min_loc);
- minlocVal_ = src.at<unsigned char>(min_loc_);
- maxlocVal = src.at<unsigned char>(max_loc);
- maxlocVal_ = src.at<unsigned char>(max_loc_);
- }
- if(src.depth() == 1)
- {
- minlocVal = src.at<signed char>(min_loc);
- minlocVal_ = src.at<signed char>(min_loc_);
- maxlocVal = src.at<signed char>(max_loc);
- maxlocVal_ = src.at<signed char>(max_loc_);
- }
- if(src.depth() == 2)
- {
- minlocVal = src.at<unsigned short>(min_loc);
- minlocVal_ = src.at<unsigned short>(min_loc_);
- maxlocVal = src.at<unsigned short>(max_loc);
- maxlocVal_ = src.at<unsigned short>(max_loc_);
- }
- if(src.depth() == 3)
- {
- minlocVal = src.at<signed short>(min_loc);
- minlocVal_ = src.at<signed short>(min_loc_);
- maxlocVal = src.at<signed short>(max_loc);
- maxlocVal_ = src.at<signed short>(max_loc_);
- }
- if(src.depth() == 4)
- {
- minlocVal = src.at<int>(min_loc);
- minlocVal_ = src.at<int>(min_loc_);
- maxlocVal = src.at<int>(max_loc);
- maxlocVal_ = src.at<int>(max_loc_);
- }
- if(src.depth() == 5)
- {
- minlocVal = src.at<float>(min_loc);
- minlocVal_ = src.at<float>(min_loc_);
- maxlocVal = src.at<float>(max_loc);
- maxlocVal_ = src.at<float>(max_loc_);
- }
- if(src.depth() == 6)
- {
- minlocVal = src.at<double>(min_loc);
- minlocVal_ = src.at<double>(min_loc_);
- maxlocVal = src.at<double>(max_loc);
- maxlocVal_ = src.at<double>(max_loc_);
- }
- error0 = ::abs(minlocVal_ - minlocVal);
- error1 = ::abs(maxlocVal_ - maxlocVal);
- if( EeceptDoubleEQ<double>(maxlocVal_, maxlocVal)
- &&EeceptDoubleEQ<double>(minlocVal_, minlocVal)
- &&EeceptDoubleEQ<double>(max_val_, max_val)
- &&EeceptDoubleEQ<double>(min_val_, min_val))
- TestSystem::instance().setAccurate(1, 0.);
- else
- TestSystem::instance().setAccurate(0, max(error0, error1));
-
- GPU_ON;
- ocl::minMaxLoc(d_src, &min_val, &max_val, &min_loc, &max_loc);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::minMaxLoc(d_src, &min_val, &max_val, &min_loc, &max_loc);
- GPU_FULL_OFF;
- }
+ ASSERT_GE(max_val, min_val);
+ SANITY_CHECK(min_val);
+ SANITY_CHECK(max_val);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::minMaxLoc(src, &min_val, &max_val, &min_loc, &max_loc);
+ ASSERT_GE(max_val, min_val);
+ SANITY_CHECK(min_val);
+ SANITY_CHECK(max_val);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// Sum ////////////////////////
-PERFTEST(Sum)
-{
- Mat src;
- Scalar cpures, gpures;
- ocl::oclMat d_src;
-
- int all_type[] = {CV_8UC1, CV_32SC1};
- std::string type_name[] = {"CV_8UC1", "CV_32SC1"};
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
- gen(src, size, size, all_type[j], 0, 60);
+CV_ENUM(SumMatTypes, CV_8UC1, CV_32SC1)
- cpures = sum(src);
+typedef tuple<Size, SumMatTypes> SumParams;
+typedef TestBaseWithParam<SumParams> SumFixture;
- CPU_ON;
- cpures = sum(src);
- CPU_OFF;
- d_src.upload(src);
-
- WARMUP_ON;
- gpures = ocl::sum(d_src);
- WARMUP_OFF;
-
- vector<double> diffs(4);
- diffs[3] = fabs(cpures[3] - gpures[3]);
- diffs[2] = fabs(cpures[2] - gpures[2]);
- diffs[1] = fabs(cpures[1] - gpures[1]);
- diffs[0] = fabs(cpures[0] - gpures[0]);
- double max_diff = *max_element(diffs.begin(), diffs.end());
- TestSystem::instance().setAccurate(max_diff<0.1?1:0, max_diff);
+PERF_TEST_P(SumFixture, Sum,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ SumMatTypes::all()))
+{
+ // getting params
+ SumParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src(srcSize, type);
+ Scalar result;
+ randu(src, 0, 60);
+ declare.in(src);
+
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src);
- GPU_ON;
- gpures = ocl::sum(d_src);
- GPU_OFF;
+ TEST_CYCLE() result = cv::ocl::sum(oclSrc);
- GPU_FULL_ON;
- d_src.upload(src);
- gpures = ocl::sum(d_src);
- GPU_FULL_OFF;
- }
+ SANITY_CHECK(result);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() result = cv::sum(src);
+ SANITY_CHECK(result);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// countNonZero ////////////////////////
-PERFTEST(countNonZero)
-{
- Mat src;
- ocl::oclMat d_src;
- int all_type[] = {CV_8UC1, CV_32FC1};
- std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
+CV_ENUM(countNonZeroMatTypes, CV_8UC1, CV_32FC1)
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src, size, size, all_type[j], 0, 256);
-
- countNonZero(src);
-
- int cpures = 0, gpures = 0;
- CPU_ON;
- cpures = countNonZero(src);
- CPU_OFF;
- d_src.upload(src);
+typedef tuple<Size, countNonZeroMatTypes> countNonZeroParams;
+typedef TestBaseWithParam<countNonZeroParams> countNonZeroFixture;
- WARMUP_ON;
- gpures = ocl::countNonZero(d_src);
- WARMUP_OFF;
-
- int diff = abs(cpures - gpures);
- if(diff == 0)
- TestSystem::instance().setAccurate(1, 0);
- else
- TestSystem::instance().setAccurate(0, diff);
+PERF_TEST_P(countNonZeroFixture, countNonZero,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ countNonZeroMatTypes::all()))
+{
+ // getting params
+ countNonZeroParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src(srcSize, type);
+ int result = 0;
+ randu(src, 0, 256);
+ declare.in(src);
+
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src);
- GPU_ON;
- ocl::countNonZero(d_src);
- GPU_OFF;
+ TEST_CYCLE() result = cv::ocl::countNonZero(oclSrc);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::countNonZero(d_src);
- GPU_FULL_OFF;
- }
+ SANITY_CHECK(result);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() result = cv::countNonZero(src);
+ SANITY_CHECK(result);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// Phase ////////////////////////
-PERFTEST(Phase)
-{
- Mat src1, src2, dst, ocl_dst;
- ocl::oclMat d_src1, d_src2, d_dst;
- int all_type[] = {CV_32FC1};
- std::string type_name[] = {"CV_32FC1"};
+typedef TestBaseWithParam<Size> PhaseFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+PERF_TEST_P(PhaseFixture, Phase, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1),
+ dst(srcSize, CV_32FC1);
+ declare.in(src1, src2).out(dst);
+ randu(src1, 0, 256);
+ randu(src2, 0, 256);
+
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src1, size, size, all_type[j], 0, 256);
- gen(src2, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
-
- phase(src1, src2, dst, 1);
-
- CPU_ON;
- phase(src1, src2, dst, 1);
- CPU_OFF;
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2),
+ oclDst(srcSize, src1.type());
- d_src1.upload(src1);
- d_src2.upload(src2);
+ TEST_CYCLE() cv::ocl::phase(oclSrc1, oclSrc2, oclDst, 1);
- WARMUP_ON;
- ocl::phase(d_src1, d_src2, d_dst, 1);
- WARMUP_OFF;
+ oclDst.download(dst);
- GPU_ON;
- ocl::phase(d_src1, d_src2, d_dst, 1);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::phase(d_src1, d_src2, d_dst, 1);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-2);
- }
+ SANITY_CHECK(dst, 1e-2);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::phase(src1, src2, dst, 1);
+ SANITY_CHECK(dst, 1e-2);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// bitwise_and////////////////////////
-PERFTEST(bitwise_and)
-{
- Mat src1, src2, dst, ocl_dst;
- ocl::oclMat d_src1, d_src2, d_dst;
- int all_type[] = {CV_8UC1, CV_32SC1};
- std::string type_name[] = {"CV_8UC1", "CV_32SC1"};
+typedef SumMatTypes BitwiseAndMatTypes;
+typedef tuple<Size, BitwiseAndMatTypes> BitwiseAndParams;
+typedef TestBaseWithParam<BitwiseAndParams> BitwiseAndFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+PERF_TEST_P(BitwiseAndFixture, bitwise_and,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ BitwiseAndMatTypes::all()))
+{
+ // getting params
+ BitwiseAndParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
+ declare.in(src1, src2).out(dst);
+ randu(src1, 0, 256);
+ randu(src2, 0, 256);
+
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst(srcSize, src1.type());
- gen(src1, size, size, all_type[j], 0, 256);
- gen(src2, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
+ TEST_CYCLE() cv::ocl::bitwise_and(oclSrc1, oclSrc2, oclDst);
- bitwise_and(src1, src2, dst);
+ oclDst.download(dst);
- CPU_ON;
- bitwise_and(src1, src2, dst);
- CPU_OFF;
- d_src1.upload(src1);
- d_src2.upload(src2);
-
- WARMUP_ON;
- ocl::bitwise_and(d_src1, d_src2, d_dst);
- WARMUP_OFF;
-
- GPU_ON;
- ocl::bitwise_and(d_src1, d_src2, d_dst);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::bitwise_and(d_src1, d_src2, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 0.0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::bitwise_and(src1, src2, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// bitwise_not////////////////////////
-PERFTEST(bitwise_not)
-{
- Mat src1, dst, ocl_dst;
- ocl::oclMat d_src1, d_dst;
- int all_type[] = {CV_8UC1, CV_32SC1};
- std::string type_name[] = {"CV_8UC1", "CV_32SC1"};
+typedef SumMatTypes BitwiseNotMatTypes;
+typedef tuple<Size, BitwiseNotMatTypes> BitwiseNotParams;
+typedef TestBaseWithParam<BitwiseNotParams> BitwiseNotFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+PERF_TEST_P(BitwiseAndFixture, bitwise_not,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ BitwiseAndMatTypes::all()))
+{
+ // getting params
+ BitwiseNotParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
+
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src1, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
-
- bitwise_not(src1, dst);
-
- CPU_ON;
- bitwise_not(src1, dst);
- CPU_OFF;
- d_src1.upload(src1);
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
- WARMUP_ON;
- ocl::bitwise_not(d_src1, d_dst);
- WARMUP_OFF;
+ TEST_CYCLE() cv::ocl::bitwise_not(oclSrc, oclDst);
- GPU_ON;
- ocl::bitwise_not(d_src1, d_dst);
- GPU_OFF;
+ oclDst.download(dst);
- GPU_FULL_ON;
- d_src1.upload(src1);
- ocl::bitwise_not(d_src1, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 0.0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::bitwise_not(src, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// compare////////////////////////
-PERFTEST(compare)
-{
- Mat src1, src2, dst, ocl_dst;
- ocl::oclMat d_src1, d_src2, d_dst;
- int CMP_EQ = 0;
- int all_type[] = {CV_8UC1, CV_32FC1};
- std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
+typedef countNonZeroMatTypes CompareMatTypes;
+typedef tuple<Size, CompareMatTypes> CompareParams;
+typedef TestBaseWithParam<CompareParams> CompareFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+PERF_TEST_P(CompareFixture, compare,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ CompareMatTypes::all()))
+{
+ // getting params
+ CompareParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, type), src2(srcSize, type), dst(srcSize, CV_8UC1);
+ declare.in(src1, src2, WARMUP_RNG).out(dst);
+
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src1, size, size, all_type[j], 0, 256);
- gen(src2, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
-
- compare(src1, src2, dst, CMP_EQ);
-
- CPU_ON;
- compare(src1, src2, dst, CMP_EQ);
- CPU_OFF;
-
- d_src1.upload(src1);
- d_src2.upload(src2);
-
- WARMUP_ON;
- ocl::compare(d_src1, d_src2, d_dst, CMP_EQ);
- WARMUP_OFF;
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst(srcSize, CV_8UC1);
- GPU_ON;
- ocl::compare(d_src1, d_src2, d_dst, CMP_EQ);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::compare(oclSrc1, oclSrc2, oclDst, CMP_EQ);
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::compare(d_src1, d_src2, d_dst, CMP_EQ);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 0.0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::compare(src1, src2, dst, CMP_EQ);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// pow ////////////////////////
-PERFTEST(pow)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
-
- int all_type[] = {CV_32FC1};
- std::string type_name[] = {"CV_32FC1"};
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
- gen(src, size, size, all_type[j], 5, 16);
+typedef TestBaseWithParam<Size> PowFixture;
- pow(src, -2.0, dst);
+PERF_TEST_P(PowFixture, pow, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
- CPU_ON;
- pow(src, -2.0, dst);
- CPU_OFF;
- d_src.upload(src);
- d_dst.upload(dst);
+ // creating src data
+ Mat src(srcSize, CV_32F), dst(srcSize, CV_32F);
+ declare.in(src, WARMUP_RNG).out(dst);
- WARMUP_ON;
- ocl::pow(d_src, -2.0, d_dst);
- WARMUP_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, src.type());
- GPU_ON;
- ocl::pow(d_src, -2.0, d_dst);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::pow(oclSrc, -2.0, oclDst);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::pow(d_src, -2.0, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1.0);
- }
+ SANITY_CHECK(dst, 5e-2);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::pow(src, -2.0, dst);
+ SANITY_CHECK(dst, 5e-2);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// MagnitudeSqr////////////////////////
-PERFTEST(MagnitudeSqr)
-{
- Mat src1, src2, dst, ocl_dst;
- ocl::oclMat d_src1, d_src2, d_dst;
-
- int all_type[] = {CV_32FC1};
- std::string type_name[] = {"CV_32FC1"};
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t t = 0; t < sizeof(all_type) / sizeof(int); t++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[t];
+typedef TestBaseWithParam<Size> MagnitudeSqrFixture;
- gen(src1, size, size, all_type[t], 0, 256);
- gen(src2, size, size, all_type[t], 0, 256);
- gen(dst, size, size, all_type[t], 0, 256);
-
- CPU_ON;
- for (int i = 0; i < src1.rows; ++i)
- for (int j = 0; j < src1.cols; ++j)
- {
- float val1 = src1.at<float>(i, j);
- float val2 = src2.at<float>(i, j);
- ((float *)(dst.data))[i * dst.step / 4 + j] = val1 * val1 + val2 * val2;
+PERF_TEST_P(MagnitudeSqrFixture, MagnitudeSqr, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
- }
- CPU_OFF;
+ // creating src data
+ Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1),
+ dst(srcSize, CV_32FC1);
+ declare.in(src1, src2, WARMUP_RNG).out(dst);
- d_src1.upload(src1);
- d_src2.upload(src2);
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst(srcSize, src1.type());
- WARMUP_ON;
- ocl::magnitudeSqr(d_src1, d_src2, d_dst);
- WARMUP_OFF;
+ TEST_CYCLE() cv::ocl::magnitudeSqr(oclSrc1, oclSrc2, oclDst);
- GPU_ON;
- ocl::magnitudeSqr(d_src1, d_src2, d_dst);
- GPU_OFF;
+ oclDst.download(dst);
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::magnitudeSqr(d_src1, d_src2, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
+ }
+ else if (impl == "plain")
+ {
+ ASSERT_EQ(1, src1.channels());
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1.0);
+ TEST_CYCLE()
+ {
+ for (int y = 0; y < srcSize.height; ++y)
+ {
+ const float * const src1Data = reinterpret_cast<float *>(src1.data + src1.step * y);
+ const float * const src2Data = reinterpret_cast<float *>(src2.data + src2.step * y);
+ float * const dstData = reinterpret_cast<float *>(dst.data + dst.step * y);
+ for (int x = 0; x < srcSize.width; ++x)
+ {
+ float t0 = src1Data[x] * src1Data[x];
+ float t1 = src2Data[x] * src2Data[x];
+ dstData[x] = t0 + t1;
+ }
+ }
}
+ SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// AddWeighted////////////////////////
-PERFTEST(AddWeighted)
-{
- Mat src1, src2, dst, ocl_dst;
- ocl::oclMat d_src1, d_src2, d_dst;
+typedef countNonZeroMatTypes AddWeightedMatTypes;
+typedef tuple<Size, AddWeightedMatTypes> AddWeightedParams;
+typedef TestBaseWithParam<AddWeightedParams> AddWeightedFixture;
+
+PERF_TEST_P(AddWeightedFixture, AddWeighted,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ AddWeightedMatTypes::all()))
+{
+ // getting params
+ AddWeightedParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, type), src2(srcSize, type), dst(srcSize, type);
+ declare.in(src1, src2, WARMUP_RNG).out(dst);
double alpha = 2.0, beta = 1.0, gama = 3.0;
- int all_type[] = {CV_8UC1, CV_32FC1};
- std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst(srcSize, type);
- gen(src1, size, size, all_type[j], 0, 256);
- gen(src2, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
+ TEST_CYCLE() cv::ocl::addWeighted(oclSrc1, alpha, oclSrc2, beta, gama, oclDst);
+ oclDst.download(dst);
- addWeighted(src1, alpha, src2, beta, gama, dst);
-
- CPU_ON;
- addWeighted(src1, alpha, src2, beta, gama, dst);
- CPU_OFF;
- d_src1.upload(src1);
- d_src2.upload(src2);
-
- WARMUP_ON;
- ocl::addWeighted(d_src1, alpha, d_src2, beta, gama, d_dst);
- WARMUP_OFF;
-
- GPU_ON;
- ocl::addWeighted(d_src1, alpha, d_src2, beta, gama, d_dst);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::addWeighted(d_src1, alpha, d_src2, beta, gama, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::addWeighted(src1, alpha, src2, beta, gama, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
+
+using namespace perf;
+
///////////// blend ////////////////////////
+
template <typename T>
-void blendLinearGold(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &weights1, const cv::Mat &weights2, cv::Mat &result_gold)
+static void blendLinearGold(const cv::Mat &img1, const cv::Mat &img2,
+ const cv::Mat &weights1, const cv::Mat &weights2,
+ cv::Mat &result_gold)
{
result_gold.create(img1.size(), img1.type());
for (int x = 0; x < img1.cols * cn; ++x)
{
- float w1 = weights1_row[x / cn];
- float w2 = weights2_row[x / cn];
- result_gold_row[x] = static_cast<T>((img1_row[x] * w1 + img2_row[x] * w2) / (w1 + w2 + 1e-5f));
+ int x1 = x * cn;
+ float w1 = weights1_row[x];
+ float w2 = weights2_row[x];
+ result_gold_row[x] = static_cast<T>((img1_row[x1] * w1
+ + img2_row[x1] * w2) / (w1 + w2 + 1e-5f));
}
}
}
-PERFTEST(blend)
+
+typedef TestBaseWithParam<Size> blendLinearFixture;
+
+PERF_TEST_P(blendLinearFixture, blendLinear, OCL_TYPICAL_MAT_SIZES)
{
- Mat src1, src2, weights1, weights2, dst, ocl_dst;
- ocl::oclMat d_src1, d_src2, d_weights1, d_weights2, d_dst;
+ // getting params
+ const Size srcSize = GetParam();
+ const int type = CV_8UC1;
+ const std::string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src1(srcSize, type), src2(srcSize, CV_8UC1), dst;
+ Mat weights1(srcSize, CV_32FC1), weights2(srcSize, CV_32FC1);
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
+ declare.in(src1, src2, WARMUP_RNG);
+ randu(weights1, 0.0f, 1.0f);
+ randu(weights2, 0.0f, 1.0f);
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] << " and CV_32FC1";
-
- gen(src1, size, size, all_type[j], 0, 256);
- gen(src2, size, size, all_type[j], 0, 256);
- gen(weights1, size, size, CV_32FC1, 0, 1);
- gen(weights2, size, size, CV_32FC1, 0, 1);
-
- blendLinearGold<uchar>(src1, src2, weights1, weights2, dst);
-
- CPU_ON;
- blendLinearGold<uchar>(src1, src2, weights1, weights2, dst);
- CPU_OFF;
-
- d_src1.upload(src1);
- d_src2.upload(src2);
- d_weights1.upload(weights1);
- d_weights2.upload(weights2);
-
- WARMUP_ON;
- ocl::blendLinear(d_src1, d_src2, d_weights1, d_weights2, d_dst);
- WARMUP_OFF;
-
- GPU_ON;
- ocl::blendLinear(d_src1, d_src2, d_weights1, d_weights2, d_dst);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- d_weights1.upload(weights1);
- d_weights2.upload(weights2);
- ocl::blendLinear(d_src1, d_src2, d_weights1, d_weights2, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.f);
- }
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2), oclDst;
+ ocl::oclMat oclWeights1(weights1), oclWeights2(weights2);
+
+ TEST_CYCLE() cv::ocl::blendLinear(oclSrc1, oclSrc2, oclWeights1, oclWeights2, oclDst);
+
+ oclDst.download(dst);
+
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() blendLinearGold<uchar>(src1, src2, weights1, weights2, dst);
+
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
+using namespace perf;
+
+#define OCL_BFMATCHER_TYPICAL_MAT_SIZES ::testing::Values(cv::Size(128, 500), cv::Size(128, 1000), cv::Size(128, 2000))
+
//////////////////// BruteForceMatch /////////////////
-PERFTEST(BruteForceMatcher)
+
+typedef TestBaseWithParam<Size> BruteForceMatcherFixture;
+
+PERF_TEST_P(BruteForceMatcherFixture, match,
+ OCL_BFMATCHER_TYPICAL_MAT_SIZES)
{
- Mat trainIdx_cpu;
- Mat distance_cpu;
- Mat allDist_cpu;
- Mat nMatches_cpu;
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- // Init CPU matcher
- int desc_len = 64;
+ vector<DMatch> matches;
+ Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
+ declare.in(query, train).time(srcSize.height == 2000 ? 8 : 4 );
+ randu(query, 0.0f, 1.0f);
+ randu(train, 0.0f, 1.0f);
+ if (impl == "plain")
+ {
BFMatcher matcher(NORM_L2);
+ TEST_CYCLE() matcher.match(query, train, matches);
- Mat query;
- gen(query, size, desc_len, CV_32F, 0, 1);
-
- Mat train;
- gen(train, size, desc_len, CV_32F, 0, 1);
- // Output
- vector< vector<DMatch> > matches(2);
- vector< vector<DMatch> > d_matches(2);
+ SANITY_CHECK_MATCHES(matches);
+ }
+ else if (impl == "ocl")
+ {
// Init GPU matcher
- ocl::BruteForceMatcher_OCL_base d_matcher(ocl::BruteForceMatcher_OCL_base::L2Dist);
+ ocl::BruteForceMatcher_OCL_base oclMatcher(ocl::BruteForceMatcher_OCL_base::L2Dist);
+ ocl::oclMat oclQuery(query), oclTrain(train);
- ocl::oclMat d_query(query);
- ocl::oclMat d_train(train);
+ TEST_CYCLE() oclMatcher.match(oclQuery, oclTrain, matches);
- ocl::oclMat d_trainIdx, d_distance, d_allDist, d_nMatches;
+ SANITY_CHECK_MATCHES(matches);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
+}
+
+//PERF_TEST_P(BruteForceMatcherFixture, matchSingle,
+// OCL_BFMATCHER_TYPICAL_MAT_SIZES)
+//{
+// const Size srcSize = GetParam();
+// const string impl = getSelectedImpl();
+
+// Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
+// Mat trainIdx, distance;
- SUBTEST << size << "; match";
+// randu(query, 0.0f, 1.0f);
+// randu(train, 0.0f, 1.0f);
- matcher.match(query, train, matches[0]);
+// if (impl == "plain")
+// CV_TEST_FAIL_NO_IMPL();
+// else if (impl == "ocl")
+// {
+// ocl::oclMat oclQuery(query), oclTrain(train), oclTrainIdx, oclDistance;
- CPU_ON;
- matcher.match(query, train, matches[0]);
- CPU_OFF;
+// TEST_CYCLE() oclMatcher->matchSingle(oclQuery, oclTrain, oclTrainIdx, oclDistance);
+
+// oclTrainIdx.download(trainIdx);
+// oclDistance.download(distance);
+
+// SANITY_CHECK(trainIdx);
+// SANITY_CHECK(distance);
+// }
+//#ifdef HAVE_OPENCV_GPU
+// else if (impl == "gpu")
+// CV_TEST_FAIL_NO_IMPL();
+//#endif
+// else
+// CV_TEST_FAIL_NO_IMPL();
+//}
+
+PERF_TEST_P(BruteForceMatcherFixture, knnMatch,
+ OCL_BFMATCHER_TYPICAL_MAT_SIZES)
+{
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
- WARMUP_ON;
- d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
- WARMUP_OFF;
+ vector<vector<DMatch> > matches(2);
+ Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
+ randu(query, 0.0f, 1.0f);
+ randu(train, 0.0f, 1.0f);
- GPU_ON;
- d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
- GPU_OFF;
+ declare.in(query, train);
+ if (srcSize.height == 2000)
+ declare.time(8);
- GPU_FULL_ON;
- d_query.upload(query);
- d_train.upload(train);
- d_matcher.match(d_query, d_train, d_matches[0]);
- GPU_FULL_OFF;
+ if (impl == "plain")
+ {
+ BFMatcher matcher (NORM_L2);
+ TEST_CYCLE() matcher.knnMatch(query, train, matches, 2);
- int diff = abs((int)d_matches[0].size() - (int)matches[0].size());
- if(diff == 0)
- TestSystem::instance().setAccurate(1, 0);
- else
- TestSystem::instance().setAccurate(0, diff);
+ std::vector<DMatch> & matches0 = matches[0], & matches1 = matches[1];
+ SANITY_CHECK_MATCHES(matches0);
+ SANITY_CHECK_MATCHES(matches1);
+ }
+ else if (impl == "ocl")
+ {
+ ocl::BruteForceMatcher_OCL_base oclMatcher(ocl::BruteForceMatcher_OCL_base::L2Dist);
+ ocl::oclMat oclQuery(query), oclTrain(train);
- SUBTEST << size << "; knnMatch";
+ TEST_CYCLE() oclMatcher.knnMatch(oclQuery, oclTrain, matches, 2);
- matcher.knnMatch(query, train, matches, 2);
+ std::vector<DMatch> & matches0 = matches[0], & matches1 = matches[1];
+ SANITY_CHECK_MATCHES(matches0);
+ SANITY_CHECK_MATCHES(matches1);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
+}
- CPU_ON;
- matcher.knnMatch(query, train, matches, 2);
- CPU_OFF;
+//PERF_TEST_P(BruteForceMatcherFixture, knnMatchSingle,
+// OCL_BFMATCHER_TYPICAL_MAT_SIZES)
+//{
+// const Size srcSize = GetParam();
+// const string impl = getSelectedImpl();
- WARMUP_ON;
- d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, 2);
- WARMUP_OFF;
+// Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
+// Mat trainIdx, distance, allDist;
- GPU_ON;
- d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, 2);
- GPU_OFF;
+// randu(query, 0.0f, 1.0f);
+// randu(train, 0.0f, 1.0f);
- GPU_FULL_ON;
- d_query.upload(query);
- d_train.upload(train);
- d_matcher.knnMatch(d_query, d_train, d_matches, 2);
- GPU_FULL_OFF;
+// if (impl == "plain")
+// CV_TEST_FAIL_NO_IMPL();
+// else if (impl == "ocl")
+// {
+// ocl::oclMat oclQuery(query), oclTrain(train), oclTrainIdx, oclDistance, oclAllDist;
- diff = abs((int)d_matches[0].size() - (int)matches[0].size());
- if(diff == 0)
- TestSystem::instance().setAccurate(1, 0);
- else
- TestSystem::instance().setAccurate(0, diff);
+// TEST_CYCLE() oclMatcher->knnMatchSingle(oclQuery, oclTrain, oclTrainIdx, oclDistance, oclAllDist, 2);
- SUBTEST << size << "; radiusMatch";
+// oclTrainIdx.download(trainIdx);
+// oclDistance.download(distance);
+// oclAllDist.download(allDist);
- float max_distance = 2.0f;
+// SANITY_CHECK(trainIdx);
+// SANITY_CHECK(distance);
+// SANITY_CHECK(allDist);
+// }
+//#ifdef HAVE_OPENCV_GPU
+// else if (impl == "gpu")
+// CV_TEST_FAIL_NO_IMPL();
+//#endif
+// else
+// CV_TEST_FAIL_NO_IMPL();
+//}
- matcher.radiusMatch(query, train, matches, max_distance);
+PERF_TEST_P(BruteForceMatcherFixture, DISABLED_radiusMatch,
+ OCL_BFMATCHER_TYPICAL_MAT_SIZES)
+{
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
- CPU_ON;
- matcher.radiusMatch(query, train, matches, max_distance);
- CPU_OFF;
+ const float max_distance = 2.0f;
+ vector<vector<DMatch> > matches(2);
+ Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
+ declare.in(query, train);
+ Mat trainIdx, distance, allDist;
- d_trainIdx.release();
+ randu(query, 0.0f, 1.0f);
+ randu(train, 0.0f, 1.0f);
- WARMUP_ON;
- d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, max_distance);
- WARMUP_OFF;
+ if (impl == "plain")
+ {
+ BFMatcher matcher (NORM_L2);
+ TEST_CYCLE() matcher.radiusMatch(query, matches, max_distance);
- GPU_ON;
- d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, max_distance);
- GPU_OFF;
+ std::vector<DMatch> & matches0 = matches[0], & matches1 = matches[1];
+ SANITY_CHECK_MATCHES(matches0);
+ SANITY_CHECK_MATCHES(matches1);
+ }
+ else if (impl == "ocl")
+ {
+ ocl::oclMat oclQuery(query), oclTrain(train);
+ ocl::BruteForceMatcher_OCL_base oclMatcher(ocl::BruteForceMatcher_OCL_base::L2Dist);
- GPU_FULL_ON;
- d_query.upload(query);
- d_train.upload(train);
- d_matcher.radiusMatch(d_query, d_train, d_matches, max_distance);
- GPU_FULL_OFF;
+ TEST_CYCLE() oclMatcher.radiusMatch(oclQuery, oclTrain, matches, max_distance);
- diff = abs((int)d_matches[0].size() - (int)matches[0].size());
- if(diff == 0)
- TestSystem::instance().setAccurate(1, 0);
- else
- TestSystem::instance().setAccurate(0, diff);
+ std::vector<DMatch> & matches0 = matches[0], & matches1 = matches[1];
+ SANITY_CHECK_MATCHES(matches0);
+ SANITY_CHECK_MATCHES(matches1);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
+
+//PERF_TEST_P(BruteForceMatcherFixture, radiusMatchSingle,
+// OCL_BFMATCHER_TYPICAL_MAT_SIZES)
+//{
+// const Size srcSize = GetParam();
+// const string impl = getSelectedImpl();
+
+// const float max_distance = 2.0f;
+// Mat query(srcSize, CV_32F), train(srcSize, CV_32F);
+// Mat trainIdx, distance, nMatches;
+
+// randu(query, 0.0f, 1.0f);
+// randu(train, 0.0f, 1.0f);
+
+// if (impl == "plain")
+// CV_TEST_FAIL_NO_IMPL();
+// else if (impl == "ocl")
+// {
+// ocl::oclMat oclQuery(query), oclTrain(train), oclTrainIdx, oclDistance, oclNMatches;
+
+// TEST_CYCLE() oclMatcher->radiusMatchSingle(oclQuery, oclTrain, oclTrainIdx, oclDistance, oclNMatches, max_distance);
+
+// oclTrainIdx.download(trainIdx);
+// oclDistance.download(distance);
+// oclNMatches.download(nMatches);
+
+// SANITY_CHECK(trainIdx);
+// SANITY_CHECK(distance);
+// SANITY_CHECK(nMatches);
+// }
+//#ifdef HAVE_OPENCV_GPU
+// else if (impl == "gpu")
+// CV_TEST_FAIL_NO_IMPL();
+//#endif
+// else
+// CV_TEST_FAIL_NO_IMPL();
+//}
+
+#undef OCL_BFMATCHER_TYPICAL_MAT_SIZES
//M*/
#include "perf_precomp.hpp"
+
///////////// StereoMatchBM ////////////////////////
-PERFTEST(StereoMatchBM)
-{
- Mat left_image = imread(abspath("aloeL.jpg"), cv::IMREAD_GRAYSCALE);
- Mat right_image = imread(abspath("aloeR.jpg"), cv::IMREAD_GRAYSCALE);
- Mat disp,dst;
- ocl::oclMat d_left, d_right,d_disp;
- int n_disp= 128;
- int winSize =19;
- SUBTEST << left_image.cols << 'x' << left_image.rows << "; aloeL.jpg ;"<< right_image.cols << 'x' << right_image.rows << "; aloeR.jpg ";
+PERF_TEST(StereoMatchBMFixture, DISABLED_StereoMatchBM)
+{
+ Mat left_image = imread(getDataPath("gpu/stereobm/aloe-L.png"), cv::IMREAD_GRAYSCALE);
+ Mat right_image = imread(getDataPath("gpu/stereobm/aloe-R.png"), cv::IMREAD_GRAYSCALE);
- StereoBM bm(0, n_disp, winSize);
- bm(left_image, right_image, dst);
+ ASSERT_TRUE(!left_image.empty()) << "no input image";
+ ASSERT_TRUE(!right_image.empty()) << "no input image";
+ ASSERT_TRUE(right_image.size() == left_image.size());
+ ASSERT_TRUE(right_image.size() == left_image.size());
- CPU_ON;
- bm(left_image, right_image, dst);
- CPU_OFF;
+ const std::string impl = getSelectedImpl();
+ const int n_disp = 128, winSize = 19;
+ Mat disp(left_image.size(), CV_16SC1);
- d_left.upload(left_image);
- d_right.upload(right_image);
+ declare.in(left_image, right_image).out(disp);
- ocl::StereoBM_OCL d_bm(0, n_disp, winSize);
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclLeft(left_image), oclRight(right_image),
+ oclDisp(left_image.size(), CV_16SC1);
+ ocl::StereoBM_OCL oclBM(0, n_disp, winSize);
- WARMUP_ON;
- d_bm(d_left, d_right, d_disp);
- WARMUP_OFF;
+ TEST_CYCLE() oclBM(oclLeft, oclRight, oclDisp);
- cv::Mat ocl_mat;
- d_disp.download(ocl_mat);
- ocl_mat.convertTo(ocl_mat, dst.type());
+ oclDisp.download(disp);
- GPU_ON;
- d_bm(d_left, d_right, d_disp);
- GPU_OFF;
+ SANITY_CHECK(disp);
+ }
+ else if (impl == "plain")
+ {
+ StereoBM bm(0, n_disp, winSize);
- GPU_FULL_ON;
- d_left.upload(left_image);
- d_right.upload(right_image);
- d_bm(d_left, d_right, d_disp);
- d_disp.download(disp);
- GPU_FULL_OFF;
+ TEST_CYCLE() bm(left_image, right_image, disp);
- TestSystem::instance().setAccurate(-1, 0.);
+ SANITY_CHECK(disp);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+ #endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
-///////////// Canny ////////////////////////
-PERFTEST(Canny)
-{
- Mat img = imread(abspath("aloeL.jpg"), CV_LOAD_IMAGE_GRAYSCALE);
-
- if (img.empty())
- {
- throw runtime_error("can't open aloeL.jpg");
- }
-
- SUBTEST << img.cols << 'x' << img.rows << "; aloeL.jpg" << "; edges" << "; CV_8UC1";
+using namespace perf;
- Mat edges(img.size(), CV_8UC1), ocl_edges;
+///////////// Canny ////////////////////////
- CPU_ON;
- Canny(img, edges, 50.0, 100.0);
- CPU_OFF;
+PERF_TEST(CannyFixture, Canny)
+{
+ Mat img = imread(getDataPath("gpu/stereobm/aloe-L.png"), cv::IMREAD_GRAYSCALE),
+ edges(img.size(), CV_8UC1);
+ ASSERT_TRUE(!img.empty()) << "can't open aloeL.jpg";
- ocl::oclMat d_img(img);
- ocl::oclMat d_edges;
- ocl::CannyBuf d_buf;
+ const std::string impl = getSelectedImpl();
+ declare.in(img).out(edges);
- WARMUP_ON;
- ocl::Canny(d_img, d_buf, d_edges, 50.0, 100.0);
- WARMUP_OFF;
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclImg(img), oclEdges(img.size(), CV_8UC1);
- GPU_ON;
- ocl::Canny(d_img, d_buf, d_edges, 50.0, 100.0);
- GPU_OFF;
+ TEST_CYCLE() Canny(oclImg, oclEdges, 50.0, 100.0);
+ oclEdges.download(edges);
- GPU_FULL_ON;
- d_img.upload(img);
- ocl::Canny(d_img, d_buf, d_edges, 50.0, 100.0);
- d_edges.download(ocl_edges);
- GPU_FULL_OFF;
+ SANITY_CHECK(edges);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() Canny(img, edges, 50.0, 100.0);
- TestSystem::instance().ExceptedMatSimilar(edges, ocl_edges, 2e-2);
+ SANITY_CHECK(edges);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
-///////////// cvtColor////////////////////////
-PERFTEST(cvtColor)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
-
- int all_type[] = {CV_8UC4};
- std::string type_name[] = {"CV_8UC4"};
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- gen(src, size, size, all_type[j], 0, 256);
- SUBTEST << size << "x" << size << "; " << type_name[j] << " ; CV_RGBA2GRAY";
-
- cvtColor(src, dst, CV_RGBA2GRAY, 4);
-
- CPU_ON;
- cvtColor(src, dst, CV_RGBA2GRAY, 4);
- CPU_OFF;
+using namespace perf;
- d_src.upload(src);
+///////////// cvtColor////////////////////////
- WARMUP_ON;
- ocl::cvtColor(d_src, d_dst, CV_RGBA2GRAY, 4);
- WARMUP_OFF;
+typedef TestBaseWithParam<Size> cvtColorFixture;
- GPU_ON;
- ocl::cvtColor(d_src, d_dst, CV_RGBA2GRAY, 4);
- GPU_OFF;
+PERF_TEST_P(cvtColorFixture, cvtColor, OCL_TYPICAL_MAT_SIZES)
+{
+ const Size srcSize = GetParam();
+ const std::string impl = getSelectedImpl();
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::cvtColor(d_src, d_dst, CV_RGBA2GRAY, 4);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ Mat src(srcSize, CV_8UC4), dst(srcSize, CV_8UC4);
+ declare.in(src).out(dst);
- TestSystem::instance().ExceptedMatSimilar(dst, ocl_dst, 1e-5);
- }
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(src.size(), CV_8UC4);
+ TEST_CYCLE() ocl::cvtColor(oclSrc, oclDst, CV_RGBA2GRAY, 4);
+ oclDst.download(dst);
+ SANITY_CHECK(dst);
}
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::cvtColor(src, dst, CV_RGBA2GRAY, 4);
-
+ SANITY_CHECK(dst);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
-///////////// dft ////////////////////////
-PERFTEST(dft)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
-
- int all_type[] = {CV_32FC2};
- std::string type_name[] = {"CV_32FC2"};
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] << " ; complex-to-complex";
+using namespace perf;
- gen(src, size, size, all_type[j], Scalar::all(0), Scalar::all(1));
+///////////// dft ////////////////////////
- dft(src, dst);
+typedef TestBaseWithParam<Size> dftFixture;
- CPU_ON;
- dft(src, dst);
- CPU_OFF;
+PERF_TEST_P(dftFixture, DISABLED_dft, OCL_TYPICAL_MAT_SIZES)
+{
+ const std::string impl = getSelectedImpl();
+ Size srcSize = GetParam();
- d_src.upload(src);
+ Mat src(srcSize, CV_32FC2), dst;
+ randu(src, 0.0f, 1.0f);
+ declare.in(src);
- WARMUP_ON;
- ocl::dft(d_src, d_dst, Size(size, size));
- WARMUP_OFF;
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst;
- GPU_ON;
- ocl::dft(d_src, d_dst, Size(size, size));
- GPU_OFF;
+ EXPECT_NO_THROW({
+ TEST_CYCLE() cv::ocl::dft(oclSrc, oclDst);
+ });
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::dft(d_src, d_dst, Size(size, size));
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, src.size().area() * 1e-4);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::dft(src, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
+using namespace perf;
+using std::tr1::get;
+using std::tr1::tuple;
+
///////////// Blur////////////////////////
-PERFTEST(Blur)
-{
- Mat src1, dst, ocl_dst;
- ocl::oclMat d_src1, d_dst;
- Size ksize = Size(3, 3);
- int bordertype = BORDER_CONSTANT;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
+CV_ENUM(BlurMatType, CV_8UC1, CV_8UC4)
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+typedef tuple<Size, BlurMatType> BlurParams;
+typedef TestBaseWithParam<BlurParams> BlurFixture;
- gen(src1, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
+PERF_TEST_P(BlurFixture, Blur,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ BlurMatType::all()))
+{
+ // getting params
+ BlurParams params = GetParam();
+ const Size srcSize = get<0>(params), ksize(3, 3);
+ const int type = get<1>(params), bordertype = BORDER_CONSTANT;
- blur(src1, dst, ksize, Point(-1, -1), bordertype);
+ const std::string impl = getSelectedImpl();
- CPU_ON;
- blur(src1, dst, ksize, Point(-1, -1), bordertype);
- CPU_OFF;
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
- d_src1.upload(src1);
+ if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
+ declare.time(5);
- WARMUP_ON;
- ocl::blur(d_src1, d_dst, ksize, Point(-1, -1), bordertype);
- WARMUP_OFF;
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
- GPU_ON;
- ocl::blur(d_src1, d_dst, ksize, Point(-1, -1), bordertype);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::blur(oclSrc, oclDst, ksize, Point(-1, -1), bordertype);
- GPU_FULL_ON;
- d_src1.upload(src1);
- ocl::blur(d_src1, d_dst, ksize, Point(-1, -1), bordertype);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1.0);
- }
+ SANITY_CHECK(dst, 1 + DBL_EPSILON);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::blur(src, dst, ksize, Point(-1, -1), bordertype);
+ SANITY_CHECK(dst, 1 + DBL_EPSILON);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
-///////////// Laplacian////////////////////////
-PERFTEST(Laplacian)
-{
- Mat src1, dst, ocl_dst;
- ocl::oclMat d_src1, d_dst;
- int ksize = 3;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
+///////////// Laplacian////////////////////////
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+typedef BlurMatType LaplacianMatType;
+typedef tuple<Size, LaplacianMatType> LaplacianParams;
+typedef TestBaseWithParam<LaplacianParams> LaplacianFixture;
- gen(src1, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
+PERF_TEST_P(LaplacianFixture, Laplacian,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ LaplacianMatType::all()))
+{
+ // getting params
+ LaplacianParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params), ksize = 3;
- Laplacian(src1, dst, -1, ksize, 1);
+ const std::string impl = getSelectedImpl();
- CPU_ON;
- Laplacian(src1, dst, -1, ksize, 1);
- CPU_OFF;
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
- d_src1.upload(src1);
+ if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
+ declare.time(6);
- WARMUP_ON;
- ocl::Laplacian(d_src1, d_dst, -1, ksize, 1);
- WARMUP_OFF;
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
- GPU_ON;
- ocl::Laplacian(d_src1, d_dst, -1, ksize, 1);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::Laplacian(oclSrc, oclDst, -1, ksize, 1);
- GPU_FULL_ON;
- d_src1.upload(src1);
- ocl::Laplacian(d_src1, d_dst, -1, ksize, 1);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::Laplacian(src, dst, -1, ksize, 1);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// Erode ////////////////////
-PERFTEST(Erode)
-{
- Mat src, dst, ker, ocl_dst;
- ocl::oclMat d_src, d_dst;
- int all_type[] = {CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4", "CV_32FC1", "CV_32FC4"};
+CV_ENUM(ErodeMatType, CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4)
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+typedef tuple<Size, ErodeMatType> ErodeParams;
+typedef TestBaseWithParam<ErodeParams> ErodeFixture;
- gen(src, size, size, all_type[j], Scalar::all(0), Scalar::all(256));
- ker = getStructuringElement(MORPH_RECT, Size(3, 3));
+PERF_TEST_P(ErodeFixture, Erode,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ ErodeMatType::all()))
+{
+ // getting params
+ ErodeParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params), ksize = 3;
+ const Mat ker = getStructuringElement(MORPH_RECT, Size(ksize, ksize));
- erode(src, dst, ker);
+ const std::string impl = getSelectedImpl();
- CPU_ON;
- erode(src, dst, ker);
- CPU_OFF;
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst).in(ker);
- d_src.upload(src);
+ if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
+ declare.time(5);
- WARMUP_ON;
- ocl::erode(d_src, d_dst, ker);
- WARMUP_OFF;
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type), oclKer(ker);
- GPU_ON;
- ocl::erode(d_src, d_dst, ker);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::erode(oclSrc, oclDst, oclKer);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::erode(d_src, d_dst, ker);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::erode(src, dst, ker);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// Sobel ////////////////////////
-PERFTEST(Sobel)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
-
- int dx = 1;
- int dy = 1;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+typedef BlurMatType SobelMatType;
+typedef tuple<Size, SobelMatType> SobelMatParams;
+typedef TestBaseWithParam<SobelMatParams> SobelFixture;
- gen(src, size, size, all_type[j], 0, 256);
+PERF_TEST_P(SobelFixture, Sobel,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ SobelMatType::all()))
+{
+ // getting params
+ SobelMatParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params), dx = 1, dy = 1;
- Sobel(src, dst, -1, dx, dy);
+ const std::string impl = getSelectedImpl();
- CPU_ON;
- Sobel(src, dst, -1, dx, dy);
- CPU_OFF;
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
- d_src.upload(src);
+ if ((srcSize == OCL_SIZE_2000 && type == CV_8UC4) ||
+ (srcSize == OCL_SIZE_4000 && type == CV_8UC1))
+ declare.time(5.5);
+ else if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
+ declare.time(20);
- WARMUP_ON;
- ocl::Sobel(d_src, d_dst, -1, dx, dy);
- WARMUP_OFF;
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
- GPU_ON;
- ocl::Sobel(d_src, d_dst, -1, dx, dy);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::Sobel(oclSrc, oclDst, -1, dx, dy);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::Sobel(d_src, d_dst, -1, dx, dy);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::Sobel(src, dst, -1, dx, dy);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
+
///////////// Scharr ////////////////////////
-PERFTEST(Scharr)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
- int dx = 1;
- int dy = 0;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
+typedef BlurMatType ScharrMatType;
+typedef tuple<Size, ScharrMatType> ScharrParams;
+typedef TestBaseWithParam<ScharrParams> ScharrFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src, size, size, all_type[j], 0, 256);
+PERF_TEST_P(ScharrFixture, Scharr,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ ScharrMatType::all()))
+{
+ // getting params
+ ScharrParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params), dx = 1, dy = 0;
- Scharr(src, dst, -1, dx, dy);
+ const std::string impl = getSelectedImpl();
- CPU_ON;
- Scharr(src, dst, -1, dx, dy);
- CPU_OFF;
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
- d_src.upload(src);
+ if ((srcSize == OCL_SIZE_2000 && type == CV_8UC4) ||
+ (srcSize == OCL_SIZE_4000 && type == CV_8UC1))
+ declare.time(5.5);
+ else if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
+ declare.time(21);
- WARMUP_ON;
- ocl::Scharr(d_src, d_dst, -1, dx, dy);
- WARMUP_OFF;
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
- GPU_ON;
- ocl::Scharr(d_src, d_dst, -1, dx, dy);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::Scharr(oclSrc, oclDst, -1, dx, dy);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::Scharr(d_src, d_dst, -1, dx, dy);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::Scharr(src, dst, -1, dx, dy);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// GaussianBlur ////////////////////////
-PERFTEST(GaussianBlur)
-{
- Mat src, dst, ocl_dst;
- int all_type[] = {CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4", "CV_32FC1", "CV_32FC4"};
- const int ksize = 7;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+typedef ErodeMatType GaussianBlurMatType;
+typedef tuple<Size, GaussianBlurMatType> GaussianBlurParams;
+typedef TestBaseWithParam<GaussianBlurParams> GaussianBlurFixture;
- gen(src, size, size, all_type[j], 0, 256);
+PERF_TEST_P(GaussianBlurFixture, GaussianBlur,
+ ::testing::Combine(::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000),
+ GaussianBlurMatType::all()))
+{
+ // getting params
+ GaussianBlurParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params), ksize = 7;
- GaussianBlur(src, dst, Size(ksize, ksize), 0);
+ const std::string impl = getSelectedImpl();
- CPU_ON;
- GaussianBlur(src, dst, Size(ksize, ksize), 0);
- CPU_OFF;
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
- ocl::oclMat d_src(src);
- ocl::oclMat d_dst;
+ const double eps = src.depth() == CV_8U ? 1 + DBL_EPSILON : 3e-4;
- WARMUP_ON;
- ocl::GaussianBlur(d_src, d_dst, Size(ksize, ksize), 0);
- WARMUP_OFF;
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
- GPU_ON;
- ocl::GaussianBlur(d_src, d_dst, Size(ksize, ksize), 0);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::GaussianBlur(oclSrc, oclDst, Size(ksize, ksize), 0);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::GaussianBlur(d_src, d_dst, Size(ksize, ksize), 0);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1.0);
- }
+ SANITY_CHECK(dst, eps);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::GaussianBlur(src, dst, Size(ksize, ksize), 0);
+ SANITY_CHECK(dst, eps);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// filter2D////////////////////////
-PERFTEST(filter2D)
-{
- Mat src;
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
-
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- gen(src, size, size, all_type[j], 0, 256);
-
- const int ksize = 3;
-
- SUBTEST << "ksize = " << ksize << "; " << size << 'x' << size << "; " << type_name[j] ;
- Mat kernel;
- gen(kernel, ksize, ksize, CV_32SC1, -3.0, 3.0);
+typedef BlurMatType filter2DMatType;
+typedef tuple<Size, filter2DMatType> filter2DParams;
+typedef TestBaseWithParam<filter2DParams> filter2DFixture;
- Mat dst, ocl_dst;
-
- cv::filter2D(src, dst, -1, kernel);
-
- CPU_ON;
- cv::filter2D(src, dst, -1, kernel);
- CPU_OFF;
+PERF_TEST_P(filter2DFixture, filter2D,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ filter2DMatType::all()))
+{
+ // getting params
+ filter2DParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params), ksize = 3;
- ocl::oclMat d_src(src), d_dst;
+ const std::string impl = getSelectedImpl();
- WARMUP_ON;
- ocl::filter2D(d_src, d_dst, -1, kernel);
- WARMUP_OFF;
+ Mat src(srcSize, type), dst(srcSize, type), kernel(ksize, ksize, CV_32SC1);
+ declare.in(src, WARMUP_RNG).in(kernel).out(dst);
+ randu(kernel, -3.0, 3.0);
- GPU_ON;
- ocl::filter2D(d_src, d_dst, -1, kernel);
- GPU_OFF;
+ if (srcSize == OCL_SIZE_4000 && type == CV_8UC4)
+ declare.time(8);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::filter2D(d_src, d_dst, -1, kernel);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type), oclKernel(kernel);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, 1e-5);
+ TEST_CYCLE() cv::ocl::filter2D(oclSrc, oclDst, -1, oclKernel);
- }
+ oclDst.download(dst);
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::filter2D(src, dst, -1, kernel);
+ SANITY_CHECK(dst);
}
+ #ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
-///////////// gemm ////////////////////////
-PERFTEST(gemm)
-{
- Mat src1, src2, src3, dst, ocl_dst;
- ocl::oclMat d_src1, d_src2, d_src3, d_dst;
+using namespace perf;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- SUBTEST << size << 'x' << size;
+///////////// gemm ////////////////////////
- gen(src1, size, size, CV_32FC1, Scalar::all(-10), Scalar::all(10));
- gen(src2, size, size, CV_32FC1, Scalar::all(-10), Scalar::all(10));
- gen(src3, size, size, CV_32FC1, Scalar::all(-10), Scalar::all(10));
+typedef TestBaseWithParam<Size> gemmFixture;
- gemm(src1, src2, 1.0, src3, 1.0, dst);
+PERF_TEST_P(gemmFixture, DISABLED_gemm, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const std::string impl = getSelectedImpl();
- CPU_ON;
- gemm(src1, src2, 1.0, src3, 1.0, dst);
- CPU_OFF;
+ Mat src1(srcSize, CV_32FC1), src2(srcSize, CV_32FC1),
+ src3(srcSize, CV_32FC1), dst(srcSize, CV_32FC1);
+ declare.in(src1, src2, src3).out(dst);
+ randu(src1, -10.0f, 10.0f);
+ randu(src2, -10.0f, 10.0f);
+ randu(src3, -10.0f, 10.0f);
- d_src1.upload(src1);
- d_src2.upload(src2);
- d_src3.upload(src3);
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2),
+ oclSrc3(src3), oclDst(srcSize, CV_32FC1);
- WARMUP_ON;
- ocl::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst);
- WARMUP_OFF;
+ TEST_CYCLE() cv::ocl::gemm(oclSrc1, oclSrc2, 1.0, oclSrc3, 1.0, oclDst);
- GPU_ON;
- ocl::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst);
- GPU_OFF;
+ oclDst.download(dst);
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- d_src3.upload(src3);
- ocl::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::gemm(src1, src2, 1.0, src3, 1.0, dst);
- TestSystem::instance().ExpectedMatNear(ocl_dst, dst, src1.cols * src1.rows * 1e-4);
+ SANITY_CHECK(dst);
}
+ #ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
#include "perf_precomp.hpp"
-///////////// GoodFeaturesToTrack ////////////////////////
-PERFTEST(GoodFeaturesToTrack)
-{
- using namespace cv;
-
- int maxCorners = 2000;
- double qualityLevel = 0.01;
-
- std::string images[] = { "rubberwhale1.png", "aloeL.jpg" };
-
- std::vector<cv::Point2f> pts_gold, pts_ocl;
-
- for(size_t imgIdx = 0; imgIdx < (sizeof(images)/sizeof(std::string)); ++imgIdx)
- {
- Mat frame = imread(abspath(images[imgIdx]), IMREAD_GRAYSCALE);
- CV_Assert(!frame.empty());
+using namespace perf;
+using std::tr1::tuple;
+using std::tr1::get;
- for(float minDistance = 0; minDistance < 4; minDistance += 3.0)
- {
- SUBTEST << "image = " << images[imgIdx] << "; ";
- SUBTEST << "minDistance = " << minDistance << "; ";
+///////////// GoodFeaturesToTrack ////////////////////////
- cv::goodFeaturesToTrack(frame, pts_gold, maxCorners, qualityLevel, minDistance);
+typedef tuple<string, double> GoodFeaturesToTrackParams;
+typedef TestBaseWithParam<GoodFeaturesToTrackParams> GoodFeaturesToTrackFixture;
- CPU_ON;
- cv::goodFeaturesToTrack(frame, pts_gold, maxCorners, qualityLevel, minDistance);
- CPU_OFF;
+PERF_TEST_P(GoodFeaturesToTrackFixture, GoodFeaturesToTrack,
+ ::testing::Combine(::testing::Values(string("gpu/opticalflow/rubberwhale1.png"),
+ string("gpu/stereobm/aloe-L.png")),
+ ::testing::Range(0.0, 4.0, 3.0)))
+{
+ std::vector<cv::Point2f> pts_gold;
- cv::ocl::GoodFeaturesToTrackDetector_OCL detector(maxCorners, qualityLevel, minDistance);
+ // getting params
+ GoodFeaturesToTrackParams param = GetParam();
+ const string fileName = getDataPath(get<0>(param)), impl = getSelectedImpl();
+ const int maxCorners = 2000;
+ const double qualityLevel = 0.01, minDistance = get<1>(param);
- ocl::oclMat frame_ocl(frame), pts_oclmat;
+ Mat frame = imread(fileName, IMREAD_GRAYSCALE);
+ declare.in(frame);
+ ASSERT_TRUE(!frame.empty()) << "no input image";
- WARMUP_ON;
- detector(frame_ocl, pts_oclmat);
- WARMUP_OFF;
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclFrame(frame), pts_oclmat;
+ cv::ocl::GoodFeaturesToTrackDetector_OCL detector(maxCorners, qualityLevel, minDistance);
- detector.downloadPoints(pts_oclmat, pts_ocl);
+ TEST_CYCLE() detector(oclFrame, pts_oclmat);
- double diff = abs(static_cast<float>(pts_gold.size() - pts_ocl.size()));
- TestSystem::instance().setAccurate(diff == 0.0, diff);
+ detector.downloadPoints(pts_oclmat, pts_gold);
- GPU_ON;
- detector(frame_ocl, pts_oclmat);
- GPU_OFF;
+ SANITY_CHECK(pts_gold);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::goodFeaturesToTrack(frame, pts_gold,
+ maxCorners, qualityLevel, minDistance);
- GPU_FULL_ON;
- frame_ocl.upload(frame);
- detector(frame_ocl, pts_oclmat);
- detector.downloadPoints(pts_oclmat, pts_ocl);
- GPU_FULL_OFF;
- }
+ SANITY_CHECK(pts_gold);
}
+ #ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
+using namespace perf;
+
///////////// Haar ////////////////////////
namespace cv
{
}
}
-PERFTEST(Haar)
-{
- Mat img = imread(abspath("basketball1.png"), CV_LOAD_IMAGE_GRAYSCALE);
- if (img.empty())
- {
- throw runtime_error("can't open basketball1.png");
- }
+PERF_TEST(HaarFixture, Haar)
+{
+ const std::string impl = getSelectedImpl();
+ vector<Rect> faces;
- CascadeClassifier faceCascadeCPU;
+ Mat img = imread(getDataPath("gpu/haarcascade/basketball1.png"), CV_LOAD_IMAGE_GRAYSCALE);
+ ASSERT_TRUE(!img.empty()) << "can't open basketball1.png";
+ declare.in(img);
- if (!faceCascadeCPU.load(abspath("haarcascade_frontalface_alt.xml")))
+ if (impl == "plain")
{
- throw runtime_error("can't load haarcascade_frontalface_alt.xml");
- }
+ CascadeClassifier faceCascade;
+ ASSERT_TRUE(faceCascade.load(getDataPath("gpu/haarcascade/haarcascade_frontalface_alt.xml")))
+ << "can't load haarcascade_frontalface_alt.xml";
- vector<Rect> faces;
+ TEST_CYCLE() faceCascade.detectMultiScale(img, faces,
+ 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
- SUBTEST << img.cols << "x" << img.rows << "; scale image";
- CPU_ON;
- faceCascadeCPU.detectMultiScale(img, faces,
- 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
- CPU_OFF;
+ SANITY_CHECK(faces, 4 + 1e-4);
+ }
+ else if (impl == "ocl")
+ {
+ ocl::CascadeClassifier_GPU faceCascade;
+ ocl::oclMat oclImg(img);
+ ASSERT_TRUE(faceCascade.load(getDataPath("gpu/haarcascade/haarcascade_frontalface_alt.xml")))
+ << "can't load haarcascade_frontalface_alt.xml";
- vector<Rect> oclfaces;
- ocl::CascadeClassifier_GPU faceCascade;
+ TEST_CYCLE() faceCascade.detectMultiScale(oclImg, faces,
+ 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
- if (!faceCascade.load(abspath("haarcascade_frontalface_alt.xml")))
- {
- throw runtime_error("can't load haarcascade_frontalface_alt.xml");
+ SANITY_CHECK(faces, 4 + 1e-4);
}
- ocl::oclMat d_img(img);
-
- WARMUP_ON;
- faceCascade.detectMultiScale(d_img, oclfaces,
- 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
- WARMUP_OFF;
-
- if(faces.size() == oclfaces.size())
- TestSystem::instance().setAccurate(1, 0);
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
else
- TestSystem::instance().setAccurate(0, abs((int)faces.size() - (int)oclfaces.size()));
-
- faces.clear();
-
- GPU_ON;
- faceCascade.detectMultiScale(d_img, oclfaces,
- 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
- GPU_OFF;
-
- GPU_FULL_ON;
- d_img.upload(img);
- faceCascade.detectMultiScale(d_img, oclfaces,
- 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
- GPU_FULL_OFF;
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
+using namespace perf;
+
///////////// HOG////////////////////////
-PERFTEST(HOG)
+PERF_TEST(HOGFixture, HOG)
{
- Mat src = imread(abspath("road.png"), cv::IMREAD_GRAYSCALE);
-
- if (src.empty())
- {
- throw runtime_error("can't open road.png");
- }
+ Mat src = imread(getDataPath("gpu/hog/road.png"), cv::IMREAD_GRAYSCALE);
+ ASSERT_TRUE(!src.empty()) << "can't open input image road.png";
- cv::HOGDescriptor hog;
- hog.setSVMDetector(hog.getDefaultPeopleDetector());
+ const std::string impl = getSelectedImpl();
std::vector<cv::Rect> found_locations;
- std::vector<cv::Rect> d_found_locations;
-
- SUBTEST << src.cols << 'x' << src.rows << "; road.png";
+ declare.in(src).time(5);
- hog.detectMultiScale(src, found_locations);
+ if (impl == "plain")
+ {
+ cv::HOGDescriptor hog;
+ hog.setSVMDetector(hog.getDefaultPeopleDetector());
- CPU_ON;
- hog.detectMultiScale(src, found_locations);
- CPU_OFF;
+ TEST_CYCLE() hog.detectMultiScale(src, found_locations);
- cv::ocl::HOGDescriptor ocl_hog;
- ocl_hog.setSVMDetector(ocl_hog.getDefaultPeopleDetector());
- ocl::oclMat d_src;
- d_src.upload(src);
+ SANITY_CHECK(found_locations, 1 + DBL_EPSILON);
+ }
+ else if (impl == "ocl")
+ {
+ cv::ocl::HOGDescriptor ocl_hog;
+ ocl_hog.setSVMDetector(ocl_hog.getDefaultPeopleDetector());
+ ocl::oclMat oclSrc(src);
- WARMUP_ON;
- ocl_hog.detectMultiScale(d_src, d_found_locations);
- WARMUP_OFF;
+ TEST_CYCLE() ocl_hog.detectMultiScale(oclSrc, found_locations);
- if(d_found_locations.size() == found_locations.size())
- TestSystem::instance().setAccurate(1, 0);
+ SANITY_CHECK(found_locations, 1 + DBL_EPSILON);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
else
- TestSystem::instance().setAccurate(0, abs((int)found_locations.size() - (int)d_found_locations.size()));
-
- GPU_ON;
- ocl_hog.detectMultiScale(d_src, found_locations);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src.upload(src);
- ocl_hog.detectMultiScale(d_src, found_locations);
- GPU_FULL_OFF;
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
-///////////// equalizeHist ////////////////////////
-PERFTEST(equalizeHist)
-{
- Mat src, dst, ocl_dst;
- int all_type[] = {CV_8UC1};
- std::string type_name[] = {"CV_8UC1"};
+using namespace perf;
+using std::tr1::tuple;
+using std::tr1::get;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src, size, size, all_type[j], 0, 256);
-
- equalizeHist(src, dst);
+///////////// equalizeHist ////////////////////////
- CPU_ON;
- equalizeHist(src, dst);
- CPU_OFF;
+typedef TestBaseWithParam<Size> equalizeHistFixture;
- ocl::oclMat d_src(src);
- ocl::oclMat d_dst;
- ocl::oclMat d_hist;
- ocl::oclMat d_buf;
+PERF_TEST_P(equalizeHistFixture, equalizeHist, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
- WARMUP_ON;
- ocl::equalizeHist(d_src, d_dst);
- WARMUP_OFF;
+ // creating src data
+ Mat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
+ declare.in(src, WARMUP_RNG).out(dst);
- GPU_ON;
- ocl::equalizeHist(d_src, d_dst);
- GPU_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, src.type());
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::equalizeHist(d_src, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ TEST_CYCLE() cv::ocl::equalizeHist(oclSrc, oclDst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.1);
- }
+ oclDst.download(dst);
+ SANITY_CHECK(dst, 1 + DBL_EPSILON);
}
-}
-/////////// CopyMakeBorder //////////////////////
-PERFTEST(CopyMakeBorder)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_dst;
-
- int bordertype = BORDER_CONSTANT;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ else if (impl == "plain")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+ TEST_CYCLE() cv::equalizeHist(src, dst);
+ SANITY_CHECK(dst, 1 + DBL_EPSILON);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
+}
- gen(src, size, size, all_type[j], 0, 256);
-
- copyMakeBorder(src, dst, 7, 5, 5, 7, bordertype, cv::Scalar(1.0));
+/////////// CopyMakeBorder //////////////////////
- CPU_ON;
- copyMakeBorder(src, dst, 7, 5, 5, 7, bordertype, cv::Scalar(1.0));
- CPU_OFF;
+CV_ENUM(CopyMakeBorderMatType, CV_8UC1, CV_8UC4)
- ocl::oclMat d_src(src);
+typedef tuple<Size, CopyMakeBorderMatType> CopyMakeBorderParams;
+typedef TestBaseWithParam<CopyMakeBorderParams> CopyMakeBorderFixture;
- WARMUP_ON;
- ocl::copyMakeBorder(d_src, d_dst, 7, 5, 5, 7, bordertype, cv::Scalar(1.0));
- WARMUP_OFF;
+PERF_TEST_P(CopyMakeBorderFixture, CopyMakeBorder,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ CopyMakeBorderMatType::all()))
+{
+ // getting params
+ CopyMakeBorderParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params), borderType = BORDER_CONSTANT;
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src(srcSize, type), dst;
+ const Size dstSize = srcSize + Size(12, 12);
+ dst.create(dstSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
+
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(dstSize, type);
- GPU_ON;
- ocl::copyMakeBorder(d_src, d_dst, 7, 5, 5, 7, bordertype, cv::Scalar(1.0));
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::copyMakeBorder(oclSrc, oclDst, 7, 5, 5, 7, borderType, cv::Scalar(1.0));
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::copyMakeBorder(d_src, d_dst, 7, 5, 5, 7, bordertype, cv::Scalar(1.0));
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 0.0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::copyMakeBorder(src, dst, 7, 5, 5, 7, borderType, cv::Scalar(1.0));
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
-///////////// cornerMinEigenVal ////////////////////////
-PERFTEST(cornerMinEigenVal)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_dst;
- int blockSize = 7, apertureSize = 1 + 2 * (rand() % 4);
- int borderType = BORDER_REFLECT;
- int all_type[] = {CV_8UC1, CV_32FC1};
- std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
+///////////// cornerMinEigenVal ////////////////////////
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+CV_ENUM(cornerMinEigenValMatType, CV_8UC1, CV_32FC1)
- gen(src, size, size, all_type[j], 0, 256);
+typedef tuple<Size, cornerMinEigenValMatType> cornerMinEigenValParams;
+typedef TestBaseWithParam<cornerMinEigenValParams> cornerMinEigenValFixture;
- cornerMinEigenVal(src, dst, blockSize, apertureSize, borderType);
+PERF_TEST_P(cornerMinEigenValFixture, cornerMinEigenVal,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ cornerMinEigenValMatType::all()))
+{
+ // getting params
+ cornerMinEigenValParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params), borderType = BORDER_REFLECT;
+ const int blockSize = 7, apertureSize = 1 + 2 * 3;
- CPU_ON;
- cornerMinEigenVal(src, dst, blockSize, apertureSize, borderType);
- CPU_OFF;
+ const string impl = getSelectedImpl();
- ocl::oclMat d_src(src);
+ // creating src data
+ Mat src(srcSize, type), dst(srcSize, CV_32FC1);
+ declare.in(src, WARMUP_RNG).out(dst)
+ .time(srcSize == OCL_SIZE_4000 ? 20 : srcSize == OCL_SIZE_2000 ? 5 : 3);
- WARMUP_ON;
- ocl::cornerMinEigenVal(d_src, d_dst, blockSize, apertureSize, borderType);
- WARMUP_OFF;
+ const int depth = CV_MAT_DEPTH(type);
+ const ERROR_TYPE errorType = depth == CV_8U ? ERROR_ABSOLUTE : ERROR_RELATIVE;
- GPU_ON;
- ocl::cornerMinEigenVal(d_src, d_dst, blockSize, apertureSize, borderType);
- GPU_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, CV_32FC1);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::cornerMinEigenVal(d_src, d_dst, blockSize, apertureSize, borderType);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ TEST_CYCLE() cv::ocl::cornerMinEigenVal(oclSrc, oclDst, blockSize, apertureSize, borderType);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.0);
- }
+ oclDst.download(dst);
+ SANITY_CHECK(dst, 1e-6, errorType);
}
-}
-///////////// cornerHarris ////////////////////////
-PERFTEST(cornerHarris)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
-
- int all_type[] = {CV_8UC1, CV_32FC1};
- std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ else if (impl == "plain")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] << " ; BORDER_REFLECT";
+ TEST_CYCLE() cv::cornerMinEigenVal(src, dst, blockSize, apertureSize, borderType);
- gen(src, size, size, all_type[j], 0, 1);
+ SANITY_CHECK(dst, 1e-6, errorType);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
+}
- cornerHarris(src, dst, 5, 7, 0.1, BORDER_REFLECT);
+///////////// cornerHarris ////////////////////////
- CPU_ON;
- cornerHarris(src, dst, 5, 7, 0.1, BORDER_REFLECT);
- CPU_OFF;
+typedef cornerMinEigenValMatType cornerHarrisMatType;
+typedef tuple<Size, cornerHarrisMatType> cornerHarrisParams;
+typedef TestBaseWithParam<cornerHarrisParams> cornerHarrisFixture;
- d_src.upload(src);
+PERF_TEST_P(cornerHarrisFixture, cornerHarris,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ cornerHarrisMatType::all()))
+{
+ // getting params
+ cornerHarrisParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params), borderType = BORDER_REFLECT;
- WARMUP_ON;
- ocl::cornerHarris(d_src, d_dst, 5, 7, 0.1, BORDER_REFLECT);
- WARMUP_OFF;
+ const string impl = getSelectedImpl();
- GPU_ON;
- ocl::cornerHarris(d_src, d_dst, 5, 7, 0.1, BORDER_REFLECT);
- GPU_OFF;
+ // creating src data
+ Mat src(srcSize, type), dst(srcSize, CV_32FC1);
+ randu(src, 0, 1);
+ declare.in(src).out(dst)
+ .time(srcSize == OCL_SIZE_4000 ? 20 : srcSize == OCL_SIZE_2000 ? 5 : 3);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::cornerHarris(d_src, d_dst, 5, 7, 0.1, BORDER_REFLECT);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, CV_32FC1);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.0);
- }
+ TEST_CYCLE() cv::ocl::cornerHarris(oclSrc, oclDst, 5, 7, 0.1, borderType);
+ oclDst.download(dst);
+ SANITY_CHECK(dst, 3e-5);
}
-}
-///////////// integral ////////////////////////
-PERFTEST(integral)
-{
- Mat src, sum, ocl_sum;
- ocl::oclMat d_src, d_sum, d_buf;
-
- int all_type[] = {CV_8UC1};
- std::string type_name[] = {"CV_8UC1"};
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ else if (impl == "plain")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+ TEST_CYCLE() cv::cornerHarris(src, dst, 5, 7, 0.1, borderType);
- gen(src, size, size, all_type[j], 0, 256);
+ SANITY_CHECK(dst, 3e-5);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
+}
- integral(src, sum);
+///////////// integral ////////////////////////
- CPU_ON;
- integral(src, sum);
- CPU_OFF;
+typedef TestBaseWithParam<Size> integralFixture;
- d_src.upload(src);
+PERF_TEST_P(integralFixture, DISABLED_integral, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
- WARMUP_ON;
- ocl::integral(d_src, d_sum);
- WARMUP_OFF;
+ // creating src data
+ Mat src(srcSize, CV_8UC1), dst;
+ declare.in(src, WARMUP_RNG);
- GPU_ON;
- ocl::integral(d_src, d_sum);
- GPU_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst;
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::integral(d_src, d_sum);
- d_sum.download(ocl_sum);
- GPU_FULL_OFF;
+ TEST_CYCLE() cv::ocl::integral(oclSrc, oclDst);
- if(sum.type() == ocl_sum.type()) //we won't test accuracy when cpu function overlow
- TestSystem::instance().ExpectedMatNear(sum, ocl_sum, 0.0);
+ oclDst.download(dst);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::integral(src, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
+
///////////// WarpAffine ////////////////////////
-PERFTEST(WarpAffine)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
+typedef CopyMakeBorderMatType WarpAffineMatType;
+typedef tuple<Size, WarpAffineMatType> WarpAffineParams;
+typedef TestBaseWithParam<WarpAffineParams> WarpAffineFixture;
+
+PERF_TEST_P(WarpAffineFixture, WarpAffine,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ WarpAffineMatType::all()))
+{
static const double coeffs[2][3] =
{
- {cos(CV_PI / 6), -sin(CV_PI / 6), 100.0},
- {sin(CV_PI / 6), cos(CV_PI / 6), -100.0}
+ { cos(CV_PI / 6), -sin(CV_PI / 6), 100.0 },
+ { sin(CV_PI / 6), cos(CV_PI / 6), -100.0 }
};
Mat M(2, 3, CV_64F, (void *)coeffs);
- int interpolation = INTER_NEAREST;
+ const int interpolation = INTER_NEAREST;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
+ // getting params
+ WarpAffineParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
+ // creating src data
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
- Size size1 = Size(size, size);
-
- warpAffine(src, dst, M, size1, interpolation);
-
- CPU_ON;
- warpAffine(src, dst, M, size1, interpolation);
- CPU_OFF;
-
- d_src.upload(src);
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
- WARMUP_ON;
- ocl::warpAffine(d_src, d_dst, M, size1, interpolation);
- WARMUP_OFF;
+ TEST_CYCLE() cv::ocl::warpAffine(oclSrc, oclDst, M, srcSize, interpolation);
- GPU_ON;
- ocl::warpAffine(d_src, d_dst, M, size1, interpolation);
- GPU_OFF;
+ oclDst.download(dst);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::warpAffine(d_src, d_dst, M, size1, interpolation);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::warpAffine(src, dst, M, srcSize, interpolation);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
+
///////////// WarpPerspective ////////////////////////
-PERFTEST(WarpPerspective)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
+typedef CopyMakeBorderMatType WarpPerspectiveMatType;
+typedef tuple<Size, WarpPerspectiveMatType> WarpPerspectiveParams;
+typedef TestBaseWithParam<WarpPerspectiveParams> WarpPerspectiveFixture;
+
+PERF_TEST_P(WarpPerspectiveFixture, WarpPerspective,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ WarpPerspectiveMatType::all()))
+{
static const double coeffs[3][3] =
{
{cos(CV_PI / 6), -sin(CV_PI / 6), 100.0},
{0.0, 0.0, 1.0}
};
Mat M(3, 3, CV_64F, (void *)coeffs);
- int interpolation = INTER_LINEAR;
-
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src, size, size, all_type[j], 0, 256);
- gen(dst, size, size, all_type[j], 0, 256);
- Size size1 = Size(size, size);
-
- warpPerspective(src, dst, M, size1, interpolation);
+ const int interpolation = INTER_LINEAR;
- CPU_ON;
- warpPerspective(src, dst, M, size1, interpolation);
- CPU_OFF;
+ // getting params
+ WarpPerspectiveParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const string impl = getSelectedImpl();
- d_src.upload(src);
+ // creating src data
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst)
+ .time(srcSize == OCL_SIZE_4000 ? 18 : srcSize == OCL_SIZE_2000 ? 5 : 2);
- WARMUP_ON;
- ocl::warpPerspective(d_src, d_dst, M, size1, interpolation);
- WARMUP_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
- GPU_ON;
- ocl::warpPerspective(d_src, d_dst, M, size1, interpolation);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::warpPerspective(oclSrc, oclDst, M, srcSize, interpolation);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::warpPerspective(d_src, d_dst, M, size1, interpolation);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::warpPerspective(src, dst, M, srcSize, interpolation);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// resize ////////////////////////
-PERFTEST(resize)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
+CV_ENUM(resizeInterType, INTER_NEAREST, INTER_LINEAR)
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
+typedef CopyMakeBorderMatType resizeMatType;
+typedef tuple<Size, resizeMatType, resizeInterType, double> resizeParams;
+typedef TestBaseWithParam<resizeParams> resizeFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+PERF_TEST_P(resizeFixture, resize,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ resizeMatType::all(),
+ resizeInterType::all(),
+ ::testing::Values(0.5, 2.0)))
+{
+ // getting params
+ resizeParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params), interType = get<2>(params);
+ double scale = get<3>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src(srcSize, type), dst;
+ const Size dstSize(cvRound(srcSize.width * scale), cvRound(srcSize.height * scale));
+ dst.create(dstSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
+ if (interType == INTER_LINEAR && type == CV_8UC4 && OCL_SIZE_4000 == srcSize)
+ declare.time(11);
+
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] << " ; up";
-
- gen(src, size, size, all_type[j], 0, 256);
+ ocl::oclMat oclSrc(src), oclDst(dstSize, type);
- resize(src, dst, Size(), 2.0, 2.0);
+ TEST_CYCLE() cv::ocl::resize(oclSrc, oclDst, Size(), scale, scale, interType);
- CPU_ON;
- resize(src, dst, Size(), 2.0, 2.0);
- CPU_OFF;
-
- d_src.upload(src);
-
- WARMUP_ON;
- ocl::resize(d_src, d_dst, Size(), 2.0, 2.0);
- WARMUP_OFF;
-
- GPU_ON;
- ocl::resize(d_src, d_dst, Size(), 2.0, 2.0);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::resize(d_src, d_dst, Size(), 2.0, 2.0);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.0);
- }
+ oclDst.download(dst);
+ SANITY_CHECK(dst, 1 + DBL_EPSILON);
}
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ else if (impl == "plain")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] << " ; down";
-
- gen(src, size, size, all_type[j], 0, 256);
-
- resize(src, dst, Size(), 0.5, 0.5);
-
- CPU_ON;
- resize(src, dst, Size(), 0.5, 0.5);
- CPU_OFF;
-
- d_src.upload(src);
-
- WARMUP_ON;
- ocl::resize(d_src, d_dst, Size(), 0.5, 0.5);
- WARMUP_OFF;
-
- GPU_ON;
- ocl::resize(d_src, d_dst, Size(), 0.5, 0.5);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::resize(d_src, d_dst, Size(), 0.5, 0.5);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.0);
- }
+ TEST_CYCLE() cv::resize(src, dst, Size(), scale, scale, interType);
+ SANITY_CHECK(dst, 1 + DBL_EPSILON);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
-///////////// threshold////////////////////////
-PERFTEST(threshold)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- SUBTEST << size << 'x' << size << "; 8UC1; THRESH_BINARY";
- gen(src, size, size, CV_8U, 0, 100);
-
- threshold(src, dst, 50.0, 0.0, THRESH_BINARY);
+///////////// threshold////////////////////////
- CPU_ON;
- threshold(src, dst, 50.0, 0.0, THRESH_BINARY);
- CPU_OFF;
+CV_ENUM(ThreshType, THRESH_BINARY, THRESH_TRUNC)
- d_src.upload(src);
+typedef tuple<Size, ThreshType> ThreshParams;
+typedef TestBaseWithParam<ThreshParams> ThreshFixture;
- WARMUP_ON;
- ocl::threshold(d_src, d_dst, 50.0, 0.0, THRESH_BINARY);
- WARMUP_OFF;
+PERF_TEST_P(ThreshFixture, threshold,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ ThreshType::all()))
+{
+ // getting params
+ ThreshParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int threshType = get<1>(params);
+ const string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src(srcSize, CV_8U), dst(srcSize, CV_8U);
+ randu(src, 0, 100);
+ declare.in(src).out(dst);
+
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, CV_8U);
- GPU_ON;
- ocl::threshold(d_src, d_dst, 50.0, 0.0, THRESH_BINARY);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::threshold(oclSrc, oclDst, 50.0, 0.0, threshType);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::threshold(d_src, d_dst, 50.0, 0.0, THRESH_BINARY);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.0);
+ SANITY_CHECK(dst);
}
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ else if (impl == "plain")
{
- SUBTEST << size << 'x' << size << "; 32FC1; THRESH_TRUNC [NPP]";
-
- gen(src, size, size, CV_32FC1, 0, 100);
-
- threshold(src, dst, 50.0, 0.0, THRESH_TRUNC);
-
- CPU_ON;
- threshold(src, dst, 50.0, 0.0, THRESH_TRUNC);
- CPU_OFF;
-
- d_src.upload(src);
+ TEST_CYCLE() cv::threshold(src, dst, 50.0, 0.0, threshType);
- WARMUP_ON;
- ocl::threshold(d_src, d_dst, 50.0, 0.0, THRESH_TRUNC);
- WARMUP_OFF;
-
- GPU_ON;
- ocl::threshold(d_src, d_dst, 50.0, 0.0, THRESH_TRUNC);
- GPU_OFF;
-
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::threshold(d_src, d_dst, 50.0, 0.0, THRESH_TRUNC);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.0);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
+
///////////// meanShiftFiltering////////////////////////
-COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep, cv::Size size, int sp, int sr, int maxIter, float eps, int *tab)
+
+typedef struct
+{
+ short x;
+ short y;
+} COOR;
+
+static COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep, cv::Size size, int sp, int sr, int maxIter, float eps, int *tab)
{
int isr2 = sr * sr;
}
}
-PERFTEST(meanShiftFiltering)
+typedef TestBaseWithParam<Size> meanShiftFilteringFixture;
+
+PERF_TEST_P(meanShiftFilteringFixture, meanShiftFiltering,
+ OCL_TYPICAL_MAT_SIZES)
{
- int sp = 5, sr = 6;
- Mat src, dst, ocl_dst;
+ const Size srcSize = GetParam();
+ const int sp = 5, sr = 6;
+ const string impl = getSelectedImpl();
+ cv::TermCriteria crit(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 5, 1);
- ocl::oclMat d_src, d_dst;
+ Mat src(srcSize, CV_8UC4), dst(srcSize, CV_8UC4);
+ declare.in(src, WARMUP_RNG).out(dst)
+ .time(srcSize == OCL_SIZE_4000 ?
+ 56 : srcSize == OCL_SIZE_2000 ? 15 : 3.8);
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ if (impl == "plain")
{
- SUBTEST << size << 'x' << size << "; 8UC3 vs 8UC4";
-
- gen(src, size, size, CV_8UC4, Scalar::all(0), Scalar::all(256));
-
- cv::TermCriteria crit(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 5, 1);
-
- meanShiftFiltering_(src, dst, sp, sr, crit);
+ TEST_CYCLE() meanShiftFiltering_(src, dst, sp, sr, crit);
- CPU_ON;
- meanShiftFiltering_(src, dst, sp, sr, crit);
- CPU_OFF;
-
- d_src.upload(src);
-
- WARMUP_ON;
- ocl::meanShiftFiltering(d_src, d_dst, sp, sr, crit);
- WARMUP_OFF;
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, CV_8UC4);
- GPU_ON;
- ocl::meanShiftFiltering(d_src, d_dst, sp, sr, crit);
- GPU_OFF;
+ TEST_CYCLE() ocl::meanShiftFiltering(oclSrc, oclDst, sp, sr, crit);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::meanShiftFiltering(d_src, d_dst, sp, sr, crit);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 0.0);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
-void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp, int sr, cv::TermCriteria crit)
+static void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp, int sr, cv::TermCriteria crit)
{
if (src_roi.empty())
{
}
}
-PERFTEST(meanShiftProc)
-{
- Mat src;
- vector<Mat> dst(2), ocl_dst(2);
- ocl::oclMat d_src, d_dst, d_dstCoor;
- TermCriteria crit(TermCriteria::COUNT + TermCriteria::EPS, 5, 1);
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- SUBTEST << size << 'x' << size << "; 8UC4 and CV_16SC2 ";
-
- gen(src, size, size, CV_8UC4, Scalar::all(0), Scalar::all(256));
+typedef TestBaseWithParam<Size> meanShiftProcFixture;
- meanShiftProc_(src, dst[0], dst[1], 5, 6, crit);
+PERF_TEST_P(meanShiftProcFixture, meanShiftProc,
+ OCL_TYPICAL_MAT_SIZES)
+{
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
+ TermCriteria crit(TermCriteria::COUNT + TermCriteria::EPS, 5, 1);
- CPU_ON;
- meanShiftProc_(src, dst[0], dst[1], 5, 6, crit);
- CPU_OFF;
+ Mat src(srcSize, CV_8UC4), dst1(srcSize, CV_8UC4),
+ dst2(srcSize, CV_16SC2);
+ declare.in(src, WARMUP_RNG).out(dst1, dst2)
+ .time(srcSize == OCL_SIZE_4000 ?
+ 56 : srcSize == OCL_SIZE_2000 ? 15 : 3.8);;
- d_src.upload(src);
+ if (impl == "plain")
+ {
+ TEST_CYCLE() meanShiftProc_(src, dst1, dst2, 5, 6, crit);
- WARMUP_ON;
- ocl::meanShiftProc(d_src, d_dst, d_dstCoor, 5, 6, crit);
- WARMUP_OFF;
+ SANITY_CHECK(dst1);
+ SANITY_CHECK(dst2);
+ }
+ else if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst1(srcSize, CV_8UC4),
+ oclDst2(srcSize, CV_16SC2);
- GPU_ON;
- ocl::meanShiftProc(d_src, d_dst, d_dstCoor, 5, 6, crit);
- GPU_OFF;
+ TEST_CYCLE() ocl::meanShiftProc(oclSrc, oclDst1, oclDst2, 5, 6, crit);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::meanShiftProc(d_src, d_dst, d_dstCoor, 5, 6, crit);
- d_dst.download(ocl_dst[0]);
- d_dstCoor.download(ocl_dst[1]);
- GPU_FULL_OFF;
+ oclDst1.download(dst1);
+ oclDst2.download(dst2);
- vector<double> eps(2, 0.);
- TestSystem::instance().ExpectMatsNear(dst, ocl_dst, eps);
+ SANITY_CHECK(dst1);
+ SANITY_CHECK(dst2);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// remap////////////////////////
-PERFTEST(remap)
-{
- Mat src, dst, xmap, ymap, ocl_dst;
- ocl::oclMat d_src, d_dst, d_xmap, d_ymap;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
+CV_ENUM(RemapInterType, INTER_NEAREST, INTER_LINEAR)
- int interpolation = INTER_LINEAR;
- int borderMode = BORDER_CONSTANT;
+typedef CopyMakeBorderMatType remapMatType;
+typedef tuple<Size, remapMatType, RemapInterType> remapParams;
+typedef TestBaseWithParam<remapParams> remapFixture;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t t = 0; t < sizeof(all_type) / sizeof(int); t++)
- {
- SUBTEST << size << 'x' << size << "; src " << type_name[t] << "; map CV_32FC1";
-
- gen(src, size, size, all_type[t], 0, 256);
+PERF_TEST_P(remapFixture, remap,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ remapMatType::all(),
+ RemapInterType::all()))
+{
+ // getting params
+ remapParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params), interpolation = get<2>(params);
+ const string impl = getSelectedImpl();
- xmap.create(size, size, CV_32FC1);
- dst.create(size, size, CV_32FC1);
- ymap.create(size, size, CV_32FC1);
+ // creating src data
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
- for (int i = 0; i < size; ++i)
- {
- float *xmap_row = xmap.ptr<float>(i);
- float *ymap_row = ymap.ptr<float>(i);
+ if (srcSize == OCL_SIZE_4000 && interpolation == INTER_LINEAR)
+ declare.time(9);
- for (int j = 0; j < size; ++j)
- {
- xmap_row[j] = (j - size * 0.5f) * 0.75f + size * 0.5f;
- ymap_row[j] = (i - size * 0.5f) * 0.75f + size * 0.5f;
- }
- }
+ Mat xmap, ymap;
+ xmap.create(srcSize, CV_32FC1);
+ ymap.create(srcSize, CV_32FC1);
- remap(src, dst, xmap, ymap, interpolation, borderMode);
+ for (int i = 0; i < srcSize.height; ++i)
+ {
+ float * const xmap_row = xmap.ptr<float>(i);
+ float * const ymap_row = ymap.ptr<float>(i);
- CPU_ON;
- remap(src, dst, xmap, ymap, interpolation, borderMode);
- CPU_OFF;
+ for (int j = 0; j < srcSize.width; ++j)
+ {
+ xmap_row[j] = (j - srcSize.width * 0.5f) * 0.75f + srcSize.width * 0.5f;
+ ymap_row[j] = (i - srcSize.height * 0.5f) * 0.75f + srcSize.height * 0.5f;
+ }
+ }
- d_src.upload(src);
- d_dst.upload(dst);
- d_xmap.upload(xmap);
- d_ymap.upload(ymap);
+ const int borderMode = BORDER_CONSTANT;
- WARMUP_ON;
- ocl::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode);
- WARMUP_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
+ ocl::oclMat oclXMap(xmap), oclYMap(ymap);
- GPU_ON;
- ocl::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode);
- GPU_OFF;
+ TEST_CYCLE() cv::ocl::remap(oclSrc, oclDst, oclXMap, oclYMap, interpolation, borderMode);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 2.0);
- }
+ SANITY_CHECK(dst, 1 + DBL_EPSILON);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::remap(src, dst, xmap, ymap, interpolation, borderMode);
+ SANITY_CHECK(dst, 1 + DBL_EPSILON);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
-///////////// CLAHE ////////////////////////
-PERFTEST(CLAHE)
-{
- Mat src, dst, ocl_dst;
- cv::ocl::oclMat d_src, d_dst;
- int all_type[] = {CV_8UC1};
- std::string type_name[] = {"CV_8UC1"};
-
- double clipLimit = 40.0;
- cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);
- cv::Ptr<cv::CLAHE> d_clahe = cv::ocl::createCLAHE(clipLimit);
+///////////// CLAHE ////////////////////////
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+typedef TestBaseWithParam<Size> CLAHEFixture;
- gen(src, size, size, all_type[j], 0, 256);
+PERF_TEST_P(CLAHEFixture, CLAHE, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
- CPU_ON;
- clahe->apply(src, dst);
- CPU_OFF;
+ // creating src data
+ Mat src(srcSize, CV_8UC1), dst;
+ const double clipLimit = 40.0;
+ declare.in(src, WARMUP_RNG);
- d_src.upload(src);
+ if (srcSize == OCL_SIZE_4000)
+ declare.time(11);
- WARMUP_ON;
- d_clahe->apply(d_src, d_dst);
- WARMUP_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst;
+ cv::Ptr<cv::CLAHE> oclClahe = cv::ocl::createCLAHE(clipLimit);
- ocl_dst = d_dst;
+ TEST_CYCLE() oclClahe->apply(oclSrc, oclDst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 1.0);
+ oclDst.download(dst);
- GPU_ON;
- d_clahe->apply(d_src, d_dst);
- GPU_OFF;
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);
+ TEST_CYCLE() clahe->apply(src, dst);
- GPU_FULL_ON;
- d_src.upload(src);
- d_clahe->apply(d_src, d_dst);
- d_dst.download(dst);
- GPU_FULL_OFF;
- }
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// columnSum////////////////////////
-PERFTEST(columnSum)
+
+typedef TestBaseWithParam<Size> columnSumFixture;
+
+static void columnSumPerfTest(const Mat & src, Mat & dst)
{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
+ for (int j = 0; j < src.cols; j++)
+ dst.at<float>(0, j) = src.at<float>(0, j);
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- SUBTEST << size << 'x' << size << "; CV_32FC1";
+ for (int i = 1; i < src.rows; ++i)
+ for (int j = 0; j < src.cols; ++j)
+ dst.at<float>(i, j) = dst.at<float>(i - 1 , j) + src.at<float>(i , j);
+}
- gen(src, size, size, CV_32FC1, 0, 256);
+PERF_TEST_P(columnSumFixture, columnSum, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const string impl = getSelectedImpl();
- CPU_ON;
- dst.create(src.size(), src.type());
- for (int j = 0; j < src.cols; j++)
- dst.at<float>(0, j) = src.at<float>(0, j);
+ // creating src data
+ Mat src(srcSize, CV_32FC1), dst(srcSize, CV_32FC1);
+ declare.in(src, WARMUP_RNG).out(dst);
- for (int i = 1; i < src.rows; ++i)
- for (int j = 0; j < src.cols; ++j)
- dst.at<float>(i, j) = dst.at<float>(i - 1 , j) + src.at<float>(i , j);
- CPU_OFF;
+ if (srcSize == OCL_SIZE_4000)
+ declare.time(5);
- d_src.upload(src);
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, CV_32FC1);
- WARMUP_ON;
- ocl::columnSum(d_src, d_dst);
- WARMUP_OFF;
+ TEST_CYCLE() cv::ocl::columnSum(oclSrc, oclDst);
- GPU_ON;
- ocl::columnSum(d_src, d_dst);
- GPU_OFF;
+ oclDst.download(dst);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::columnSum(d_src, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() columnSumPerfTest(src, dst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 5e-1);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
-/////////// matchTemplate ////////////////////////
-//void InitMatchTemplate()
-//{
-// Mat src; gen(src, 500, 500, CV_32F, 0, 1);
-// Mat templ; gen(templ, 500, 500, CV_32F, 0, 1);
-// ocl::oclMat d_src(src), d_templ(templ), d_dst;
-// ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
-//}
-PERFTEST(matchTemplate)
-{
- //InitMatchTemplate();
- Mat src, templ, dst, ocl_dst;
- int templ_size = 5;
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- int all_type[] = {CV_32FC1, CV_32FC4};
- std::string type_name[] = {"CV_32FC1", "CV_32FC4"};
-
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- for(templ_size = 5; templ_size <= 5; templ_size *= 5)
- {
- gen(src, size, size, all_type[j], 0, 1);
-
- SUBTEST << src.cols << 'x' << src.rows << "; " << type_name[j] << "; templ " << templ_size << 'x' << templ_size << "; CCORR";
-
- gen(templ, templ_size, templ_size, all_type[j], 0, 1);
-
- matchTemplate(src, templ, dst, CV_TM_CCORR);
-
- CPU_ON;
- matchTemplate(src, templ, dst, CV_TM_CCORR);
- CPU_OFF;
-
- ocl::oclMat d_src(src), d_templ(templ), d_dst;
-
- WARMUP_ON;
- ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
- WARMUP_OFF;
+using namespace perf;
+using std::tr1::tuple;
+using std::tr1::get;
- GPU_ON;
- ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
- GPU_OFF;
+/////////// matchTemplate ////////////////////////
- GPU_FULL_ON;
- d_src.upload(src);
- d_templ.upload(templ);
- ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+CV_ENUM(CV_TM_CCORRMatType, CV_32FC1, CV_32FC4)
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, templ.rows * templ.cols * 1e-1);
- }
- }
+typedef tuple<Size, CV_TM_CCORRMatType> CV_TM_CCORRParams;
+typedef TestBaseWithParam<CV_TM_CCORRParams> CV_TM_CCORRFixture;
- int all_type_8U[] = {CV_8UC1};
- std::string type_name_8U[] = {"CV_8UC1"};
+PERF_TEST_P(CV_TM_CCORRFixture, matchTemplate,
+ ::testing::Combine(::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000),
+ CV_TM_CCORRMatType::all()))
+{
+ // getting params
+ CV_TM_CCORRParams params = GetParam();
+ const Size srcSize = get<0>(params), templSize(5, 5);
+ const int type = get<1>(params);
+
+ std::string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src(srcSize, type), templ(templSize, type);
+ const Size dstSize(src.cols - templ.cols + 1, src.rows - templ.rows + 1);
+ Mat dst(dstSize, CV_32F);
+ randu(src, 0.0f, 1.0f);
+ randu(templ, 0.0f, 1.0f);
+ declare.time(srcSize == OCL_SIZE_2000 ? 20 : 6).in(src, templ).out(dst);
+
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclTempl(templ), oclDst(dstSize, CV_32F);
- for (size_t j = 0; j < sizeof(all_type_8U) / sizeof(int); j++)
- {
- for(templ_size = 5; templ_size <= 5; templ_size *= 5)
- {
- SUBTEST << src.cols << 'x' << src.rows << "; " << type_name_8U[j] << "; templ " << templ_size << 'x' << templ_size << "; CCORR_NORMED";
+ TEST_CYCLE() cv::ocl::matchTemplate(oclSrc, oclTempl, oclDst, CV_TM_CCORR);
- gen(src, size, size, all_type_8U[j], 0, 255);
+ oclDst.download(dst);
- gen(templ, templ_size, templ_size, all_type_8U[j], 0, 255);
+ SANITY_CHECK(dst, 1e-4);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::matchTemplate(src, templ, dst, CV_TM_CCORR);
- matchTemplate(src, templ, dst, CV_TM_CCORR_NORMED);
+ SANITY_CHECK(dst, 1e-4);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
+}
- CPU_ON;
- matchTemplate(src, templ, dst, CV_TM_CCORR_NORMED);
- CPU_OFF;
+typedef TestBaseWithParam<Size> CV_TM_CCORR_NORMEDFixture;
- ocl::oclMat d_src(src);
- ocl::oclMat d_templ(templ), d_dst;
+PERF_TEST_P(CV_TM_CCORR_NORMEDFixture, matchTemplate, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam(), templSize(5, 5);
+ const std::string impl = getSelectedImpl();
+
+ // creating src data
+ Mat src(srcSize, CV_8UC1), templ(templSize, CV_8UC1), dst;
+ const Size dstSize(src.cols - templ.cols + 1, src.rows - templ.rows + 1);
+ dst.create(dstSize, CV_8UC1);
+ declare.in(src, templ, WARMUP_RNG).out(dst)
+ .time(srcSize == OCL_SIZE_2000 ? 10 : srcSize == OCL_SIZE_4000 ? 23 : 2);
+
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclTempl(templ), oclDst(dstSize, CV_8UC1);
- WARMUP_ON;
- ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR_NORMED);
- WARMUP_OFF;
+ TEST_CYCLE() cv::ocl::matchTemplate(oclSrc, oclTempl, oclDst, CV_TM_CCORR_NORMED);
- GPU_ON;
- ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR_NORMED);
- GPU_OFF;
+ oclDst.download(dst);
- GPU_FULL_ON;
- d_src.upload(src);
- d_templ.upload(templ);
- ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR_NORMED);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ SANITY_CHECK(dst, 2e-2);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::matchTemplate(src, templ, dst, CV_TM_CCORR_NORMED);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, templ.rows * templ.cols * 1e-1);
- }
- }
+ SANITY_CHECK(dst, 2e-2);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
-///////////// ConvertTo////////////////////////
-PERFTEST(ConvertTo)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
+using namespace perf;
+using std::tr1::tuple;
+using std::tr1::get;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
-
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] << " to 32FC1";
+///////////// ConvertTo////////////////////////
- gen(src, size, size, all_type[j], 0, 256);
- //gen(dst, size, size, all_type[j], 0, 256);
+CV_ENUM(ConvertToMatType, CV_8UC1, CV_8UC4)
- //d_dst.upload(dst);
+typedef tuple<Size, ConvertToMatType> ConvertToParams;
+typedef TestBaseWithParam<ConvertToParams> ConvertToFixture;
- src.convertTo(dst, CV_32FC1);
+PERF_TEST_P(ConvertToFixture, ConvertTo,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ ConvertToMatType::all()))
+{
+ // getting params
+ ConvertToParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
- CPU_ON;
- src.convertTo(dst, CV_32FC1);
- CPU_OFF;
+ std::string impl = getSelectedImpl();
- d_src.upload(src);
+ // creating src data
+ Mat src(srcSize, type), dst;
+ const int dstType = CV_MAKE_TYPE(CV_32F, src.channels());
+ dst.create(srcSize, dstType);
+ declare.in(src, WARMUP_RNG).out(dst);
- WARMUP_ON;
- d_src.convertTo(d_dst, CV_32FC1);
- WARMUP_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, dstType);
- GPU_ON;
- d_src.convertTo(d_dst, CV_32FC1);
- GPU_OFF;
+ TEST_CYCLE() oclSrc.convertTo(oclDst, dstType);
- GPU_FULL_ON;
- d_src.upload(src);
- d_src.convertTo(d_dst, CV_32FC1);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 0.0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() src.convertTo(dst, dstType);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
-///////////// copyTo////////////////////////
-PERFTEST(copyTo)
-{
- Mat src, dst, ocl_dst;
- ocl::oclMat d_src, d_dst;
-
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src, size, size, all_type[j], 0, 256);
- //gen(dst, size, size, all_type[j], 0, 256);
+///////////// copyTo////////////////////////
- //d_dst.upload(dst);
+typedef ConvertToMatType copyToMatType;
+typedef tuple<Size, copyToMatType> copyToParams;
+typedef TestBaseWithParam<copyToParams> copyToFixture;
- src.copyTo(dst);
+PERF_TEST_P(copyToFixture, copyTo,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ copyToMatType::all()))
+{
+ // getting params
+ copyToParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
- CPU_ON;
- src.copyTo(dst);
- CPU_OFF;
+ std::string impl = getSelectedImpl();
- d_src.upload(src);
+ // creating src data
+ Mat src(srcSize, type), dst(srcSize, type);
+ declare.in(src, WARMUP_RNG).out(dst);
- WARMUP_ON;
- d_src.copyTo(d_dst);
- WARMUP_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(srcSize, type);
- GPU_ON;
- d_src.copyTo(d_dst);
- GPU_OFF;
+ TEST_CYCLE() oclSrc.copyTo(oclDst);
- GPU_FULL_ON;
- d_src.upload(src);
- d_src.copyTo(d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ oclDst.download(dst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 0.0);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() src.copyTo(dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
-///////////// setTo////////////////////////
-PERFTEST(setTo)
-{
- Mat src, ocl_src;
- Scalar val(1, 2, 3, 4);
- ocl::oclMat d_src;
-
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
-
- gen(src, size, size, all_type[j], 0, 256);
+///////////// setTo////////////////////////
- src.setTo(val);
+typedef ConvertToMatType setToMatType;
+typedef tuple<Size, setToMatType> setToParams;
+typedef TestBaseWithParam<setToParams> setToFixture;
- CPU_ON;
- src.setTo(val);
- CPU_OFF;
+PERF_TEST_P(setToFixture, setTo,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ setToMatType::all()))
+{
+ // getting params
+ setToParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
+ const Scalar val(1, 2, 3, 4);
- d_src.upload(src);
+ std::string impl = getSelectedImpl();
- WARMUP_ON;
- d_src.setTo(val);
- WARMUP_OFF;
+ // creating src data
+ Mat src(srcSize, type);
+ declare.in(src);
- d_src.download(ocl_src);
- TestSystem::instance().ExpectedMatNear(src, ocl_src, 1.0);
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(srcSize, type);
- GPU_ON;;
- d_src.setTo(val);
- GPU_OFF;
+ TEST_CYCLE() oclSrc.setTo(val);
+ oclSrc.download(src);
- GPU_FULL_ON;
- d_src.upload(src);
- d_src.setTo(val);
- GPU_FULL_OFF;
- }
+ SANITY_CHECK(src);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() src.setTo(val);
+ SANITY_CHECK(src);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
+
#include "perf_precomp.hpp"
-///////////// Moments ////////////////////////
-PERFTEST(Moments)
-{
- Mat src;
- bool binaryImage = 0;
- int all_type[] = {CV_8UC1, CV_16SC1, CV_32FC1, CV_64FC1};
- std::string type_name[] = {"CV_8UC1", "CV_16SC1", "CV_32FC1", "CV_64FC1"};
+using namespace perf;
+using std::tr1::tuple;
+using std::tr1::get;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j];
+///////////// Moments ////////////////////////
- gen(src, size, size, all_type[j], 0, 256);
+CV_ENUM(MomentsMatType, CV_8UC1, CV_16SC1, CV_32FC1, CV_64FC1)
- cv::Moments CvMom = moments(src, binaryImage);
+typedef tuple<Size, MomentsMatType> MomentsParams;
+typedef TestBaseWithParam<MomentsParams> MomentsFixture;
- CPU_ON;
- moments(src, binaryImage);
- CPU_OFF;
+PERF_TEST_P(MomentsFixture, DISABLED_Moments,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ MomentsMatType::all()))
+{
+ // getting params
+ MomentsParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
- cv::Moments oclMom;
- WARMUP_ON;
- oclMom = ocl::ocl_moments(src, binaryImage);
- WARMUP_OFF;
+ std::string impl = getSelectedImpl();
- Mat gpu_dst, cpu_dst;
- HuMoments(CvMom, cpu_dst);
- HuMoments(oclMom, gpu_dst);
+ // creating src data
+ Mat src(srcSize, type), dst(7, 1, CV_64F);
+ const bool binaryImage = false;
+ cv::Moments mom;
- GPU_ON;
- ocl::ocl_moments(src, binaryImage);
- GPU_OFF;
+ declare.in(src, WARMUP_RNG).out(dst);
- GPU_FULL_ON;
- ocl::ocl_moments(src, binaryImage);
- GPU_FULL_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src);
- TestSystem::instance().ExpectedMatNear(gpu_dst, cpu_dst, .5);
+ TEST_CYCLE() mom = cv::ocl::ocl_moments(oclSrc, binaryImage);
+ cv::HuMoments(mom, dst);
- }
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() mom = cv::moments(src, binaryImage);
+ cv::HuMoments(mom, dst);
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
-///////////// norm////////////////////////
-PERFTEST(norm)
-{
- Mat src1, src2, ocl_src1;
- ocl::oclMat d_src1, d_src2;
+using namespace perf;
+using std::tr1::tuple;
+using std::tr1::get;
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- SUBTEST << size << 'x' << size << "; CV_8UC1; NORM_INF";
-
- gen(src1, size, size, CV_8UC1, Scalar::all(0), Scalar::all(1));
- gen(src2, size, size, CV_8UC1, Scalar::all(0), Scalar::all(1));
+///////////// norm////////////////////////
- norm(src1, src2, NORM_INF);
+typedef TestBaseWithParam<Size> normFixture;
- CPU_ON;
- norm(src1, src2, NORM_INF);
- CPU_OFF;
+PERF_TEST_P(normFixture, DISABLED_norm, OCL_TYPICAL_MAT_SIZES)
+{
+ // getting params
+ const Size srcSize = GetParam();
+ const std::string impl = getSelectedImpl();
+ double value = 0.0;
- d_src1.upload(src1);
- d_src2.upload(src2);
+ // creating src data
+ Mat src1(srcSize, CV_8UC1), src2(srcSize, CV_8UC1);
+ declare.in(src1, src2);
+ randu(src1, 0, 1);
+ randu(src2, 0, 1);
- WARMUP_ON;
- ocl::norm(d_src1, d_src2, NORM_INF);
- WARMUP_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc1(src1), oclSrc2(src2);
- d_src1.download(ocl_src1);
- TestSystem::instance().ExpectedMatNear(src1, ocl_src1, .5);
+ TEST_CYCLE() value = cv::ocl::norm(oclSrc1, oclSrc2, NORM_INF);
- GPU_ON;
- ocl::norm(d_src1, d_src2, NORM_INF);
- GPU_OFF;
+ SANITY_CHECK(value);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() value = cv::norm(src1, src2, NORM_INF);
- GPU_FULL_ON;
- d_src1.upload(src1);
- d_src2.upload(src2);
- ocl::norm(d_src1, d_src2, NORM_INF);
- GPU_FULL_OFF;
+ SANITY_CHECK(value);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
#include "perf_precomp.hpp"
///////////// PyrLKOpticalFlow ////////////////////////
-PERFTEST(PyrLKOpticalFlow)
-{
- std::string images1[] = {"rubberwhale1.png", "aloeL.jpg"};
- std::string images2[] = {"rubberwhale2.png", "aloeR.jpg"};
-
- for (size_t i = 0; i < sizeof(images1) / sizeof(std::string); i++)
- {
- Mat frame0 = imread(abspath(images1[i]), i == 0 ? IMREAD_COLOR : IMREAD_GRAYSCALE);
-
- if (frame0.empty())
- {
- std::string errstr = "can't open " + images1[i];
- throw runtime_error(errstr);
- }
-
- Mat frame1 = imread(abspath(images2[i]), i == 0 ? IMREAD_COLOR : IMREAD_GRAYSCALE);
-
- if (frame1.empty())
- {
- std::string errstr = "can't open " + images2[i];
- throw runtime_error(errstr);
- }
-
- Mat gray_frame;
-
- if (i == 0)
- {
- cvtColor(frame0, gray_frame, COLOR_BGR2GRAY);
- }
-
- for (int points = Min_Size; points <= Max_Size; points *= Multiple)
- {
- if (i == 0)
- SUBTEST << frame0.cols << "x" << frame0.rows << "; color; " << points << " points";
- else
- SUBTEST << frame0.cols << "x" << frame0.rows << "; gray; " << points << " points";
- Mat ocl_nextPts;
- Mat ocl_status;
-
- vector<Point2f> pts;
- goodFeaturesToTrack(i == 0 ? gray_frame : frame0, pts, points, 0.01, 0.0);
-
- vector<Point2f> nextPts;
- vector<unsigned char> status;
- vector<float> err;
+using namespace perf;
+using std::tr1::get;
+using std::tr1::tuple;
+using std::tr1::make_tuple;
- calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, err);
-
- CPU_ON;
- calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, err);
- CPU_OFF;
-
- ocl::PyrLKOpticalFlow d_pyrLK;
-
- ocl::oclMat d_frame0(frame0);
- ocl::oclMat d_frame1(frame1);
-
- ocl::oclMat d_pts;
- Mat pts_mat(1, (int)pts.size(), CV_32FC2, (void *)&pts[0]);
- d_pts.upload(pts_mat);
-
- ocl::oclMat d_nextPts;
- ocl::oclMat d_status;
- ocl::oclMat d_err;
+template <typename T>
+static vector<T> & MatToVector(const ocl::oclMat & oclSrc, vector<T> & instance)
+{
+ Mat src;
+ oclSrc.download(src);
- WARMUP_ON;
- d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status, &d_err);
- WARMUP_OFF;
+ for (int i = 0; i < src.cols; ++i)
+ instance.push_back(src.at<T>(0, i));
- GPU_ON;
- d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status, &d_err);
- GPU_OFF;
+ return instance;
+}
- GPU_FULL_ON;
- d_frame0.upload(frame0);
- d_frame1.upload(frame1);
- d_pts.upload(pts_mat);
- d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status, &d_err);
+CV_ENUM(LoadMode, IMREAD_GRAYSCALE, IMREAD_COLOR)
+
+typedef tuple<int, tuple<string, string, LoadMode> > PyrLKOpticalFlowParamType;
+typedef TestBaseWithParam<PyrLKOpticalFlowParamType> PyrLKOpticalFlowFixture;
+
+PERF_TEST_P(PyrLKOpticalFlowFixture,
+ PyrLKOpticalFlow,
+ ::testing::Combine(
+ ::testing::Values(1000, 2000, 4000),
+ ::testing::Values(
+ make_tuple<string, string, LoadMode>
+ (
+ string("gpu/opticalflow/rubberwhale1.png"),
+ string("gpu/opticalflow/rubberwhale1.png"),
+ LoadMode(IMREAD_COLOR)
+ )
+// , make_tuple<string, string, LoadMode>
+// (
+// string("gpu/stereobm/aloe-L.png"),
+// string("gpu/stereobm/aloe-R.png"),
+// LoadMode(IMREAD_GRAYSCALE)
+// )
+ )
+ )
+ )
+{
+ PyrLKOpticalFlowParamType params = GetParam();
+ tuple<string, string, LoadMode> fileParam = get<1>(params);
+ const int pointsCount = get<0>(params);
+ const int openMode = static_cast<int>(get<2>(fileParam));
+ const string fileName0 = get<0>(fileParam), fileName1 = get<1>(fileParam);
+ Mat frame0 = imread(getDataPath(fileName0), openMode);
+ Mat frame1 = imread(getDataPath(fileName1), openMode);
+ const string impl = getSelectedImpl();
+
+ ASSERT_FALSE(frame0.empty()) << "can't load " << fileName0;
+ ASSERT_FALSE(frame1.empty()) << "can't load " << fileName1;
+
+ Mat grayFrame;
+ if (openMode == IMREAD_COLOR)
+ cvtColor(frame0, grayFrame, COLOR_BGR2GRAY);
+ else
+ grayFrame = frame0;
+
+ // initialization
+ vector<Point2f> pts, nextPts;
+ vector<unsigned char> status;
+ vector<float> err;
+ goodFeaturesToTrack(grayFrame, pts, pointsCount, 0.01, 0.0);
+
+ // selecting implementation
+ if (impl == "plain")
+ {
+ TEST_CYCLE()
+ cv::calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, err);
- if (!d_nextPts.empty())
- d_nextPts.download(ocl_nextPts);
+ SANITY_CHECK(nextPts);
+ SANITY_CHECK(status);
+ SANITY_CHECK(err);
+ }
+ else if (impl == "ocl")
+ {
+ ocl::PyrLKOpticalFlow oclPyrLK;
+ ocl::oclMat oclFrame0(frame0), oclFrame1(frame1);
+ ocl::oclMat oclPts(1, static_cast<int>(pts.size()), CV_32FC2, (void *)&pts[0]);
+ ocl::oclMat oclNextPts, oclStatus, oclErr;
- if (!d_status.empty())
- d_status.download(ocl_status);
- GPU_FULL_OFF;
+ TEST_CYCLE()
+ oclPyrLK.sparse(oclFrame0, oclFrame1, oclPts, oclNextPts, oclStatus, &oclErr);
- size_t mismatch = 0;
- for (int i = 0; i < (int)nextPts.size(); ++i)
- {
- if(status[i] != ocl_status.at<unsigned char>(0, i))
- {
- mismatch++;
- continue;
- }
- if(status[i])
- {
- Point2f gpu_rst = ocl_nextPts.at<Point2f>(0, i);
- Point2f cpu_rst = nextPts[i];
- if(fabs(gpu_rst.x - cpu_rst.x) >= 1. || fabs(gpu_rst.y - cpu_rst.y) >= 1.)
- mismatch++;
- }
- }
- double ratio = (double)mismatch / (double)nextPts.size();
- if(ratio < .02)
- TestSystem::instance().setAccurate(1, ratio);
- else
- TestSystem::instance().setAccurate(0, ratio);
- }
+ MatToVector(oclNextPts, nextPts);
+ MatToVector(oclStatus, status);
+ MatToVector(oclErr, err);
+ SANITY_CHECK(nextPts);
+ SANITY_CHECK(status);
+ SANITY_CHECK(err);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
+
+// size_t mismatch = 0;
+// for (int i = 0; i < (int)nextPts.size(); ++i)
+// {
+// if(status[i] != ocl_status.at<unsigned char>(0, i))
+// {
+// mismatch++;
+// continue;
+// }
+// if(status[i])
+// {
+// Point2f gpu_rst = ocl_nextPts.at<Point2f>(0, i);
+// Point2f cpu_rst = nextPts[i];
+// if(fabs(gpu_rst.x - cpu_rst.x) >= 1. || fabs(gpu_rst.y - cpu_rst.y) >= 1.)
+// mismatch++;
+// }
+// }
+// double ratio = (double)mismatch / (double)nextPts.size();
+// if(ratio < .02)
+// TestSystem::instance().setAccurate(1, ratio);
+// else
+// TestSystem::instance().setAccurate(0, ratio);
}
//
//M*/
+#ifdef __GNUC__
+# pragma GCC diagnostic ignored "-Wmissing-declarations"
+# pragma GCC diagnostic ignored "-Wunused-function"
+# if defined __clang__ || defined __APPLE__
+# pragma GCC diagnostic ignored "-Wmissing-prototypes"
+# pragma GCC diagnostic ignored "-Wextra"
+# endif
+#endif
+
#ifndef __OPENCV_PERF_PRECOMP_HPP__
#define __OPENCV_PERF_PRECOMP_HPP__
#include <cstdio>
#include <vector>
#include <numeric>
+
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/ocl/ocl.hpp"
#include "opencv2/ts/ts.hpp"
-#include "opencv2/ts/ts_perf.hpp"
-#include "opencv2/ts/ts_gtest.h"
+#define OCL_SIZE_1000 cv::Size(1000, 1000)
+#define OCL_SIZE_2000 cv::Size(2000, 2000)
+#define OCL_SIZE_4000 cv::Size(4000, 4000)
+
+#define OCL_TYPICAL_MAT_SIZES ::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000, OCL_SIZE_4000)
#define Min_Size 1000
#define Max_Size 4000
string abspath(const string &relpath);
int CV_CDECL cvErrorCallback(int, const char *, const char *, const char *, int, void *);
-typedef struct
-{
- short x;
- short y;
-} COOR;
-COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep,
- cv::Size size, int sp, int sr, int maxIter, float eps, int *tab);
-void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi,
- int sp, int sr, cv::TermCriteria crit);
+//typedef struct
+//{
+// short x;
+// short y;
+//} COOR;
+//COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep,
+// cv::Size size, int sp, int sr, int maxIter, float eps, int *tab);
+//void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi,
+// int sp, int sr, cv::TermCriteria crit);
template<class T1, class T2>
//M*/
#include "perf_precomp.hpp"
+using namespace perf;
+using std::tr1::tuple;
+using std::tr1::get;
+
///////////// pyrDown //////////////////////
-PERFTEST(pyrDown)
-{
- Mat src, dst, ocl_dst;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+CV_ENUM(pyrDownMatType, CV_8UC1, CV_8UC4)
- gen(src, size, size, all_type[j], 0, 256);
+typedef tuple<Size, pyrDownMatType> pyrDownParams;
+typedef TestBaseWithParam<pyrDownParams> pyrDownFixture;
- pyrDown(src, dst);
+PERF_TEST_P(pyrDownFixture, pyrDown,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ pyrDownMatType::all()))
+{
+ // getting params
+ pyrDownParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
- CPU_ON;
- pyrDown(src, dst);
- CPU_OFF;
+ std::string impl = getSelectedImpl();
- ocl::oclMat d_src(src);
- ocl::oclMat d_dst;
+ // creating src data
+ Mat src(srcSize, type), dst;
+ Size dstSize((srcSize.height + 1) >> 1, (srcSize.width + 1) >> 1);
+ dst.create(dstSize, type);
+ declare.in(src).out(dst);
- WARMUP_ON;
- ocl::pyrDown(d_src, d_dst);
- WARMUP_OFF;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(dstSize, type);
+
+ TEST_CYCLE() cv::ocl::pyrDown(oclSrc, oclDst);
- GPU_ON;
- ocl::pyrDown(d_src, d_dst);
- GPU_OFF;
+ oclDst.download(dst);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::pyrDown(d_src, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::pyrDown(src, dst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, dst.depth() == CV_32F ? 1e-4f : 1.0f);
- }
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
///////////// pyrUp ////////////////////////
-PERFTEST(pyrUp)
-{
- Mat src, dst, ocl_dst;
- int all_type[] = {CV_8UC1, CV_8UC4};
- std::string type_name[] = {"CV_8UC1", "CV_8UC4"};
- for (int size = 500; size <= 2000; size *= 2)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
+typedef pyrDownMatType pyrUpMatType;
+typedef tuple<Size, pyrUpMatType> pyrUpParams;
+typedef TestBaseWithParam<pyrUpParams> pyrUpFixture;
- gen(src, size, size, all_type[j], 0, 256);
+PERF_TEST_P(pyrUpFixture, pyrUp,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ pyrUpMatType::all()))
+{
+ // getting params
+ pyrUpParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int type = get<1>(params);
- pyrUp(src, dst);
+ std::string impl = getSelectedImpl();
- CPU_ON;
- pyrUp(src, dst);
- CPU_OFF;
+ // creating src data
+ Mat src(srcSize, type), dst;
+ Size dstSize(srcSize.height << 1, srcSize.width << 1);
+ dst.create(dstSize, type);
+ declare.in(src).out(dst);
- ocl::oclMat d_src(src);
- ocl::oclMat d_dst;
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src), oclDst(dstSize, type);
- WARMUP_ON;
- ocl::pyrUp(d_src, d_dst);
- WARMUP_OFF;
+ TEST_CYCLE() cv::ocl::pyrDown(oclSrc, oclDst);
- GPU_ON;
- ocl::pyrUp(d_src, d_dst);
- GPU_OFF;
+ oclDst.download(dst);
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::pyrUp(d_src, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::pyrDown(src, dst);
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, (src.depth() == CV_32F ? 1e-4f : 1.0));
- }
+ SANITY_CHECK(dst);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}
//M*/
#include "perf_precomp.hpp"
+using namespace perf;
+using std::tr1::tuple;
+using std::tr1::get;
+
///////////// Merge////////////////////////
-PERFTEST(Merge)
-{
- Mat dst, ocl_dst;
- ocl::oclMat d_dst;
- int channels = 4;
- int all_type[] = {CV_8UC1, CV_32FC1};
- std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
+CV_ENUM(MergeMatType, CV_8U, CV_32F)
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
- {
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j] ;
- Size size1 = Size(size, size);
- std::vector<Mat> src(channels);
-
- for (int i = 0; i < channels; ++i)
- {
- src[i] = Mat(size1, all_type[j], cv::Scalar::all(i));
- }
-
- merge(src, dst);
-
- CPU_ON;
- merge(src, dst);
- CPU_OFF;
-
- std::vector<ocl::oclMat> d_src(channels);
-
- for (int i = 0; i < channels; ++i)
- {
- d_src[i] = ocl::oclMat(size1, all_type[j], cv::Scalar::all(i));
- }
-
- WARMUP_ON;
- ocl::merge(d_src, d_dst);
- WARMUP_OFF;
-
- GPU_ON;
- ocl::merge(d_src, d_dst);
- GPU_OFF;
-
- GPU_FULL_ON;
- for (int i = 0; i < channels; ++i)
- {
- d_src[i] = ocl::oclMat(size1, all_type[j], cv::Scalar::all(i));
- }
- ocl::merge(d_src, d_dst);
- d_dst.download(ocl_dst);
- GPU_FULL_OFF;
-
- TestSystem::instance().ExpectedMatNear(dst, ocl_dst, 0.0);
- }
+typedef tuple<Size, MergeMatType> MergeParams;
+typedef TestBaseWithParam<MergeParams> MergeFixture;
- }
-}
-
-///////////// Split////////////////////////
-PERFTEST(Split)
+PERF_TEST_P(MergeFixture, Merge,
+ ::testing::Combine(::testing::Values(OCL_SIZE_1000, OCL_SIZE_2000),
+ MergeMatType::all()))
{
- //int channels = 4;
- int all_type[] = {CV_8UC1, CV_32FC1};
- std::string type_name[] = {"CV_8UC1", "CV_32FC1"};
+ // getting params
+ MergeParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int depth = get<1>(params), channels = 3;
+
+ std::string impl = getSelectedImpl();
+
+ // creating src data
+ const int dstType = CV_MAKE_TYPE(depth, channels);
+ Mat dst(srcSize, dstType);
+ vector<Mat> src(channels);
+ for (vector<Mat>::iterator i = src.begin(), end = src.end(); i != end; ++i)
+ {
+ i->create(srcSize, CV_MAKE_TYPE(depth, 1));
+ declare.in(*i, WARMUP_RNG);
+ }
+ declare.out(dst);
- for (int size = Min_Size; size <= Max_Size; size *= Multiple)
+ // select implementation
+ if (impl == "ocl")
{
- for (size_t j = 0; j < sizeof(all_type) / sizeof(int); j++)
- {
- SUBTEST << size << 'x' << size << "; " << type_name[j];
- Size size1 = Size(size, size);
+ ocl::oclMat oclDst(srcSize, dstType);
+ vector<ocl::oclMat> oclSrc(src.size());
+ for (vector<ocl::oclMat>::size_type i = 0, end = src.size(); i < end; ++i)
+ oclSrc[i] = src[i];
- Mat src(size1, CV_MAKE_TYPE(all_type[j], 4), cv::Scalar(1, 2, 3, 4));
+ TEST_CYCLE() cv::ocl::merge(oclSrc, oclDst);
- std::vector<cv::Mat> dst, ocl_dst(4);
+ oclDst.download(dst);
- split(src, dst);
+ SANITY_CHECK(dst);
+ }
+ else if (impl == "plain")
+ {
+ TEST_CYCLE() cv::merge(src, dst);
- CPU_ON;
- split(src, dst);
- CPU_OFF;
+ SANITY_CHECK(dst);
+ }
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
+}
- ocl::oclMat d_src(size1, CV_MAKE_TYPE(all_type[j], 4), cv::Scalar(1, 2, 3, 4));
- std::vector<cv::ocl::oclMat> d_dst;
+///////////// Split////////////////////////
- WARMUP_ON;
- ocl::split(d_src, d_dst);
- WARMUP_OFF;
+typedef MergeMatType SplitMatType;
+typedef tuple<Size, SplitMatType> SplitParams;
+typedef TestBaseWithParam<SplitParams> SplitFixture;
- GPU_ON;
- ocl::split(d_src, d_dst);
- GPU_OFF;
+PERF_TEST_P(SplitFixture, Split,
+ ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
+ SplitMatType::all()))
+{
+ // getting params
+ MergeParams params = GetParam();
+ const Size srcSize = get<0>(params);
+ const int depth = get<1>(params), channels = 3;
- GPU_FULL_ON;
- d_src.upload(src);
- ocl::split(d_src, d_dst);
- for(size_t i = 0; i < dst.size(); i++)
- d_dst[i].download(ocl_dst[i]);
- GPU_FULL_OFF;
+ std::string impl = getSelectedImpl();
- vector<double> eps(4, 0.);
- TestSystem::instance().ExpectMatsNear(dst, ocl_dst, eps);
- }
+ // creating src data
+ Mat src(srcSize, CV_MAKE_TYPE(depth, channels));
+ declare.in(src, WARMUP_RNG);
+ // select implementation
+ if (impl == "ocl")
+ {
+ ocl::oclMat oclSrc(src);
+ vector<ocl::oclMat> oclDst(channels, ocl::oclMat(srcSize, CV_MAKE_TYPE(depth, 1)));
+
+ TEST_CYCLE() cv::ocl::split(oclSrc, oclDst);
+
+ AssertEQ(channels, 3);
+ Mat dst0, dst1, dst2;
+ oclDst[0].download(dst0);
+ oclDst[1].download(dst1);
+ oclDst[2].download(dst2);
+ SANITY_CHECK(dst0);
+ SANITY_CHECK(dst1);
+ SANITY_CHECK(dst2);
+ }
+ else if (impl == "plain")
+ {
+ vector<Mat> dst(channels, Mat(srcSize, CV_MAKE_TYPE(depth, 1)));
+ TEST_CYCLE() cv::split(src, dst);
+
+ AssertEQ(channels, 3);
+ Mat & dst0 = dst[0], & dst1 = dst[1], & dst2 = dst[2];
+ SANITY_CHECK(dst0);
+ SANITY_CHECK(dst1);
+ SANITY_CHECK(dst2);
}
+#ifdef HAVE_OPENCV_GPU
+ else if (impl == "gpu")
+ CV_TEST_FAIL_NO_IMPL();
+#endif
+ else
+ CV_TEST_FAIL_NO_IMPL();
}