mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge branch 4.x
This commit is contained in:
@@ -202,8 +202,8 @@ struct CvtHelper
|
||||
int stype = _src.type();
|
||||
scn = CV_MAT_CN(stype), depth = CV_MAT_DEPTH(stype);
|
||||
|
||||
CV_Check(scn, VScn::contains(scn), "Invalid number of channels in input image");
|
||||
CV_Check(dcn, VDcn::contains(dcn), "Invalid number of channels in output image");
|
||||
CV_CheckChannels(scn, VScn::contains(scn), "Invalid number of channels in input image");
|
||||
CV_CheckChannels(dcn, VDcn::contains(dcn), "Invalid number of channels in output image");
|
||||
CV_CheckDepth(depth, VDepth::contains(depth), "Unsupported depth of input image");
|
||||
|
||||
if (_src.getObj() == _dst.getObj()) // inplace processing (#6653)
|
||||
@@ -247,8 +247,8 @@ struct OclHelper
|
||||
int scn = src.channels();
|
||||
int depth = src.depth();
|
||||
|
||||
CV_Check(scn, VScn::contains(scn), "Invalid number of channels in input image");
|
||||
CV_Check(dcn, VDcn::contains(dcn), "Invalid number of channels in output image");
|
||||
CV_CheckChannels(scn, VScn::contains(scn), "Invalid number of channels in input image");
|
||||
CV_CheckChannels(dcn, VDcn::contains(dcn), "Invalid number of channels in output image");
|
||||
CV_CheckDepth(depth, VDepth::contains(depth), "Unsupported depth of input image");
|
||||
|
||||
switch (sizePolicy)
|
||||
|
||||
@@ -89,8 +89,8 @@ struct CvtHelper
|
||||
int stype = _src.type();
|
||||
scn = CV_MAT_CN(stype), depth = CV_MAT_DEPTH(stype);
|
||||
|
||||
CV_Check(scn, VScn::contains(scn), "Invalid number of channels in input image");
|
||||
CV_Check(dcn, VDcn::contains(dcn), "Invalid number of channels in output image");
|
||||
CV_CheckChannels(scn, VScn::contains(scn), "Invalid number of channels in input image");
|
||||
CV_CheckChannels(dcn, VDcn::contains(dcn), "Invalid number of channels in output image");
|
||||
CV_CheckDepth(depth, VDepth::contains(depth), "Unsupported depth of input image");
|
||||
|
||||
if (_src.getObj() == _dst.getObj()) // inplace processing (#6653)
|
||||
|
||||
@@ -177,41 +177,102 @@ public:
|
||||
vst1_u8(dst + 8, p.val[1]);
|
||||
}
|
||||
#else
|
||||
v_uint16x8 _b2y = v_setall_u16((ushort)(rcoeff*2));
|
||||
v_uint16x8 _g2y = v_setall_u16((ushort)(gcoeff*2));
|
||||
v_uint16x8 _r2y = v_setall_u16((ushort)(bcoeff*2));
|
||||
v_uint16x8 v255 = v_setall_u16(255);
|
||||
v_int16x8 v_descale = v_setall_s16(static_cast<short>(1 << 14));
|
||||
v_int16x8 dummy;
|
||||
v_int16x8 cxrb;
|
||||
v_int16x8 cxg2;
|
||||
v_zip(v_setall_s16(static_cast<short>(rcoeff)),
|
||||
v_setall_s16(static_cast<short>(bcoeff)),
|
||||
cxrb,
|
||||
dummy);
|
||||
v_zip(v_setall_s16(static_cast<short>(gcoeff)),
|
||||
v_setall_s16(static_cast<short>(2)),
|
||||
cxg2,
|
||||
dummy);
|
||||
|
||||
const uchar* bayer_end = bayer + width;
|
||||
|
||||
for( ; bayer <= bayer_end - 18; bayer += 14, dst += 14 )
|
||||
for (; bayer < bayer_end - 14; bayer += 14, dst += 14)
|
||||
{
|
||||
v_uint16x8 r0 = v_reinterpret_as_u16(v_load(bayer));
|
||||
v_uint16x8 r1 = v_reinterpret_as_u16(v_load(bayer+bayer_step));
|
||||
v_uint16x8 r2 = v_reinterpret_as_u16(v_load(bayer+bayer_step*2));
|
||||
v_uint16x8 first_line = v_reinterpret_as_u16(v_load(bayer));
|
||||
v_uint16x8 second_line = v_reinterpret_as_u16(v_load(bayer + bayer_step));
|
||||
v_uint16x8 third_line = v_reinterpret_as_u16(v_load(bayer + bayer_step * 2));
|
||||
|
||||
v_uint16x8 b1 = v_add(v_shr<7>(v_shl<8>(r0)), v_shr<7>(v_shl<8>(r2)));
|
||||
v_uint16x8 b0 = v_add(v_rotate_right<1>(b1), b1);
|
||||
b1 = v_shl<1>(v_rotate_right<1>(b1));
|
||||
// bayer[0]
|
||||
v_uint16x8 first_line0 = v_and(first_line, v255);
|
||||
// bayer[bayer_step*2]
|
||||
v_uint16x8 third_line0 = v_and(third_line, v255);
|
||||
// bayer[0] + bayer[bayer_step*2]
|
||||
v_uint16x8 first_third_line0 = v_add(first_line0, third_line0);
|
||||
// bayer[2] + bayer[bayer_step*2+2]
|
||||
v_uint16x8 first_third_line2 = v_rotate_right<1>(first_third_line0);
|
||||
// bayer[0] + bayer[2] + bayer[bayer_step*2] + bayer[bayer_step*2+2]
|
||||
v_int16x8 r0 = v_reinterpret_as_s16(v_add(first_third_line0, first_third_line2));
|
||||
// (bayer[2] + bayer[bayer_step*2+2]) * 2
|
||||
v_int16x8 r1 = v_reinterpret_as_s16(v_shl<1>(first_third_line2));
|
||||
|
||||
v_uint16x8 g0 = v_add(v_shr<7>(r0), v_shr<7>(r2));
|
||||
v_uint16x8 g1 = v_shr<7>(v_shl<8>(r1));
|
||||
g0 = v_add(g0, v_add(v_rotate_right<1>(g1), g1));
|
||||
g1 = v_shl<2>(v_rotate_right<1>(g1));
|
||||
// bayer[bayer_step+1]
|
||||
v_uint16x8 second_line1 = v_shr<8>(second_line);
|
||||
// bayer[bayer_step+1] * 4
|
||||
v_int16x8 b0 = v_reinterpret_as_s16(v_shl<2>(second_line1));
|
||||
// bayer[bayer_step+3]
|
||||
v_uint16x8 second_line3 = v_rotate_right<1>(second_line1);
|
||||
// bayer[bayer_step+1] + bayer[bayer_step+3]
|
||||
v_uint16x8 second_line13 = v_add(second_line1, second_line3);
|
||||
// (bayer[bayer_step+1] + bayer[bayer_step+3]) * 2
|
||||
v_int16x8 b1 = v_reinterpret_as_s16(v_shl(second_line13, 1));
|
||||
|
||||
r0 = v_shr<8>(r1);
|
||||
r1 = v_shl<2>(v_add(v_rotate_right<1>(r0), r0));
|
||||
r0 = v_shl<3>(r0);
|
||||
// bayer[1]
|
||||
v_uint16x8 first_line1 = v_shr<8>(first_line);
|
||||
// bayer[bayer_step]
|
||||
v_uint16x8 second_line0 = v_and(second_line, v255);
|
||||
// bayer[bayer_step+2]
|
||||
v_uint16x8 second_line2 = v_rotate_right<1>(second_line0);
|
||||
// bayer[bayer_step] + bayer[bayer_step+2]
|
||||
v_uint16x8 second_line02 = v_add(second_line0, second_line2);
|
||||
// bayer[bayer_step*2+1]
|
||||
v_uint16x8 third_line1 = v_shr<8>(third_line);
|
||||
// bayer[1] + bayer[bayer_step*2+1]
|
||||
v_uint16x8 first_third_line1 = v_add(first_line1, third_line1);
|
||||
// bayer[1] + bayer[bayer_step] + bayer[bayer_step+2] + bayer[bayer_step*2+1]
|
||||
v_int16x8 g0 = v_reinterpret_as_s16(v_add(first_third_line1, second_line02));
|
||||
// bayer[bayer_step+2] * 4
|
||||
v_int16x8 g1 = v_reinterpret_as_s16(v_shl<2>(second_line2));
|
||||
|
||||
g0 = v_shr<2>(v_add(v_add(v_mul_hi(b0, _b2y), v_mul_hi(g0, _g2y)), v_mul_hi(r0, _r2y)));
|
||||
g1 = v_shr<2>(v_add(v_add(v_mul_hi(b1, _b2y), v_mul_hi(g1, _g2y)), v_mul_hi(r1, _r2y)));
|
||||
v_uint8x16 pack_lo, pack_hi;
|
||||
v_zip(v_pack_u(v_reinterpret_as_s16(g0), v_reinterpret_as_s16(g0)),
|
||||
v_pack_u(v_reinterpret_as_s16(g1), v_reinterpret_as_s16(g1)),
|
||||
pack_lo, pack_hi);
|
||||
v_store(dst, pack_lo);
|
||||
v_int16x8 rb0;
|
||||
v_int16x8 rb1;
|
||||
v_int16x8 rb2;
|
||||
v_int16x8 rb3;
|
||||
v_zip(r0, b0, rb0, rb1);
|
||||
v_zip(r1, b1, rb2, rb3);
|
||||
|
||||
v_int16x8 gd0;
|
||||
v_int16x8 gd1;
|
||||
v_int16x8 gd2;
|
||||
v_int16x8 gd3;
|
||||
v_zip(g0, v_descale, gd0, gd1);
|
||||
v_zip(g1, v_descale, gd2, gd3);
|
||||
|
||||
v_int32x4 gray_even0 = v_shr<16>(v_add(v_dotprod(rb0, cxrb), v_dotprod(gd0, cxg2)));
|
||||
v_int32x4 gray_even1 = v_shr<16>(v_add(v_dotprod(rb1, cxrb), v_dotprod(gd1, cxg2)));
|
||||
v_int32x4 gray_odd0 = v_shr<16>(v_add(v_dotprod(rb2, cxrb), v_dotprod(gd2, cxg2)));
|
||||
v_int32x4 gray_odd1 = v_shr<16>(v_add(v_dotprod(rb3, cxrb), v_dotprod(gd3, cxg2)));
|
||||
|
||||
v_int16x8 gray_even = v_pack(gray_even0, gray_even1);
|
||||
v_int16x8 gray_odd = v_pack(gray_odd0, gray_odd1);
|
||||
|
||||
v_int16x8 gray_d0;
|
||||
v_int16x8 gray_d1;
|
||||
v_zip(gray_even, gray_odd, gray_d0, gray_d1);
|
||||
|
||||
v_uint8x16 gray = v_pack(v_reinterpret_as_u16(gray_d0), v_reinterpret_as_u16(gray_d1));
|
||||
|
||||
v_store(dst, gray);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (int)(bayer - (bayer_end - width));
|
||||
return static_cast<int>(bayer - (bayer_end - width));
|
||||
}
|
||||
|
||||
int bayer2RGB(const uchar* bayer, int bayer_step, uchar* dst, int width, int blue) const
|
||||
|
||||
@@ -2044,8 +2044,11 @@ void fillPoly( InputOutputArray _img, const Point** pts, const int* npts, int nc
|
||||
edges.reserve( total + 1 );
|
||||
for (i = 0; i < ncontours; i++)
|
||||
{
|
||||
std::vector<Point2l> _pts(pts[i], pts[i] + npts[i]);
|
||||
CollectPolyEdges(img, _pts.data(), npts[i], edges, buf, line_type, shift, offset);
|
||||
if (npts[i] > 0 && pts[i])
|
||||
{
|
||||
std::vector<Point2l> _pts(pts[i], pts[i] + npts[i]);
|
||||
CollectPolyEdges(img, _pts.data(), npts[i], edges, buf, line_type, shift, offset);
|
||||
}
|
||||
}
|
||||
|
||||
FillEdgeCollection(img, edges, buf, line_type);
|
||||
@@ -2105,7 +2108,7 @@ void cv::fillPoly(InputOutputArray img, InputArrayOfArrays pts,
|
||||
for( i = 0; i < ncontours; i++ )
|
||||
{
|
||||
Mat p = pts.getMat(manyContours ? i : -1);
|
||||
CV_Assert(p.checkVector(2, CV_32S) >= 0);
|
||||
CV_Assert(p.checkVector(2, CV_32S) > 0);
|
||||
ptsptr[i] = p.ptr<Point>();
|
||||
npts[i] = p.rows*p.cols*p.channels()/2;
|
||||
}
|
||||
|
||||
@@ -1247,6 +1247,33 @@ inline int hal_ni_pyrdown(const uchar* src_data, size_t src_step, int src_width,
|
||||
#define cv_hal_pyrdown hal_ni_pyrdown
|
||||
//! @endcond
|
||||
|
||||
/**
|
||||
@brief Perform Gaussian Blur and downsampling for input tile with optional margins for submatrix
|
||||
@param src_data Source image data
|
||||
@param src_step Source image step
|
||||
@param src_width Source image width
|
||||
@param src_height Source image height
|
||||
@param dst_data Destination image data
|
||||
@param dst_step Destination image step
|
||||
@param dst_width Destination image width
|
||||
@param dst_height Destination image height
|
||||
@param depth Depths of source and destination image
|
||||
@param cn Number of channels
|
||||
@param margin_left Left margins for source image
|
||||
@param margin_top Top margins for source image
|
||||
@param margin_right Right margins for source image
|
||||
@param margin_bottom Bottom margins for source image
|
||||
@param border_type Border type
|
||||
*/
|
||||
inline int hal_ni_pyrdown_offset(const uchar* src_data, size_t src_step, int src_width, int src_height,
|
||||
uchar* dst_data, size_t dst_step, int dst_width, int dst_height,
|
||||
int depth, int cn, int margin_left, int margin_top, int margin_right, int margin_bottom, int border_type)
|
||||
{ return CV_HAL_ERROR_NOT_IMPLEMENTED; }
|
||||
|
||||
//! @cond IGNORED
|
||||
#define cv_hal_pyrdown_offset hal_ni_pyrdown_offset
|
||||
//! @endcond
|
||||
|
||||
/**
|
||||
@brief Canny edge detector
|
||||
@param src_data Source image data
|
||||
|
||||
@@ -845,7 +845,7 @@ void medianBlur(const Mat& src0, /*const*/ Mat& dst, int ksize)
|
||||
CV_INSTRUMENT_REGION();
|
||||
|
||||
bool useSortNet = ksize == 3 || (ksize == 5
|
||||
#if !(CV_SIMD)
|
||||
#if !((CV_SIMD || CV_SIMD_SCALABLE))
|
||||
&& ( src0.depth() > CV_8U || src0.channels() == 2 || src0.channels() > 4 )
|
||||
#endif
|
||||
);
|
||||
@@ -881,7 +881,7 @@ void medianBlur(const Mat& src0, /*const*/ Mat& dst, int ksize)
|
||||
|
||||
double img_size_mp = (double)(src0.total())/(1 << 20);
|
||||
if( ksize <= 3 + (img_size_mp < 1 ? 12 : img_size_mp < 4 ? 6 : 2)*
|
||||
(CV_SIMD ? 1 : 3))
|
||||
((CV_SIMD || CV_SIMD_SCALABLE) ? 1 : 3))
|
||||
medianBlur_8u_Om( src, dst, ksize );
|
||||
else
|
||||
medianBlur_8u_O1( src, dst, ksize );
|
||||
|
||||
@@ -1265,69 +1265,6 @@ static bool ocl_pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int
|
||||
|
||||
}
|
||||
|
||||
#if defined(HAVE_IPP)
|
||||
namespace cv
|
||||
{
|
||||
static bool ipp_pyrdown( InputArray _src, OutputArray _dst, const Size& _dsz, int borderType )
|
||||
{
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
#if IPP_VERSION_X100 >= 810 && !IPP_DISABLE_PYRAMIDS_DOWN
|
||||
Size dsz = _dsz.empty() ? Size((_src.cols() + 1)/2, (_src.rows() + 1)/2) : _dsz;
|
||||
bool isolated = (borderType & BORDER_ISOLATED) != 0;
|
||||
int borderTypeNI = borderType & ~BORDER_ISOLATED;
|
||||
|
||||
Mat src = _src.getMat();
|
||||
_dst.create( dsz, src.type() );
|
||||
Mat dst = _dst.getMat();
|
||||
int depth = src.depth();
|
||||
|
||||
|
||||
{
|
||||
bool isolated = (borderType & BORDER_ISOLATED) != 0;
|
||||
int borderTypeNI = borderType & ~BORDER_ISOLATED;
|
||||
if (borderTypeNI == BORDER_DEFAULT && (!src.isSubmatrix() || isolated) && dsz == Size(src.cols*2, src.rows*2))
|
||||
{
|
||||
typedef IppStatus (CV_STDCALL * ippiPyrUp)(const void* pSrc, int srcStep, void* pDst, int dstStep, IppiSize srcRoi, Ipp8u* buffer);
|
||||
int type = src.type();
|
||||
CV_SUPPRESS_DEPRECATED_START
|
||||
ippiPyrUp pyrUpFunc = type == CV_8UC1 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_8u_C1R :
|
||||
type == CV_8UC3 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_8u_C3R :
|
||||
type == CV_32FC1 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_32f_C1R :
|
||||
type == CV_32FC3 ? (ippiPyrUp) ippiPyrUp_Gauss5x5_32f_C3R : 0;
|
||||
CV_SUPPRESS_DEPRECATED_END
|
||||
|
||||
if (pyrUpFunc)
|
||||
{
|
||||
int bufferSize;
|
||||
IppiSize srcRoi = { src.cols, src.rows };
|
||||
IppDataType dataType = depth == CV_8U ? ipp8u : ipp32f;
|
||||
CV_SUPPRESS_DEPRECATED_START
|
||||
IppStatus ok = ippiPyrUpGetBufSize_Gauss5x5(srcRoi.width, dataType, src.channels(), &bufferSize);
|
||||
CV_SUPPRESS_DEPRECATED_END
|
||||
if (ok >= 0)
|
||||
{
|
||||
Ipp8u* buffer = ippsMalloc_8u_L(bufferSize);
|
||||
ok = pyrUpFunc(src.data, (int) src.step, dst.data, (int) dst.step, srcRoi, buffer);
|
||||
ippsFree(buffer);
|
||||
|
||||
if (ok >= 0)
|
||||
{
|
||||
CV_IMPL_ADD(CV_IMPL_IPP);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
CV_UNUSED(_src); CV_UNUSED(_dst); CV_UNUSED(_dsz); CV_UNUSED(borderType);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borderType )
|
||||
{
|
||||
CV_INSTRUMENT_REGION();
|
||||
@@ -1343,15 +1280,19 @@ void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borde
|
||||
Mat dst = _dst.getMat();
|
||||
int depth = src.depth();
|
||||
|
||||
CALL_HAL(pyrDown, cv_hal_pyrdown, src.data, src.step, src.cols, src.rows, dst.data, dst.step, dst.cols, dst.rows, depth, src.channels(), borderType);
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
bool isolated = (borderType & BORDER_ISOLATED) != 0;
|
||||
int borderTypeNI = borderType & ~BORDER_ISOLATED;
|
||||
#endif
|
||||
CV_IPP_RUN(borderTypeNI == BORDER_DEFAULT && (!_src.isSubmatrix() || isolated) && dsz == Size((_src.cols() + 1)/2, (_src.rows() + 1)/2),
|
||||
ipp_pyrdown( _src, _dst, _dsz, borderType));
|
||||
|
||||
if(src.isSubmatrix() && !(borderType & BORDER_ISOLATED))
|
||||
{
|
||||
Point ofs;
|
||||
Size wsz(src.cols, src.rows);
|
||||
src.locateROI( wsz, ofs );
|
||||
CALL_HAL(pyrDown, cv_hal_pyrdown_offset, src.data, src.step, src.cols, src.rows,
|
||||
dst.data, dst.step, dst.cols, dst.rows, depth, src.channels(),
|
||||
ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, borderType & (~BORDER_ISOLATED));
|
||||
}
|
||||
else
|
||||
{
|
||||
CALL_HAL(pyrDown, cv_hal_pyrdown, src.data, src.step, src.cols, src.rows, dst.data, dst.step, dst.cols, dst.rows, depth, src.channels(), borderType);
|
||||
}
|
||||
|
||||
PyrFunc func = 0;
|
||||
if( depth == CV_8U )
|
||||
|
||||
Reference in New Issue
Block a user