Commit de0f310e authored by Alexander Alekhin's avatar Alexander Alekhin

ocl: tests: RNG usage refactoring

parent 8224f984
This diff is collapsed.
......@@ -85,9 +85,7 @@ PARAM_TEST_CASE(mog, UseGray, LearningRate, bool)
virtual void SetUp()
{
useGray = GET_PARAM(0);
learningRate = GET_PARAM(1);
useRoi = GET_PARAM(2);
}
};
......@@ -103,7 +101,7 @@ TEST_P(mog, Update)
ASSERT_FALSE(frame.empty());
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::Mat foreground_gold;
......@@ -120,7 +118,7 @@ TEST_P(mog, Update)
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);
......@@ -165,7 +163,7 @@ TEST_P(mog2, Update)
cv::ocl::MOG2 mog2;
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;
mog2_gold.set("detectShadows", detectShadow);
......@@ -183,7 +181,7 @@ TEST_P(mog2, Update)
cv::swap(temp, frame);
}
mog2(loadMat_ocl(frame, useRoi), foreground);
mog2(loadMat_ocl(rng, frame, useRoi), foreground);
mog2_gold(frame, foreground_gold);
......@@ -218,12 +216,12 @@ TEST_P(mog2, getBackgroundImage)
cap >> frame;
ASSERT_FALSE(frame.empty());
mog2(loadMat_ocl(frame, useRoi), foreground);
mog2(loadMat_ocl(rng, frame, useRoi), foreground);
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);
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
countFactor = 4; // do not change it
cv::RNG &rng = cvtest::TS::ptr()->get_rng();
cv::Mat queryBuf, trainBuf;
// Generate query descriptors randomly.
......
......@@ -46,10 +46,10 @@
#include "test_precomp.hpp"
#include <iomanip>
#ifdef HAVE_OPENCL
using namespace cv;
#ifdef HAVE_OPENCL
PARAM_TEST_CASE(StereoMatchBM, int, int)
{
int n_disp;
......
......@@ -91,7 +91,6 @@ PARAM_TEST_CASE(FilterTestBase,
{
#ifdef RANDOMROI
//randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(2, mat1.cols);
roirows = rng.uniform(2, mat1.rows);
src1x = rng.uniform(0, mat1.cols - roicols);
......@@ -201,7 +200,6 @@ struct ErodeDilate : FilterTestBase
type = GET_PARAM(0);
iterations = GET_PARAM(3);
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);
}
......@@ -304,7 +302,6 @@ struct GaussianBlur : FilterTestBase
ksize = GET_PARAM(1);
bordertype = GET_PARAM(3);
Init(type);
cv::RNG &rng = TS::ptr()->get_rng();
sigma1 = rng.uniform(0.1, 1.0);
sigma2 = rng.uniform(0.1, 1.0);
}
......@@ -368,7 +365,6 @@ struct Bilateral : FilterTestBase
ksize = GET_PARAM(1);
bordertype = GET_PARAM(3);
Init(type);
cv::RNG &rng = TS::ptr()->get_rng();
sigmacolor = rng.uniform(20, 100);
sigmaspace = rng.uniform(10, 40);
}
......
......@@ -351,33 +351,32 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo
type3 = GET_PARAM(2);
type4 = GET_PARAM(3);
type5 = GET_PARAM(4);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(MWIDTH, MHEIGHT);
double min = 1, max = 20;
if(type1 != nulltype)
{
mat1 = randomMat(rng, size, type1, min, max, false);
mat1 = randomMat(size, type1, min, max, false);
clmat1 = mat1;
}
if(type2 != nulltype)
{
mat2 = randomMat(rng, size, type2, min, max, false);
mat2 = randomMat(size, type2, min, max, false);
clmat2 = mat2;
}
if(type3 != nulltype)
{
dst = randomMat(rng, size, type3, min, max, false);
dst = randomMat(size, type3, min, max, false);
cldst = dst;
}
if(type4 != nulltype)
{
dst1 = randomMat(rng, size, type4, min, max, false);
dst1 = randomMat(size, type4, min, max, false);
cldst1 = dst1;
}
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);
clmask = mask;
}
......@@ -388,7 +387,6 @@ PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bo
{
#ifdef RANDOMROI
//randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, mat1.cols);
roirows = rng.uniform(1, mat1.rows);
src1x = rng.uniform(0, mat1.cols - roicols);
......@@ -482,7 +480,6 @@ struct CopyMakeBorder : ImgprocTestBase {};
TEST_P(CopyMakeBorder, Mat)
{
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 bottom = rng.uniform(0, 10);
int left = rng.uniform(0, 10);
......@@ -634,22 +631,17 @@ PARAM_TEST_CASE(WarpTestBase, MatType, int)
virtual void SetUp()
{
type = GET_PARAM(0);
//dsize = GET_PARAM(1);
interpolation = GET_PARAM(1);
cv::RNG &rng = TS::ptr()->get_rng();
size = cv::Size(MWIDTH, MHEIGHT);
mat1 = randomMat(rng, size, type, 5, 16, false);
dst = randomMat(rng, size, type, 5, 16, false);
mat1 = randomMat(size, type, 5, 16, false);
dst = randomMat(size, type, 5, 16, false);
}
void random_roi()
{
#ifdef RANDOMROI
//randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
src_roicols = rng.uniform(1, mat1.cols);
src_roirows = rng.uniform(1, mat1.rows);
dst_roicols = rng.uniform(1, dst.cols);
......@@ -798,23 +790,22 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int)
interpolation = GET_PARAM(3);
bordertype = GET_PARAM(4);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size srcSize = cv::Size(MWIDTH, MHEIGHT);
cv::Size map1Size = cv::Size(MWIDTH, MHEIGHT);
double min = 5, max = 16;
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))
{
map1 = randomMat(rng, map1Size, map1Type, min, max, false);
map1 = randomMat(map1Size, map1Type, min, max, false);
}
else if (map1Type == CV_32FC1 && map2Type == CV_32FC1)
{
map1 = randomMat(rng, map1Size, map1Type, min, max, false);
map2 = randomMat(rng, map1Size, map1Type, min, max, false);
map1 = randomMat(map1Size, map1Type, min, max, false);
map2 = randomMat(map1Size, map1Type, min, max, false);
}
else
......@@ -823,7 +814,7 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int)
return;
}
dst = randomMat(rng, map1Size, srcType, min, max, false);
dst = randomMat(map1Size, srcType, min, max, false);
switch (src.channels())
{
case 1:
......@@ -843,8 +834,6 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int)
}
void random_roi()
{
cv::RNG &rng = TS::ptr()->get_rng();
dst_roicols = rng.uniform(1, dst.cols);
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);
interpolation = GET_PARAM(4);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(MWIDTH, MHEIGHT);
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);
}
mat1 = randomMat(rng, size, type, 5, 16, false);
dst = randomMat(rng, dsize, type, 5, 16, false);
mat1 = randomMat(size, 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
//randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
src_roicols = rng.uniform(1, mat1.cols);
src_roirows = rng.uniform(1, mat1.rows);
dst_roicols = (int)(src_roicols * fx);
......@@ -1070,18 +1056,16 @@ PARAM_TEST_CASE(Threshold, MatType, ThreshOp)
type = GET_PARAM(0);
threshOp = GET_PARAM(1);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(MWIDTH, MHEIGHT);
mat1 = randomMat(rng, size, type, 5, 16, false);
dst = randomMat(rng, size, type, 5, 16, false);
mat1 = randomMat(size, type, 5, 16, false);
dst = randomMat(size, type, 5, 16, false);
}
void random_roi()
{
#ifdef RANDOMROI
//randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, mat1.cols);
roirows = rng.uniform(1, mat1.rows);
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);
crit = GET_PARAM(4);
cv::RNG &rng = TS::ptr()->get_rng();
// MWIDTH=256, MHEIGHT=256. defined in utility.hpp
cv::Size size = cv::Size(MWIDTH, MHEIGHT);
src = randomMat(rng, size, type, 5, 16, false);
dst = randomMat(rng, size, type, 5, 16, false);
dstCoor = randomMat(rng, size, typeCoor, 5, 16, false);
src = randomMat(size, type, 5, 16, false);
dst = randomMat(size, type, 5, 16, false);
dstCoor = randomMat(size, typeCoor, 5, 16, false);
}
void random_roi()
{
#ifdef RANDOMROI
cv::RNG &rng = TS::ptr()->get_rng();
//randomize ROI
roicols = rng.uniform(1, src.cols);
roirows = rng.uniform(1, src.rows);
......@@ -1295,18 +1275,15 @@ PARAM_TEST_CASE(histTestBase, MatType, MatType)
{
type_src = GET_PARAM(0);
cv::RNG &rng = TS::ptr()->get_rng();
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()
{
#ifdef RANDOMROI
cv::RNG &rng = TS::ptr()->get_rng();
//randomize ROI
roicols = rng.uniform(1, src.cols);
roirows = rng.uniform(1, src.rows);
......@@ -1360,8 +1337,7 @@ PARAM_TEST_CASE(CLAHE, cv::Size, double)
gridSize = GET_PARAM(0);
clipLimit = GET_PARAM(1);
cv::RNG &rng = TS::ptr()->get_rng();
src = randomMat(rng, cv::Size(MWIDTH, MHEIGHT), CV_8UC1, 0, 256, false);
src = randomMat(cv::Size(MWIDTH, MHEIGHT), CV_8UC1, 0, 256, false);
g_src.upload(src);
}
};
......@@ -1413,19 +1389,15 @@ PARAM_TEST_CASE(ConvolveTestBase, MatType, bool)
{
type = GET_PARAM(0);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(MWIDTH, MHEIGHT);
mat1 = randomMat(rng, size, type, 5, 16, false);
mat2 = randomMat(rng, size, type, 5, 16, false);
dst = randomMat(rng, size, type, 5, 16, false);
dst1 = randomMat(rng, size, type, 5, 16, false);
mat1 = randomMat(size, type, 5, 16, false);
mat2 = randomMat(size, type, 5, 16, false);
dst = randomMat(size, type, 5, 16, false);
dst1 = randomMat(size, type, 5, 16, false);
}
void random_roi()
{
cv::RNG &rng = TS::ptr()->get_rng();
#ifdef RANDOMROI
//randomize ROI
roicols = rng.uniform(1, mat1.cols);
......@@ -1530,7 +1502,7 @@ PARAM_TEST_CASE(ColumnSum, cv::Size)
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_src(src);
......
......@@ -69,8 +69,6 @@ TEST_P(Kalman, Accuracy)
const double max_init = 1;
const double max_noise = 0.1;
cv::RNG &rng = TS::ptr()->get_rng();
Mat sample_mat(Dim, 1, CV_32F), temp_mat;
oclMat Sample(Dim, 1, CV_32F);
oclMat Temp(Dim, 1, CV_32F);
......@@ -78,7 +76,7 @@ TEST_P(Kalman, Accuracy)
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);
//ocl start
......@@ -120,7 +118,7 @@ TEST_P(Kalman, Accuracy)
cv::gemm(kalman_filter_cpu.transitionMatrix, sample_mat, 1, cv::Mat(), 0, Temp_cpu);
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);
......
......@@ -66,12 +66,11 @@ PARAM_TEST_CASE(Kmeans, int, int, int)
Mat labels, centers;
ocl::oclMat d_labels, d_centers;
cv::RNG rng ;
virtual void SetUp(){
virtual void SetUp()
{
K = GET_PARAM(0);
type = GET_PARAM(1);
flags = GET_PARAM(2);
rng = TS::ptr()->get_rng();
// MWIDTH=256, MHEIGHT=256. defined in utility.hpp
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);
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;
}
row_idx += 1 + max_neighbour;
......
......@@ -72,8 +72,8 @@ PARAM_TEST_CASE(MatchTemplate8U, cv::Size, TemplateSize, Channels, TemplateMetho
TEST_P(MatchTemplate8U, Accuracy)
{
cv::Mat image = randomMat(size, CV_MAKETYPE(CV_8U, cn));
cv::Mat templ = randomMat(templ_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), 0, 255);
cv::ocl::oclMat dst, ocl_image(image), ocl_templ(templ);
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)
{
cv::Mat image = randomMat(size, CV_MAKETYPE(CV_32F, cn));
cv::Mat templ = randomMat(templ_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), 0, 255);
cv::ocl::oclMat dst, ocl_image(image), ocl_templ(templ);
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);
cv::RNG &rng = TS::ptr()->get_rng();
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);
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);
}
void random_roi()
......@@ -101,7 +99,6 @@ PARAM_TEST_CASE(ConvertToTestBase, MatType, MatType, int, bool)
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, mat.cols - roicols);
......@@ -178,11 +175,9 @@ PARAM_TEST_CASE(CopyToTestBase, MatType, int, bool)
int type = CV_MAKETYPE(GET_PARAM(0), GET_PARAM(1));
use_roi = GET_PARAM(2);
cv::RNG &rng = TS::ptr()->get_rng();
src = randomMat(rng, randomSize(MIN_VALUE, MAX_VALUE), type, 5, 16, 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);
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);
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);
}
......@@ -192,7 +187,6 @@ PARAM_TEST_CASE(CopyToTestBase, MatType, int, bool)
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);
......@@ -295,11 +289,10 @@ PARAM_TEST_CASE(SetToTestBase, MatType, int, bool)
channels = GET_PARAM(1);
use_roi = GET_PARAM(2);
cv::RNG &rng = TS::ptr()->get_rng();
int type = CV_MAKE_TYPE(depth, channels);
src = randomMat(rng, 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);
src = randomMat(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);
cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
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)
{
// 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);
......@@ -401,8 +393,7 @@ PARAM_TEST_CASE(convertC3C4, MatType, bool)
use_roi = GET_PARAM(1);
int type = CV_MAKE_TYPE(depth, 3);
cv::RNG &rng = TS::ptr()->get_rng();
src = randomMat(rng, randomSize(1, MAX_VALUE), type, 0, 40, false);
src = randomMat(randomSize(1, MAX_VALUE), type, 0, 40, false);
}
void random_roi()
......@@ -410,7 +401,6 @@ PARAM_TEST_CASE(convertC3C4, MatType, bool)
if (use_roi)
{
//randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, src.cols);
roirows = rng.uniform(1, src.rows);
srcx = rng.uniform(0, src.cols - roicols);
......
......@@ -50,10 +50,9 @@ using namespace cv::ocl;
using namespace cvtest;
using namespace testing;
///////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)
{
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(trainDataCol, trainDataRow);
trainData = randomMat(rng, size, CV_32FC1, 1.0, 1000.0, false);
if(nClasses != 0)
......@@ -85,10 +84,10 @@ TEST_P(KNN, Accuracy)
{
Mat trainData, trainLabels;
const int trainDataRow = 500;
genTrainData(trainData, trainDataRow, trainDataCol, trainLabels, nClass);
genTrainData(rng, trainData, trainDataRow, trainDataCol, trainLabels, nClass);
Mat testData, testLabels;
genTrainData(testData, testDataRow, trainDataCol);
genTrainData(rng, testData, testDataRow, trainDataCol);
KNearestNeighbour knn_ocl;
CvKNearest knn_cpu;
......@@ -130,7 +129,6 @@ PARAM_TEST_CASE(SVM_OCL, int, int, int)
int svm_type;
Mat src, labels, samples, labels_predict;
int K;
cv::RNG rng ;
virtual void SetUp()
{
......@@ -138,7 +136,6 @@ PARAM_TEST_CASE(SVM_OCL, int, int, int)
kernel_type = GET_PARAM(0);
svm_type = GET_PARAM(1);
K = GET_PARAM(2);
rng = TS::ptr()->get_rng();
cv::Size size = cv::Size(MWIDTH, MHEIGHT);
src.create(size, CV_32FC1);
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);
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;
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);
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;
labels_predict.at<int>(0, row_idx + 1 + j) = i;
}
......
......@@ -9,7 +9,7 @@ using namespace cv::ocl;
using namespace cvtest;
using namespace testing;
using namespace std;
extern string workdir;
PARAM_TEST_CASE(MomentsTest, MatType, bool)
{
int type;
......@@ -20,9 +20,8 @@ PARAM_TEST_CASE(MomentsTest, MatType, bool)
{
type = GET_PARAM(0);
test_contours = GET_PARAM(1);
cv::RNG &rng = TS::ptr()->get_rng();
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)
......@@ -39,7 +38,6 @@ PARAM_TEST_CASE(MomentsTest, MatType, bool)
TEST_P(MomentsTest, Mat)
{
bool binaryImage = 0;
SetUp();
for(int j = 0; j < LOOP_TIMES; j++)
{
......
......@@ -51,8 +51,6 @@ using namespace cv;
using namespace testing;
#ifdef HAVE_OPENCL
extern string workdir;
///////////////////// HOG /////////////////////////////
PARAM_TEST_CASE(HOG, Size, int)
{
......
......@@ -54,9 +54,6 @@ using namespace cvtest;
using namespace testing;
using namespace std;
extern string workdir;
//////////////////////////////////////////////////////
// GoodFeaturesToTrack
namespace
......@@ -153,9 +150,8 @@ TEST_P(TVL1, Accuracy)
ASSERT_FALSE(frame1.empty());
cv::ocl::OpticalFlowDual_TVL1_OCL d_alg;
cv::RNG &rng = TS::ptr()->get_rng();
cv::Mat flowx = randomMat(rng, frame0.size(), CV_32FC1, 0, 0, useRoi);
cv::Mat flowy = randomMat(rng, frame0.size(), CV_32FC1, 0, 0, useRoi);
cv::Mat flowx = randomMat(frame0.size(), CV_32FC1, 0, 0, useRoi);
cv::Mat flowy = randomMat(frame0.size(), CV_32FC1, 0, 0, useRoi);
cv::ocl::oclMat d_flowx(flowx), d_flowy(flowy);
d_alg(oclMat(frame0), oclMat(frame1), d_flowx, d_flowy);
......
......@@ -73,4 +73,6 @@
#include "utility.hpp"
//#include "add_test_info.h"
using namespace cvtest;
#endif
......@@ -79,7 +79,7 @@ TEST_P(PyrDown, Mat)
for (int j = 0; j < LOOP_TIMES; j++)
{
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);
pyrDown(src, dst_cpu);
......@@ -102,7 +102,7 @@ TEST_P(PyrUp, Accuracy)
for (int j = 0; j < LOOP_TIMES; j++)
{
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);
pyrUp(src, dst_cpu);
......
......@@ -90,12 +90,11 @@ PARAM_TEST_CASE(MergeTestBase, MatType, int, bool)
channels = GET_PARAM(1);
use_roi = GET_PARAM(2);
cv::RNG &rng = TS::ptr()->get_rng();
cv::Size size(MWIDTH, MHEIGHT);
for (int i = 0; i < channels; ++i)
mat[i] = randomMat(rng, size, CV_MAKETYPE(type, 1), 5, 16, false);
dst = randomMat(rng, size, CV_MAKETYPE(type, channels), 5, 16, false);
mat[i] = randomMat(size, CV_MAKETYPE(type, 1), 5, 16, false);
dst = randomMat(size, CV_MAKETYPE(type, channels), 5, 16, false);
}
void random_roi()
......@@ -103,7 +102,6 @@ PARAM_TEST_CASE(MergeTestBase, MatType, int, bool)
if (use_roi)
{
//randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, mat[0].cols);
roirows = rng.uniform(1, mat[0].rows);
......@@ -191,19 +189,17 @@ PARAM_TEST_CASE(SplitTestBase, MatType, int, bool)
channels = GET_PARAM(1);
use_roi = GET_PARAM(2);
cv::RNG &rng = TS::ptr()->get_rng();
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)
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()
{
if (use_roi)
{
//randomize ROI
cv::RNG &rng = TS::ptr()->get_rng();
roicols = rng.uniform(1, mat.cols);
roirows = rng.uniform(1, mat.rows);
srcx = rng.uniform(0, mat.cols - roicols);
......
......@@ -46,7 +46,7 @@ using namespace cv;
using namespace cv::gpu;
using namespace cvtest;
namespace cvtest {
//std::string generateVarList(int first,...)
//{
// vector<std::string> varname;
......@@ -73,41 +73,14 @@ using namespace cvtest;
// return ss.str();
//};
int randomInt(int minVal, int maxVal)
{
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)
cv::ocl::oclMat createMat_ocl(cv::RNG& rng, Size size, int type, bool useRoi)
{
Size size0 = size;
if (useRoi)
{
size0.width += randomInt(5, 15);
size0.height += randomInt(5, 15);
size0.width += rng.uniform(5, 15);
size0.height += rng.uniform(5, 15);
}
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;
}
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::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;
Point pt;
......@@ -138,38 +111,6 @@ cv::ocl::oclMat loadMat_ocl(const Mat& m, bool useRoi)
m_ocl.copyTo(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)
{
......@@ -289,3 +230,5 @@ double checkRectSimilarity(Size sz, std::vector<Rect>& ob1, std::vector<Rect>& o
}
return final_test_result;
}
} // namespace cvtest
......@@ -42,7 +42,7 @@
#ifndef __OPENCV_TEST_UTILITY_HPP__
#define __OPENCV_TEST_UTILITY_HPP__
#define LOOP_TIMES 1
#define LOOP_TIMES 10
#define MWIDTH 256
#define MHEIGHT 256
......@@ -50,16 +50,12 @@
#define MIN_VALUE 171
#define MAX_VALUE 357
//#define RANDOMROI
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);
namespace cvtest {
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.
// 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 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) \
{ \
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); \
}
namespace cv
{
namespace ocl
{
// void PrintTo(const DeviceInfo& info, std::ostream* os);
}
}
using perf::MatDepth;
using perf::MatType;
......@@ -132,79 +117,105 @@ private:
void PrintTo(const Inverse &useRoi, std::ostream *os);
enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
#define OCL_RNG_SEED 123456
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)
template <typename T>
struct TSTestWithParam : public ::testing::TestWithParam<T>
{
cv::RNG rng;
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)
TSTestWithParam()
{
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())
#define DEVICES(feature) testing::ValuesIn(devices(feature))
Size randomSize(int minVal, int maxVal)
{
#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())
#define TYPES(depth_start, depth_end, cn_start, cn_end) testing::ValuesIn(types(depth_start, depth_end, cn_start, cn_end))
Size randomSize(int minValX, int maxValX, int minValY, int maxValY)
{
#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
#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
#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; \
}
struct Border
{
int top, bot, lef, rig;
};
#define R_T2( test ) \
{ \
std::cout<< "\n" #test "\n----------------------"; \
R_TEST( test, 15 ) \
clock_t st = clock(); \
R_T( test ) \
std::cout<< clock() - st << "ms\n"; \
}
#define R_T( test ) \
R_TEST( test, REPEAT )
#define R_TEST( test, repeat ) \
try{ \
for( int i = 0; i < repeat; i ++ ) { test; } \
} catch( ... ) { std::cout << "||||| Exception catched! |||||\n"; return; }
Border randomBorder(int minValue = 0, int maxValue = MAX_VALUE)
{
Border border = {
(int)randomDoubleLog(minValue, maxValue),
(int)randomDoubleLog(minValue, maxValue),
(int)randomDoubleLog(minValue, maxValue),
(int)randomDoubleLog(minValue, maxValue)
};
return border;
}
void randomSubMat(Mat& whole, Mat& subMat, const Size& roiSize, const Border& border, int type, double minVal, double maxVal)
{
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))
#ifndef IMPLEMENT_PARAM_CLASS
......@@ -225,4 +236,22 @@ void run_perf_test();
IMPLEMENT_PARAM_CLASS(Channels, int)
#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__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment