mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge branch 4.x
This commit is contained in:
@@ -12,7 +12,7 @@ CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR)
|
||||
CV_ENUM(InterTypeExtended, INTER_NEAREST, INTER_LINEAR, WARP_RELATIVE_MAP)
|
||||
CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH)
|
||||
|
||||
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode> > TestWarpAffine;
|
||||
typedef TestBaseWithParam< tuple<MatType, Size, InterType, BorderMode> > TestWarpAffine;
|
||||
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode, int> > TestWarpPerspective;
|
||||
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode, MatType> > TestWarpPerspectiveNear_t;
|
||||
typedef TestBaseWithParam< tuple<MatType, Size, InterTypeExtended, BorderMode, RemapMode> > TestRemap;
|
||||
@@ -21,6 +21,7 @@ void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode, boo
|
||||
|
||||
PERF_TEST_P( TestWarpAffine, WarpAffine,
|
||||
Combine(
|
||||
Values(CV_8UC1, CV_8UC4),
|
||||
Values( szVGA, sz720p, sz1080p ),
|
||||
InterType::all(),
|
||||
BorderMode::all()
|
||||
@@ -28,13 +29,14 @@ PERF_TEST_P( TestWarpAffine, WarpAffine,
|
||||
)
|
||||
{
|
||||
Size sz, szSrc(512, 512);
|
||||
int borderMode, interType;
|
||||
sz = get<0>(GetParam());
|
||||
interType = get<1>(GetParam());
|
||||
borderMode = get<2>(GetParam());
|
||||
int borderMode, interType, dataType;
|
||||
dataType = get<0>(GetParam());
|
||||
sz = get<1>(GetParam());
|
||||
interType = get<2>(GetParam());
|
||||
borderMode = get<3>(GetParam());
|
||||
Scalar borderColor = Scalar::all(150);
|
||||
|
||||
Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);
|
||||
Mat src(szSrc, dataType), dst(sz, dataType);
|
||||
cvtest::fillGradient(src);
|
||||
if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
|
||||
Mat warpMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
|
||||
@@ -47,6 +49,7 @@ PERF_TEST_P( TestWarpAffine, WarpAffine,
|
||||
|
||||
PERF_TEST_P(TestWarpAffine, DISABLED_WarpAffine_ovx,
|
||||
Combine(
|
||||
Values(CV_8UC1, CV_8UC4),
|
||||
Values(szVGA, sz720p, sz1080p),
|
||||
InterType::all(),
|
||||
BorderMode::all()
|
||||
@@ -54,13 +57,16 @@ PERF_TEST_P(TestWarpAffine, DISABLED_WarpAffine_ovx,
|
||||
)
|
||||
{
|
||||
Size sz, szSrc(512, 512);
|
||||
int borderMode, interType;
|
||||
sz = get<0>(GetParam());
|
||||
interType = get<1>(GetParam());
|
||||
borderMode = get<2>(GetParam());
|
||||
int borderMode, interType, dataType;
|
||||
|
||||
dataType = get<0>(GetParam());
|
||||
sz = get<1>(GetParam());
|
||||
interType = get<2>(GetParam());
|
||||
borderMode = get<3>(GetParam());
|
||||
|
||||
Scalar borderColor = Scalar::all(150);
|
||||
|
||||
Mat src(szSrc, CV_8UC1), dst(sz, CV_8UC1);
|
||||
Mat src(szSrc, dataType), dst(sz, dataType);
|
||||
cvtest::fillGradient(src);
|
||||
if (borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
|
||||
Mat warpMat = getRotationMatrix2D(Point2f(src.cols / 2.f, src.rows / 2.f), 30., 2.2);
|
||||
|
||||
@@ -1088,11 +1088,6 @@ struct mRGBA2RGBA<uchar>
|
||||
|
||||
uchar v3_half = v3 / 2;
|
||||
|
||||
dst[0] = (v3==0)? 0 : (v0 * max_val + v3_half) / v3;
|
||||
dst[1] = (v3==0)? 0 : (v1 * max_val + v3_half) / v3;
|
||||
dst[2] = (v3==0)? 0 : (v2 * max_val + v3_half) / v3;
|
||||
dst[3] = v3;
|
||||
|
||||
dst[0] = (v3==0)? 0 : saturate_cast<uchar>((v0 * max_val + v3_half) / v3);
|
||||
dst[1] = (v3==0)? 0 : saturate_cast<uchar>((v1 * max_val + v3_half) / v3);
|
||||
dst[2] = (v3==0)? 0 : saturate_cast<uchar>((v2 * max_val + v3_half) / v3);
|
||||
|
||||
@@ -1983,65 +1983,46 @@ void cv::convertMaps( InputArray _map1, InputArray _map2,
|
||||
}
|
||||
else if( m1type == CV_32FC2 && dstm1type == CV_16SC2 )
|
||||
{
|
||||
if( nninterpolate )
|
||||
#if CV_TRY_SSE4_1
|
||||
if( useSSE4_1 )
|
||||
opt_SSE4_1::convertMaps_32f2c16s_SSE41(src1f, dst1, dst2, size.width);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#if CV_SIMD128
|
||||
int span = VTraits<v_float32x4>::vlanes();
|
||||
{
|
||||
for( ; x <= (size.width << 1) - span * 2; x += span * 2 )
|
||||
v_store(dst1 + x, v_pack(v_round(v_load(src1f + x)),
|
||||
v_round(v_load(src1f + x + span))));
|
||||
v_float32x4 v_scale = v_setall_f32((float)INTER_TAB_SIZE);
|
||||
v_int32x4 v_mask = v_setall_s32(INTER_TAB_SIZE - 1);
|
||||
v_int32x4 v_scale3 = v_setall_s32(INTER_TAB_SIZE);
|
||||
int span = VTraits<v_uint16x8>::vlanes();
|
||||
for (; x <= size.width - span; x += span )
|
||||
{
|
||||
v_float32x4 v_src0[2], v_src1[2];
|
||||
v_load_deinterleave(src1f + (x << 1), v_src0[0], v_src0[1]);
|
||||
v_load_deinterleave(src1f + (x << 1) + span, v_src1[0], v_src1[1]);
|
||||
v_int32x4 v_ix0 = v_round(v_mul(v_src0[0], v_scale));
|
||||
v_int32x4 v_ix1 = v_round(v_mul(v_src1[0], v_scale));
|
||||
v_int32x4 v_iy0 = v_round(v_mul(v_src0[1], v_scale));
|
||||
v_int32x4 v_iy1 = v_round(v_mul(v_src1[1], v_scale));
|
||||
|
||||
v_int16x8 v_dst[2];
|
||||
v_dst[0] = v_pack(v_shr<INTER_BITS>(v_ix0), v_shr<INTER_BITS>(v_ix1));
|
||||
v_dst[1] = v_pack(v_shr<INTER_BITS>(v_iy0), v_shr<INTER_BITS>(v_iy1));
|
||||
v_store_interleave(dst1 + (x << 1), v_dst[0], v_dst[1]);
|
||||
|
||||
v_store(dst2 + x, v_pack_u(
|
||||
v_muladd(v_scale3, (v_and(v_iy0, v_mask)), (v_and(v_ix0, v_mask))),
|
||||
v_muladd(v_scale3, (v_and(v_iy1, v_mask)), (v_and(v_ix1, v_mask)))));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for( ; x < size.width; x++ )
|
||||
{
|
||||
dst1[x*2] = saturate_cast<short>(src1f[x*2]);
|
||||
dst1[x*2+1] = saturate_cast<short>(src1f[x*2+1]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if CV_TRY_SSE4_1
|
||||
if( useSSE4_1 )
|
||||
opt_SSE4_1::convertMaps_32f2c16s_SSE41(src1f, dst1, dst2, size.width);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#if CV_SIMD128
|
||||
{
|
||||
v_float32x4 v_scale = v_setall_f32((float)INTER_TAB_SIZE);
|
||||
v_int32x4 v_mask = v_setall_s32(INTER_TAB_SIZE - 1);
|
||||
v_int32x4 v_scale3 = v_setall_s32(INTER_TAB_SIZE);
|
||||
int span = VTraits<v_uint16x8>::vlanes();
|
||||
for (; x <= size.width - span; x += span )
|
||||
{
|
||||
v_float32x4 v_src0[2], v_src1[2];
|
||||
v_load_deinterleave(src1f + (x << 1), v_src0[0], v_src0[1]);
|
||||
v_load_deinterleave(src1f + (x << 1) + span, v_src1[0], v_src1[1]);
|
||||
v_int32x4 v_ix0 = v_round(v_mul(v_src0[0], v_scale));
|
||||
v_int32x4 v_ix1 = v_round(v_mul(v_src1[0], v_scale));
|
||||
v_int32x4 v_iy0 = v_round(v_mul(v_src0[1], v_scale));
|
||||
v_int32x4 v_iy1 = v_round(v_mul(v_src1[1], v_scale));
|
||||
|
||||
v_int16x8 v_dst[2];
|
||||
v_dst[0] = v_pack(v_shr<INTER_BITS>(v_ix0), v_shr<INTER_BITS>(v_ix1));
|
||||
v_dst[1] = v_pack(v_shr<INTER_BITS>(v_iy0), v_shr<INTER_BITS>(v_iy1));
|
||||
v_store_interleave(dst1 + (x << 1), v_dst[0], v_dst[1]);
|
||||
|
||||
v_store(dst2 + x, v_pack_u(
|
||||
v_muladd(v_scale3, (v_and(v_iy0, v_mask)), (v_and(v_ix0, v_mask))),
|
||||
v_muladd(v_scale3, (v_and(v_iy1, v_mask)), (v_and(v_ix1, v_mask)))));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for( ; x < size.width; x++ )
|
||||
{
|
||||
int ix = saturate_cast<int>(src1f[x*2]*INTER_TAB_SIZE);
|
||||
int iy = saturate_cast<int>(src1f[x*2+1]*INTER_TAB_SIZE);
|
||||
dst1[x*2] = saturate_cast<short>(ix >> INTER_BITS);
|
||||
dst1[x*2+1] = saturate_cast<short>(iy >> INTER_BITS);
|
||||
dst2[x] = (ushort)((iy & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + (ix & (INTER_TAB_SIZE-1)));
|
||||
}
|
||||
int ix = saturate_cast<int>(src1f[x*2]*INTER_TAB_SIZE);
|
||||
int iy = saturate_cast<int>(src1f[x*2+1]*INTER_TAB_SIZE);
|
||||
dst1[x*2] = saturate_cast<short>(ix >> INTER_BITS);
|
||||
dst1[x*2+1] = saturate_cast<short>(iy >> INTER_BITS);
|
||||
dst2[x] = (ushort)((iy & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + (ix & (INTER_TAB_SIZE-1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,10 @@ static void hlineResize(ET* src, int cn, int *ofst, FT* m, FT* dst, int dst_min,
|
||||
}
|
||||
}
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
ET* src_last = src + cn*ofst[dst_width - 1];
|
||||
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
|
||||
{
|
||||
@@ -125,6 +129,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 1>
|
||||
ET* px = src + ofst[i];
|
||||
*(dst++) = m[0] * px[0] + m[1] * px[1];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
src0 = (src + ofst[dst_width - 1])[0];
|
||||
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
|
||||
{
|
||||
@@ -149,6 +157,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 2>
|
||||
*(dst++) = m[0] * px[0] + m[1] * px[2];
|
||||
*(dst++) = m[0] * px[1] + m[1] * px[3];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
src0 = (src + 2*ofst[dst_width - 1])[0];
|
||||
src1 = (src + 2*ofst[dst_width - 1])[1];
|
||||
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
|
||||
@@ -177,6 +189,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 3>
|
||||
*(dst++) = m[0] * px[1] + m[1] * px[4];
|
||||
*(dst++) = m[0] * px[2] + m[1] * px[5];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
src0 = (src + 3*ofst[dst_width - 1])[0];
|
||||
src1 = (src + 3*ofst[dst_width - 1])[1];
|
||||
src2 = (src + 3*ofst[dst_width - 1])[2];
|
||||
@@ -209,6 +225,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 4>
|
||||
*(dst++) = m[0] * px[2] + m[1] * px[6];
|
||||
*(dst++) = m[0] * px[3] + m[1] * px[7];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
src0 = (src + 4*ofst[dst_width - 1])[0];
|
||||
src1 = (src + 4*ofst[dst_width - 1])[1];
|
||||
src2 = (src + 4*ofst[dst_width - 1])[2];
|
||||
@@ -237,6 +257,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 1>
|
||||
ET* px = src + ofst[i];
|
||||
*(dst++) = m[0] * src[0] + m[1] * src[1] + m[2] * src[2] + m[3] * src[3];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
src0 = (src + ofst[dst_width - 1])[0];
|
||||
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
|
||||
{
|
||||
@@ -261,6 +285,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 2>
|
||||
*(dst++) = m[0] * src[0] + m[1] * src[2] + m[2] * src[4] + m[3] * src[6];
|
||||
*(dst++) = m[0] * src[1] + m[1] * src[3] + m[2] * src[5] + m[3] * src[7];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
src0 = (src + 2*ofst[dst_width - 1])[0];
|
||||
src1 = (src + 2*ofst[dst_width - 1])[1];
|
||||
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
|
||||
@@ -289,6 +317,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 3>
|
||||
*(dst++) = m[0] * src[1] + m[1] * src[4] + m[2] * src[7] + m[3] * src[10];
|
||||
*(dst++) = m[0] * src[2] + m[1] * src[5] + m[2] * src[8] + m[3] * src[11];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
src0 = (src + 3*ofst[dst_width - 1])[0];
|
||||
src1 = (src + 3*ofst[dst_width - 1])[1];
|
||||
src2 = (src + 3*ofst[dst_width - 1])[2];
|
||||
@@ -321,6 +353,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 4>
|
||||
*(dst++) = m[0] * src[2] + m[1] * src[6] + m[2] * src[10] + m[3] * src[14];
|
||||
*(dst++) = m[0] * src[3] + m[1] * src[7] + m[2] * src[11] + m[3] * src[15];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
src0 = (src + 4*ofst[dst_width - 1])[0];
|
||||
src1 = (src + 4*ofst[dst_width - 1])[1];
|
||||
src2 = (src + 4*ofst[dst_width - 1])[2];
|
||||
@@ -382,6 +418,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 1>(uint8_t* src, int, int *o
|
||||
uint8_t* px = src + ofst[i];
|
||||
*(dst++) = m[0] * px[0] + m[1] * px[1];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
src_0 = (src + ofst[dst_width - 1])[0];
|
||||
#if (CV_SIMD || CV_SIMD_SCALABLE)
|
||||
v_src_0 = vx_setall_u16(*((uint16_t*)&src_0));
|
||||
@@ -438,6 +478,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 2>(uint8_t* src, int, int *o
|
||||
*(dst++) = m[0] * px[0] + m[1] * px[2];
|
||||
*(dst++) = m[0] * px[1] + m[1] * px[3];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
((ufixedpoint16*)(srccn.w))[0] = (src + 2 * ofst[dst_width - 1])[0]; ((ufixedpoint16*)(srccn.w))[1] = (src + 2 * ofst[dst_width - 1])[1];
|
||||
#if (CV_SIMD || CV_SIMD_SCALABLE)
|
||||
v_srccn = v_reinterpret_as_u16(vx_setall_u32(srccn.d));
|
||||
@@ -510,6 +554,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 3>(uint8_t* src, int, int *o
|
||||
*(dst++) = m[0] * px[1] + m[1] * px[4];
|
||||
*(dst++) = m[0] * px[2] + m[1] * px[5];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
((ufixedpoint16*)(srccn.w))[0] = (src + 3*ofst[dst_width - 1])[0];
|
||||
((ufixedpoint16*)(srccn.w))[1] = (src + 3*ofst[dst_width - 1])[1];
|
||||
((ufixedpoint16*)(srccn.w))[2] = (src + 3*ofst[dst_width - 1])[2];
|
||||
@@ -583,6 +631,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 4>(uint8_t* src, int, int *o
|
||||
*(dst++) = m[0] * px[2] + m[1] * px[6];
|
||||
*(dst++) = m[0] * px[3] + m[1] * px[7];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
((ufixedpoint16*)(srccn.w))[0] = (src + 4 * ofst[dst_width - 1])[0]; ((ufixedpoint16*)(srccn.w))[1] = (src + 4 * ofst[dst_width - 1])[1];
|
||||
((ufixedpoint16*)(srccn.w))[2] = (src + 4 * ofst[dst_width - 1])[2]; ((ufixedpoint16*)(srccn.w))[3] = (src + 4 * ofst[dst_width - 1])[3];
|
||||
#if (CV_SIMD || CV_SIMD_SCALABLE)
|
||||
@@ -634,6 +686,10 @@ void hlineResizeCn<uint16_t, ufixedpoint32, 2, true, 1>(uint16_t* src, int, int
|
||||
uint16_t* px = src + ofst[i];
|
||||
*(dst++) = m[0] * px[0] + m[1] * px[1];
|
||||
}
|
||||
// Avoid reading a potentially unset ofst, leading to a random memory read.
|
||||
if (i >= dst_width) {
|
||||
return;
|
||||
}
|
||||
src_0 = (src + ofst[dst_width - 1])[0];
|
||||
#if (CV_SIMD || CV_SIMD_SCALABLE)
|
||||
v_src_0 = vx_setall_u32(*((uint32_t*)&src_0));
|
||||
|
||||
@@ -455,7 +455,7 @@ void CV_ColorGrayTest::get_test_array_types_and_sizes( int test_case_idx, vector
|
||||
double CV_ColorGrayTest::get_success_error_level( int /*test_case_idx*/, int i, int j )
|
||||
{
|
||||
int depth = test_mat[i][j].depth();
|
||||
return depth == CV_8U ? 2 : depth == CV_16U ? 16 : 1e-5;
|
||||
return depth == CV_8U ? 1 : depth == CV_16U ? 2 : 1e-5;
|
||||
}
|
||||
|
||||
|
||||
@@ -2844,6 +2844,11 @@ void runCvtColorBitExactCheck(ColorConversionCodes code, int inputType, uint32_t
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_cvtColor_BE, COLOR_RGB2GRAY) { runCvtColorBitExactCheck(COLOR_RGB2GRAY, CV_8UC3, 0x416bd44a); }
|
||||
TEST(Imgproc_cvtColor_BE, COLOR_RGBA2GRAY) { runCvtColorBitExactCheck(COLOR_RGBA2GRAY, CV_8UC3, 0x416bd44a); }
|
||||
TEST(Imgproc_cvtColor_BE, COLOR_BGR2GRAY) { runCvtColorBitExactCheck(COLOR_BGR2GRAY, CV_8UC3, 0x3008c6b8); }
|
||||
TEST(Imgproc_cvtColor_BE, COLOR_BGRA2GRAY) { runCvtColorBitExactCheck(COLOR_BGRA2GRAY, CV_8UC3, 0x3008c6b8); }
|
||||
|
||||
TEST(Imgproc_cvtColor_BE, COLOR_BGR2YUV) { runCvtColorBitExactCheck(COLOR_BGR2YUV, CV_8UC3, 0xc2cbcfda); }
|
||||
TEST(Imgproc_cvtColor_BE, COLOR_RGB2YUV) { runCvtColorBitExactCheck(COLOR_RGB2YUV, CV_8UC3, 0x4e98e757); }
|
||||
TEST(Imgproc_cvtColor_BE, COLOR_YUV2BGR) { runCvtColorBitExactCheck(COLOR_YUV2BGR, CV_8UC3, 0xb2c62a3f); }
|
||||
|
||||
Reference in New Issue
Block a user