updated the new arithmetic tests

pull/13383/head
Vadim Pisarevsky 14 years ago
parent 57f917d6f2
commit d2c2c07ad2
  1. 68
      modules/core/test/test_arithm.cpp
  2. 29
      modules/gtest/include/opencv2/gtest/gtestcv.hpp
  3. 1114
      modules/gtest/src/gtestcv.cpp

@ -1,25 +1,61 @@
#include "precomp.hpp" #include "precomp.hpp"
#include <iostream>
using namespace cv; using namespace cv;
using namespace std;
const int ARITHM_NTESTS = 1000;
const int ARITHM_RNG_SEED = -1;
const int ARITHM_MAX_NDIMS = 4;
const int ARITHM_MAX_SIZE_LOG = 10;
const int ARITHM_MAX_CHANNELS = 4;
static void getArithmValueRange(int depth, double& minval, double& maxval)
{
minval = depth < CV_32S ? cvtest::getMinVal(depth) : depth == CV_32S ? -1000000 : -1000.;
maxval = depth < CV_32S ? cvtest::getMinVal(depth) : depth == CV_32S ? 1000000 : 1000.;
}
static double getArithmMaxErr(int depth)
{
return depth < CV_32F ? 0 : 4;
}
TEST(ArithmTest, add) TEST(ArithmTest, add)
{ {
typedef uchar _Tp; int testIdx = 0;
RNG rng(ARITHM_RNG_SEED);
Mat A(30,30,DataType<_Tp>::type), B(A.size(), A.type()), C0, C; for( testIdx = 0; testIdx < ARITHM_NTESTS; testIdx++ )
RNG rng(-1);
rng.fill(A, RNG::UNIFORM, Scalar::all(0), Scalar::all(256));
rng.fill(B, RNG::UNIFORM, Scalar::all(0), Scalar::all(256));
C0.create(A.size(), A.type());
int i, j, cols = A.cols*A.channels();
for(i = 0; i < A.rows; i++)
{ {
const _Tp* aptr = A.ptr<_Tp>(i); double minval, maxval;
const _Tp* bptr = B.ptr<_Tp>(i); vector<int> size;
_Tp* cptr = C0.ptr<_Tp>(i); cvtest::randomSize(rng, 2, ARITHM_MAX_NDIMS, ARITHM_MAX_SIZE_LOG, size);
for(j = 0; j < cols; j++) int type = cvtest::randomType(rng, cvtest::TYPE_MASK_ALL, 1, ARITHM_MAX_CHANNELS);
cptr[j] = saturate_cast<_Tp>(aptr[j] + bptr[j]); int depth = CV_MAT_DEPTH(type);
bool haveMask = rng.uniform(0, 4) == 0;
getArithmValueRange(depth, minval, maxval);
Mat src1 = cvtest::randomMat(rng, size, type, minval, maxval, true);
Mat src2 = cvtest::randomMat(rng, size, type, minval, maxval, true);
Mat dst0 = cvtest::randomMat(rng, size, type, minval, maxval, false);
Mat dst = cvtest::randomMat(rng, size, type, minval, maxval, true);
Mat mask;
if( haveMask )
{
mask = cvtest::randomMat(rng, size, CV_8U, 0, 2, true);
cvtest::copy(dst0, dst);
cvtest::add(src1, 1, src2, 1, Scalar::all(0), dst0, dst.type());
cvtest::copy(dst, dst0, mask, true);
add(src1, src2, dst, mask);
}
else
{
cvtest::add(src1, 1, src2, 1, Scalar::all(0), dst0, dst.type());
add(src1, src2, dst);
}
double maxErr = getArithmMaxErr(depth);
vector<int> pos;
ASSERT_TRUE(cvtest::cmpEps(dst0, dst, maxErr, &pos)) << "position: " << Mat(pos);
} }
add(A, B, C);
EXPECT_EQ(norm(C, C0, NORM_INF), 0);
} }

@ -27,29 +27,38 @@ enum
TYPE_MASK_ALL = (TYPE_MASK_64F<<1)-1, TYPE_MASK_ALL = (TYPE_MASK_64F<<1)-1,
TYPE_MASK_ALL_BUT_8S = TYPE_MASK_ALL & ~TYPE_MASK_8S TYPE_MASK_ALL_BUT_8S = TYPE_MASK_ALL & ~TYPE_MASK_8S
}; };
CV_EXPORTS double getMinVal(int depth);
CV_EXPORTS double getMaxVal(int depth);
CV_EXPORTS Size randomSize(RNG& rng, double maxSizeLog); CV_EXPORTS Size randomSize(RNG& rng, double maxSizeLog);
CV_EXPORTS void randomSize(RNG& rng, int minDims, int maxDims, double maxSizeLog, vector<int>& sz); CV_EXPORTS void randomSize(RNG& rng, int minDims, int maxDims, double maxSizeLog, vector<int>& sz);
CV_EXPORTS int randomType(RNG& rng, int typeMask, int minChannels, int maxChannels); CV_EXPORTS int randomType(RNG& rng, int typeMask, int minChannels, int maxChannels);
CV_EXPORTS Mat randomMat(RNG& rng, Size size, int type, bool useRoi); CV_EXPORTS Mat randomMat(RNG& rng, Size size, int type, double minVal, double maxVal, bool useRoi);
CV_EXPORTS Mat randomMat(RNG& rng, const vector<int>& size, int type, bool useRoi); CV_EXPORTS Mat randomMat(RNG& rng, const vector<int>& size, int type, double minVal, double maxVal, bool useRoi);
CV_EXPORTS void add(const Mat& a, double alpha, const Mat& b, double beta, CV_EXPORTS void add(const Mat& a, double alpha, const Mat& b, double beta,
Scalar gamma, Mat& c, int ctype, bool calcAbs); Scalar gamma, Mat& c, int ctype, bool calcAbs=false);
CV_EXPORTS void convert(const Mat& src, Mat& dst, int dtype, double alpha, double beta); CV_EXPORTS void convert(const Mat& src, Mat& dst, int dtype, double alpha=1, double beta=0);
CV_EXPORTS void copy(const Mat& src, Mat& dst, const Mat& mask=Mat()); CV_EXPORTS void copy(const Mat& src, Mat& dst, const Mat& mask=Mat(), bool invertMask=false);
CV_EXPORTS void set(Mat& dst, const Scalar& gamma, const Mat& mask=Mat()); CV_EXPORTS void set(Mat& dst, const Scalar& gamma, const Mat& mask=Mat());
CV_EXPORTS void minMaxFilter(const Mat& a, Mat& maxresult, const Mat& minresult, const Mat& kernel, Point anchor); CV_EXPORTS void erode(const Mat& src, Mat& dst, const Mat& _kernel, Point anchor=Point(-1,-1),
CV_EXPORTS void filter2D(const Mat& src, Mat& dst, int ddepth, const Mat& kernel, Point anchor, double delta, int borderType); int borderType=IPL_BORDER_CONSTANT, const Scalar& borderValue=Scalar());
CV_EXPORTS void copyMakeBorder(const Mat& src, Mat& dst, int top, int bottom, int left, int right, int borderType, Scalar borderValue); CV_EXPORTS void dilate(const Mat& src, Mat& dst, const Mat& _kernel, Point anchor=Point(-1,-1),
int borderType=IPL_BORDER_CONSTANT, const Scalar& borderValue=Scalar());
CV_EXPORTS void filter2D(const Mat& src, Mat& dst, int ddepth, const Mat& kernel,
Point anchor, double delta, int borderType,
const Scalar& borderValue=Scalar());
CV_EXPORTS void copyMakeBorder(const Mat& src, Mat& dst, int top, int bottom, int left, int right,
int borderType, const Scalar& borderValue=Scalar());
CV_EXPORTS void minMaxLoc(const Mat& src, double* maxval, double* minval, CV_EXPORTS void minMaxLoc(const Mat& src, double* maxval, double* minval,
vector<int>* maxloc, vector<int>* minloc, const Mat& mask=Mat()); vector<int>* maxloc, vector<int>* minloc, const Mat& mask=Mat());
CV_EXPORTS double norm(const Mat& src, int normType, const Mat& mask=Mat()); CV_EXPORTS double norm(const Mat& src, int normType, const Mat& mask=Mat());
CV_EXPORTS double norm(const Mat& src1, const Mat& src2, int normType, const Mat& mask=Mat()); CV_EXPORTS double norm(const Mat& src1, const Mat& src2, int normType, const Mat& mask=Mat());
CV_EXPORTS bool cmpEps(const Mat& src1, const Mat& src2, double maxDiff, vector<int>* loc); CV_EXPORTS bool cmpEps(const Mat& src1, const Mat& src2, int maxDiff, vector<int>* loc);
CV_EXPORTS void logicOp(const Mat& src1, const Mat& src2, Mat& dst, char c); CV_EXPORTS void logicOp(const Mat& src1, const Mat& src2, Mat& dst, char c);
CV_EXPORTS void logicOp(const Mat& src, const Scalar& s, Mat& dst, char c); CV_EXPORTS void logicOp(const Mat& src, const Scalar& s, Mat& dst, char c);
CV_EXPORTS void compare(const Mat& src1, const Mat& src2, Mat& dst, int cmpop); CV_EXPORTS void compare(const Mat& src1, const Mat& src2, Mat& dst, int cmpop);
CV_EXPORTS void compare(const Mat& src, const Scalar& s, Mat& dst, int cmpop); CV_EXPORTS void compare(const Mat& src, double s, Mat& dst, int cmpop);
CV_EXPORTS void gemm(const Mat& src1, const Mat& src2, double alpha, CV_EXPORTS void gemm(const Mat& src1, const Mat& src2, double alpha,
const Mat& src3, double beta, Mat& dst, int flags); const Mat& src3, double beta, Mat& dst, int flags);
CV_EXPORTS void crosscorr(const Mat& src1, const Mat& src2, Mat& dst, int dtype); CV_EXPORTS void crosscorr(const Mat& src1, const Mat& src2, Mat& dst, int dtype);

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save