ocl: tests: RNG usage refactoring

pull/1545/head
Alexander Alekhin 11 years ago
parent 8224f9843e
commit de0f310e81
  1. 330
      modules/ocl/test/test_arithm.cpp
  2. 14
      modules/ocl/test/test_bgfg.cpp
  3. 2
      modules/ocl/test/test_brute_force_matcher.cpp
  4. 4
      modules/ocl/test/test_calib3d.cpp
  5. 4
      modules/ocl/test/test_filters.cpp
  6. 80
      modules/ocl/test/test_imgproc.cpp
  7. 6
      modules/ocl/test/test_kalman.cpp
  8. 7
      modules/ocl/test/test_kmeans.cpp
  9. 8
      modules/ocl/test/test_match_template.cpp
  10. 26
      modules/ocl/test/test_matrix_operation.cpp
  11. 13
      modules/ocl/test/test_ml.cpp
  12. 6
      modules/ocl/test/test_moments.cpp
  13. 2
      modules/ocl/test/test_objdetect.cpp
  14. 8
      modules/ocl/test/test_optflow.cpp
  15. 2
      modules/ocl/test/test_precomp.hpp
  16. 4
      modules/ocl/test/test_pyramids.cpp
  17. 12
      modules/ocl/test/test_split_merge.cpp
  18. 73
      modules/ocl/test/utility.cpp
  19. 193
      modules/ocl/test/utility.hpp

@ -80,12 +80,14 @@ PARAM_TEST_CASE(Lut, int, int, bool, bool)
cv::Mat dst_roi; cv::Mat dst_roi;
// ocl dst mat for testing // ocl dst mat for testing
cv::ocl::oclMat gsrc_whole;
cv::ocl::oclMat glut_whole;
cv::ocl::oclMat gdst_whole; cv::ocl::oclMat gdst_whole;
// ocl mat with roi // ocl mat with roi
cv::ocl::oclMat gsrc; cv::ocl::oclMat gsrc_roi;
cv::ocl::oclMat glut; cv::ocl::oclMat glut_roi;
cv::ocl::oclMat gdst; cv::ocl::oclMat gdst_roi;
virtual void SetUp() virtual void SetUp()
{ {
@ -93,66 +95,34 @@ PARAM_TEST_CASE(Lut, int, int, bool, bool)
cn = GET_PARAM(1); cn = GET_PARAM(1);
same_cn = GET_PARAM(2); same_cn = GET_PARAM(2);
use_roi = GET_PARAM(3); use_roi = GET_PARAM(3);
const int src_type = CV_MAKE_TYPE(CV_8U, cn);
const int lut_type = CV_MAKE_TYPE(lut_depth, same_cn ? cn : 1);
const int dst_type = CV_MAKE_TYPE(lut_depth, cn);
cv::RNG &rng = TS::ptr()->get_rng();
src = randomMat(rng, randomSize(MIN_VALUE, MAX_VALUE), src_type, 0, 256, false);
lut = randomMat(rng, use_roi ? randomSize(260, 300) : Size(256, 1), lut_type, 5, 16, false);
dst = randomMat(rng, use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : src.size(), dst_type, 5, 16, false);
} }
void random_roi() void random_roi()
{ {
// set up roi const int src_type = CV_MAKE_TYPE(CV_8U, cn);
int roicols, roirows; const int lut_type = CV_MAKE_TYPE(lut_depth, same_cn ? cn : 1);
int srcx, srcy; const int dst_type = CV_MAKE_TYPE(lut_depth, cn);
int lutx, luty;
int dstx, dsty;
if (use_roi)
{
// randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, MIN_VALUE);
roirows = rng.uniform(1, MIN_VALUE);
srcx = rng.uniform(0, src.cols - roicols);
srcy = rng.uniform(0, src.rows - roirows);
lutx = rng.uniform(0, lut.cols - 256);
luty = rng.uniform(0, lut.rows - 1);
dstx = rng.uniform(0, dst.cols - roicols); Size roiSize = randomSize(1, MAX_VALUE);
dsty = rng.uniform(0, dst.rows - roirows); Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
} randomSubMat(src, src_roi, roiSize, srcBorder, src_type, 0, 256);
else
{
roicols = src.cols;
roirows = src.rows;
srcx = srcy = 0;
lutx = luty = 0;
dstx = dsty = 0;
}
src_roi = src(Rect(srcx, srcy, roicols, roirows)); Size lutRoiSize = Size(256, 1);
lut_roi = lut(Rect(lutx, luty, 256, 1)); Border lutBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
dst_roi = dst(Rect(dstx, dsty, roicols, roirows)); randomSubMat(lut, lut_roi, lutRoiSize, lutBorder, lut_type, 5, 16);
gdst_whole = dst; Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows)); randomSubMat(dst, dst_roi, roiSize, dstBorder, dst_type, 5, 16);
gsrc = src_roi; generateOclMat(gsrc_whole, gsrc_roi, src, roiSize, srcBorder);
glut = lut_roi; generateOclMat(glut_whole, glut_roi, lut, lutRoiSize, lutBorder);
generateOclMat(gdst_whole, gdst_roi, dst, roiSize, dstBorder);
} }
void Near(double threshold = 0.) void Near(double threshold = 0.)
{ {
EXPECT_MAT_NEAR(dst, Mat(gdst_whole), threshold); EXPECT_MAT_NEAR(dst, Mat(gdst_whole), threshold);
EXPECT_MAT_NEAR(dst_roi, Mat(gdst), threshold); EXPECT_MAT_NEAR(dst_roi, Mat(gdst_roi), threshold);
} }
}; };
@ -163,7 +133,7 @@ TEST_P(Lut, Mat)
random_roi(); random_roi();
cv::LUT(src_roi, lut_roi, dst_roi); cv::LUT(src_roi, lut_roi, dst_roi);
cv::ocl::LUT(gsrc, glut, gdst); cv::ocl::LUT(gsrc_roi, glut_roi, gdst_roi);
Near(); Near();
} }
@ -183,50 +153,34 @@ PARAM_TEST_CASE(ArithmTestBase, int, int, bool)
cv::Mat src2; cv::Mat src2;
cv::Mat mask; cv::Mat mask;
cv::Mat dst1; cv::Mat dst1;
cv::Mat dst2; // for two outputs cv::Mat dst2;
// set up roi
int roicols, roirows;
int src1x, src1y;
int src2x, src2y;
int dst1x, dst1y;
int dst2x, dst2y;
int maskx, masky;
// src mat with roi // src mat with roi
cv::Mat src1_roi; cv::Mat src1_roi;
cv::Mat src2_roi; cv::Mat src2_roi;
cv::Mat mask_roi; cv::Mat mask_roi;
cv::Mat dst1_roi; cv::Mat dst1_roi;
cv::Mat dst2_roi; // for two outputs cv::Mat dst2_roi;
// ocl dst mat for testing // ocl dst mat for testing
cv::ocl::oclMat gsrc1_whole;
cv::ocl::oclMat gsrc2_whole;
cv::ocl::oclMat gdst1_whole; cv::ocl::oclMat gdst1_whole;
cv::ocl::oclMat gdst2_whole; // for two outputs cv::ocl::oclMat gdst2_whole;
cv::ocl::oclMat gmask_whole;
// ocl mat with roi // ocl mat with roi
cv::ocl::oclMat gsrc1; cv::ocl::oclMat gsrc1_roi;
cv::ocl::oclMat gsrc2; cv::ocl::oclMat gsrc2_roi;
cv::ocl::oclMat gdst1; cv::ocl::oclMat gdst1_roi;
cv::ocl::oclMat gdst2; // for two outputs cv::ocl::oclMat gdst2_roi;
cv::ocl::oclMat gmask; cv::ocl::oclMat gmask_roi;
virtual void SetUp() virtual void SetUp()
{ {
depth = GET_PARAM(0); depth = GET_PARAM(0);
cn = GET_PARAM(1); cn = GET_PARAM(1);
use_roi = GET_PARAM(2); use_roi = GET_PARAM(2);
const int type = CV_MAKE_TYPE(depth, cn);
cv::RNG &rng = TS::ptr()->get_rng();
src1 = randomMat(rng, randomSize(MIN_VALUE, MAX_VALUE), type, 2, 11, false);
src2 = randomMat(rng, !use_roi ? src1.size() : randomSize(MIN_VALUE, MAX_VALUE), type, -1540, 1740, false);
dst1 = randomMat(rng, !use_roi ? src1.size() : randomSize(MIN_VALUE, MAX_VALUE), type, 5, 16, false);
dst2 = randomMat(rng, !use_roi ? src1.size() : randomSize(MIN_VALUE, MAX_VALUE), type, 5, 16, false);
mask = randomMat(rng, !use_roi ? src1.size() : randomSize(MIN_VALUE, MAX_VALUE), CV_8UC1, 0, 2, false);
cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
val = cv::Scalar(rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0), val = cv::Scalar(rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0),
rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0)); rng.uniform(-100.0, 100.0), rng.uniform(-100.0, 100.0));
@ -234,65 +188,43 @@ PARAM_TEST_CASE(ArithmTestBase, int, int, bool)
void random_roi() void random_roi()
{ {
if (use_roi) const int type = CV_MAKE_TYPE(depth, cn);
{
// randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, MIN_VALUE);
roirows = rng.uniform(1, MIN_VALUE);
src1x = rng.uniform(0, src1.cols - roicols); Size roiSize = randomSize(1, MAX_VALUE);
src1y = rng.uniform(0, src1.rows - roirows); Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
src2x = rng.uniform(0, src2.cols - roicols); randomSubMat(src1, src1_roi, roiSize, srcBorder, type, 2, 11);
src2y = rng.uniform(0, src2.rows - roirows);
dst1x = rng.uniform(0, dst1.cols - roicols); Border src2Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
dst1y = rng.uniform(0, dst1.rows - roirows); randomSubMat(src2, src2_roi, roiSize, src2Border, type, -1540, 1740);
dst2x = rng.uniform(0, dst2.cols - roicols);
dst2y = rng.uniform(0, dst2.rows - roirows);
maskx = rng.uniform(0, mask.cols - roicols); Border dst1Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
masky = rng.uniform(0, mask.rows - roirows); randomSubMat(dst1, dst1_roi, roiSize, dst1Border, type, 5, 16);
}
else
{
roicols = src1.cols;
roirows = src1.rows;
src1x = src1y = 0;
src2x = src2y = 0;
dst1x = dst1y = 0;
dst2x = dst2y = 0;
maskx = masky = 0;
}
src1_roi = src1(Rect(src1x, src1y, roicols, roirows)); Border dst2Border = randomBorder(0, use_roi ? MAX_VALUE : 0);
src2_roi = src2(Rect(src2x, src2y, roicols, roirows)); randomSubMat(dst2, dst2_roi, roiSize, dst2Border, type, 5, 16);
mask_roi = mask(Rect(maskx, masky, roicols, roirows));
dst1_roi = dst1(Rect(dst1x, dst1y, roicols, roirows));
dst2_roi = dst2(Rect(dst2x, dst2y, roicols, roirows));
gdst1_whole = dst1; Border maskBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
gdst1 = gdst1_whole(Rect(dst1x, dst1y, roicols, roirows)); randomSubMat(mask, mask_roi, roiSize, maskBorder, CV_8UC1, 0, 2);
cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
gdst2_whole = dst2;
gdst2 = gdst2_whole(Rect(dst2x, dst2y, roicols, roirows));
gsrc1 = src1_roi; generateOclMat(gsrc1_whole, gsrc1_roi, src1, roiSize, srcBorder);
gsrc2 = src2_roi; generateOclMat(gsrc2_whole, gsrc2_roi, src2, roiSize, src2Border);
gmask = mask_roi; generateOclMat(gdst1_whole, gdst1_roi, dst1, roiSize, dst1Border);
generateOclMat(gdst2_whole, gdst2_roi, dst2, roiSize, dst2Border);
generateOclMat(gmask_whole, gmask_roi, mask, roiSize, maskBorder);
} }
void Near(double threshold = 0.) void Near(double threshold = 0.)
{ {
EXPECT_MAT_NEAR(dst1, Mat(gdst1_whole), threshold); EXPECT_MAT_NEAR(dst1, Mat(gdst1_whole), threshold);
EXPECT_MAT_NEAR(dst1_roi, Mat(gdst1), threshold); EXPECT_MAT_NEAR(dst1_roi, Mat(gdst1_roi), threshold);
} }
void Near1(double threshold = 0.) void Near1(double threshold = 0.)
{ {
EXPECT_MAT_NEAR(dst2, Mat(gdst2_whole), threshold); EXPECT_MAT_NEAR(dst2, Mat(gdst2_whole), threshold);
EXPECT_MAT_NEAR(dst2_roi, Mat(gdst2), threshold); EXPECT_MAT_NEAR(dst2_roi, Mat(gdst2_roi), threshold);
} }
}; };
@ -307,7 +239,7 @@ TEST_P(Exp, Mat)
random_roi(); random_roi();
cv::exp(src1_roi, dst1_roi); cv::exp(src1_roi, dst1_roi);
cv::ocl::exp(gsrc1, gdst1); cv::ocl::exp(gsrc1_roi, gdst1_roi);
Near(2); Near(2);
} }
@ -324,7 +256,7 @@ TEST_P(Log, Mat)
random_roi(); random_roi();
cv::log(src1_roi, dst1_roi); cv::log(src1_roi, dst1_roi);
cv::ocl::log(gsrc1, gdst1); cv::ocl::log(gsrc1_roi, gdst1_roi);
Near(1); Near(1);
} }
} }
@ -340,7 +272,7 @@ TEST_P(Add, Mat)
random_roi(); random_roi();
cv::add(src1_roi, src2_roi, dst1_roi); cv::add(src1_roi, src2_roi, dst1_roi);
cv::ocl::add(gsrc1, gsrc2, gdst1); cv::ocl::add(gsrc1_roi, gsrc2_roi, gdst1_roi);
Near(0); Near(0);
} }
} }
@ -352,7 +284,7 @@ TEST_P(Add, Mat_Mask)
random_roi(); random_roi();
cv::add(src1_roi, src2_roi, dst1_roi, mask_roi); cv::add(src1_roi, src2_roi, dst1_roi, mask_roi);
cv::ocl::add(gsrc1, gsrc2, gdst1, gmask); cv::ocl::add(gsrc1_roi, gsrc2_roi, gdst1_roi, gmask_roi);
Near(0); Near(0);
} }
} }
@ -364,7 +296,7 @@ TEST_P(Add, Scalar)
random_roi(); random_roi();
cv::add(src1_roi, val, dst1_roi); cv::add(src1_roi, val, dst1_roi);
cv::ocl::add(gsrc1, val, gdst1); cv::ocl::add(gsrc1_roi, val, gdst1_roi);
Near(1e-5); Near(1e-5);
} }
} }
@ -376,7 +308,7 @@ TEST_P(Add, Scalar_Mask)
random_roi(); random_roi();
cv::add(src1_roi, val, dst1_roi, mask_roi); cv::add(src1_roi, val, dst1_roi, mask_roi);
cv::ocl::add(gsrc1, val, gdst1, gmask); cv::ocl::add(gsrc1_roi, val, gdst1_roi, gmask_roi);
Near(1e-5); Near(1e-5);
} }
} }
@ -392,7 +324,7 @@ TEST_P(Sub, Mat)
random_roi(); random_roi();
cv::subtract(src1_roi, src2_roi, dst1_roi); cv::subtract(src1_roi, src2_roi, dst1_roi);
cv::ocl::subtract(gsrc1, gsrc2, gdst1); cv::ocl::subtract(gsrc1_roi, gsrc2_roi, gdst1_roi);
Near(0); Near(0);
} }
@ -405,7 +337,7 @@ TEST_P(Sub, Mat_Mask)
random_roi(); random_roi();
cv::subtract(src1_roi, src2_roi, dst1_roi, mask_roi); cv::subtract(src1_roi, src2_roi, dst1_roi, mask_roi);
cv::ocl::subtract(gsrc1, gsrc2, gdst1, gmask); cv::ocl::subtract(gsrc1_roi, gsrc2_roi, gdst1_roi, gmask_roi);
Near(0); Near(0);
} }
} }
@ -417,7 +349,7 @@ TEST_P(Sub, Scalar)
random_roi(); random_roi();
cv::subtract(src1_roi, val, dst1_roi); cv::subtract(src1_roi, val, dst1_roi);
cv::ocl::subtract(gsrc1, val, gdst1); cv::ocl::subtract(gsrc1_roi, val, gdst1_roi);
Near(1e-5); Near(1e-5);
} }
@ -430,7 +362,7 @@ TEST_P(Sub, Scalar_Mask)
random_roi(); random_roi();
cv::subtract(src1_roi, val, dst1_roi, mask_roi); cv::subtract(src1_roi, val, dst1_roi, mask_roi);
cv::ocl::subtract(gsrc1, val, gdst1, gmask); cv::ocl::subtract(gsrc1_roi, val, gdst1_roi, gmask_roi);
Near(1e-5); Near(1e-5);
} }
} }
@ -446,7 +378,7 @@ TEST_P(Mul, Mat)
random_roi(); random_roi();
cv::multiply(src1_roi, src2_roi, dst1_roi); cv::multiply(src1_roi, src2_roi, dst1_roi);
cv::ocl::multiply(gsrc1, gsrc2, gdst1); cv::ocl::multiply(gsrc1_roi, gsrc2_roi, gdst1_roi);
Near(0); Near(0);
} }
} }
@ -458,9 +390,9 @@ TEST_P(Mul, Scalar)
random_roi(); random_roi();
cv::multiply(val[0], src1_roi, dst1_roi); cv::multiply(val[0], src1_roi, dst1_roi);
cv::ocl::multiply(val[0], gsrc1, gdst1); cv::ocl::multiply(val[0], gsrc1_roi, gdst1_roi);
Near(gdst1.depth() >= CV_32F ? 1e-3 : 1); Near(gdst1_roi.depth() >= CV_32F ? 1e-3 : 1);
} }
} }
@ -471,9 +403,9 @@ TEST_P(Mul, Mat_Scalar)
random_roi(); random_roi();
cv::multiply(src1_roi, src2_roi, dst1_roi, val[0]); cv::multiply(src1_roi, src2_roi, dst1_roi, val[0]);
cv::ocl::multiply(gsrc1, gsrc2, gdst1, val[0]); cv::ocl::multiply(gsrc1_roi, gsrc2_roi, gdst1_roi, val[0]);
Near(gdst1.depth() >= CV_32F ? 1e-3 : 1); Near(gdst1_roi.depth() >= CV_32F ? 1e-3 : 1);
} }
} }
@ -488,7 +420,7 @@ TEST_P(Div, Mat)
random_roi(); random_roi();
cv::divide(src1_roi, src2_roi, dst1_roi); cv::divide(src1_roi, src2_roi, dst1_roi);
cv::ocl::divide(gsrc1, gsrc2, gdst1); cv::ocl::divide(gsrc1_roi, gsrc2_roi, gdst1_roi);
Near(1); Near(1);
} }
} }
@ -500,9 +432,9 @@ TEST_P(Div, Scalar)
random_roi(); random_roi();
cv::divide(val[0], src1_roi, dst1_roi); cv::divide(val[0], src1_roi, dst1_roi);
cv::ocl::divide(val[0], gsrc1, gdst1); cv::ocl::divide(val[0], gsrc1_roi, gdst1_roi);
Near(gdst1.depth() >= CV_32F ? 1e-3 : 1); Near(gdst1_roi.depth() >= CV_32F ? 1e-3 : 1);
} }
} }
@ -513,9 +445,9 @@ TEST_P(Div, Mat_Scalar)
random_roi(); random_roi();
cv::divide(src1_roi, src2_roi, dst1_roi, val[0]); cv::divide(src1_roi, src2_roi, dst1_roi, val[0]);
cv::ocl::divide(gsrc1, gsrc2, gdst1, val[0]); cv::ocl::divide(gsrc1_roi, gsrc2_roi, gdst1_roi, val[0]);
Near(gdst1.depth() >= CV_32F ? 1e-3 : 1); Near(gdst1_roi.depth() >= CV_32F ? 1e-3 : 1);
} }
} }
@ -530,7 +462,7 @@ TEST_P(Absdiff, Mat)
random_roi(); random_roi();
cv::absdiff(src1_roi, src2_roi, dst1_roi); cv::absdiff(src1_roi, src2_roi, dst1_roi);
cv::ocl::absdiff(gsrc1, gsrc2, gdst1); cv::ocl::absdiff(gsrc1_roi, gsrc2_roi, gdst1_roi);
Near(0); Near(0);
} }
} }
@ -542,7 +474,7 @@ TEST_P(Absdiff, Mat_Scalar)
random_roi(); random_roi();
cv::absdiff(src1_roi, val, dst1_roi); cv::absdiff(src1_roi, val, dst1_roi);
cv::ocl::absdiff(gsrc1, val, gdst1); cv::ocl::absdiff(gsrc1_roi, val, gdst1_roi);
Near(1e-5); Near(1e-5);
} }
} }
@ -558,7 +490,7 @@ TEST_P(CartToPolar, angleInDegree)
random_roi(); random_roi();
cv::cartToPolar(src1_roi, src2_roi, dst1_roi, dst2_roi, true); cv::cartToPolar(src1_roi, src2_roi, dst1_roi, dst2_roi, true);
cv::ocl::cartToPolar(gsrc1, gsrc2, gdst1, gdst2, true); cv::ocl::cartToPolar(gsrc1_roi, gsrc2_roi, gdst1_roi, gdst2_roi, true);
Near(.5); Near(.5);
Near1(.5); Near1(.5);
} }
@ -571,7 +503,7 @@ TEST_P(CartToPolar, angleInRadians)
random_roi(); random_roi();
cv::cartToPolar(src1_roi, src2_roi, dst1_roi, dst2_roi); cv::cartToPolar(src1_roi, src2_roi, dst1_roi, dst2_roi);
cv::ocl::cartToPolar(gsrc1, gsrc2, gdst1, gdst2); cv::ocl::cartToPolar(gsrc1_roi, gsrc2_roi, gdst1_roi, gdst2_roi);
Near(.5); Near(.5);
Near1(.5); Near1(.5);
} }
@ -588,7 +520,7 @@ TEST_P(PolarToCart, angleInDegree)
random_roi(); random_roi();
cv::polarToCart(src1_roi, src2_roi, dst1_roi, dst2_roi, true); cv::polarToCart(src1_roi, src2_roi, dst1_roi, dst2_roi, true);
cv::ocl::polarToCart(gsrc1, gsrc2, gdst1, gdst2, true); cv::ocl::polarToCart(gsrc1_roi, gsrc2_roi, gdst1_roi, gdst2_roi, true);
Near(.5); Near(.5);
Near1(.5); Near1(.5);
@ -602,7 +534,7 @@ TEST_P(PolarToCart, angleInRadians)
random_roi(); random_roi();
cv::polarToCart(src1_roi, src2_roi, dst1_roi, dst2_roi); cv::polarToCart(src1_roi, src2_roi, dst1_roi, dst2_roi);
cv::ocl::polarToCart(gsrc1, gsrc2, gdst1, gdst2); cv::ocl::polarToCart(gsrc1_roi, gsrc2_roi, gdst1_roi, gdst2_roi);
Near(.5); Near(.5);
Near1(.5); Near1(.5);
@ -620,7 +552,7 @@ TEST_P(Magnitude, Mat)
random_roi(); random_roi();
cv::magnitude(src1_roi, src2_roi, dst1_roi); cv::magnitude(src1_roi, src2_roi, dst1_roi);
cv::ocl::magnitude(gsrc1, gsrc2, gdst1); cv::ocl::magnitude(gsrc1_roi, gsrc2_roi, gdst1_roi);
Near(depth == CV_64F ? 1e-5 : 1e-2); Near(depth == CV_64F ? 1e-5 : 1e-2);
} }
} }
@ -636,7 +568,7 @@ TEST_P(Transpose, Mat)
random_roi(); random_roi();
cv::transpose(src1_roi, dst1_roi); cv::transpose(src1_roi, dst1_roi);
cv::ocl::transpose(gsrc1, gdst1); cv::ocl::transpose(gsrc1_roi, gdst1_roi);
Near(1e-5); Near(1e-5);
} }
@ -644,35 +576,23 @@ TEST_P(Transpose, Mat)
TEST_P(Transpose, SquareInplace) TEST_P(Transpose, SquareInplace)
{ {
cv::RNG &rng = TS::ptr()->get_rng(); const int type = CV_MAKE_TYPE(depth, cn);
int value = randomInt(MIN_VALUE, MAX_VALUE);
src1 = randomMat(rng, Size(value, value), CV_MAKE_TYPE(depth, cn), 5, 16, false);
if (use_roi) for (int j = 0; j < LOOP_TIMES; j++)
{ {
roirows = roicols = randomInt(1, src1.cols); Size roiSize = randomSize(1, MAX_VALUE);
roiSize.height = roiSize.width; // make it square
src1x = randomInt(0, src1.cols - roicols); Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
src1y = randomInt(0, src1.rows - roirows); randomSubMat(src1, src1_roi, roiSize, srcBorder, type, 5, 16);
}
else
{
roicols = roirows = src1.cols;
src1x = src1y = 0;
}
Rect r(src1x, src1y, roicols, roirows); generateOclMat(gsrc1_whole, gsrc1_roi, src1, roiSize, srcBorder);
src1_roi = src1(r);
gdst1_whole = src1;
gdst1 = gdst1_whole(r);
for (int j = 0; j < LOOP_TIMES; j++)
{
cv::transpose(src1_roi, src1_roi); cv::transpose(src1_roi, src1_roi);
cv::ocl::transpose(gdst1, gdst1); cv::ocl::transpose(gsrc1_roi, gsrc1_roi);
EXPECT_MAT_NEAR(src1, Mat(gdst1_whole), 0.0); EXPECT_MAT_NEAR(src1, Mat(gsrc1_whole), 0.0);
EXPECT_MAT_NEAR(src1_roi, Mat(gdst1), 0.0); EXPECT_MAT_NEAR(src1_roi, Mat(gsrc1_roi), 0.0);
} }
} }
@ -687,7 +607,7 @@ TEST_P(Flip, X)
random_roi(); random_roi();
cv::flip(src1_roi, dst1_roi, 0); cv::flip(src1_roi, dst1_roi, 0);
cv::ocl::flip(gsrc1, gdst1, 0); cv::ocl::flip(gsrc1_roi, gdst1_roi, 0);
Near(1e-5); Near(1e-5);
} }
} }
@ -699,7 +619,7 @@ TEST_P(Flip, Y)
random_roi(); random_roi();
cv::flip(src1_roi, dst1_roi, 1); cv::flip(src1_roi, dst1_roi, 1);
cv::ocl::flip(gsrc1, gdst1, 1); cv::ocl::flip(gsrc1_roi, gdst1_roi, 1);
Near(1e-5); Near(1e-5);
} }
} }
@ -711,7 +631,7 @@ TEST_P(Flip, BOTH)
random_roi(); random_roi();
cv::flip(src1_roi, dst1_roi, -1); cv::flip(src1_roi, dst1_roi, -1);
cv::ocl::flip(gsrc1, gdst1, -1); cv::ocl::flip(gsrc1_roi, gdst1_roi, -1);
Near(1e-5); Near(1e-5);
} }
} }
@ -739,12 +659,12 @@ TEST_P(MinMax, MAT)
{ {
signed char val = src1_roi.at<signed char>(i, j); signed char val = src1_roi.at<signed char>(i, j);
if (val < minVal) minVal = val; if (val < minVal) minVal = val;
else if (val > maxVal) maxVal = val; if (val > maxVal) maxVal = val;
} }
} }
double minVal_, maxVal_; double minVal_, maxVal_;
cv::ocl::minMax(gsrc1, &minVal_, &maxVal_); cv::ocl::minMax(gsrc1_roi, &minVal_, &maxVal_);
EXPECT_DOUBLE_EQ(minVal_, minVal); EXPECT_DOUBLE_EQ(minVal_, minVal);
EXPECT_DOUBLE_EQ(maxVal_, maxVal); EXPECT_DOUBLE_EQ(maxVal_, maxVal);
@ -777,7 +697,7 @@ TEST_P(MinMax, MASK)
} }
double minVal_, maxVal_; double minVal_, maxVal_;
cv::ocl::minMax(gsrc1, &minVal_, &maxVal_, gmask); cv::ocl::minMax(gsrc1_roi, &minVal_, &maxVal_, gmask_roi);
EXPECT_DOUBLE_EQ(minVal, minVal_); EXPECT_DOUBLE_EQ(minVal, minVal_);
EXPECT_DOUBLE_EQ(maxVal, maxVal_); EXPECT_DOUBLE_EQ(maxVal, maxVal_);
@ -825,7 +745,7 @@ TEST_P(MinMaxLoc, MAT)
double minVal_, maxVal_; double minVal_, maxVal_;
cv::Point minLoc_, maxLoc_; cv::Point minLoc_, maxLoc_;
cv::ocl::minMaxLoc(gsrc1, &minVal_, &maxVal_, &minLoc_, &maxLoc_, cv::ocl::oclMat()); cv::ocl::minMaxLoc(gsrc1_roi, &minVal_, &maxVal_, &minLoc_, &maxLoc_, cv::ocl::oclMat());
double error0 = 0., error1 = 0., minlocVal = 0., minlocVal_ = 0., maxlocVal = 0., maxlocVal_ = 0.; double error0 = 0., error1 = 0., minlocVal = 0., minlocVal_ = 0., maxlocVal = 0., maxlocVal_ = 0.;
if (depth == 0) if (depth == 0)
@ -938,7 +858,7 @@ TEST_P(MinMaxLoc, MASK)
double minVal_, maxVal_; double minVal_, maxVal_;
cv::Point minLoc_, maxLoc_; cv::Point minLoc_, maxLoc_;
cv::ocl::minMaxLoc(gsrc1, &minVal_, &maxVal_, &minLoc_, &maxLoc_, gmask); cv::ocl::minMaxLoc(gsrc1_roi, &minVal_, &maxVal_, &minLoc_, &maxLoc_, gmask_roi);
double error0 = 0., error1 = 0., minlocVal = 0., minlocVal_ = 0., maxlocVal = 0., maxlocVal_ = 0.; double error0 = 0., error1 = 0., minlocVal = 0., minlocVal_ = 0., maxlocVal = 0., maxlocVal_ = 0.;
if (minLoc_.x == -1 || minLoc_.y == -1 || maxLoc_.x == -1 || maxLoc_.y == -1) continue; if (minLoc_.x == -1 || minLoc_.y == -1 || maxLoc_.x == -1 || maxLoc_.y == -1) continue;
@ -1027,7 +947,7 @@ TEST_P(Sum, MAT)
random_roi(); random_roi();
Scalar cpures = cv::sum(src1_roi); Scalar cpures = cv::sum(src1_roi);
Scalar gpures = cv::ocl::sum(gsrc1); Scalar gpures = cv::ocl::sum(gsrc1_roi);
// check results // check results
EXPECT_NEAR(cpures[0], gpures[0], 0.1); EXPECT_NEAR(cpures[0], gpures[0], 0.1);
@ -1085,7 +1005,7 @@ TEST_P(SqrSum, MAT)
CV_Assert(func != 0); CV_Assert(func != 0);
Scalar cpures = func(src1_roi); Scalar cpures = func(src1_roi);
Scalar gpures = cv::ocl::sqrSum(gsrc1); Scalar gpures = cv::ocl::sqrSum(gsrc1_roi);
// check results // check results
EXPECT_NEAR(cpures[0], gpures[0], 1.0); EXPECT_NEAR(cpures[0], gpures[0], 1.0);
@ -1141,7 +1061,7 @@ TEST_P(AbsSum, MAT)
CV_Assert(func != 0); CV_Assert(func != 0);
Scalar cpures = func(src1_roi); Scalar cpures = func(src1_roi);
Scalar gpures = cv::ocl::absSum(gsrc1); Scalar gpures = cv::ocl::absSum(gsrc1_roi);
// check results // check results
EXPECT_NEAR(cpures[0], gpures[0], 0.1); EXPECT_NEAR(cpures[0], gpures[0], 0.1);
@ -1161,7 +1081,7 @@ TEST_P(CountNonZero, MAT)
{ {
random_roi(); random_roi();
int cpures = cv::countNonZero(src1_roi); int cpures = cv::countNonZero(src1_roi);
int gpures = cv::ocl::countNonZero(gsrc1); int gpures = cv::ocl::countNonZero(gsrc1_roi);
EXPECT_DOUBLE_EQ((double)cpures, (double)gpures); EXPECT_DOUBLE_EQ((double)cpures, (double)gpures);
} }
@ -1177,7 +1097,7 @@ TEST_P(Phase, angleInDegrees)
{ {
random_roi(); random_roi();
cv::phase(src1_roi, src2_roi, dst1_roi, true); cv::phase(src1_roi, src2_roi, dst1_roi, true);
cv::ocl::phase(gsrc1, gsrc2, gdst1, true); cv::ocl::phase(gsrc1_roi, gsrc2_roi, gdst1_roi, true);
Near(1e-2); Near(1e-2);
} }
@ -1189,7 +1109,7 @@ TEST_P(Phase, angleInRadians)
{ {
random_roi(); random_roi();
cv::phase(src1_roi, src2_roi, dst1_roi); cv::phase(src1_roi, src2_roi, dst1_roi);
cv::ocl::phase(gsrc1, gsrc2, gdst1); cv::ocl::phase(gsrc1_roi, gsrc2_roi, gdst1_roi);
Near(1e-2); Near(1e-2);
} }
@ -1206,7 +1126,7 @@ TEST_P(Bitwise_and, Mat)
random_roi(); random_roi();
cv::bitwise_and(src1_roi, src2_roi, dst1_roi); cv::bitwise_and(src1_roi, src2_roi, dst1_roi);
cv::ocl::bitwise_and(gsrc1, gsrc2, gdst1); cv::ocl::bitwise_and(gsrc1_roi, gsrc2_roi, gdst1_roi);
Near(0); Near(0);
} }
} }
@ -1218,7 +1138,7 @@ TEST_P(Bitwise_and, Mat_Mask)
random_roi(); random_roi();
cv::bitwise_and(src1_roi, src2_roi, dst1_roi, mask_roi); cv::bitwise_and(src1_roi, src2_roi, dst1_roi, mask_roi);
cv::ocl::bitwise_and(gsrc1, gsrc2, gdst1, gmask); cv::ocl::bitwise_and(gsrc1_roi, gsrc2_roi, gdst1_roi, gmask_roi);
Near(0); Near(0);
} }
} }
@ -1230,7 +1150,7 @@ TEST_P(Bitwise_and, Scalar)
random_roi(); random_roi();
cv::bitwise_and(src1_roi, val, dst1_roi); cv::bitwise_and(src1_roi, val, dst1_roi);
cv::ocl::bitwise_and(gsrc1, val, gdst1); cv::ocl::bitwise_and(gsrc1_roi, val, gdst1_roi);
Near(1e-5); Near(1e-5);
} }
} }
@ -1242,7 +1162,7 @@ TEST_P(Bitwise_and, Scalar_Mask)
random_roi(); random_roi();
cv::bitwise_and(src1_roi, val, dst1_roi, mask_roi); cv::bitwise_and(src1_roi, val, dst1_roi, mask_roi);
cv::ocl::bitwise_and(gsrc1, val, gdst1, gmask); cv::ocl::bitwise_and(gsrc1_roi, val, gdst1_roi, gmask_roi);
Near(1e-5); Near(1e-5);
} }
} }
@ -1258,7 +1178,7 @@ TEST_P(Bitwise_or, Mat)
random_roi(); random_roi();
cv::bitwise_or(src1_roi, src2_roi, dst1_roi); cv::bitwise_or(src1_roi, src2_roi, dst1_roi);
cv::ocl::bitwise_or(gsrc1, gsrc2, gdst1); cv::ocl::bitwise_or(gsrc1_roi, gsrc2_roi, gdst1_roi);
Near(0); Near(0);
} }
} }
@ -1270,7 +1190,7 @@ TEST_P(Bitwise_or, Mat_Mask)
random_roi(); random_roi();
cv::bitwise_or(src1_roi, src2_roi, dst1_roi, mask_roi); cv::bitwise_or(src1_roi, src2_roi, dst1_roi, mask_roi);
cv::ocl::bitwise_or(gsrc1, gsrc2, gdst1, gmask); cv::ocl::bitwise_or(gsrc1_roi, gsrc2_roi, gdst1_roi, gmask_roi);
Near(0); Near(0);
} }
} }
@ -1282,7 +1202,7 @@ TEST_P(Bitwise_or, Scalar)
random_roi(); random_roi();
cv::bitwise_or(src1_roi, val, dst1_roi); cv::bitwise_or(src1_roi, val, dst1_roi);
cv::ocl::bitwise_or(gsrc1, val, gdst1); cv::ocl::bitwise_or(gsrc1_roi, val, gdst1_roi);
Near(1e-5); Near(1e-5);
} }
} }
@ -1294,7 +1214,7 @@ TEST_P(Bitwise_or, Scalar_Mask)
random_roi(); random_roi();
cv::bitwise_or(src1_roi, val, dst1_roi, mask_roi); cv::bitwise_or(src1_roi, val, dst1_roi, mask_roi);
cv::ocl::bitwise_or(gsrc1, val, gdst1, gmask); cv::ocl::bitwise_or(gsrc1_roi, val, gdst1_roi, gmask_roi);
Near(1e-5); Near(1e-5);
} }
} }
@ -1310,7 +1230,7 @@ TEST_P(Bitwise_xor, Mat)
random_roi(); random_roi();
cv::bitwise_xor(src1_roi, src2_roi, dst1_roi); cv::bitwise_xor(src1_roi, src2_roi, dst1_roi);
cv::ocl::bitwise_xor(gsrc1, gsrc2, gdst1); cv::ocl::bitwise_xor(gsrc1_roi, gsrc2_roi, gdst1_roi);
Near(0); Near(0);
} }
} }
@ -1322,7 +1242,7 @@ TEST_P(Bitwise_xor, Mat_Mask)
random_roi(); random_roi();
cv::bitwise_xor(src1_roi, src2_roi, dst1_roi, mask_roi); cv::bitwise_xor(src1_roi, src2_roi, dst1_roi, mask_roi);
cv::ocl::bitwise_xor(gsrc1, gsrc2, gdst1, gmask); cv::ocl::bitwise_xor(gsrc1_roi, gsrc2_roi, gdst1_roi, gmask_roi);
Near(0); Near(0);
} }
} }
@ -1334,7 +1254,7 @@ TEST_P(Bitwise_xor, Scalar)
random_roi(); random_roi();
cv::bitwise_xor(src1_roi, val, dst1_roi); cv::bitwise_xor(src1_roi, val, dst1_roi);
cv::ocl::bitwise_xor(gsrc1, val, gdst1); cv::ocl::bitwise_xor(gsrc1_roi, val, gdst1_roi);
Near(1e-5); Near(1e-5);
} }
} }
@ -1346,7 +1266,7 @@ TEST_P(Bitwise_xor, Scalar_Mask)
random_roi(); random_roi();
cv::bitwise_xor(src1_roi, val, dst1_roi, mask_roi); cv::bitwise_xor(src1_roi, val, dst1_roi, mask_roi);
cv::ocl::bitwise_xor(gsrc1, val, gdst1, gmask); cv::ocl::bitwise_xor(gsrc1_roi, val, gdst1_roi, gmask_roi);
Near(1e-5); Near(1e-5);
} }
} }
@ -1362,7 +1282,7 @@ TEST_P(Bitwise_not, Mat)
random_roi(); random_roi();
cv::bitwise_not(src1_roi, dst1_roi); cv::bitwise_not(src1_roi, dst1_roi);
cv::ocl::bitwise_not(gsrc1, gdst1); cv::ocl::bitwise_not(gsrc1_roi, gdst1_roi);
Near(0); Near(0);
} }
} }
@ -1382,7 +1302,7 @@ TEST_P(Compare, Mat)
random_roi(); random_roi();
cv::compare(src1_roi, src2_roi, dst1_roi, cmp_codes[i]); cv::compare(src1_roi, src2_roi, dst1_roi, cmp_codes[i]);
cv::ocl::compare(gsrc1, gsrc2, gdst1, cmp_codes[i]); cv::ocl::compare(gsrc1_roi, gsrc2_roi, gdst1_roi, cmp_codes[i]);
Near(0); Near(0);
} }
@ -1399,7 +1319,7 @@ TEST_P(Pow, Mat)
random_roi(); random_roi();
double p = 4.5; double p = 4.5;
cv::pow(src1_roi, p, dst1_roi); cv::pow(src1_roi, p, dst1_roi);
cv::ocl::pow(gsrc1, p, gdst1); cv::ocl::pow(gsrc1_roi, p, gdst1_roi);
Near(1); Near(1);
} }
} }
@ -1417,7 +1337,7 @@ TEST_P(AddWeighted, Mat)
const double alpha = 2.0, beta = 1.0, gama = 3.0; const double alpha = 2.0, beta = 1.0, gama = 3.0;
cv::addWeighted(src1_roi, alpha, src2_roi, beta, gama, dst1_roi); cv::addWeighted(src1_roi, alpha, src2_roi, beta, gama, dst1_roi);
cv::ocl::addWeighted(gsrc1, alpha, gsrc2, beta, gama, gdst1); cv::ocl::addWeighted(gsrc1_roi, alpha, gsrc2_roi, beta, gama, gdst1_roi);
Near(1e-5); Near(1e-5);
} }
@ -1434,7 +1354,7 @@ TEST_P(SetIdentity, Mat)
random_roi(); random_roi();
cv::setIdentity(dst1_roi, val); cv::setIdentity(dst1_roi, val);
cv::ocl::setIdentity(gdst1, val); cv::ocl::setIdentity(gdst1_roi, val);
Near(0); Near(0);
} }
@ -1454,7 +1374,7 @@ TEST_P(MeanStdDev, Mat)
Scalar gpu_mean, gpu_stddev; Scalar gpu_mean, gpu_stddev;
cv::meanStdDev(src1_roi, cpu_mean, cpu_stddev); cv::meanStdDev(src1_roi, cpu_mean, cpu_stddev);
cv::ocl::meanStdDev(gsrc1, gpu_mean, gpu_stddev); cv::ocl::meanStdDev(gsrc1_roi, gpu_mean, gpu_stddev);
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
{ {
@ -1480,7 +1400,7 @@ TEST_P(Norm, NORM_INF)
type |= NORM_RELATIVE; type |= NORM_RELATIVE;
const double cpuRes = cv::norm(src1_roi, src2_roi, type); const double cpuRes = cv::norm(src1_roi, src2_roi, type);
const double gpuRes = cv::ocl::norm(gsrc1, gsrc2, type); const double gpuRes = cv::ocl::norm(gsrc1_roi, gsrc2_roi, type);
EXPECT_NEAR(cpuRes, gpuRes, 0.1); EXPECT_NEAR(cpuRes, gpuRes, 0.1);
} }
@ -1498,7 +1418,7 @@ TEST_P(Norm, NORM_L1)
type |= NORM_RELATIVE; type |= NORM_RELATIVE;
const double cpuRes = cv::norm(src1_roi, src2_roi, type); const double cpuRes = cv::norm(src1_roi, src2_roi, type);
const double gpuRes = cv::ocl::norm(gsrc1, gsrc2, type); const double gpuRes = cv::ocl::norm(gsrc1_roi, gsrc2_roi, type);
EXPECT_NEAR(cpuRes, gpuRes, 0.1); EXPECT_NEAR(cpuRes, gpuRes, 0.1);
} }
@ -1516,7 +1436,7 @@ TEST_P(Norm, NORM_L2)
type |= NORM_RELATIVE; type |= NORM_RELATIVE;
const double cpuRes = cv::norm(src1_roi, src2_roi, type); const double cpuRes = cv::norm(src1_roi, src2_roi, type);
const double gpuRes = cv::ocl::norm(gsrc1, gsrc2, type); const double gpuRes = cv::ocl::norm(gsrc1_roi, gsrc2_roi, type);
EXPECT_NEAR(cpuRes, gpuRes, 0.1); EXPECT_NEAR(cpuRes, gpuRes, 0.1);
} }

@ -85,9 +85,7 @@ PARAM_TEST_CASE(mog, UseGray, LearningRate, bool)
virtual void SetUp() virtual void SetUp()
{ {
useGray = GET_PARAM(0); useGray = GET_PARAM(0);
learningRate = GET_PARAM(1); learningRate = GET_PARAM(1);
useRoi = GET_PARAM(2); useRoi = GET_PARAM(2);
} }
}; };
@ -103,7 +101,7 @@ TEST_P(mog, Update)
ASSERT_FALSE(frame.empty()); ASSERT_FALSE(frame.empty());
cv::ocl::MOG mog; cv::ocl::MOG mog;
cv::ocl::oclMat foreground = createMat_ocl(frame.size(), CV_8UC1, useRoi); cv::ocl::oclMat foreground = createMat_ocl(rng, frame.size(), CV_8UC1, useRoi);
cv::BackgroundSubtractorMOG mog_gold; cv::BackgroundSubtractorMOG mog_gold;
cv::Mat foreground_gold; cv::Mat foreground_gold;
@ -120,7 +118,7 @@ TEST_P(mog, Update)
cv::swap(temp, frame); cv::swap(temp, frame);
} }
mog(loadMat_ocl(frame, useRoi), foreground, (float)learningRate); mog(loadMat_ocl(rng, frame, useRoi), foreground, (float)learningRate);
mog_gold(frame, foreground_gold, learningRate); mog_gold(frame, foreground_gold, learningRate);
@ -165,7 +163,7 @@ TEST_P(mog2, Update)
cv::ocl::MOG2 mog2; cv::ocl::MOG2 mog2;
mog2.bShadowDetection = detectShadow; mog2.bShadowDetection = detectShadow;
cv::ocl::oclMat foreground = createMat_ocl(frame.size(), CV_8UC1, useRoi); cv::ocl::oclMat foreground = createMat_ocl(rng, frame.size(), CV_8UC1, useRoi);
cv::BackgroundSubtractorMOG2 mog2_gold; cv::BackgroundSubtractorMOG2 mog2_gold;
mog2_gold.set("detectShadows", detectShadow); mog2_gold.set("detectShadows", detectShadow);
@ -183,7 +181,7 @@ TEST_P(mog2, Update)
cv::swap(temp, frame); cv::swap(temp, frame);
} }
mog2(loadMat_ocl(frame, useRoi), foreground); mog2(loadMat_ocl(rng, frame, useRoi), foreground);
mog2_gold(frame, foreground_gold); mog2_gold(frame, foreground_gold);
@ -218,12 +216,12 @@ TEST_P(mog2, getBackgroundImage)
cap >> frame; cap >> frame;
ASSERT_FALSE(frame.empty()); ASSERT_FALSE(frame.empty());
mog2(loadMat_ocl(frame, useRoi), foreground); mog2(loadMat_ocl(rng, frame, useRoi), foreground);
mog2_gold(frame, foreground_gold); mog2_gold(frame, foreground_gold);
} }
cv::ocl::oclMat background = createMat_ocl(frame.size(), frame.type(), useRoi); cv::ocl::oclMat background = createMat_ocl(rng, frame.size(), frame.type(), useRoi);
mog2.getBackgroundImage(background); mog2.getBackgroundImage(background);
cv::Mat background_gold; cv::Mat background_gold;

@ -72,8 +72,6 @@ namespace
queryDescCount = 300; // must be even number because we split train data in some cases in two queryDescCount = 300; // must be even number because we split train data in some cases in two
countFactor = 4; // do not change it countFactor = 4; // do not change it
cv::RNG &rng = cvtest::TS::ptr()->get_rng();
cv::Mat queryBuf, trainBuf; cv::Mat queryBuf, trainBuf;
// Generate query descriptors randomly. // Generate query descriptors randomly.

@ -46,10 +46,10 @@
#include "test_precomp.hpp" #include "test_precomp.hpp"
#include <iomanip> #include <iomanip>
#ifdef HAVE_OPENCL
using namespace cv; using namespace cv;
#ifdef HAVE_OPENCL
PARAM_TEST_CASE(StereoMatchBM, int, int) PARAM_TEST_CASE(StereoMatchBM, int, int)
{ {
int n_disp; int n_disp;

@ -91,7 +91,6 @@ PARAM_TEST_CASE(FilterTestBase,
{ {
#ifdef RANDOMROI #ifdef RANDOMROI
//randomize ROI //randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(2, mat1.cols); roicols = rng.uniform(2, mat1.cols);
roirows = rng.uniform(2, mat1.rows); roirows = rng.uniform(2, mat1.rows);
src1x = rng.uniform(0, mat1.cols - roicols); src1x = rng.uniform(0, mat1.cols - roicols);
@ -201,7 +200,6 @@ struct ErodeDilate : FilterTestBase
type = GET_PARAM(0); type = GET_PARAM(0);
iterations = GET_PARAM(3); iterations = GET_PARAM(3);
Init(type); Init(type);
// rng.fill(kernel, cv::RNG::UNIFORM, cv::Scalar::all(0), cv::Scalar::all(3));
kernel = randomMat(Size(3, 3), CV_8UC1, 0, 3); kernel = randomMat(Size(3, 3), CV_8UC1, 0, 3);
} }
@ -304,7 +302,6 @@ struct GaussianBlur : FilterTestBase
ksize = GET_PARAM(1); ksize = GET_PARAM(1);
bordertype = GET_PARAM(3); bordertype = GET_PARAM(3);
Init(type); Init(type);
cv::RNG &rng = TS::ptr()->get_rng();
sigma1 = rng.uniform(0.1, 1.0); sigma1 = rng.uniform(0.1, 1.0);
sigma2 = rng.uniform(0.1, 1.0); sigma2 = rng.uniform(0.1, 1.0);
} }
@ -368,7 +365,6 @@ struct Bilateral : FilterTestBase
ksize = GET_PARAM(1); ksize = GET_PARAM(1);
bordertype = GET_PARAM(3); bordertype = GET_PARAM(3);
Init(type); Init(type);
cv::RNG &rng = TS::ptr()->get_rng();
sigmacolor = rng.uniform(20, 100); sigmacolor = rng.uniform(20, 100);
sigmaspace = rng.uniform(10, 40); sigmaspace = rng.uniform(10, 40);
} }

@ -351,33 +351,32 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo
type3 = GET_PARAM(2); type3 = GET_PARAM(2);
type4 = GET_PARAM(3); type4 = GET_PARAM(3);
type5 = GET_PARAM(4); type5 = GET_PARAM(4);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(MWIDTH, MHEIGHT); cv::Size size(MWIDTH, MHEIGHT);
double min = 1, max = 20; double min = 1, max = 20;
if(type1 != nulltype) if(type1 != nulltype)
{ {
mat1 = randomMat(rng, size, type1, min, max, false); mat1 = randomMat(size, type1, min, max, false);
clmat1 = mat1; clmat1 = mat1;
} }
if(type2 != nulltype) if(type2 != nulltype)
{ {
mat2 = randomMat(rng, size, type2, min, max, false); mat2 = randomMat(size, type2, min, max, false);
clmat2 = mat2; clmat2 = mat2;
} }
if(type3 != nulltype) if(type3 != nulltype)
{ {
dst = randomMat(rng, size, type3, min, max, false); dst = randomMat(size, type3, min, max, false);
cldst = dst; cldst = dst;
} }
if(type4 != nulltype) if(type4 != nulltype)
{ {
dst1 = randomMat(rng, size, type4, min, max, false); dst1 = randomMat(size, type4, min, max, false);
cldst1 = dst1; cldst1 = dst1;
} }
if(type5 != nulltype) if(type5 != nulltype)
{ {
mask = randomMat(rng, size, CV_8UC1, 0, 2, false); mask = randomMat(size, CV_8UC1, 0, 2, false);
cv::threshold(mask, mask, 0.5, 255., type5); cv::threshold(mask, mask, 0.5, 255., type5);
clmask = mask; clmask = mask;
} }
@ -388,7 +387,6 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo
{ {
#ifdef RANDOMROI #ifdef RANDOMROI
//randomize ROI //randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, mat1.cols); roicols = rng.uniform(1, mat1.cols);
roirows = rng.uniform(1, mat1.rows); roirows = rng.uniform(1, mat1.rows);
src1x = rng.uniform(0, mat1.cols - roicols); src1x = rng.uniform(0, mat1.cols - roicols);
@ -482,7 +480,6 @@ struct CopyMakeBorder : ImgprocTestBase {};
TEST_P(CopyMakeBorder, Mat) TEST_P(CopyMakeBorder, Mat)
{ {
int bordertype[] = {cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, cv::BORDER_REFLECT, cv::BORDER_WRAP, cv::BORDER_REFLECT_101}; int bordertype[] = {cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, cv::BORDER_REFLECT, cv::BORDER_WRAP, cv::BORDER_REFLECT_101};
cv::RNG &rng = TS::ptr()->get_rng();
int top = rng.uniform(0, 10); int top = rng.uniform(0, 10);
int bottom = rng.uniform(0, 10); int bottom = rng.uniform(0, 10);
int left = rng.uniform(0, 10); int left = rng.uniform(0, 10);
@ -634,22 +631,17 @@ PARAM_TEST_CASE(WarpTestBase, MatType, int)
virtual void SetUp() virtual void SetUp()
{ {
type = GET_PARAM(0); type = GET_PARAM(0);
//dsize = GET_PARAM(1);
interpolation = GET_PARAM(1); interpolation = GET_PARAM(1);
cv::RNG &rng = TS::ptr()->get_rng();
size = cv::Size(MWIDTH, MHEIGHT); size = cv::Size(MWIDTH, MHEIGHT);
mat1 = randomMat(rng, size, type, 5, 16, false); mat1 = randomMat(size, type, 5, 16, false);
dst = randomMat(rng, size, type, 5, 16, false); dst = randomMat(size, type, 5, 16, false);
} }
void random_roi() void random_roi()
{ {
#ifdef RANDOMROI #ifdef RANDOMROI
//randomize ROI //randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
src_roicols = rng.uniform(1, mat1.cols); src_roicols = rng.uniform(1, mat1.cols);
src_roirows = rng.uniform(1, mat1.rows); src_roirows = rng.uniform(1, mat1.rows);
dst_roicols = rng.uniform(1, dst.cols); dst_roicols = rng.uniform(1, dst.cols);
@ -798,23 +790,22 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int)
interpolation = GET_PARAM(3); interpolation = GET_PARAM(3);
bordertype = GET_PARAM(4); bordertype = GET_PARAM(4);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size srcSize = cv::Size(MWIDTH, MHEIGHT); cv::Size srcSize = cv::Size(MWIDTH, MHEIGHT);
cv::Size map1Size = cv::Size(MWIDTH, MHEIGHT); cv::Size map1Size = cv::Size(MWIDTH, MHEIGHT);
double min = 5, max = 16; double min = 5, max = 16;
if(srcType != nulltype) if(srcType != nulltype)
{ {
src = randomMat(rng, srcSize, srcType, min, max, false); src = randomMat(srcSize, srcType, min, max, false);
} }
if((map1Type == CV_16SC2 && map2Type == nulltype) || (map1Type == CV_32FC2 && map2Type == nulltype)) if((map1Type == CV_16SC2 && map2Type == nulltype) || (map1Type == CV_32FC2 && map2Type == nulltype))
{ {
map1 = randomMat(rng, map1Size, map1Type, min, max, false); map1 = randomMat(map1Size, map1Type, min, max, false);
} }
else if (map1Type == CV_32FC1 && map2Type == CV_32FC1) else if (map1Type == CV_32FC1 && map2Type == CV_32FC1)
{ {
map1 = randomMat(rng, map1Size, map1Type, min, max, false); map1 = randomMat(map1Size, map1Type, min, max, false);
map2 = randomMat(rng, map1Size, map1Type, min, max, false); map2 = randomMat(map1Size, map1Type, min, max, false);
} }
else else
@ -823,7 +814,7 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int)
return; return;
} }
dst = randomMat(rng, map1Size, srcType, min, max, false); dst = randomMat(map1Size, srcType, min, max, false);
switch (src.channels()) switch (src.channels())
{ {
case 1: case 1:
@ -843,8 +834,6 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int)
} }
void random_roi() void random_roi()
{ {
cv::RNG &rng = TS::ptr()->get_rng();
dst_roicols = rng.uniform(1, dst.cols); dst_roicols = rng.uniform(1, dst.cols);
dst_roirows = rng.uniform(1, dst.rows); dst_roirows = rng.uniform(1, dst.rows);
@ -954,8 +943,6 @@ PARAM_TEST_CASE(Resize, MatType, cv::Size, double, double, int)
fy = GET_PARAM(3); fy = GET_PARAM(3);
interpolation = GET_PARAM(4); interpolation = GET_PARAM(4);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(MWIDTH, MHEIGHT); cv::Size size(MWIDTH, MHEIGHT);
if(dsize == cv::Size() && !(fx > 0 && fy > 0)) if(dsize == cv::Size() && !(fx > 0 && fy > 0))
@ -970,8 +957,8 @@ PARAM_TEST_CASE(Resize, MatType, cv::Size, double, double, int)
dsize.height = (int)(size.height * fy); dsize.height = (int)(size.height * fy);
} }
mat1 = randomMat(rng, size, type, 5, 16, false); mat1 = randomMat(size, type, 5, 16, false);
dst = randomMat(rng, dsize, type, 5, 16, false); dst = randomMat(dsize, type, 5, 16, false);
} }
@ -979,7 +966,6 @@ PARAM_TEST_CASE(Resize, MatType, cv::Size, double, double, int)
{ {
#ifdef RANDOMROI #ifdef RANDOMROI
//randomize ROI //randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
src_roicols = rng.uniform(1, mat1.cols); src_roicols = rng.uniform(1, mat1.cols);
src_roirows = rng.uniform(1, mat1.rows); src_roirows = rng.uniform(1, mat1.rows);
dst_roicols = (int)(src_roicols * fx); dst_roicols = (int)(src_roicols * fx);
@ -1070,18 +1056,16 @@ PARAM_TEST_CASE(Threshold, MatType, ThreshOp)
type = GET_PARAM(0); type = GET_PARAM(0);
threshOp = GET_PARAM(1); threshOp = GET_PARAM(1);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(MWIDTH, MHEIGHT); cv::Size size(MWIDTH, MHEIGHT);
mat1 = randomMat(rng, size, type, 5, 16, false); mat1 = randomMat(size, type, 5, 16, false);
dst = randomMat(rng, size, type, 5, 16, false); dst = randomMat(size, type, 5, 16, false);
} }
void random_roi() void random_roi()
{ {
#ifdef RANDOMROI #ifdef RANDOMROI
//randomize ROI //randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, mat1.cols); roicols = rng.uniform(1, mat1.cols);
roirows = rng.uniform(1, mat1.rows); roirows = rng.uniform(1, mat1.rows);
src1x = rng.uniform(0, mat1.cols - roicols); src1x = rng.uniform(0, mat1.cols - roicols);
@ -1167,22 +1151,18 @@ PARAM_TEST_CASE(meanShiftTestBase, MatType, MatType, int, int, cv::TermCriteria)
sr = GET_PARAM(3); sr = GET_PARAM(3);
crit = GET_PARAM(4); crit = GET_PARAM(4);
cv::RNG &rng = TS::ptr()->get_rng();
// MWIDTH=256, MHEIGHT=256. defined in utility.hpp // MWIDTH=256, MHEIGHT=256. defined in utility.hpp
cv::Size size = cv::Size(MWIDTH, MHEIGHT); cv::Size size = cv::Size(MWIDTH, MHEIGHT);
src = randomMat(rng, size, type, 5, 16, false); src = randomMat(size, type, 5, 16, false);
dst = randomMat(rng, size, type, 5, 16, false); dst = randomMat(size, type, 5, 16, false);
dstCoor = randomMat(rng, size, typeCoor, 5, 16, false); dstCoor = randomMat(size, typeCoor, 5, 16, false);
} }
void random_roi() void random_roi()
{ {
#ifdef RANDOMROI #ifdef RANDOMROI
cv::RNG &rng = TS::ptr()->get_rng();
//randomize ROI //randomize ROI
roicols = rng.uniform(1, src.cols); roicols = rng.uniform(1, src.cols);
roirows = rng.uniform(1, src.rows); roirows = rng.uniform(1, src.rows);
@ -1295,18 +1275,15 @@ PARAM_TEST_CASE(histTestBase, MatType, MatType)
{ {
type_src = GET_PARAM(0); type_src = GET_PARAM(0);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size = cv::Size(MWIDTH, MHEIGHT); cv::Size size = cv::Size(MWIDTH, MHEIGHT);
src = randomMat(rng, size, type_src, 0, 256, false); src = randomMat(size, type_src, 0, 256, false);
} }
void random_roi() void random_roi()
{ {
#ifdef RANDOMROI #ifdef RANDOMROI
cv::RNG &rng = TS::ptr()->get_rng();
//randomize ROI //randomize ROI
roicols = rng.uniform(1, src.cols); roicols = rng.uniform(1, src.cols);
roirows = rng.uniform(1, src.rows); roirows = rng.uniform(1, src.rows);
@ -1360,8 +1337,7 @@ PARAM_TEST_CASE(CLAHE, cv::Size, double)
gridSize = GET_PARAM(0); gridSize = GET_PARAM(0);
clipLimit = GET_PARAM(1); clipLimit = GET_PARAM(1);
cv::RNG &rng = TS::ptr()->get_rng(); src = randomMat(cv::Size(MWIDTH, MHEIGHT), CV_8UC1, 0, 256, false);
src = randomMat(rng, cv::Size(MWIDTH, MHEIGHT), CV_8UC1, 0, 256, false);
g_src.upload(src); g_src.upload(src);
} }
}; };
@ -1413,19 +1389,15 @@ PARAM_TEST_CASE(ConvolveTestBase, MatType, bool)
{ {
type = GET_PARAM(0); type = GET_PARAM(0);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(MWIDTH, MHEIGHT); cv::Size size(MWIDTH, MHEIGHT);
mat1 = randomMat(rng, size, type, 5, 16, false); mat1 = randomMat(size, type, 5, 16, false);
mat2 = randomMat(rng, size, type, 5, 16, false); mat2 = randomMat(size, type, 5, 16, false);
dst = randomMat(rng, size, type, 5, 16, false); dst = randomMat(size, type, 5, 16, false);
dst1 = randomMat(rng, size, type, 5, 16, false); dst1 = randomMat(size, type, 5, 16, false);
} }
void random_roi() void random_roi()
{ {
cv::RNG &rng = TS::ptr()->get_rng();
#ifdef RANDOMROI #ifdef RANDOMROI
//randomize ROI //randomize ROI
roicols = rng.uniform(1, mat1.cols); roicols = rng.uniform(1, mat1.cols);
@ -1530,7 +1502,7 @@ PARAM_TEST_CASE(ColumnSum, cv::Size)
TEST_P(ColumnSum, Accuracy) TEST_P(ColumnSum, Accuracy)
{ {
cv::Mat src = randomMat(size, CV_32FC1); cv::Mat src = randomMat(size, CV_32FC1, 0, 255);
cv::ocl::oclMat d_dst; cv::ocl::oclMat d_dst;
cv::ocl::oclMat d_src(src); cv::ocl::oclMat d_src(src);

@ -69,8 +69,6 @@ TEST_P(Kalman, Accuracy)
const double max_init = 1; const double max_init = 1;
const double max_noise = 0.1; const double max_noise = 0.1;
cv::RNG &rng = TS::ptr()->get_rng();
Mat sample_mat(Dim, 1, CV_32F), temp_mat; Mat sample_mat(Dim, 1, CV_32F), temp_mat;
oclMat Sample(Dim, 1, CV_32F); oclMat Sample(Dim, 1, CV_32F);
oclMat Temp(Dim, 1, CV_32F); oclMat Temp(Dim, 1, CV_32F);
@ -78,7 +76,7 @@ TEST_P(Kalman, Accuracy)
Size size(Sample.cols, Sample.rows); Size size(Sample.cols, Sample.rows);
sample_mat = randomMat(rng, size, Sample.type(), -max_init, max_init, false); sample_mat = randomMat(size, Sample.type(), -max_init, max_init, false);
Sample.upload(sample_mat); Sample.upload(sample_mat);
//ocl start //ocl start
@ -120,7 +118,7 @@ TEST_P(Kalman, Accuracy)
cv::gemm(kalman_filter_cpu.transitionMatrix, sample_mat, 1, cv::Mat(), 0, Temp_cpu); cv::gemm(kalman_filter_cpu.transitionMatrix, sample_mat, 1, cv::Mat(), 0, Temp_cpu);
Size size1(Temp.cols, Temp.rows); Size size1(Temp.cols, Temp.rows);
Mat temp = randomMat(rng, size1, Temp.type(), 0, 0xffff, false); Mat temp = randomMat(size1, Temp.type(), 0, 0xffff, false);
cv::multiply(2, temp, temp); cv::multiply(2, temp, temp);

@ -66,12 +66,11 @@ PARAM_TEST_CASE(Kmeans, int, int, int)
Mat labels, centers; Mat labels, centers;
ocl::oclMat d_labels, d_centers; ocl::oclMat d_labels, d_centers;
cv::RNG rng ; virtual void SetUp()
virtual void SetUp(){ {
K = GET_PARAM(0); K = GET_PARAM(0);
type = GET_PARAM(1); type = GET_PARAM(1);
flags = GET_PARAM(2); flags = GET_PARAM(2);
rng = TS::ptr()->get_rng();
// MWIDTH=256, MHEIGHT=256. defined in utility.hpp // MWIDTH=256, MHEIGHT=256. defined in utility.hpp
cv::Size size = cv::Size(MWIDTH, MHEIGHT); cv::Size size = cv::Size(MWIDTH, MHEIGHT);
@ -92,7 +91,7 @@ PARAM_TEST_CASE(Kmeans, int, int, int)
{ {
Mat cur_row_header = src.row(row_idx + 1 + j); Mat cur_row_header = src.row(row_idx + 1 + j);
center_row_header.copyTo(cur_row_header); center_row_header.copyTo(cur_row_header);
Mat tmpmat = randomMat(rng, cur_row_header.size(), cur_row_header.type(), -200, 200, false); Mat tmpmat = randomMat(cur_row_header.size(), cur_row_header.type(), -200, 200, false);
cur_row_header += tmpmat; cur_row_header += tmpmat;
} }
row_idx += 1 + max_neighbour; row_idx += 1 + max_neighbour;

@ -72,8 +72,8 @@ PARAM_TEST_CASE(MatchTemplate8U, cv::Size, TemplateSize, Channels, TemplateMetho
TEST_P(MatchTemplate8U, Accuracy) TEST_P(MatchTemplate8U, Accuracy)
{ {
cv::Mat image = randomMat(size, CV_MAKETYPE(CV_8U, cn)); cv::Mat image = randomMat(size, CV_MAKETYPE(CV_8U, cn), 0, 255);
cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_8U, cn)); cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_8U, cn), 0, 255);
cv::ocl::oclMat dst, ocl_image(image), ocl_templ(templ); cv::ocl::oclMat dst, ocl_image(image), ocl_templ(templ);
cv::ocl::matchTemplate(ocl_image, ocl_templ, dst, method); cv::ocl::matchTemplate(ocl_image, ocl_templ, dst, method);
@ -105,8 +105,8 @@ PARAM_TEST_CASE(MatchTemplate32F, cv::Size, TemplateSize, Channels, TemplateMeth
TEST_P(MatchTemplate32F, Accuracy) TEST_P(MatchTemplate32F, Accuracy)
{ {
cv::Mat image = randomMat(size, CV_MAKETYPE(CV_32F, cn)); cv::Mat image = randomMat(size, CV_MAKETYPE(CV_32F, cn), 0, 255);
cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_32F, cn)); cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_32F, cn), 0, 255);
cv::ocl::oclMat dst, ocl_image(image), ocl_templ(templ); cv::ocl::oclMat dst, ocl_image(image), ocl_templ(templ);
cv::ocl::matchTemplate(ocl_image, ocl_templ, dst, method); cv::ocl::matchTemplate(ocl_image, ocl_templ, dst, method);

@ -90,10 +90,8 @@ PARAM_TEST_CASE(ConvertToTestBase, MatType, MatType, int, bool)
use_roi = GET_PARAM(3); use_roi = GET_PARAM(3);
cv::RNG &rng = TS::ptr()->get_rng(); mat = randomMat(randomSize(MIN_VALUE, MAX_VALUE), src_type, 5, 136, false);
dst = randomMat(use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : mat.size(), dst_type, 5, 136, false);
mat = randomMat(rng, randomSize(MIN_VALUE, MAX_VALUE), src_type, 5, 136, false);
dst = randomMat(rng, use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : mat.size(), dst_type, 5, 136, false);
} }
void random_roi() void random_roi()
@ -101,7 +99,6 @@ PARAM_TEST_CASE(ConvertToTestBase, MatType, MatType, int, bool)
if (use_roi) if (use_roi)
{ {
// randomize ROI // randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, MIN_VALUE); roicols = rng.uniform(1, MIN_VALUE);
roirows = rng.uniform(1, MIN_VALUE); roirows = rng.uniform(1, MIN_VALUE);
srcx = rng.uniform(0, mat.cols - roicols); srcx = rng.uniform(0, mat.cols - roicols);
@ -178,11 +175,9 @@ PARAM_TEST_CASE(CopyToTestBase, MatType, int, bool)
int type = CV_MAKETYPE(GET_PARAM(0), GET_PARAM(1)); int type = CV_MAKETYPE(GET_PARAM(0), GET_PARAM(1));
use_roi = GET_PARAM(2); use_roi = GET_PARAM(2);
cv::RNG &rng = TS::ptr()->get_rng(); src = randomMat(randomSize(MIN_VALUE, MAX_VALUE), type, 5, 16, false);
dst = randomMat(use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : src.size(), type, 5, 16, false);
src = randomMat(rng, randomSize(MIN_VALUE, MAX_VALUE), type, 5, 16, false); mask = randomMat(use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : src.size(), CV_8UC1, 0, 2, false);
dst = randomMat(rng, use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : src.size(), type, 5, 16, false);
mask = randomMat(rng, use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : src.size(), CV_8UC1, 0, 2, false);
cv::threshold(mask, mask, 0.5, 255., CV_8UC1); cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
} }
@ -192,7 +187,6 @@ PARAM_TEST_CASE(CopyToTestBase, MatType, int, bool)
if (use_roi) if (use_roi)
{ {
// randomize ROI // randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, MIN_VALUE); roicols = rng.uniform(1, MIN_VALUE);
roirows = rng.uniform(1, MIN_VALUE); roirows = rng.uniform(1, MIN_VALUE);
srcx = rng.uniform(0, src.cols - roicols); srcx = rng.uniform(0, src.cols - roicols);
@ -295,11 +289,10 @@ PARAM_TEST_CASE(SetToTestBase, MatType, int, bool)
channels = GET_PARAM(1); channels = GET_PARAM(1);
use_roi = GET_PARAM(2); use_roi = GET_PARAM(2);
cv::RNG &rng = TS::ptr()->get_rng();
int type = CV_MAKE_TYPE(depth, channels); int type = CV_MAKE_TYPE(depth, channels);
src = randomMat(rng, randomSize(MIN_VALUE, MAX_VALUE), type, 5, 16, false); src = randomMat(randomSize(MIN_VALUE, MAX_VALUE), type, 5, 16, false);
mask = randomMat(rng, use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : src.size(), CV_8UC1, 0, 2, false); mask = randomMat(use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : src.size(), CV_8UC1, 0, 2, false);
cv::threshold(mask, mask, 0.5, 255., CV_8UC1); cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
val = cv::Scalar(rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), val = cv::Scalar(rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0),
@ -311,7 +304,6 @@ PARAM_TEST_CASE(SetToTestBase, MatType, int, bool)
if (use_roi) if (use_roi)
{ {
// randomize ROI // randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, MIN_VALUE); roicols = rng.uniform(1, MIN_VALUE);
roirows = rng.uniform(1, MIN_VALUE); roirows = rng.uniform(1, MIN_VALUE);
srcx = rng.uniform(0, src.cols - roicols); srcx = rng.uniform(0, src.cols - roicols);
@ -401,8 +393,7 @@ PARAM_TEST_CASE(convertC3C4, MatType, bool)
use_roi = GET_PARAM(1); use_roi = GET_PARAM(1);
int type = CV_MAKE_TYPE(depth, 3); int type = CV_MAKE_TYPE(depth, 3);
cv::RNG &rng = TS::ptr()->get_rng(); src = randomMat(randomSize(1, MAX_VALUE), type, 0, 40, false);
src = randomMat(rng, randomSize(1, MAX_VALUE), type, 0, 40, false);
} }
void random_roi() void random_roi()
@ -410,7 +401,6 @@ PARAM_TEST_CASE(convertC3C4, MatType, bool)
if (use_roi) if (use_roi)
{ {
//randomize ROI //randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, src.cols); roicols = rng.uniform(1, src.cols);
roirows = rng.uniform(1, src.rows); roirows = rng.uniform(1, src.rows);
srcx = rng.uniform(0, src.cols - roicols); srcx = rng.uniform(0, src.cols - roicols);

@ -50,10 +50,9 @@ using namespace cv::ocl;
using namespace cvtest; using namespace cvtest;
using namespace testing; using namespace testing;
///////K-NEAREST NEIGHBOR////////////////////////// ///////K-NEAREST NEIGHBOR//////////////////////////
static void genTrainData(Mat& trainData, int trainDataRow, int trainDataCol, static void genTrainData(cv::RNG& rng, Mat& trainData, int trainDataRow, int trainDataCol,
Mat& trainLabel = Mat().setTo(Scalar::all(0)), int nClasses = 0) Mat& trainLabel = Mat().setTo(Scalar::all(0)), int nClasses = 0)
{ {
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(trainDataCol, trainDataRow); cv::Size size(trainDataCol, trainDataRow);
trainData = randomMat(rng, size, CV_32FC1, 1.0, 1000.0, false); trainData = randomMat(rng, size, CV_32FC1, 1.0, 1000.0, false);
if(nClasses != 0) if(nClasses != 0)
@ -85,10 +84,10 @@ TEST_P(KNN, Accuracy)
{ {
Mat trainData, trainLabels; Mat trainData, trainLabels;
const int trainDataRow = 500; const int trainDataRow = 500;
genTrainData(trainData, trainDataRow, trainDataCol, trainLabels, nClass); genTrainData(rng, trainData, trainDataRow, trainDataCol, trainLabels, nClass);
Mat testData, testLabels; Mat testData, testLabels;
genTrainData(testData, testDataRow, trainDataCol); genTrainData(rng, testData, testDataRow, trainDataCol);
KNearestNeighbour knn_ocl; KNearestNeighbour knn_ocl;
CvKNearest knn_cpu; CvKNearest knn_cpu;
@ -130,7 +129,6 @@ PARAM_TEST_CASE(SVM_OCL, int, int, int)
int svm_type; int svm_type;
Mat src, labels, samples, labels_predict; Mat src, labels, samples, labels_predict;
int K; int K;
cv::RNG rng ;
virtual void SetUp() virtual void SetUp()
{ {
@ -138,7 +136,6 @@ PARAM_TEST_CASE(SVM_OCL, int, int, int)
kernel_type = GET_PARAM(0); kernel_type = GET_PARAM(0);
svm_type = GET_PARAM(1); svm_type = GET_PARAM(1);
K = GET_PARAM(2); K = GET_PARAM(2);
rng = TS::ptr()->get_rng();
cv::Size size = cv::Size(MWIDTH, MHEIGHT); cv::Size size = cv::Size(MWIDTH, MHEIGHT);
src.create(size, CV_32FC1); src.create(size, CV_32FC1);
labels.create(1, size.height, CV_32SC1); labels.create(1, size.height, CV_32SC1);
@ -160,7 +157,7 @@ PARAM_TEST_CASE(SVM_OCL, int, int, int)
{ {
Mat cur_row_header = src.row(row_idx + 1 + j); Mat cur_row_header = src.row(row_idx + 1 + j);
center_row_header.copyTo(cur_row_header); center_row_header.copyTo(cur_row_header);
Mat tmpmat = randomMat(rng, cur_row_header.size(), cur_row_header.type(), 1, 100, false); Mat tmpmat = randomMat(cur_row_header.size(), cur_row_header.type(), 1, 100, false);
cur_row_header += tmpmat; cur_row_header += tmpmat;
labels.at<int>(0, row_idx + 1 + j) = i; labels.at<int>(0, row_idx + 1 + j) = i;
} }
@ -187,7 +184,7 @@ PARAM_TEST_CASE(SVM_OCL, int, int, int)
{ {
Mat cur_row_header = samples.row(row_idx + 1 + j); Mat cur_row_header = samples.row(row_idx + 1 + j);
center_row_header.copyTo(cur_row_header); center_row_header.copyTo(cur_row_header);
Mat tmpmat = randomMat(rng, cur_row_header.size(), cur_row_header.type(), 1, 100, false); Mat tmpmat = randomMat(cur_row_header.size(), cur_row_header.type(), 1, 100, false);
cur_row_header += tmpmat; cur_row_header += tmpmat;
labels_predict.at<int>(0, row_idx + 1 + j) = i; labels_predict.at<int>(0, row_idx + 1 + j) = i;
} }

@ -9,7 +9,7 @@ using namespace cv::ocl;
using namespace cvtest; using namespace cvtest;
using namespace testing; using namespace testing;
using namespace std; using namespace std;
extern string workdir;
PARAM_TEST_CASE(MomentsTest, MatType, bool) PARAM_TEST_CASE(MomentsTest, MatType, bool)
{ {
int type; int type;
@ -20,9 +20,8 @@ PARAM_TEST_CASE(MomentsTest, MatType, bool)
{ {
type = GET_PARAM(0); type = GET_PARAM(0);
test_contours = GET_PARAM(1); test_contours = GET_PARAM(1);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(10*MWIDTH, 10*MHEIGHT); cv::Size size(10*MWIDTH, 10*MHEIGHT);
mat1 = randomMat(rng, size, type, 5, 16, false); mat1 = randomMat(size, type, 5, 16, false);
} }
void Compare(Moments& cpu, Moments& gpu) void Compare(Moments& cpu, Moments& gpu)
@ -39,7 +38,6 @@ PARAM_TEST_CASE(MomentsTest, MatType, bool)
TEST_P(MomentsTest, Mat) TEST_P(MomentsTest, Mat)
{ {
bool binaryImage = 0; bool binaryImage = 0;
SetUp();
for(int j = 0; j < LOOP_TIMES; j++) for(int j = 0; j < LOOP_TIMES; j++)
{ {

@ -51,8 +51,6 @@ using namespace cv;
using namespace testing; using namespace testing;
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
extern string workdir;
///////////////////// HOG ///////////////////////////// ///////////////////// HOG /////////////////////////////
PARAM_TEST_CASE(HOG, Size, int) PARAM_TEST_CASE(HOG, Size, int)
{ {

@ -54,9 +54,6 @@ using namespace cvtest;
using namespace testing; using namespace testing;
using namespace std; using namespace std;
extern string workdir;
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// GoodFeaturesToTrack // GoodFeaturesToTrack
namespace namespace
@ -153,9 +150,8 @@ TEST_P(TVL1, Accuracy)
ASSERT_FALSE(frame1.empty()); ASSERT_FALSE(frame1.empty());
cv::ocl::OpticalFlowDual_TVL1_OCL d_alg; cv::ocl::OpticalFlowDual_TVL1_OCL d_alg;
cv::RNG &rng = TS::ptr()->get_rng(); cv::Mat flowx = randomMat(frame0.size(), CV_32FC1, 0, 0, useRoi);
cv::Mat flowx = randomMat(rng, frame0.size(), CV_32FC1, 0, 0, useRoi); cv::Mat flowy = randomMat(frame0.size(), CV_32FC1, 0, 0, useRoi);
cv::Mat flowy = randomMat(rng, frame0.size(), CV_32FC1, 0, 0, useRoi);
cv::ocl::oclMat d_flowx(flowx), d_flowy(flowy); cv::ocl::oclMat d_flowx(flowx), d_flowy(flowy);
d_alg(oclMat(frame0), oclMat(frame1), d_flowx, d_flowy); d_alg(oclMat(frame0), oclMat(frame1), d_flowx, d_flowy);

@ -73,4 +73,6 @@
#include "utility.hpp" #include "utility.hpp"
//#include "add_test_info.h" //#include "add_test_info.h"
using namespace cvtest;
#endif #endif

@ -79,7 +79,7 @@ TEST_P(PyrDown, Mat)
for (int j = 0; j < LOOP_TIMES; j++) for (int j = 0; j < LOOP_TIMES; j++)
{ {
Size size(MWIDTH, MHEIGHT); Size size(MWIDTH, MHEIGHT);
Mat src = randomMat(size, CV_MAKETYPE(depth, channels)); Mat src = randomMat(size, CV_MAKETYPE(depth, channels), 0, 255);
oclMat gsrc(src); oclMat gsrc(src);
pyrDown(src, dst_cpu); pyrDown(src, dst_cpu);
@ -102,7 +102,7 @@ TEST_P(PyrUp, Accuracy)
for (int j = 0; j < LOOP_TIMES; j++) for (int j = 0; j < LOOP_TIMES; j++)
{ {
Size size(MWIDTH, MHEIGHT); Size size(MWIDTH, MHEIGHT);
Mat src = randomMat(size, CV_MAKETYPE(depth, channels)); Mat src = randomMat(size, CV_MAKETYPE(depth, channels), 0, 255);
oclMat gsrc(src); oclMat gsrc(src);
pyrUp(src, dst_cpu); pyrUp(src, dst_cpu);

@ -90,12 +90,11 @@ PARAM_TEST_CASE(MergeTestBase, MatType, int, bool)
channels = GET_PARAM(1); channels = GET_PARAM(1);
use_roi = GET_PARAM(2); use_roi = GET_PARAM(2);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(MWIDTH, MHEIGHT); cv::Size size(MWIDTH, MHEIGHT);
for (int i = 0; i < channels; ++i) for (int i = 0; i < channels; ++i)
mat[i] = randomMat(rng, size, CV_MAKETYPE(type, 1), 5, 16, false); mat[i] = randomMat(size, CV_MAKETYPE(type, 1), 5, 16, false);
dst = randomMat(rng, size, CV_MAKETYPE(type, channels), 5, 16, false); dst = randomMat(size, CV_MAKETYPE(type, channels), 5, 16, false);
} }
void random_roi() void random_roi()
@ -103,7 +102,6 @@ PARAM_TEST_CASE(MergeTestBase, MatType, int, bool)
if (use_roi) if (use_roi)
{ {
//randomize ROI //randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, mat[0].cols); roicols = rng.uniform(1, mat[0].cols);
roirows = rng.uniform(1, mat[0].rows); roirows = rng.uniform(1, mat[0].rows);
@ -191,19 +189,17 @@ PARAM_TEST_CASE(SplitTestBase, MatType, int, bool)
channels = GET_PARAM(1); channels = GET_PARAM(1);
use_roi = GET_PARAM(2); use_roi = GET_PARAM(2);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(MWIDTH, MHEIGHT); cv::Size size(MWIDTH, MHEIGHT);
mat = randomMat(rng, size, CV_MAKETYPE(type, channels), 5, 16, false); mat = randomMat(size, CV_MAKETYPE(type, channels), 5, 16, false);
for (int i = 0; i < channels; ++i) for (int i = 0; i < channels; ++i)
dst[i] = randomMat(rng, size, CV_MAKETYPE(type, 1), 5, 16, false); } dst[i] = randomMat(size, CV_MAKETYPE(type, 1), 5, 16, false); }
void random_roi() void random_roi()
{ {
if (use_roi) if (use_roi)
{ {
//randomize ROI //randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, mat.cols); roicols = rng.uniform(1, mat.cols);
roirows = rng.uniform(1, mat.rows); roirows = rng.uniform(1, mat.rows);
srcx = rng.uniform(0, mat.cols - roicols); srcx = rng.uniform(0, mat.cols - roicols);

@ -46,7 +46,7 @@ using namespace cv;
using namespace cv::gpu; using namespace cv::gpu;
using namespace cvtest; using namespace cvtest;
namespace cvtest {
//std::string generateVarList(int first,...) //std::string generateVarList(int first,...)
//{ //{
// vector<std::string> varname; // vector<std::string> varname;
@ -73,41 +73,14 @@ using namespace cvtest;
// return ss.str(); // return ss.str();
//}; //};
int randomInt(int minVal, int maxVal) cv::ocl::oclMat createMat_ocl(cv::RNG& rng, Size size, int type, bool useRoi)
{
RNG &rng = TS::ptr()->get_rng();
return rng.uniform(minVal, maxVal);
}
double randomDouble(double minVal, double maxVal)
{
RNG &rng = TS::ptr()->get_rng();
return rng.uniform(minVal, maxVal);
}
Size randomSize(int minVal, int maxVal)
{
return cv::Size(randomInt(minVal, maxVal), randomInt(minVal, maxVal));
}
Scalar randomScalar(double minVal, double maxVal)
{
return Scalar(randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal));
}
Mat randomMat(Size size, int type, double minVal, double maxVal)
{
return randomMat(TS::ptr()->get_rng(), size, type, minVal, maxVal, false);
}
cv::ocl::oclMat createMat_ocl(Size size, int type, bool useRoi)
{ {
Size size0 = size; Size size0 = size;
if (useRoi) if (useRoi)
{ {
size0.width += randomInt(5, 15); size0.width += rng.uniform(5, 15);
size0.height += randomInt(5, 15); size0.height += rng.uniform(5, 15);
} }
cv::ocl::oclMat d_m(size0, type); cv::ocl::oclMat d_m(size0, type);
@ -118,11 +91,11 @@ cv::ocl::oclMat createMat_ocl(Size size, int type, bool useRoi)
return d_m; return d_m;
} }
cv::ocl::oclMat loadMat_ocl(const Mat& m, bool useRoi) cv::ocl::oclMat loadMat_ocl(cv::RNG& rng, const Mat& m, bool useRoi)
{ {
CV_Assert(m.type() == CV_8UC1 || m.type() == CV_8UC3); CV_Assert(m.type() == CV_8UC1 || m.type() == CV_8UC3);
cv::ocl::oclMat d_m; cv::ocl::oclMat d_m;
d_m = createMat_ocl(m.size(), m.type(), useRoi); d_m = createMat_ocl(rng, m.size(), m.type(), useRoi);
Size ls; Size ls;
Point pt; Point pt;
@ -138,38 +111,6 @@ cv::ocl::oclMat loadMat_ocl(const Mat& m, bool useRoi)
m_ocl.copyTo(d_m); m_ocl.copyTo(d_m);
return d_m; return d_m;
} }
/*
void showDiff(InputArray gold_, InputArray actual_, double eps)
{
Mat gold;
if (gold_.kind() == _InputArray::MAT)
gold = gold_.getMat();
else
gold_.getGpuMat().download(gold);
Mat actual;
if (actual_.kind() == _InputArray::MAT)
actual = actual_.getMat();
else
actual_.getGpuMat().download(actual);
Mat diff;
absdiff(gold, actual, diff);
threshold(diff, diff, eps, 255.0, cv::THRESH_BINARY);
namedWindow("gold", WINDOW_NORMAL);
namedWindow("actual", WINDOW_NORMAL);
namedWindow("diff", WINDOW_NORMAL);
imshow("gold", gold);
imshow("actual", actual);
imshow("diff", diff);
waitKey();
}
*/
vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end) vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end)
{ {
@ -289,3 +230,5 @@ double checkRectSimilarity(Size sz, std::vector<Rect>& ob1, std::vector<Rect>& o
} }
return final_test_result; return final_test_result;
} }
} // namespace cvtest

@ -42,7 +42,7 @@
#ifndef __OPENCV_TEST_UTILITY_HPP__ #ifndef __OPENCV_TEST_UTILITY_HPP__
#define __OPENCV_TEST_UTILITY_HPP__ #define __OPENCV_TEST_UTILITY_HPP__
#define LOOP_TIMES 1 #define LOOP_TIMES 10
#define MWIDTH 256 #define MWIDTH 256
#define MHEIGHT 256 #define MHEIGHT 256
@ -50,16 +50,12 @@
#define MIN_VALUE 171 #define MIN_VALUE 171
#define MAX_VALUE 357 #define MAX_VALUE 357
//#define RANDOMROI namespace cvtest {
int randomInt(int minVal, int maxVal);
double randomDouble(double minVal, double maxVal);
//std::string generateVarList(int first,...);
std::string generateVarList(int &p1, int &p2);
cv::Size randomSize(int minVal, int maxVal);
cv::Scalar randomScalar(double minVal, double maxVal);
cv::Mat randomMat(cv::Size size, int type, double minVal = 0.0, double maxVal = 255.0);
void showDiff(cv::InputArray gold, cv::InputArray actual, double eps); //void showDiff(cv::InputArray gold, cv::InputArray actual, double eps);
cv::ocl::oclMat createMat_ocl(cv::RNG& rng, Size size, int type, bool useRoi);
cv::ocl::oclMat loadMat_ocl(cv::RNG& rng, const Mat& m, bool useRoi);
// This function test if gpu_rst matches cpu_rst. // This function test if gpu_rst matches cpu_rst.
// If the two vectors are not equal, it will return the difference in vector size // If the two vectors are not equal, it will return the difference in vector size
@ -76,10 +72,6 @@ double checkNorm(const cv::Mat &m);
double checkNorm(const cv::Mat &m1, const cv::Mat &m2); double checkNorm(const cv::Mat &m1, const cv::Mat &m2);
double checkSimilarity(const cv::Mat &m1, const cv::Mat &m2); double checkSimilarity(const cv::Mat &m1, const cv::Mat &m2);
//oclMat create
cv::ocl::oclMat createMat_ocl(cv::Size size, int type, bool useRoi = false);
cv::ocl::oclMat loadMat_ocl(const cv::Mat& m, bool useRoi = false);
#define EXPECT_MAT_NORM(mat, eps) \ #define EXPECT_MAT_NORM(mat, eps) \
{ \ { \
EXPECT_LE(checkNorm(cv::Mat(mat)), eps) \ EXPECT_LE(checkNorm(cv::Mat(mat)), eps) \
@ -99,13 +91,6 @@ cv::ocl::oclMat loadMat_ocl(const cv::Mat& m, bool useRoi = false);
EXPECT_LE(checkSimilarity(cv::Mat(mat1), cv::Mat(mat2)), eps); \ EXPECT_LE(checkSimilarity(cv::Mat(mat1), cv::Mat(mat2)), eps); \
} }
namespace cv
{
namespace ocl
{
// void PrintTo(const DeviceInfo& info, std::ostream* os);
}
}
using perf::MatDepth; using perf::MatDepth;
using perf::MatType; using perf::MatType;
@ -132,79 +117,105 @@ private:
void PrintTo(const Inverse &useRoi, std::ostream *os); void PrintTo(const Inverse &useRoi, std::ostream *os);
enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1}; #define OCL_RNG_SEED 123456
CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
CV_ENUM(CmpCode, CMP_EQ, CMP_GT, CMP_GE, CMP_LT, CMP_LE, CMP_NE) template <typename T>
CV_ENUM(NormCode, NORM_INF, NORM_L1, NORM_L2, NORM_TYPE_MASK, NORM_RELATIVE, NORM_MINMAX) struct TSTestWithParam : public ::testing::TestWithParam<T>
CV_ENUM(ReduceOp, CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN) {
CV_ENUM(MorphOp, MORPH_OPEN, MORPH_CLOSE, MORPH_GRADIENT, MORPH_TOPHAT, MORPH_BLACKHAT) cv::RNG rng;
CV_ENUM(ThreshOp, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV)
CV_ENUM(Interpolation, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC)
CV_ENUM(Border, BORDER_REFLECT101, BORDER_REPLICATE, BORDER_CONSTANT, BORDER_REFLECT, BORDER_WRAP)
CV_ENUM(TemplateMethod, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED)
CV_FLAGS(GemmFlags, GEMM_1_T, GEMM_2_T, GEMM_3_T); TSTestWithParam()
CV_FLAGS(WarpFlags, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, WARP_INVERSE_MAP) {
CV_FLAGS(DftFlags, DFT_INVERSE, DFT_SCALE, DFT_ROWS, DFT_COMPLEX_OUTPUT, DFT_REAL_OUTPUT) rng = cv::RNG(OCL_RNG_SEED);
}
void run_perf_test(); int randomInt(int minVal, int maxVal)
{
return rng.uniform(minVal, maxVal);
}
#define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< std::tr1::tuple< __VA_ARGS__ > > double randomDouble(double minVal, double maxVal)
{
return rng.uniform(minVal, maxVal);
}
#define GET_PARAM(k) std::tr1::get< k >(GetParam()) double randomDoubleLog(double minVal, double maxVal)
{
double logMin = log((double)minVal + 1);
double logMax = log((double)maxVal + 1);
double pow = rng.uniform(logMin, logMax);
double v = exp(pow) - 1;
CV_Assert(v >= minVal && (v < maxVal || (v == minVal && v == maxVal)));
return v;
}
#define ALL_DEVICES testing::ValuesIn(devices()) Size randomSize(int minVal, int maxVal)
#define DEVICES(feature) testing::ValuesIn(devices(feature)) {
#if 1
return cv::Size((int)randomDoubleLog(minVal, maxVal), (int)randomDoubleLog(minVal, maxVal));
#else
return cv::Size(randomInt(minVal, maxVal), randomInt(minVal, maxVal));
#endif
}
#define ALL_TYPES testing::ValuesIn(all_types()) Size randomSize(int minValX, int maxValX, int minValY, int maxValY)
#define TYPES(depth_start, depth_end, cn_start, cn_end) testing::ValuesIn(types(depth_start, depth_end, cn_start, cn_end)) {
#if 1
return cv::Size(randomDoubleLog(minValX, maxValX), randomDoubleLog(minValY, maxValY));
#else
return cv::Size(randomInt(minVal, maxVal), randomInt(minVal, maxVal));
#endif
}
#define DIFFERENT_SIZES testing::Values(cv::Size(128, 128), cv::Size(113, 113), cv::Size(1300, 1300)) Scalar randomScalar(double minVal, double maxVal)
{
return Scalar(randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal));
}
#define DIRECT_INVERSE testing::Values(Inverse(false), Inverse(true)) Mat randomMat(Size size, int type, double minVal, double maxVal, bool useRoi = false)
{
RNG dataRng(rng.next());
return cvtest::randomMat(dataRng, size, type, minVal, maxVal, useRoi);
}
#ifndef ALL_DEPTH struct Border
#define ALL_DEPTH testing::Values(MatDepth(CV_8U), MatDepth(CV_8S), MatDepth(CV_16U), MatDepth(CV_16S), MatDepth(CV_32S), MatDepth(CV_32F), MatDepth(CV_64F)) {
#endif int top, bot, lef, rig;
#define REPEAT 1000 };
#define COUNT_U 0 // count the uploading execution time for ocl mat structures
#define COUNT_D 0
// the following macro section tests the target function (kernel) performance
// upload is the code snippet for converting cv::mat to cv::ocl::oclMat
// downloading is the code snippet for converting cv::ocl::oclMat back to cv::mat
// change COUNT_U and COUNT_D to take downloading and uploading time into account
#define P_TEST_FULL( upload, kernel_call, download ) \
{ \
std::cout<< "\n" #kernel_call "\n----------------------"; \
{upload;} \
R_TEST( kernel_call, 2 ); \
double t = (double)cvGetTickCount(); \
R_T( { \
if( COUNT_U ) {upload;} \
kernel_call; \
if( COUNT_D ) {download;} \
} ); \
t = (double)cvGetTickCount() - t; \
std::cout << "runtime is " << t/((double)cvGetTickFrequency()* 1000.) << "ms" << std::endl; \
}
#define R_T2( test ) \ Border randomBorder(int minValue = 0, int maxValue = MAX_VALUE)
{ \ {
std::cout<< "\n" #test "\n----------------------"; \ Border border = {
R_TEST( test, 15 ) \ (int)randomDoubleLog(minValue, maxValue),
clock_t st = clock(); \ (int)randomDoubleLog(minValue, maxValue),
R_T( test ) \ (int)randomDoubleLog(minValue, maxValue),
std::cout<< clock() - st << "ms\n"; \ (int)randomDoubleLog(minValue, maxValue)
} };
#define R_T( test ) \ return border;
R_TEST( test, REPEAT ) }
#define R_TEST( test, repeat ) \
try{ \ void randomSubMat(Mat& whole, Mat& subMat, const Size& roiSize, const Border& border, int type, double minVal, double maxVal)
for( int i = 0; i < repeat; i ++ ) { test; } \ {
} catch( ... ) { std::cout << "||||| Exception catched! |||||\n"; return; } Size wholeSize = Size(roiSize.width + border.lef + border.rig, roiSize.height + border.top + border.bot);
whole = randomMat(wholeSize, type, minVal, maxVal, false);
subMat = whole(Rect(border.lef, border.top, roiSize.width, roiSize.height));
}
void generateOclMat(cv::ocl::oclMat& whole, cv::ocl::oclMat& subMat, const Mat& wholeMat, const Size& roiSize, const Border& border)
{
whole = wholeMat;
subMat = whole(Rect(border.lef, border.top, roiSize.width, roiSize.height));
}
};
#define PARAM_TEST_CASE(name, ...) struct name : public TSTestWithParam< std::tr1::tuple< __VA_ARGS__ > >
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
#define ALL_TYPES testing::ValuesIn(all_types())
#define TYPES(depth_start, depth_end, cn_start, cn_end) testing::ValuesIn(types(depth_start, depth_end, cn_start, cn_end))
//////// Utility #define DIFFERENT_SIZES testing::Values(cv::Size(128, 128), cv::Size(113, 113), cv::Size(1300, 1300))
#define IMAGE_CHANNELS testing::Values(Channels(1), Channels(3), Channels(4)) #define IMAGE_CHANNELS testing::Values(Channels(1), Channels(3), Channels(4))
#ifndef IMPLEMENT_PARAM_CLASS #ifndef IMPLEMENT_PARAM_CLASS
@ -225,4 +236,22 @@ void run_perf_test();
IMPLEMENT_PARAM_CLASS(Channels, int) IMPLEMENT_PARAM_CLASS(Channels, int)
#endif // IMPLEMENT_PARAM_CLASS #endif // IMPLEMENT_PARAM_CLASS
} // namespace cvtest
enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
CV_ENUM(CmpCode, CMP_EQ, CMP_GT, CMP_GE, CMP_LT, CMP_LE, CMP_NE)
CV_ENUM(NormCode, NORM_INF, NORM_L1, NORM_L2, NORM_TYPE_MASK, NORM_RELATIVE, NORM_MINMAX)
CV_ENUM(ReduceOp, CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN)
CV_ENUM(MorphOp, MORPH_OPEN, MORPH_CLOSE, MORPH_GRADIENT, MORPH_TOPHAT, MORPH_BLACKHAT)
CV_ENUM(ThreshOp, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV)
CV_ENUM(Interpolation, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC)
CV_ENUM(Border, BORDER_REFLECT101, BORDER_REPLICATE, BORDER_CONSTANT, BORDER_REFLECT, BORDER_WRAP)
CV_ENUM(TemplateMethod, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED)
CV_FLAGS(GemmFlags, GEMM_1_T, GEMM_2_T, GEMM_3_T);
CV_FLAGS(WarpFlags, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, WARP_INVERSE_MAP)
CV_FLAGS(DftFlags, DFT_INVERSE, DFT_SCALE, DFT_ROWS, DFT_COMPLEX_OUTPUT, DFT_REAL_OUTPUT)
#endif // __OPENCV_TEST_UTILITY_HPP__ #endif // __OPENCV_TEST_UTILITY_HPP__

Loading…
Cancel
Save