1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

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

This commit is contained in:
Alexander Alekhin
2018-11-10 20:10:57 +00:00
90 changed files with 6261 additions and 6657 deletions
+101 -2
View File
@@ -119,10 +119,14 @@ template <typename R> struct Data
d[i] += (LaneType)m;
return *this;
}
void fill(LaneType val, int s, int c = R::nlanes)
{
for (int i = s; i < c; ++i)
d[i] = val;
}
void fill(LaneType val)
{
for (int i = 0; i < R::nlanes; ++i)
d[i] = val;
fill(val, 0);
}
void reverse()
{
@@ -739,6 +743,23 @@ template<typename R> struct TheTest
return *this;
}
TheTest & test_absdiffs()
{
Data<R> dataA(std::numeric_limits<LaneType>::max()),
dataB(std::numeric_limits<LaneType>::min());
dataA[0] = (LaneType)-1;
dataB[0] = 1;
dataA[1] = 2;
dataB[1] = (LaneType)-2;
R a = dataA, b = dataB;
Data<R> resC = v_absdiffs(a, b);
for (int i = 0; i < R::nlanes; ++i)
{
EXPECT_EQ(saturate_cast<LaneType>(std::abs(dataA[i] - dataB[i])), resC[i]);
}
return *this;
}
TheTest & test_reduce()
{
Data<R> dataA;
@@ -874,6 +895,81 @@ template<typename R> struct TheTest
return *this;
}
// v_uint8 only
TheTest & test_pack_b()
{
// 16-bit
Data<R> dataA, dataB;
dataB.fill(0, R::nlanes / 2);
R a = dataA, b = dataB;
Data<R> maskA = a == b, maskB = a != b;
a = maskA; b = maskB;
Data<R> res = v_pack_b(v_reinterpret_as_u16(a), v_reinterpret_as_u16(b));
for (int i = 0; i < v_uint16::nlanes; ++i)
{
SCOPED_TRACE(cv::format("i=%d", i));
EXPECT_EQ(maskA[i * 2], res[i]);
EXPECT_EQ(maskB[i * 2], res[i + v_uint16::nlanes]);
}
// 32-bit
Data<R> dataC, dataD;
dataD.fill(0, R::nlanes / 2);
R c = dataC, d = dataD;
Data<R> maskC = c == d, maskD = c != d;
c = maskC; d = maskD;
res = v_pack_b
(
v_reinterpret_as_u32(a), v_reinterpret_as_u32(b),
v_reinterpret_as_u32(c), v_reinterpret_as_u32(d)
);
for (int i = 0; i < v_uint32::nlanes; ++i)
{
SCOPED_TRACE(cv::format("i=%d", i));
EXPECT_EQ(maskA[i * 4], res[i]);
EXPECT_EQ(maskB[i * 4], res[i + v_uint32::nlanes]);
EXPECT_EQ(maskC[i * 4], res[i + v_uint32::nlanes * 2]);
EXPECT_EQ(maskD[i * 4], res[i + v_uint32::nlanes * 3]);
}
// 64-bit
Data<R> dataE, dataF, dataG(0), dataH(0xFF);
dataF.fill(0, R::nlanes / 2);
R e = dataE, f = dataF, g = dataG, h = dataH;
Data<R> maskE = e == f, maskF = e != f;
e = maskE; f = maskF;
res = v_pack_b
(
v_reinterpret_as_u64(a), v_reinterpret_as_u64(b),
v_reinterpret_as_u64(c), v_reinterpret_as_u64(d),
v_reinterpret_as_u64(e), v_reinterpret_as_u64(f),
v_reinterpret_as_u64(g), v_reinterpret_as_u64(h)
);
for (int i = 0; i < v_uint64::nlanes; ++i)
{
SCOPED_TRACE(cv::format("i=%d", i));
EXPECT_EQ(maskA[i * 8], res[i]);
EXPECT_EQ(maskB[i * 8], res[i + v_uint64::nlanes]);
EXPECT_EQ(maskC[i * 8], res[i + v_uint64::nlanes * 2]);
EXPECT_EQ(maskD[i * 8], res[i + v_uint64::nlanes * 3]);
EXPECT_EQ(maskE[i * 8], res[i + v_uint64::nlanes * 4]);
EXPECT_EQ(maskF[i * 8], res[i + v_uint64::nlanes * 5]);
EXPECT_EQ(dataG[i * 8], res[i + v_uint64::nlanes * 6]);
EXPECT_EQ(dataH[i * 8], res[i + v_uint64::nlanes * 7]);
}
return *this;
}
TheTest & test_unpack()
{
Data<R> dataA, dataB;
@@ -1228,6 +1324,7 @@ void test_hal_intrin_uint8()
.test_popcount()
.test_pack<1>().test_pack<2>().test_pack<3>().test_pack<8>()
.test_pack_u<1>().test_pack_u<2>().test_pack_u<3>().test_pack_u<8>()
.test_pack_b()
.test_unpack()
.test_extract<0>().test_extract<1>().test_extract<8>().test_extract<15>()
.test_rotate<0>().test_rotate<1>().test_rotate<8>().test_rotate<15>()
@@ -1259,6 +1356,7 @@ void test_hal_intrin_int8()
.test_logic()
.test_min_max()
.test_absdiff()
.test_absdiffs()
.test_abs()
.test_mask()
.test_popcount()
@@ -1317,6 +1415,7 @@ void test_hal_intrin_int16()
.test_logic()
.test_min_max()
.test_absdiff()
.test_absdiffs()
.test_abs()
.test_reduce()
.test_mask()
+31
View File
@@ -1930,5 +1930,36 @@ TEST(Core_InputArray, support_CustomType)
}
}
TEST(Core_Vectors, issue_13078)
{
float floats_[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
std::vector<float> floats(floats_, floats_ + 8);
std::vector<int> ints(4);
Mat m(4, 1, CV_32FC1, floats.data(), sizeof(floats[0]) * 2);
m.convertTo(ints, CV_32S);
ASSERT_EQ(1, ints[0]);
ASSERT_EQ(3, ints[1]);
ASSERT_EQ(5, ints[2]);
ASSERT_EQ(7, ints[3]);
}
TEST(Core_Vectors, issue_13078_workaround)
{
float floats_[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
std::vector<float> floats(floats_, floats_ + 8);
std::vector<int> ints(4);
Mat m(4, 1, CV_32FC1, floats.data(), sizeof(floats[0]) * 2);
m.convertTo(Mat(ints), CV_32S);
ASSERT_EQ(1, ints[0]);
ASSERT_EQ(3, ints[1]);
ASSERT_EQ(5, ints[2]);
ASSERT_EQ(7, ints[3]);
}
}} // namespace