7 const int ARITHM_NTESTS = 1000;
8 const int ARITHM_RNG_SEED = -1;
9 const int ARITHM_MAX_NDIMS = 4;
10 const int ARITHM_MAX_SIZE_LOG = 10;
11 const int ARITHM_MAX_CHANNELS = 4;
13 static void getArithmValueRange(int depth, double& minval, double& maxval)
15 minval = depth < CV_32S ? cvtest::getMinVal(depth) : depth == CV_32S ? -1000000 : -1000.;
16 maxval = depth < CV_32S ? cvtest::getMinVal(depth) : depth == CV_32S ? 1000000 : 1000.;
19 static double getArithmMaxErr(int depth)
21 return depth < CV_32F ? 0 : 4;
27 RNG rng(ARITHM_RNG_SEED);
28 for( testIdx = 0; testIdx < ARITHM_NTESTS; testIdx++ )
30 double minval, maxval;
32 cvtest::randomSize(rng, 2, ARITHM_MAX_NDIMS, ARITHM_MAX_SIZE_LOG, size);
33 int type = cvtest::randomType(rng, cvtest::TYPE_MASK_ALL, 1, ARITHM_MAX_CHANNELS);
34 int depth = CV_MAT_DEPTH(type);
35 bool haveMask = rng.uniform(0, 4) == 0;
37 getArithmValueRange(depth, minval, maxval);
38 Mat src1 = cvtest::randomMat(rng, size, type, minval, maxval, true);
39 Mat src2 = cvtest::randomMat(rng, size, type, minval, maxval, true);
40 Mat dst0 = cvtest::randomMat(rng, size, type, minval, maxval, false);
41 Mat dst = cvtest::randomMat(rng, size, type, minval, maxval, true);
45 mask = cvtest::randomMat(rng, size, CV_8U, 0, 2, true);
46 cvtest::copy(dst0, dst);
47 cvtest::add(src1, 1, src2, 1, Scalar::all(0), dst0, dst.type());
48 cvtest::copy(dst, dst0, mask, true);
49 add(src1, src2, dst, mask);
53 cvtest::add(src1, 1, src2, 1, Scalar::all(0), dst0, dst.type());
57 double maxErr = getArithmMaxErr(depth);
59 ASSERT_TRUE(cvtest::cmpEps(dst0, dst, maxErr, &pos)) << "position: " << Mat(pos);