1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge remote-tracking branch 'upstream/3.4' into merge-3.4

This commit is contained in:
Alexander Alekhin
2018-09-07 12:40:27 +03:00
141 changed files with 3074 additions and 4777 deletions
+4 -6
View File
@@ -1123,7 +1123,6 @@ template<typename R> struct TheTest
return *this;
}
#if CV_FP16
TheTest & test_loadstore_fp16_f32()
{
printf("test_loadstore_fp16_f32 ...\n");
@@ -1133,14 +1132,14 @@ template<typename R> struct TheTest
AlignedData<v_float32> data_f32; data_f32.a.clear();
AlignedData<v_uint16> out;
R r1 = vx_load_fp16_f32((short*)data.a.d);
R r1 = vx_load_expand((const cv::float16_t*)data.a.d);
R r2(r1);
EXPECT_EQ(1.0f, r1.get0());
vx_store(data_f32.a.d, r2);
EXPECT_EQ(-2.0f, data_f32.a.d[R::nlanes - 1]);
out.a.clear();
vx_store_fp16((short*)out.a.d, r2);
v_pack_store((cv::float16_t*)out.a.d, r2);
for (int i = 0; i < R::nlanes; ++i)
{
EXPECT_EQ(data.a[i], out.a[i]) << "i=" << i;
@@ -1148,9 +1147,8 @@ template<typename R> struct TheTest
return *this;
}
#endif
#if CV_SIMD_FP16
#if 0
TheTest & test_loadstore_fp16()
{
printf("test_loadstore_fp16 ...\n");
@@ -1165,7 +1163,7 @@ template<typename R> struct TheTest
// check some initialization methods
R r1 = data.u;
R r2 = vx_load_f16(data.a.d);
R r2 = vx_load_expand((const float16_t*)data.a.d);
R r3(r2);
EXPECT_EQ(data.u[0], r1.get0());
EXPECT_EQ(data.a[0], r2.get0());
+3 -3
View File
@@ -214,7 +214,7 @@ protected:
}
CvMat* m = (CvMat*)fs["test_mat"].readObj();
CvMat _test_mat = test_mat;
CvMat _test_mat = cvMat(test_mat);
double max_diff = 0;
CvMat stub1, _test_stub1;
cvReshape(m, &stub1, 1, 0);
@@ -234,7 +234,7 @@ protected:
cvReleaseMat(&m);
CvMatND* m_nd = (CvMatND*)fs["test_mat_nd"].readObj();
CvMatND _test_mat_nd = test_mat_nd;
CvMatND _test_mat_nd = cvMatND(test_mat_nd);
if( !m_nd || !CV_IS_MATND(m_nd) )
{
@@ -263,7 +263,7 @@ protected:
MatND mat_nd2;
fs["test_mat_nd"] >> mat_nd2;
CvMatND m_nd2 = mat_nd2;
CvMatND m_nd2 = cvMatND(mat_nd2);
cvGetMat(&m_nd2, &stub, 0, 1);
cvReshape(&stub, &stub1, 1, 0);
+17 -17
View File
@@ -415,15 +415,15 @@ TEST(Core_PCA, accuracy)
#ifdef CHECK_C
// 4. check C PCA & ROW
_points = rPoints;
_testPoints = rTestPoints;
_avg = avg;
_eval = eval;
_evec = evec;
_points = cvMat(rPoints);
_testPoints = cvMat(rTestPoints);
_avg = cvMat(avg);
_eval = cvMat(eval);
_evec = cvMat(evec);
prjTestPoints.create(rTestPoints.rows, maxComponents, rTestPoints.type() );
backPrjTestPoints.create(rPoints.size(), rPoints.type() );
_prjTestPoints = prjTestPoints;
_backPrjTestPoints = backPrjTestPoints;
_prjTestPoints = cvMat(prjTestPoints);
_backPrjTestPoints = cvMat(backPrjTestPoints);
cvCalcPCA( &_points, &_avg, &_eval, &_evec, CV_PCA_DATA_AS_ROW );
cvProjectPCA( &_testPoints, &_avg, &_evec, &_prjTestPoints );
@@ -435,13 +435,13 @@ TEST(Core_PCA, accuracy)
ASSERT_LE(err, diffBackPrjEps) << "bad accuracy of cvBackProjectPCA() (CV_PCA_DATA_AS_ROW)";
// 5. check C PCA & COL
_points = cPoints;
_testPoints = cTestPoints;
avg = avg.t(); _avg = avg;
eval = eval.t(); _eval = eval;
evec = evec.t(); _evec = evec;
prjTestPoints = prjTestPoints.t(); _prjTestPoints = prjTestPoints;
backPrjTestPoints = backPrjTestPoints.t(); _backPrjTestPoints = backPrjTestPoints;
_points = cvMat(cPoints);
_testPoints = cvMat(cTestPoints);
avg = avg.t(); _avg = cvMat(avg);
eval = eval.t(); _eval = cvMat(eval);
evec = evec.t(); _evec = cvMat(evec);
prjTestPoints = prjTestPoints.t(); _prjTestPoints = cvMat(prjTestPoints);
backPrjTestPoints = backPrjTestPoints.t(); _backPrjTestPoints = cvMat(backPrjTestPoints);
cvCalcPCA( &_points, &_avg, &_eval, &_evec, CV_PCA_DATA_AS_COL );
cvProjectPCA( &_testPoints, &_avg, &_evec, &_prjTestPoints );
@@ -615,7 +615,7 @@ void Core_ArrayOpTest::run( int /* start_from */)
{
int sz3[] = {5, 10, 15};
MatND A(3, sz3, CV_32F), B(3, sz3, CV_16SC4);
CvMatND matA = A, matB = B;
CvMatND matA = cvMatND(A), matB = cvMatND(B);
RNG rng;
rng.fill(A, CV_RAND_UNI, Scalar::all(-10), Scalar::all(10));
rng.fill(B, CV_RAND_UNI, Scalar::all(-10), Scalar::all(10));
@@ -625,8 +625,8 @@ void Core_ArrayOpTest::run( int /* start_from */)
Scalar val1(-1000, 30, 3, 8);
cvSetRealND(&matA, idx0, val0);
cvSetReal3D(&matA, idx1[0], idx1[1], idx1[2], -val0);
cvSetND(&matB, idx0, val1);
cvSet3D(&matB, idx1[0], idx1[1], idx1[2], -val1);
cvSetND(&matB, idx0, cvScalar(val1));
cvSet3D(&matB, idx1[0], idx1[1], idx1[2], cvScalar(-val1));
Ptr<CvMatND> matC(cvCloneMatND(&matB));
if( A.at<float>(idx0[0], idx0[1], idx0[2]) != val0 ||
+49 -62
View File
@@ -526,7 +526,7 @@ void Core_CrossProductTest::get_test_array_types_and_sizes( int,
RNG& rng = ts->get_rng();
int depth = cvtest::randInt(rng) % 2 + CV_32F;
int cn = cvtest::randInt(rng) & 1 ? 3 : 1, type = CV_MAKETYPE(depth, cn);
CvSize sz;
Size sz;
types[INPUT][0] = types[INPUT][1] = types[OUTPUT][0] = types[REF_OUTPUT][0] = type;
@@ -549,7 +549,7 @@ void Core_CrossProductTest::run_func()
void Core_CrossProductTest::prepare_to_validation( int )
{
CvScalar a(0), b(0), c(0);
cv::Scalar a, b, c;
if( test_mat[INPUT][0].rows > 1 )
{
@@ -595,7 +595,7 @@ void Core_CrossProductTest::prepare_to_validation( int )
}
else
{
cvSet1D( test_array[REF_OUTPUT][0], 0, c );
cvSet1D( test_array[REF_OUTPUT][0], 0, cvScalar(c) );
}
}
@@ -896,7 +896,7 @@ double Core_TransformTest::get_success_error_level( int test_case_idx, int i, in
void Core_TransformTest::run_func()
{
CvMat _m = test_mat[INPUT][1], _shift = test_mat[INPUT][2];
CvMat _m = cvMat(test_mat[INPUT][1]), _shift = cvMat(test_mat[INPUT][2]);
cvTransform( test_array[INPUT][0], test_array[OUTPUT][0], &_m, _shift.data.ptr ? &_shift : 0);
}
@@ -1010,7 +1010,7 @@ double Core_PerspectiveTransformTest::get_success_error_level( int test_case_idx
void Core_PerspectiveTransformTest::run_func()
{
CvMat _m = test_mat[INPUT][1];
CvMat _m = cvMat(test_mat[INPUT][1]);
cvPerspectiveTransform( test_array[INPUT][0], test_array[OUTPUT][0], &_m );
}
@@ -1117,7 +1117,7 @@ static void cvTsPerspectiveTransform( const CvArr* _src, CvArr* _dst, const CvMa
void Core_PerspectiveTransformTest::prepare_to_validation( int )
{
CvMat transmat = test_mat[INPUT][1];
CvMat transmat = cvMat(test_mat[INPUT][1]);
cvTsPerspectiveTransform( test_array[INPUT][0], test_array[REF_OUTPUT][0], &transmat );
}
@@ -1287,9 +1287,9 @@ int Core_CovarMatrixTest::prepare_test_case( int test_case_idx )
if( single_matrix )
{
if( !are_images )
*((CvMat*)_hdr_data) = test_mat[INPUT][0];
*((CvMat*)_hdr_data) = cvMat(test_mat[INPUT][0]);
else
*((IplImage*)_hdr_data) = test_mat[INPUT][0];
*((IplImage*)_hdr_data) = cvIplImage(test_mat[INPUT][0]);
temp_hdrs[0] = _hdr_data;
}
else
@@ -1304,9 +1304,9 @@ int Core_CovarMatrixTest::prepare_test_case( int test_case_idx )
part = test_mat[INPUT][0].col(i);
if( !are_images )
*((CvMat*)ptr) = part;
*((CvMat*)ptr) = cvMat(part);
else
*((IplImage*)ptr) = part;
*((IplImage*)ptr) = cvIplImage(part);
temp_hdrs[i] = ptr;
}
@@ -1539,7 +1539,7 @@ static double cvTsLU( CvMat* a, CvMat* b=NULL, CvMat* x=NULL, int* rank=0 )
void Core_DetTest::prepare_to_validation( int )
{
test_mat[INPUT][0].convertTo(test_mat[TEMP][0], test_mat[TEMP][0].type());
CvMat temp0 = test_mat[TEMP][0];
CvMat temp0 = cvMat(test_mat[TEMP][0]);
test_mat[REF_OUTPUT][0].at<Scalar>(0,0) = cvRealScalar(cvTsLU(&temp0, 0, 0));
}
@@ -1676,7 +1676,7 @@ void Core_InvertTest::prepare_to_validation( int )
Mat& temp1 = test_mat[TEMP][1];
Mat& dst0 = test_mat[REF_OUTPUT][0];
Mat& dst = test_mat[OUTPUT][0];
CvMat _input = input;
CvMat _input = cvMat(input);
double ratio = 0, det = cvTsSVDet( &_input, &ratio );
double threshold = (input.depth() == CV_32F ? FLT_EPSILON : DBL_EPSILON)*1000;
@@ -1733,7 +1733,7 @@ void Core_SolveTest::get_test_array_types_and_sizes( int test_case_idx, vector<v
RNG& rng = ts->get_rng();
int bits = cvtest::randInt(rng);
Base::get_test_array_types_and_sizes( test_case_idx, sizes, types );
CvSize in_sz = sizes[INPUT][0];
CvSize in_sz = cvSize(sizes[INPUT][0]);
if( in_sz.width > in_sz.height )
in_sz = cvSize(in_sz.height, in_sz.width);
Base::get_test_array_types_and_sizes( test_case_idx, sizes, types );
@@ -1813,14 +1813,14 @@ void Core_SolveTest::prepare_to_validation( int )
Mat& temp1 = test_mat[TEMP][1];
cvtest::convert(input, temp1, temp1.type());
dst = Scalar::all(0);
CvMat _temp1 = temp1;
CvMat _temp1 = cvMat(temp1);
double det = cvTsLU( &_temp1, 0, 0 );
dst0 = Scalar::all(det != 0);
return;
}
double threshold = (input.type() == CV_32F ? FLT_EPSILON : DBL_EPSILON)*1000;
CvMat _input = input;
CvMat _input = cvMat(input);
double ratio = 0, det = cvTsSVDet( &_input, &ratio );
if( det < threshold || ratio < threshold )
{
@@ -2105,7 +2105,7 @@ void Core_SVBkSbTest::get_test_array_types_and_sizes( int test_case_idx, vector<
int bits = cvtest::randInt(rng);
Base::get_test_array_types_and_sizes( test_case_idx, sizes, types );
int min_size, i, m, n;
CvSize b_size;
cv::Size b_size;
min_size = MIN( sizes[INPUT][0].width, sizes[INPUT][0].height );
@@ -2122,7 +2122,7 @@ void Core_SVBkSbTest::get_test_array_types_and_sizes( int test_case_idx, vector<
n = sizes[INPUT][0].width;
sizes[INPUT][1] = Size(0,0);
b_size = Size(m,m);
b_size = cvSize(m, m);
if( have_b )
{
sizes[INPUT][1].height = sizes[INPUT][0].height;
@@ -2174,7 +2174,7 @@ int Core_SVBkSbTest::prepare_test_case( int test_case_idx )
cvtest::copy( temp, input );
}
CvMat _input = input;
CvMat _input = cvMat(input);
cvSVD( &_input, test_array[TEMP][0], test_array[TEMP][1], test_array[TEMP][2], flags );
}
@@ -2210,7 +2210,7 @@ void Core_SVBkSbTest::prepare_to_validation( int )
Size w_size = compact ? Size(min_size,min_size) : Size(m,n);
Mat& w = test_mat[TEMP][0];
Mat wdb( w_size.height, w_size.width, CV_64FC1 );
CvMat _w = w, _wdb = wdb;
CvMat _w = cvMat(w), _wdb = cvMat(wdb);
// use exactly the same threshold as in icvSVD... ,
// so the changes in the library and here should be synchronized.
double threshold = cv::sum(w)[0]*(DBL_EPSILON*2);//(is_float ? FLT_EPSILON*10 : DBL_EPSILON*2);
@@ -3230,6 +3230,22 @@ softdouble naiveExp(softdouble x)
}
}
static float makeFP32(int sign, int exponent, int significand)
{
Cv32suf x;
x.u = (unsigned)(((sign & 1) << 31) | ((exponent&255) << 23) | (significand & 0x7fffff));
return x.f;
}
static float makeRandomFP32(RNG& rng, int sign, int exprange)
{
if( sign == -1 )
sign = rng() % 2;
int exponent = rng() % exprange;
int significand = rng() % (1 << 23);
return makeFP32(sign, exponent, significand);
}
TEST(Core_SoftFloat, exp32)
{
//special cases
@@ -3246,13 +3262,11 @@ TEST(Core_SoftFloat, exp32)
inputs.push_back(softfloat::min());
for(int i = 0; i < 50000; i++)
{
Cv32suf x;
x.fmt.sign = rng() % 2;
x.fmt.exponent = rng() % (10 + 127); //bigger exponent will produce inf
x.fmt.significand = rng() % (1 << 23);
if(softfloat(x.f) > ln_max)
x.f = rng.uniform(0.0f, (float)ln_max);
inputs.push_back(softfloat(x.f));
float x = makeRandomFP32(rng, -1, 10+127 //bigger exponent will produce inf
);
if(softfloat(x) > ln_max)
x = rng.uniform(0.0f, (float)ln_max);
inputs.push_back(softfloat(x));
}
for(size_t i = 0; i < inputs.size(); i++)
@@ -3323,11 +3337,7 @@ TEST(Core_SoftFloat, log32)
EXPECT_TRUE(log(softfloat::nan()).isNaN());
for(int i = 0; i < nValues; i++)
{
Cv32suf x;
x.fmt.sign = 1;
x.fmt.exponent = rng() % 255;
x.fmt.significand = rng() % (1 << 23);
softfloat x32(x.f);
softfloat x32(makeRandomFP32(rng, 1, 255));
ASSERT_TRUE(log(x32).isNaN());
}
EXPECT_TRUE(log(softfloat::zero()).isInf());
@@ -3340,11 +3350,7 @@ TEST(Core_SoftFloat, log32)
inputs.push_back(softfloat::max());
for(int i = 0; i < nValues; i++)
{
Cv32suf x;
x.fmt.sign = 0;
x.fmt.exponent = rng() % 255;
x.fmt.significand = rng() % (1 << 23);
inputs.push_back(softfloat(x.f));
inputs.push_back(softfloat(makeRandomFP32(rng, 0, 255)));
}
for(size_t i = 0; i < inputs.size(); i++)
@@ -3426,11 +3432,7 @@ TEST(Core_SoftFloat, cbrt32)
inputs.push_back(softfloat::min());
for(int i = 0; i < 50000; i++)
{
Cv32suf x;
x.fmt.sign = rng() % 2;
x.fmt.exponent = rng() % 255;
x.fmt.significand = rng() % (1 << 23);
inputs.push_back(softfloat(x.f));
inputs.push_back(softfloat(makeRandomFP32(rng, -1, 255)));
}
for(size_t i = 0; i < inputs.size(); i++)
@@ -3522,11 +3524,8 @@ TEST(Core_SoftFloat, pow32)
// inf ** y == inf, if y > 0
for(size_t i = 0; i < nValues; i++)
{
Cv32suf x;
x.fmt.sign = 0;
x.fmt.exponent = rng() % 255;
x.fmt.significand = rng() % (1 << 23);
softfloat x32 = softfloat(x.f);
float x = makeRandomFP32(rng, 0, 255);
softfloat x32 = softfloat(x);
ASSERT_TRUE(pow( inf, x32).isInf());
ASSERT_TRUE(pow(-inf, x32).isInf());
ASSERT_EQ(pow( inf, -x32), zero);
@@ -3538,17 +3537,9 @@ TEST(Core_SoftFloat, pow32)
// x ** y == nan, if x < 0 and y is not integer
for(size_t i = 0; i < nValues; i++)
{
Cv32suf x;
x.fmt.sign = 1;
x.fmt.exponent = rng() % 255;
x.fmt.significand = rng() % (1 << 23);
softfloat x32(x.f);
Cv32suf y;
y.fmt.sign = rng() % 2;
//bigger exponent produces integer numbers only
y.fmt.exponent = rng() % (23 + 127);
y.fmt.significand = rng() % (1 << 23);
softfloat y32(y.f);
softfloat x32(makeRandomFP32(rng, 1, 255));
softfloat y32(makeRandomFP32(rng, -1, 23+127 //bigger exponent produces integer numbers only
));
int yi = cvRound(y32);
if(y32 != softfloat(yi))
ASSERT_TRUE(pow(x32, y32).isNaN());
@@ -3565,11 +3556,7 @@ TEST(Core_SoftFloat, pow32)
// 0 ** y == 0, if y > 0
for(size_t i = 0; i < nValues; i++)
{
Cv32suf x;
x.fmt.sign = 0;
x.fmt.exponent = rng() % 255;
x.fmt.significand = rng() % (1 << 23);
softfloat x32(x.f);
softfloat x32(makeRandomFP32(rng, 0, 255));
ASSERT_TRUE(pow(zero, -x32).isInf());
if(x32 != one)
{
+1 -1
View File
@@ -970,7 +970,7 @@ bool CV_OperationsTest::operations1()
Size sz(10, 20);
if (sz.area() != 200) throw test_excep();
if (sz.width != 10 || sz.height != 20) throw test_excep();
if (((CvSize)sz).width != 10 || ((CvSize)sz).height != 20) throw test_excep();
if (cvSize(sz).width != 10 || cvSize(sz).height != 20) throw test_excep();
Vec<double, 5> v5d(1, 1, 1, 1, 1);
Vec<double, 6> v6d(1, 1, 1, 1, 1, 1);