Merge remote-tracking branch 'upstream/3.4' into merge-3.4
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Mon, 11 Mar 2019 19:20:22 +0000 (19:20 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Mon, 11 Mar 2019 19:20:22 +0000 (19:20 +0000)
14 files changed:
1  2 
modules/core/include/opencv2/core/private.hpp
modules/core/src/matrix_wrap.cpp
modules/dnn/src/layers/convolution_layer.cpp
modules/dnn/test/test_backends.cpp
modules/imgcodecs/include/opencv2/imgcodecs.hpp
modules/imgcodecs/src/grfmt_tiff.cpp
modules/imgproc/perf/perf_warp.cpp
modules/imgproc/src/box_filter.simd.hpp
modules/imgproc/src/color.cpp
modules/imgproc/src/color.simd_helpers.hpp
modules/imgproc/src/color_rgb.simd.hpp
modules/imgproc/src/morph.dispatch.cpp
modules/video/perf/perf_optflowpyrlk.cpp
modules/videoio/src/cap_gstreamer.cpp

Simple merge
Simple merge
@@@ -92,10 -92,10 +92,11 @@@ enum ImwriteFlags 
         IMWRITE_EXR_TYPE            = (3 << 4) + 0, /* 48 */ //!< override EXR storage type (FLOAT (FP32) is default)
         IMWRITE_WEBP_QUALITY        = 64, //!< For WEBP, it can be a quality from 1 to 100 (the higher is the better). By default (without any parameter) and for quality above 100 the lossless compression is used.
         IMWRITE_PAM_TUPLETYPE       = 128,//!< For PAM, sets the TUPLETYPE field to the corresponding string value that is defined for the format
 -       IMWRITE_TIFF_RESUNIT = 256,//!< For TIFF, use to specify which DPI resolution unit to set; see libtiff documentation for valid values.
 -       IMWRITE_TIFF_XDPI = 257,//!< For TIFF, use to specify the X direction DPI.
 -       IMWRITE_TIFF_YDPI = 258, //!< For TIFF, use to specify the Y direction DPI.
 -       IMWRITE_TIFF_COMPRESSION = 259 //!< For TIFF, use to specify the image compression scheme. See libtiff for integer constants corresponding to compression formats. Note, for images whose depth is CV_32F, only libtiff's SGILOG compression scheme is used. For other supported depths, the compression scheme can be specified by this flag; LZW compression is the default.
 +       IMWRITE_TIFF_RESUNIT = 256,//!< For TIFF, use to specify which DPI resolution unit to set; see libtiff documentation for valid values
 +       IMWRITE_TIFF_XDPI = 257,//!< For TIFF, use to specify the X direction DPI
 +       IMWRITE_TIFF_YDPI = 258, //!< For TIFF, use to specify the Y direction DPI
++       IMWRITE_TIFF_COMPRESSION = 259, //!< For TIFF, use to specify the image compression scheme. See libtiff for integer constants corresponding to compression formats. Note, for images whose depth is CV_32F, only libtiff's SGILOG compression scheme is used. For other supported depths, the compression scheme can be specified by this flag; LZW compression is the default.
 +       IMWRITE_JPEG2000_COMPRESSION_X1000 = 272 //!< For JPEG2000, use to specify the target compression rate (multiplied by 1000). The value can be from 0 to 1000. Default is 1000.
       };
  
  enum ImwriteEXRTypeFlags {
Simple merge
Simple merge
@@@ -1496,195 -1271,8 +1271,7 @@@ Ptr<FilterEngine> createBoxFilter(int s
             srcType, dstType, sumType, borderType );
  }
  
- #ifdef HAVE_OPENVX
- namespace cv
- {
-     namespace ovx {
-         template <> inline bool skipSmallImages<VX_KERNEL_BOX_3x3>(int w, int h) { return w*h < 640 * 480; }
-     }
-     static bool openvx_boxfilter(InputArray _src, OutputArray _dst, int ddepth,
-                                  Size ksize, Point anchor,
-                                  bool normalize, int borderType)
-     {
-         if (ddepth < 0)
-             ddepth = CV_8UC1;
-         if (_src.type() != CV_8UC1 || ddepth != CV_8U || !normalize ||
-             _src.cols() < 3 || _src.rows() < 3 ||
-             ksize.width != 3 || ksize.height != 3 ||
-             (anchor.x >= 0 && anchor.x != 1) ||
-             (anchor.y >= 0 && anchor.y != 1) ||
-             ovx::skipSmallImages<VX_KERNEL_BOX_3x3>(_src.cols(), _src.rows()))
-             return false;
-         Mat src = _src.getMat();
-         if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix())
-             return false; //Process isolated borders only
-         vx_enum border;
-         switch (borderType & ~BORDER_ISOLATED)
-         {
-         case BORDER_CONSTANT:
-             border = VX_BORDER_CONSTANT;
-             break;
-         case BORDER_REPLICATE:
-             border = VX_BORDER_REPLICATE;
-             break;
-         default:
-             return false;
-         }
-         _dst.create(src.size(), CV_8UC1);
-         Mat dst = _dst.getMat();
-         try
-         {
-             ivx::Context ctx = ovx::getOpenVXContext();
-             Mat a;
-             if (dst.data != src.data)
-                 a = src;
-             else
-                 src.copyTo(a);
-             ivx::Image
-                 ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
-                                                   ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data),
-                 ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
-                                                   ivx::Image::createAddressing(dst.cols, dst.rows, 1, (vx_int32)(dst.step)), dst.data);
-             //ATTENTION: VX_CONTEXT_IMMEDIATE_BORDER attribute change could lead to strange issues in multi-threaded environments
-             //since OpenVX standard says nothing about thread-safety for now
-             ivx::border_t prevBorder = ctx.immediateBorder();
-             ctx.setImmediateBorder(border, (vx_uint8)(0));
-             ivx::IVX_CHECK_STATUS(vxuBox3x3(ctx, ia, ib));
-             ctx.setImmediateBorder(prevBorder);
-         }
-         catch (const ivx::RuntimeError & e)
-         {
-             VX_DbgThrow(e.what());
-         }
-         catch (const ivx::WrapperError & e)
-         {
-             VX_DbgThrow(e.what());
-         }
-         return true;
-     }
- }
- #endif
- #if defined(HAVE_IPP) && OPENCV_IPP_REDUCE_SIZE == 0
- namespace cv
- {
- static bool ipp_boxfilter(Mat &src, Mat &dst, Size ksize, Point anchor, bool normalize, int borderType)
- {
- #ifdef HAVE_IPP_IW
-     CV_INSTRUMENT_REGION_IPP();
- #if IPP_VERSION_X100 < 201801
-     // Problem with SSE42 optimization for 16s and some 8u modes
-     if(ipp::getIppTopFeatures() == ippCPUID_SSE42 && (((src.depth() == CV_16S || src.depth() == CV_16U) && (src.channels() == 3 || src.channels() == 4)) || (src.depth() == CV_8U && src.channels() == 3 && (ksize.width > 5 || ksize.height > 5))))
-         return false;
-     // Other optimizations has some degradations too
-     if((((src.depth() == CV_16S || src.depth() == CV_16U) && (src.channels() == 4)) || (src.depth() == CV_8U && src.channels() == 1 && (ksize.width > 5 || ksize.height > 5))))
-         return false;
- #endif
-     if(!normalize)
-         return false;
-     if(!ippiCheckAnchor(anchor, ksize))
-         return false;
-     try
-     {
-         ::ipp::IwiImage       iwSrc      = ippiGetImage(src);
-         ::ipp::IwiImage       iwDst      = ippiGetImage(dst);
-         ::ipp::IwiSize        iwKSize    = ippiGetSize(ksize);
-         ::ipp::IwiBorderSize  borderSize(iwKSize);
-         ::ipp::IwiBorderType  ippBorder(ippiGetBorder(iwSrc, borderType, borderSize));
-         if(!ippBorder)
-             return false;
-         CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterBox, iwSrc, iwDst, iwKSize, ::ipp::IwDefault(), ippBorder);
-     }
-     catch (const ::ipp::IwException &)
-     {
-         return false;
-     }
-     return true;
- #else
-     CV_UNUSED(src); CV_UNUSED(dst); CV_UNUSED(ksize); CV_UNUSED(anchor); CV_UNUSED(normalize); CV_UNUSED(borderType);
-     return false;
- #endif
- }
- }
- #endif
- void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth,
-                 Size ksize, Point anchor,
-                 bool normalize, int borderType )
- {
-     CV_INSTRUMENT_REGION();
-     CV_OCL_RUN(_dst.isUMat() &&
-                (borderType == BORDER_REPLICATE || borderType == BORDER_CONSTANT ||
-                 borderType == BORDER_REFLECT || borderType == BORDER_REFLECT_101),
-                ocl_boxFilter3x3_8UC1(_src, _dst, ddepth, ksize, anchor, borderType, normalize))
-     CV_OCL_RUN(_dst.isUMat(), ocl_boxFilter(_src, _dst, ddepth, ksize, anchor, borderType, normalize))
-     Mat src = _src.getMat();
-     int stype = src.type(), sdepth = CV_MAT_DEPTH(stype), cn = CV_MAT_CN(stype);
-     if( ddepth < 0 )
-         ddepth = sdepth;
-     _dst.create( src.size(), CV_MAKETYPE(ddepth, cn) );
-     Mat dst = _dst.getMat();
-     if( borderType != BORDER_CONSTANT && normalize && (borderType & BORDER_ISOLATED) != 0 )
-     {
-         if( src.rows == 1 )
-             ksize.height = 1;
-         if( src.cols == 1 )
-             ksize.width = 1;
-     }
-     Point ofs;
-     Size wsz(src.cols, src.rows);
-     if(!(borderType&BORDER_ISOLATED))
-         src.locateROI( wsz, ofs );
-     CALL_HAL(boxFilter, cv_hal_boxFilter, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, ddepth, cn,
-              ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height,
-              anchor.x, anchor.y, normalize, borderType&~BORDER_ISOLATED);
-     CV_OVX_RUN(true,
-                openvx_boxfilter(src, dst, ddepth, ksize, anchor, normalize, borderType))
- #if OPENCV_IPP_REDUCE_SIZE == 0
-     CV_IPP_RUN_FAST(ipp_boxfilter(src, dst, ksize, anchor, normalize, borderType));
- #endif
-     borderType = (borderType&~BORDER_ISOLATED);
-     Ptr<FilterEngine> f = createBoxFilter( src.type(), dst.type(),
-                         ksize, anchor, normalize, borderType );
-     f->apply( src, dst, wsz, ofs );
- }
- void cv::blur( InputArray src, OutputArray dst,
-            Size ksize, Point anchor, int borderType )
- {
-     CV_INSTRUMENT_REGION();
-     boxFilter( src, dst, -1, ksize, anchor, true, borderType );
- }
  
 -
  /****************************************************************************************\
                                      Squared Box Filter
  \****************************************************************************************/
Simple merge
index 0000000,343491f..47f00fd
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,167 +1,171 @@@
+ // This file is part of OpenCV project.
+ // It is subject to the license terms in the LICENSE file found in the top-level directory
+ // of this distribution and at http://opencv.org/license.html
+ #define  CV_DESCALE(x,n)     (((x) + (1 << ((n)-1))) >> (n))
+ namespace {
+ //constants for conversion from/to RGB and Gray, YUV, YCrCb according to BT.601
+ static const float B2YF = 0.114f;
+ static const float G2YF = 0.587f;
+ static const float R2YF = 0.299f;
+ enum
+ {
++    gray_shift = 15,
+     yuv_shift = 14,
+     xyz_shift = 12,
+     R2Y = 4899, // == R2YF*16384
+     G2Y = 9617, // == G2YF*16384
+     B2Y = 1868, // == B2YF*16384
++    RY15 =  9798, // == R2YF*32768 + 0.5
++    GY15 = 19235, // == G2YF*32768 + 0.5
++    BY15 =  3735, // == B2YF*32768 + 0.5
+     BLOCK_SIZE = 256
+ };
+ template<typename _Tp> struct ColorChannel
+ {
+     typedef float worktype_f;
+     static inline _Tp max() { return std::numeric_limits<_Tp>::max(); }
+     static inline _Tp half() { return (_Tp)(max()/2 + 1); }
+ };
+ template<> struct ColorChannel<float>
+ {
+     typedef float worktype_f;
+     static inline float max() { return 1.f; }
+     static inline float half() { return 0.5f; }
+ };
+ /*template<> struct ColorChannel<double>
+ {
+     typedef double worktype_f;
+     static double max() { return 1.; }
+     static double half() { return 0.5; }
+ };*/
+ template<int i0, int i1 = -1, int i2 = -1>
+ struct Set
+ {
+     static inline bool contains(int i)
+     {
+         return (i == i0 || i == i1 || i == i2);
+     }
+ };
+ template<int i0, int i1>
+ struct Set<i0, i1, -1>
+ {
+     static inline bool contains(int i)
+     {
+         return (i == i0 || i == i1);
+     }
+ };
+ template<int i0>
+ struct Set<i0, -1, -1>
+ {
+     static inline bool contains(int i)
+     {
+         return (i == i0);
+     }
+ };
+ enum SizePolicy
+ {
+     TO_YUV, FROM_YUV, NONE
+ };
+ template< typename VScn, typename VDcn, typename VDepth, SizePolicy sizePolicy = NONE >
+ struct CvtHelper
+ {
+     CvtHelper(InputArray _src, OutputArray _dst, int dcn)
+     {
+         CV_Assert(!_src.empty());
+         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_CheckDepth(depth, VDepth::contains(depth), "Unsupported depth of input image");
+         if (_src.getObj() == _dst.getObj()) // inplace processing (#6653)
+             _src.copyTo(src);
+         else
+             src = _src.getMat();
+         Size sz = src.size();
+         switch (sizePolicy)
+         {
+         case TO_YUV:
+             CV_Assert( sz.width % 2 == 0 && sz.height % 2 == 0);
+             dstSz = Size(sz.width, sz.height / 2 * 3);
+             break;
+         case FROM_YUV:
+             CV_Assert( sz.width % 2 == 0 && sz.height % 3 == 0);
+             dstSz = Size(sz.width, sz.height * 2 / 3);
+             break;
+         case NONE:
+         default:
+             dstSz = sz;
+             break;
+         }
+         _dst.create(dstSz, CV_MAKETYPE(depth, dcn));
+         dst = _dst.getMat();
+     }
+     Mat src, dst;
+     int depth, scn;
+     Size dstSz;
+ };
+ ///////////////////////////// Top-level template function ////////////////////////////////
+ template <typename Cvt>
+ class CvtColorLoop_Invoker : public ParallelLoopBody
+ {
+     typedef typename Cvt::channel_type _Tp;
+ public:
+     CvtColorLoop_Invoker(const uchar * src_data_, size_t src_step_, uchar * dst_data_, size_t dst_step_, int width_, const Cvt& _cvt) :
+         ParallelLoopBody(), src_data(src_data_), src_step(src_step_), dst_data(dst_data_), dst_step(dst_step_),
+         width(width_), cvt(_cvt)
+     {
+     }
+     virtual void operator()(const Range& range) const CV_OVERRIDE
+     {
+         CV_TRACE_FUNCTION();
+         const uchar* yS = src_data + static_cast<size_t>(range.start) * src_step;
+         uchar* yD = dst_data + static_cast<size_t>(range.start) * dst_step;
+         for( int i = range.start; i < range.end; ++i, yS += src_step, yD += dst_step )
+             cvt(reinterpret_cast<const _Tp*>(yS), reinterpret_cast<_Tp*>(yD), width);
+     }
+ private:
+     const uchar * src_data;
+     const size_t src_step;
+     uchar * dst_data;
+     const size_t dst_step;
+     const int width;
+     const Cvt& cvt;
+     CvtColorLoop_Invoker(const CvtColorLoop_Invoker&);  // = delete;
+     const CvtColorLoop_Invoker& operator= (const CvtColorLoop_Invoker&);  // = delete;
+ };
+ template <typename Cvt> static inline
+ void CvtColorLoop(const uchar * src_data, size_t src_step, uchar * dst_data, size_t dst_step, int width, int height, const Cvt& cvt)
+ {
+     CV_AVX_GUARD
+     parallel_for_(Range(0, height),
+                   CvtColorLoop_Invoker<Cvt>(src_data, src_step, dst_data, dst_step, width, cvt),
+                   (width * height) / static_cast<double>(1<<16));
+ }
+ } //namespace
@@@ -1816,10 -1079,8 +1079,8 @@@ static bool ocl_morphologyEx(InputArra
  #endif
  
  #define IPP_DISABLE_MORPH_ADV 1
 -#ifdef HAVE_IPP
 +#if 0 //defined HAVE_IPP
  #if !IPP_DISABLE_MORPH_ADV
- namespace cv {
  static bool ipp_morphologyEx(int op, InputArray _src, OutputArray _dst,
                       InputArray _kernel,
                       Point anchor, int iterations,
@@@ -1590,7 -1811,13 +1590,11 @@@ void handleMessage(GstElement * pipelin
  
      while(gst_bus_have_pending(bus)) {
          msg = gst_bus_pop(bus);
+         if (!msg || !GST_IS_MESSAGE(msg))
+         {
+             continue;
+         }
  
 -        //printf("\t\tGot %s message\n", GST_MESSAGE_TYPE_NAME(msg));
 -
          if(gst_is_missing_plugin_message(msg))
          {
              CV_WARN("your gstreamer installation is missing a required plugin\n");