diff --git a/exe/FaceLandmarkImg/FaceLandmarkImg.vcxproj b/exe/FaceLandmarkImg/FaceLandmarkImg.vcxproj index 38bc8fdb..ad1383da 100644 --- a/exe/FaceLandmarkImg/FaceLandmarkImg.vcxproj +++ b/exe/FaceLandmarkImg/FaceLandmarkImg.vcxproj @@ -58,34 +58,34 @@ - + - + - + - + diff --git a/exe/FaceLandmarkVid/FaceLandmarkVid.vcxproj b/exe/FaceLandmarkVid/FaceLandmarkVid.vcxproj index 98ad4bae..6b1a0fb2 100644 --- a/exe/FaceLandmarkVid/FaceLandmarkVid.vcxproj +++ b/exe/FaceLandmarkVid/FaceLandmarkVid.vcxproj @@ -58,34 +58,34 @@ - + - + - + - + diff --git a/exe/FaceLandmarkVidMulti/FaceLandmarkVidMulti.vcxproj b/exe/FaceLandmarkVidMulti/FaceLandmarkVidMulti.vcxproj index d82f3ddf..0eec0218 100644 --- a/exe/FaceLandmarkVidMulti/FaceLandmarkVidMulti.vcxproj +++ b/exe/FaceLandmarkVidMulti/FaceLandmarkVidMulti.vcxproj @@ -57,34 +57,34 @@ - + - + - + - + diff --git a/exe/FeatureExtraction/FeatureExtraction.vcxproj b/exe/FeatureExtraction/FeatureExtraction.vcxproj index cc9be52b..623927c5 100644 --- a/exe/FeatureExtraction/FeatureExtraction.vcxproj +++ b/exe/FeatureExtraction/FeatureExtraction.vcxproj @@ -57,34 +57,34 @@ - + - + - + - + diff --git a/exe/Recording/Recording.vcxproj b/exe/Recording/Recording.vcxproj index ffd4bbd5..4cb2e17c 100644 --- a/exe/Recording/Recording.vcxproj +++ b/exe/Recording/Recording.vcxproj @@ -55,23 +55,23 @@ - + - + - + - + diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/interface.h b/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/interface.h deleted file mode 100644 index 51f76061..00000000 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/interface.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _HAL_INTERFACE_HPP_INCLUDED_ -#define _HAL_INTERFACE_HPP_INCLUDED_ - -//! @addtogroup core_hal_interface -//! @{ - -#define CV_HAL_ERROR_OK 0 -#define CV_HAL_ERROR_NOT_IMPLEMENTED 1 -#define CV_HAL_ERROR_UNKNOWN -1 - -#define CV_HAL_CMP_EQ 0 -#define CV_HAL_CMP_GT 1 -#define CV_HAL_CMP_GE 2 -#define CV_HAL_CMP_LT 3 -#define CV_HAL_CMP_LE 4 -#define CV_HAL_CMP_NE 5 - -#ifdef __cplusplus -#include -#else -#include -#endif - -/* primitive types */ -/* - schar - signed 1 byte integer - uchar - unsigned 1 byte integer - short - signed 2 byte integer - ushort - unsigned 2 byte integer - int - signed 4 byte integer - uint - unsigned 4 byte integer - int64 - signed 8 byte integer - uint64 - unsigned 8 byte integer -*/ - -#if !defined _MSC_VER && !defined __BORLANDC__ -# if defined __cplusplus && __cplusplus >= 201103L && !defined __APPLE__ -# include - typedef std::uint32_t uint; -# else -# include - typedef uint32_t uint; -# endif -#else - typedef unsigned uint; -#endif - -typedef signed char schar; - -#ifndef __IPL_H__ - typedef unsigned char uchar; - typedef unsigned short ushort; -#endif - -#if defined _MSC_VER || defined __BORLANDC__ - typedef __int64 int64; - typedef unsigned __int64 uint64; -# define CV_BIG_INT(n) n##I64 -# define CV_BIG_UINT(n) n##UI64 -#else - typedef int64_t int64; - typedef uint64_t uint64; -# define CV_BIG_INT(n) n##LL -# define CV_BIG_UINT(n) n##ULL -#endif - -//! @} - -#endif diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/private.cuda.hpp b/lib/3rdParty/OpenCV3.1/include/opencv2/core/private.cuda.hpp deleted file mode 100644 index d676ce85..00000000 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/private.cuda.hpp +++ /dev/null @@ -1,172 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Copyright (C) 2013, OpenCV Foundation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#ifndef __OPENCV_CORE_PRIVATE_CUDA_HPP__ -#define __OPENCV_CORE_PRIVATE_CUDA_HPP__ - -#ifndef __OPENCV_BUILD -# error this is a private header which should not be used from outside of the OpenCV library -#endif - -#include "cvconfig.h" - -#include "opencv2/core/cvdef.h" -#include "opencv2/core/base.hpp" - -#include "opencv2/core/cuda.hpp" - -#ifdef HAVE_CUDA -# include -# include -# include -# include "opencv2/core/cuda_stream_accessor.hpp" -# include "opencv2/core/cuda/common.hpp" - -# define NPP_VERSION (NPP_VERSION_MAJOR * 1000 + NPP_VERSION_MINOR * 100 + NPP_VERSION_BUILD) - -# define CUDART_MINIMUM_REQUIRED_VERSION 4020 - -# if (CUDART_VERSION < CUDART_MINIMUM_REQUIRED_VERSION) -# error "Insufficient Cuda Runtime library version, please update it." -# endif - -# if defined(CUDA_ARCH_BIN_OR_PTX_10) -# error "OpenCV CUDA module doesn't support NVIDIA compute capability 1.0" -# endif -#endif - -//! @cond IGNORED - -namespace cv { namespace cuda { - CV_EXPORTS cv::String getNppErrorMessage(int code); - CV_EXPORTS cv::String getCudaDriverApiErrorMessage(int code); - - CV_EXPORTS GpuMat getInputMat(InputArray _src, Stream& stream); - - CV_EXPORTS GpuMat getOutputMat(OutputArray _dst, int rows, int cols, int type, Stream& stream); - static inline GpuMat getOutputMat(OutputArray _dst, Size size, int type, Stream& stream) - { - return getOutputMat(_dst, size.height, size.width, type, stream); - } - - CV_EXPORTS void syncOutput(const GpuMat& dst, OutputArray _dst, Stream& stream); -}} - -#ifndef HAVE_CUDA - -static inline void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The library is compiled without CUDA support"); } - -#else // HAVE_CUDA - -static inline void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); } - -namespace cv { namespace cuda -{ - class CV_EXPORTS BufferPool - { - public: - explicit BufferPool(Stream& stream); - - GpuMat getBuffer(int rows, int cols, int type); - GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); } - - GpuMat::Allocator* getAllocator() const { return allocator_; } - - private: - GpuMat::Allocator* allocator_; - }; - - static inline void checkNppError(int code, const char* file, const int line, const char* func) - { - if (code < 0) - cv::error(cv::Error::GpuApiCallError, getNppErrorMessage(code), func, file, line); - } - - static inline void checkCudaDriverApiError(int code, const char* file, const int line, const char* func) - { - if (code != CUDA_SUCCESS) - cv::error(cv::Error::GpuApiCallError, getCudaDriverApiErrorMessage(code), func, file, line); - } - - template struct NPPTypeTraits; - template<> struct NPPTypeTraits { typedef Npp8u npp_type; }; - template<> struct NPPTypeTraits { typedef Npp8s npp_type; }; - template<> struct NPPTypeTraits { typedef Npp16u npp_type; }; - template<> struct NPPTypeTraits { typedef Npp16s npp_type; }; - template<> struct NPPTypeTraits { typedef Npp32s npp_type; }; - template<> struct NPPTypeTraits { typedef Npp32f npp_type; }; - template<> struct NPPTypeTraits { typedef Npp64f npp_type; }; - - class NppStreamHandler - { - public: - inline explicit NppStreamHandler(Stream& newStream) - { - oldStream = nppGetStream(); - nppSetStream(StreamAccessor::getStream(newStream)); - } - - inline explicit NppStreamHandler(cudaStream_t newStream) - { - oldStream = nppGetStream(); - nppSetStream(newStream); - } - - inline ~NppStreamHandler() - { - nppSetStream(oldStream); - } - - private: - cudaStream_t oldStream; - }; -}} - -#define nppSafeCall(expr) cv::cuda::checkNppError(expr, __FILE__, __LINE__, CV_Func) -#define cuSafeCall(expr) cv::cuda::checkCudaDriverApiError(expr, __FILE__, __LINE__, CV_Func) - -#endif // HAVE_CUDA - -//! @endcond - -#endif // __OPENCV_CORE_CUDA_PRIVATE_HPP__ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/private.hpp b/lib/3rdParty/OpenCV3.1/include/opencv2/core/private.hpp deleted file mode 100644 index c71ec626..00000000 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/private.hpp +++ /dev/null @@ -1,425 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Copyright (C) 2013, OpenCV Foundation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#ifndef __OPENCV_CORE_PRIVATE_HPP__ -#define __OPENCV_CORE_PRIVATE_HPP__ - -#ifndef __OPENCV_BUILD -# error this is a private header which should not be used from outside of the OpenCV library -#endif - -#include "opencv2/core.hpp" -#include "cvconfig.h" - -#ifdef HAVE_EIGEN -# if defined __GNUC__ && defined __APPLE__ -# pragma GCC diagnostic ignored "-Wshadow" -# endif -# include -# include "opencv2/core/eigen.hpp" -#endif - -#ifdef HAVE_TBB -# include "tbb/tbb_stddef.h" -# if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202 -# include "tbb/tbb.h" -# include "tbb/task.h" -# undef min -# undef max -# else -# undef HAVE_TBB -# endif -#endif - -//! @cond IGNORED - -namespace cv -{ -#ifdef HAVE_TBB - - typedef tbb::blocked_range BlockedRange; - - template static inline - void parallel_for( const BlockedRange& range, const Body& body ) - { - tbb::parallel_for(range, body); - } - - typedef tbb::split Split; - - template static inline - void parallel_reduce( const BlockedRange& range, Body& body ) - { - tbb::parallel_reduce(range, body); - } - - typedef tbb::concurrent_vector ConcurrentRectVector; -#else - class BlockedRange - { - public: - BlockedRange() : _begin(0), _end(0), _grainsize(0) {} - BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {} - int begin() const { return _begin; } - int end() const { return _end; } - int grainsize() const { return _grainsize; } - - protected: - int _begin, _end, _grainsize; - }; - - template static inline - void parallel_for( const BlockedRange& range, const Body& body ) - { - body(range); - } - typedef std::vector ConcurrentRectVector; - - class Split {}; - - template static inline - void parallel_reduce( const BlockedRange& range, Body& body ) - { - body(range); - } -#endif - - // Returns a static string if there is a parallel framework, - // NULL otherwise. - CV_EXPORTS const char* currentParallelFramework(); -} //namespace cv - -/****************************************************************************************\ -* Common declarations * -\****************************************************************************************/ - -/* the alignment of all the allocated buffers */ -#define CV_MALLOC_ALIGN 16 - -/* IEEE754 constants and macros */ -#define CV_TOGGLE_FLT(x) ((x)^((int)(x) < 0 ? 0x7fffffff : 0)) -#define CV_TOGGLE_DBL(x) ((x)^((int64)(x) < 0 ? CV_BIG_INT(0x7fffffffffffffff) : 0)) - -static inline void* cvAlignPtr( const void* ptr, int align = 32 ) -{ - CV_DbgAssert ( (align & (align-1)) == 0 ); - return (void*)( ((size_t)ptr + align - 1) & ~(size_t)(align-1) ); -} - -static inline int cvAlign( int size, int align ) -{ - CV_DbgAssert( (align & (align-1)) == 0 && size < INT_MAX ); - return (size + align - 1) & -align; -} - -#ifdef IPL_DEPTH_8U -static inline cv::Size cvGetMatSize( const CvMat* mat ) -{ - return cv::Size(mat->cols, mat->rows); -} -#endif - -namespace cv -{ -CV_EXPORTS void scalarToRawData(const cv::Scalar& s, void* buf, int type, int unroll_to = 0); -} - -// property implementation macros - -#define CV_IMPL_PROPERTY_RO(type, name, member) \ - inline type get##name() const { return member; } - -#define CV_HELP_IMPL_PROPERTY(r_type, w_type, name, member) \ - CV_IMPL_PROPERTY_RO(r_type, name, member) \ - inline void set##name(w_type val) { member = val; } - -#define CV_HELP_WRAP_PROPERTY(r_type, w_type, name, internal_name, internal_obj) \ - r_type get##name() const { return internal_obj.get##internal_name(); } \ - void set##name(w_type val) { internal_obj.set##internal_name(val); } - -#define CV_IMPL_PROPERTY(type, name, member) CV_HELP_IMPL_PROPERTY(type, type, name, member) -#define CV_IMPL_PROPERTY_S(type, name, member) CV_HELP_IMPL_PROPERTY(type, const type &, name, member) - -#define CV_WRAP_PROPERTY(type, name, internal_name, internal_obj) CV_HELP_WRAP_PROPERTY(type, type, name, internal_name, internal_obj) -#define CV_WRAP_PROPERTY_S(type, name, internal_name, internal_obj) CV_HELP_WRAP_PROPERTY(type, const type &, name, internal_name, internal_obj) - -#define CV_WRAP_SAME_PROPERTY(type, name, internal_obj) CV_WRAP_PROPERTY(type, name, name, internal_obj) -#define CV_WRAP_SAME_PROPERTY_S(type, name, internal_obj) CV_WRAP_PROPERTY_S(type, name, name, internal_obj) - -/****************************************************************************************\ -* Structures and macros for integration with IPP * -\****************************************************************************************/ - -#ifdef HAVE_IPP -#include "ipp.h" - -#ifndef IPP_VERSION_UPDATE // prior to 7.1 -#define IPP_VERSION_UPDATE 0 -#endif - -#define IPP_VERSION_X100 (IPP_VERSION_MAJOR * 100 + IPP_VERSION_MINOR*10 + IPP_VERSION_UPDATE) - -// General define for ipp function disabling -#define IPP_DISABLE_BLOCK 0 - -#ifdef CV_MALLOC_ALIGN -#undef CV_MALLOC_ALIGN -#endif -#define CV_MALLOC_ALIGN 32 // required for AVX optimization - -#define setIppErrorStatus() cv::ipp::setIppStatus(-1, CV_Func, __FILE__, __LINE__) - -static inline IppiSize ippiSize(int width, int height) -{ - IppiSize size = { width, height }; - return size; -} - -static inline IppiSize ippiSize(const cv::Size & _size) -{ - IppiSize size = { _size.width, _size.height }; - return size; -} - -static inline IppiBorderType ippiGetBorderType(int borderTypeNI) -{ - return borderTypeNI == cv::BORDER_CONSTANT ? ippBorderConst : - borderTypeNI == cv::BORDER_WRAP ? ippBorderWrap : - borderTypeNI == cv::BORDER_REPLICATE ? ippBorderRepl : - borderTypeNI == cv::BORDER_REFLECT_101 ? ippBorderMirror : - borderTypeNI == cv::BORDER_REFLECT ? ippBorderMirrorR : (IppiBorderType)-1; -} - -static inline IppDataType ippiGetDataType(int depth) -{ - return depth == CV_8U ? ipp8u : - depth == CV_8S ? ipp8s : - depth == CV_16U ? ipp16u : - depth == CV_16S ? ipp16s : - depth == CV_32S ? ipp32s : - depth == CV_32F ? ipp32f : - depth == CV_64F ? ipp64f : (IppDataType)-1; -} - -// IPP temporary buffer hepler -template -class IppAutoBuffer -{ -public: - IppAutoBuffer() { m_pBuffer = NULL; } - IppAutoBuffer(int size) { Alloc(size); } - ~IppAutoBuffer() { Release(); } - T* Alloc(int size) { m_pBuffer = (T*)ippMalloc(size); return m_pBuffer; } - void Release() { if(m_pBuffer) ippFree(m_pBuffer); } - inline operator T* () { return (T*)m_pBuffer;} - inline operator const T* () const { return (const T*)m_pBuffer;} -private: - // Disable copy operations - IppAutoBuffer(IppAutoBuffer &) {}; - IppAutoBuffer& operator =(const IppAutoBuffer &) {return *this;}; - - T* m_pBuffer; -}; - -#else -#define IPP_VERSION_X100 0 -#endif - -// There shoud be no API difference in OpenCV between ICV and IPP since 9.0 -#if (defined HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 900 -#undef HAVE_IPP_ICV_ONLY -#endif - -#ifdef HAVE_IPP_ICV_ONLY -#define HAVE_ICV 1 -#else -#define HAVE_ICV 0 -#endif - -#if defined HAVE_IPP -#if IPP_VERSION_X100 >= 900 -#define IPP_INITIALIZER(FEAT) \ -{ \ - if(FEAT) \ - ippSetCpuFeatures(FEAT); \ - else \ - ippInit(); \ -} -#elif IPP_VERSION_X100 >= 800 -#define IPP_INITIALIZER(FEAT) \ -{ \ - ippInit(); \ -} -#else -#define IPP_INITIALIZER(FEAT) \ -{ \ - ippStaticInit(); \ -} -#endif - -#ifdef CVAPI_EXPORTS -#define IPP_INITIALIZER_AUTO \ -struct __IppInitializer__ \ -{ \ - __IppInitializer__() \ - {IPP_INITIALIZER(cv::ipp::getIppFeatures())} \ -}; \ -static struct __IppInitializer__ __ipp_initializer__; -#else -#define IPP_INITIALIZER_AUTO -#endif -#else -#define IPP_INITIALIZER -#define IPP_INITIALIZER_AUTO -#endif - -#define CV_IPP_CHECK_COND (cv::ipp::useIPP()) -#define CV_IPP_CHECK() if(CV_IPP_CHECK_COND) - -#ifdef HAVE_IPP - -#ifdef CV_IPP_RUN_VERBOSE -#define CV_IPP_RUN_(condition, func, ...) \ - { \ - if (cv::ipp::useIPP() && (condition) && func) \ - { \ - printf("%s: IPP implementation is running\n", CV_Func); \ - fflush(stdout); \ - CV_IMPL_ADD(CV_IMPL_IPP); \ - return __VA_ARGS__; \ - } \ - else \ - { \ - printf("%s: Plain implementation is running\n", CV_Func); \ - fflush(stdout); \ - } \ - } -#elif defined CV_IPP_RUN_ASSERT -#define CV_IPP_RUN_(condition, func, ...) \ - { \ - if (cv::ipp::useIPP() && (condition)) \ - { \ - if(func) \ - { \ - CV_IMPL_ADD(CV_IMPL_IPP); \ - } \ - else \ - { \ - setIppErrorStatus(); \ - CV_Error(cv::Error::StsAssert, #func); \ - } \ - return __VA_ARGS__; \ - } \ - } -#else -#define CV_IPP_RUN_(condition, func, ...) \ - if (cv::ipp::useIPP() && (condition) && func) \ - { \ - CV_IMPL_ADD(CV_IMPL_IPP); \ - return __VA_ARGS__; \ - } -#endif - -#else -#define CV_IPP_RUN_(condition, func, ...) -#endif - -#define CV_IPP_RUN(condition, func, ...) CV_IPP_RUN_(condition, func, __VA_ARGS__) - - -#ifndef IPPI_CALL -# define IPPI_CALL(func) CV_Assert((func) >= 0) -#endif - -/* IPP-compatible return codes */ -typedef enum CvStatus -{ - CV_BADMEMBLOCK_ERR = -113, - CV_INPLACE_NOT_SUPPORTED_ERR= -112, - CV_UNMATCHED_ROI_ERR = -111, - CV_NOTFOUND_ERR = -110, - CV_BADCONVERGENCE_ERR = -109, - - CV_BADDEPTH_ERR = -107, - CV_BADROI_ERR = -106, - CV_BADHEADER_ERR = -105, - CV_UNMATCHED_FORMATS_ERR = -104, - CV_UNSUPPORTED_COI_ERR = -103, - CV_UNSUPPORTED_CHANNELS_ERR = -102, - CV_UNSUPPORTED_DEPTH_ERR = -101, - CV_UNSUPPORTED_FORMAT_ERR = -100, - - CV_BADARG_ERR = -49, //ipp comp - CV_NOTDEFINED_ERR = -48, //ipp comp - - CV_BADCHANNELS_ERR = -47, //ipp comp - CV_BADRANGE_ERR = -44, //ipp comp - CV_BADSTEP_ERR = -29, //ipp comp - - CV_BADFLAG_ERR = -12, - CV_DIV_BY_ZERO_ERR = -11, //ipp comp - CV_BADCOEF_ERR = -10, - - CV_BADFACTOR_ERR = -7, - CV_BADPOINT_ERR = -6, - CV_BADSCALE_ERR = -4, - CV_OUTOFMEM_ERR = -3, - CV_NULLPTR_ERR = -2, - CV_BADSIZE_ERR = -1, - CV_NO_ERR = 0, - CV_OK = CV_NO_ERR -} -CvStatus; - -#ifdef HAVE_TEGRA_OPTIMIZATION -namespace tegra { - -CV_EXPORTS bool useTegra(); -CV_EXPORTS void setUseTegra(bool flag); - -} -#endif - -//! @endcond - -#endif // __OPENCV_CORE_PRIVATE_HPP__ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/dummy.h b/lib/3rdParty/OpenCV3.1/include/opencv2/flann/dummy.h deleted file mode 100644 index 26bd3fa5..00000000 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/dummy.h +++ /dev/null @@ -1,16 +0,0 @@ - -#ifndef OPENCV_FLANN_DUMMY_H_ -#define OPENCV_FLANN_DUMMY_H_ - -namespace cvflann -{ - -#if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS -__declspec(dllexport) -#endif -void dummyfunc(); - -} - - -#endif /* OPENCV_FLANN_DUMMY_H_ */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videoio.hpp b/lib/3rdParty/OpenCV3.1/include/opencv2/videoio.hpp deleted file mode 100644 index ccd6c063..00000000 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videoio.hpp +++ /dev/null @@ -1,680 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistribution's of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistribution's in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#ifndef __OPENCV_VIDEOIO_HPP__ -#define __OPENCV_VIDEOIO_HPP__ - -#include "opencv2/core.hpp" - -/** - @defgroup videoio Media I/O - @{ - @defgroup videoio_c C API - @defgroup videoio_ios iOS glue - @defgroup videoio_winrt WinRT glue - @} -*/ - -////////////////////////////////// video io ///////////////////////////////// - -typedef struct CvCapture CvCapture; -typedef struct CvVideoWriter CvVideoWriter; - -namespace cv -{ - -//! @addtogroup videoio -//! @{ - -// Camera API -enum { CAP_ANY = 0, // autodetect - CAP_VFW = 200, // platform native - CAP_V4L = 200, - CAP_V4L2 = CAP_V4L, - CAP_FIREWARE = 300, // IEEE 1394 drivers - CAP_FIREWIRE = CAP_FIREWARE, - CAP_IEEE1394 = CAP_FIREWARE, - CAP_DC1394 = CAP_FIREWARE, - CAP_CMU1394 = CAP_FIREWARE, - CAP_QT = 500, // QuickTime - CAP_UNICAP = 600, // Unicap drivers - CAP_DSHOW = 700, // DirectShow (via videoInput) - CAP_PVAPI = 800, // PvAPI, Prosilica GigE SDK - CAP_OPENNI = 900, // OpenNI (for Kinect) - CAP_OPENNI_ASUS = 910, // OpenNI (for Asus Xtion) - CAP_ANDROID = 1000, // Android - not used - CAP_XIAPI = 1100, // XIMEA Camera API - CAP_AVFOUNDATION = 1200, // AVFoundation framework for iOS (OS X Lion will have the same API) - CAP_GIGANETIX = 1300, // Smartek Giganetix GigEVisionSDK - CAP_MSMF = 1400, // Microsoft Media Foundation (via videoInput) - CAP_WINRT = 1410, // Microsoft Windows Runtime using Media Foundation - CAP_INTELPERC = 1500, // Intel Perceptual Computing SDK - CAP_OPENNI2 = 1600, // OpenNI2 (for Kinect) - CAP_OPENNI2_ASUS = 1610, // OpenNI2 (for Asus Xtion and Occipital Structure sensors) - CAP_GPHOTO2 = 1700, // gPhoto2 connection - CAP_GSTREAMER = 1800, // GStreamer - CAP_FFMPEG = 1900, // FFMPEG - CAP_IMAGES = 2000 // OpenCV Image Sequence (e.g. img_%02d.jpg) - }; - -// generic properties (based on DC1394 properties) -enum { CAP_PROP_POS_MSEC =0, - CAP_PROP_POS_FRAMES =1, - CAP_PROP_POS_AVI_RATIO =2, - CAP_PROP_FRAME_WIDTH =3, - CAP_PROP_FRAME_HEIGHT =4, - CAP_PROP_FPS =5, - CAP_PROP_FOURCC =6, - CAP_PROP_FRAME_COUNT =7, - CAP_PROP_FORMAT =8, - CAP_PROP_MODE =9, - CAP_PROP_BRIGHTNESS =10, - CAP_PROP_CONTRAST =11, - CAP_PROP_SATURATION =12, - CAP_PROP_HUE =13, - CAP_PROP_GAIN =14, - CAP_PROP_EXPOSURE =15, - CAP_PROP_CONVERT_RGB =16, - CAP_PROP_WHITE_BALANCE_BLUE_U =17, - CAP_PROP_RECTIFICATION =18, - CAP_PROP_MONOCHROME =19, - CAP_PROP_SHARPNESS =20, - CAP_PROP_AUTO_EXPOSURE =21, // DC1394: exposure control done by camera, user can adjust refernce level using this feature - CAP_PROP_GAMMA =22, - CAP_PROP_TEMPERATURE =23, - CAP_PROP_TRIGGER =24, - CAP_PROP_TRIGGER_DELAY =25, - CAP_PROP_WHITE_BALANCE_RED_V =26, - CAP_PROP_ZOOM =27, - CAP_PROP_FOCUS =28, - CAP_PROP_GUID =29, - CAP_PROP_ISO_SPEED =30, - CAP_PROP_BACKLIGHT =32, - CAP_PROP_PAN =33, - CAP_PROP_TILT =34, - CAP_PROP_ROLL =35, - CAP_PROP_IRIS =36, - CAP_PROP_SETTINGS =37, - CAP_PROP_BUFFERSIZE =38, - CAP_PROP_AUTOFOCUS =39 - }; - - -// Generic camera output modes. -// Currently, these are supported through the libv4l interface only. -enum { CAP_MODE_BGR = 0, // BGR24 (default) - CAP_MODE_RGB = 1, // RGB24 - CAP_MODE_GRAY = 2, // Y8 - CAP_MODE_YUYV = 3 // YUYV - }; - - -// DC1394 only -// modes of the controlling registers (can be: auto, manual, auto single push, absolute Latter allowed with any other mode) -// every feature can have only one mode turned on at a time -enum { CAP_PROP_DC1394_OFF = -4, //turn the feature off (not controlled manually nor automatically) - CAP_PROP_DC1394_MODE_MANUAL = -3, //set automatically when a value of the feature is set by the user - CAP_PROP_DC1394_MODE_AUTO = -2, - CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO = -1, - CAP_PROP_DC1394_MAX = 31 - }; - - -// OpenNI map generators -enum { CAP_OPENNI_DEPTH_GENERATOR = 1 << 31, - CAP_OPENNI_IMAGE_GENERATOR = 1 << 30, - CAP_OPENNI_GENERATORS_MASK = CAP_OPENNI_DEPTH_GENERATOR + CAP_OPENNI_IMAGE_GENERATOR - }; - -// Properties of cameras available through OpenNI interfaces -enum { CAP_PROP_OPENNI_OUTPUT_MODE = 100, - CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 101, // in mm - CAP_PROP_OPENNI_BASELINE = 102, // in mm - CAP_PROP_OPENNI_FOCAL_LENGTH = 103, // in pixels - CAP_PROP_OPENNI_REGISTRATION = 104, // flag that synchronizes the remapping depth map to image map - // by changing depth generator's view point (if the flag is "on") or - // sets this view point to its normal one (if the flag is "off"). - CAP_PROP_OPENNI_REGISTRATION_ON = CAP_PROP_OPENNI_REGISTRATION, - CAP_PROP_OPENNI_APPROX_FRAME_SYNC = 105, - CAP_PROP_OPENNI_MAX_BUFFER_SIZE = 106, - CAP_PROP_OPENNI_CIRCLE_BUFFER = 107, - CAP_PROP_OPENNI_MAX_TIME_DURATION = 108, - CAP_PROP_OPENNI_GENERATOR_PRESENT = 109, - CAP_PROP_OPENNI2_SYNC = 110, - CAP_PROP_OPENNI2_MIRROR = 111 - }; - -// OpenNI shortcats -enum { CAP_OPENNI_IMAGE_GENERATOR_PRESENT = CAP_OPENNI_IMAGE_GENERATOR + CAP_PROP_OPENNI_GENERATOR_PRESENT, - CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CAP_OPENNI_IMAGE_GENERATOR + CAP_PROP_OPENNI_OUTPUT_MODE, - CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_BASELINE, - CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_FOCAL_LENGTH, - CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_REGISTRATION, - CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON = CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION - }; - -// OpenNI data given from depth generator -enum { CAP_OPENNI_DEPTH_MAP = 0, // Depth values in mm (CV_16UC1) - CAP_OPENNI_POINT_CLOUD_MAP = 1, // XYZ in meters (CV_32FC3) - CAP_OPENNI_DISPARITY_MAP = 2, // Disparity in pixels (CV_8UC1) - CAP_OPENNI_DISPARITY_MAP_32F = 3, // Disparity in pixels (CV_32FC1) - CAP_OPENNI_VALID_DEPTH_MASK = 4, // CV_8UC1 - - // Data given from RGB image generator - CAP_OPENNI_BGR_IMAGE = 5, - CAP_OPENNI_GRAY_IMAGE = 6 - }; - -// Supported output modes of OpenNI image generator -enum { CAP_OPENNI_VGA_30HZ = 0, - CAP_OPENNI_SXGA_15HZ = 1, - CAP_OPENNI_SXGA_30HZ = 2, - CAP_OPENNI_QVGA_30HZ = 3, - CAP_OPENNI_QVGA_60HZ = 4 - }; - - -// GStreamer -enum { CAP_PROP_GSTREAMER_QUEUE_LENGTH = 200 // default is 1 - }; - - -// PVAPI -enum { CAP_PROP_PVAPI_MULTICASTIP = 300, // ip for anable multicast master mode. 0 for disable multicast - CAP_PROP_PVAPI_FRAMESTARTTRIGGERMODE = 301, // FrameStartTriggerMode: Determines how a frame is initiated - CAP_PROP_PVAPI_DECIMATIONHORIZONTAL = 302, // Horizontal sub-sampling of the image - CAP_PROP_PVAPI_DECIMATIONVERTICAL = 303, // Vertical sub-sampling of the image - CAP_PROP_PVAPI_BINNINGX = 304, // Horizontal binning factor - CAP_PROP_PVAPI_BINNINGY = 305, // Vertical binning factor - CAP_PROP_PVAPI_PIXELFORMAT = 306 // Pixel format - }; - -// PVAPI: FrameStartTriggerMode -enum { CAP_PVAPI_FSTRIGMODE_FREERUN = 0, // Freerun - CAP_PVAPI_FSTRIGMODE_SYNCIN1 = 1, // SyncIn1 - CAP_PVAPI_FSTRIGMODE_SYNCIN2 = 2, // SyncIn2 - CAP_PVAPI_FSTRIGMODE_FIXEDRATE = 3, // FixedRate - CAP_PVAPI_FSTRIGMODE_SOFTWARE = 4 // Software - }; - -// PVAPI: DecimationHorizontal, DecimationVertical -enum { CAP_PVAPI_DECIMATION_OFF = 1, // Off - CAP_PVAPI_DECIMATION_2OUTOF4 = 2, // 2 out of 4 decimation - CAP_PVAPI_DECIMATION_2OUTOF8 = 4, // 2 out of 8 decimation - CAP_PVAPI_DECIMATION_2OUTOF16 = 8 // 2 out of 16 decimation - }; - -// PVAPI: PixelFormat -enum { CAP_PVAPI_PIXELFORMAT_MONO8 = 1, // Mono8 - CAP_PVAPI_PIXELFORMAT_MONO16 = 2, // Mono16 - CAP_PVAPI_PIXELFORMAT_BAYER8 = 3, // Bayer8 - CAP_PVAPI_PIXELFORMAT_BAYER16 = 4, // Bayer16 - CAP_PVAPI_PIXELFORMAT_RGB24 = 5, // Rgb24 - CAP_PVAPI_PIXELFORMAT_BGR24 = 6, // Bgr24 - CAP_PVAPI_PIXELFORMAT_RGBA32 = 7, // Rgba32 - CAP_PVAPI_PIXELFORMAT_BGRA32 = 8, // Bgra32 - }; - -// Properties of cameras available through XIMEA SDK interface -enum { CAP_PROP_XI_DOWNSAMPLING = 400, // Change image resolution by binning or skipping. - CAP_PROP_XI_DATA_FORMAT = 401, // Output data format. - CAP_PROP_XI_OFFSET_X = 402, // Horizontal offset from the origin to the area of interest (in pixels). - CAP_PROP_XI_OFFSET_Y = 403, // Vertical offset from the origin to the area of interest (in pixels). - CAP_PROP_XI_TRG_SOURCE = 404, // Defines source of trigger. - CAP_PROP_XI_TRG_SOFTWARE = 405, // Generates an internal trigger. PRM_TRG_SOURCE must be set to TRG_SOFTWARE. - CAP_PROP_XI_GPI_SELECTOR = 406, // Selects general purpose input - CAP_PROP_XI_GPI_MODE = 407, // Set general purpose input mode - CAP_PROP_XI_GPI_LEVEL = 408, // Get general purpose level - CAP_PROP_XI_GPO_SELECTOR = 409, // Selects general purpose output - CAP_PROP_XI_GPO_MODE = 410, // Set general purpose output mode - CAP_PROP_XI_LED_SELECTOR = 411, // Selects camera signalling LED - CAP_PROP_XI_LED_MODE = 412, // Define camera signalling LED functionality - CAP_PROP_XI_MANUAL_WB = 413, // Calculates White Balance(must be called during acquisition) - CAP_PROP_XI_AUTO_WB = 414, // Automatic white balance - CAP_PROP_XI_AEAG = 415, // Automatic exposure/gain - CAP_PROP_XI_EXP_PRIORITY = 416, // Exposure priority (0.5 - exposure 50%, gain 50%). - CAP_PROP_XI_AE_MAX_LIMIT = 417, // Maximum limit of exposure in AEAG procedure - CAP_PROP_XI_AG_MAX_LIMIT = 418, // Maximum limit of gain in AEAG procedure - CAP_PROP_XI_AEAG_LEVEL = 419, // Average intensity of output signal AEAG should achieve(in %) - CAP_PROP_XI_TIMEOUT = 420 // Image capture timeout in milliseconds - }; - -// Properties of cameras available through AVFOUNDATION interface -enum { CAP_PROP_IOS_DEVICE_FOCUS = 9001, - CAP_PROP_IOS_DEVICE_EXPOSURE = 9002, - CAP_PROP_IOS_DEVICE_FLASH = 9003, - CAP_PROP_IOS_DEVICE_WHITEBALANCE = 9004, - CAP_PROP_IOS_DEVICE_TORCH = 9005 - }; - - -// Properties of cameras available through Smartek Giganetix Ethernet Vision interface -/* --- Vladimir Litvinenko (litvinenko.vladimir@gmail.com) --- */ -enum { CAP_PROP_GIGA_FRAME_OFFSET_X = 10001, - CAP_PROP_GIGA_FRAME_OFFSET_Y = 10002, - CAP_PROP_GIGA_FRAME_WIDTH_MAX = 10003, - CAP_PROP_GIGA_FRAME_HEIGH_MAX = 10004, - CAP_PROP_GIGA_FRAME_SENS_WIDTH = 10005, - CAP_PROP_GIGA_FRAME_SENS_HEIGH = 10006 - }; - -enum { CAP_PROP_INTELPERC_PROFILE_COUNT = 11001, - CAP_PROP_INTELPERC_PROFILE_IDX = 11002, - CAP_PROP_INTELPERC_DEPTH_LOW_CONFIDENCE_VALUE = 11003, - CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE = 11004, - CAP_PROP_INTELPERC_DEPTH_CONFIDENCE_THRESHOLD = 11005, - CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_HORZ = 11006, - CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_VERT = 11007 - }; - -// Intel PerC streams -enum { CAP_INTELPERC_DEPTH_GENERATOR = 1 << 29, - CAP_INTELPERC_IMAGE_GENERATOR = 1 << 28, - CAP_INTELPERC_GENERATORS_MASK = CAP_INTELPERC_DEPTH_GENERATOR + CAP_INTELPERC_IMAGE_GENERATOR - }; - -enum { CAP_INTELPERC_DEPTH_MAP = 0, // Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian depth. - CAP_INTELPERC_UVDEPTH_MAP = 1, // Each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of depth coordinates to the color coordinates. - CAP_INTELPERC_IR_MAP = 2, // Each pixel is a 16-bit integer. The value indicates the intensity of the reflected laser beam. - CAP_INTELPERC_IMAGE = 3 - }; - -enum { VIDEOWRITER_PROP_QUALITY = 1, // Quality (0..100%) of the videostream encoded - VIDEOWRITER_PROP_FRAMEBYTES = 2, // (Read-only): Size of just encoded video frame - VIDEOWRITER_PROP_NSTRIPES = 3 // Number of stripes for parallel encoding. -1 for auto detection - }; - -// gPhoto2 properties, if propertyId is less than 0 then work on widget with that __additive inversed__ camera setting ID -// Get IDs by using CAP_PROP_GPHOTO2_WIDGET_ENUMERATE. -// @see CvCaptureCAM_GPHOTO2 for more info -enum { CAP_PROP_GPHOTO2_PREVIEW = 17001, // Capture only preview from liveview mode. - CAP_PROP_GPHOTO2_WIDGET_ENUMERATE = 17002, // Readonly, returns (const char *). - CAP_PROP_GPHOTO2_RELOAD_CONFIG = 17003, // Trigger, only by set. Reload camera settings. - CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE = 17004, // Reload all settings on set. - CAP_PROP_GPHOTO2_COLLECT_MSGS = 17005, // Collect messages with details. - CAP_PROP_GPHOTO2_FLUSH_MSGS = 17006, // Readonly, returns (const char *). - CAP_PROP_SPEED = 17007, // Exposure speed. Can be readonly, depends on camera program. - CAP_PROP_APERTURE = 17008, // Aperture. Can be readonly, depends on camera program. - CAP_PROP_EXPOSUREPROGRAM = 17009, // Camera exposure program. - CAP_PROP_VIEWFINDER = 17010 // Enter liveview mode. - }; - -//enum { - -class IVideoCapture; - -/** @brief Class for video capturing from video files, image sequences or cameras. The class provides C++ API -for capturing video from cameras or for reading video files and image sequences. Here is how the -class can be used: : -@code - #include "opencv2/opencv.hpp" - - using namespace cv; - - int main(int, char**) - { - VideoCapture cap(0); // open the default camera - if(!cap.isOpened()) // check if we succeeded - return -1; - - Mat edges; - namedWindow("edges",1); - for(;;) - { - Mat frame; - cap >> frame; // get a new frame from camera - cvtColor(frame, edges, COLOR_BGR2GRAY); - GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5); - Canny(edges, edges, 0, 30, 3); - imshow("edges", edges); - if(waitKey(30) >= 0) break; - } - // the camera will be deinitialized automatically in VideoCapture destructor - return 0; - } -@endcode -@note In C API the black-box structure CvCapture is used instead of VideoCapture. - -@note -- A basic sample on using the VideoCapture interface can be found at - opencv_source_code/samples/cpp/starter_video.cpp -- Another basic video processing sample can be found at - opencv_source_code/samples/cpp/video_dmtx.cpp -- (Python) A basic sample on using the VideoCapture interface can be found at - opencv_source_code/samples/python/video.py -- (Python) Another basic video processing sample can be found at - opencv_source_code/samples/python/video_dmtx.py -- (Python) A multi threaded video processing sample can be found at - opencv_source_code/samples/python/video_threaded.py - */ -class CV_EXPORTS_W VideoCapture -{ -public: - /** @brief - @note In C API, when you finished working with video, release CvCapture structure with - cvReleaseCapture(), or use Ptr\ that calls cvReleaseCapture() automatically in the - destructor. - */ - CV_WRAP VideoCapture(); - - /** @overload - @param filename name of the opened video file (eg. video.avi) or image sequence (eg. - img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...) - */ - CV_WRAP VideoCapture(const String& filename); - - /** @overload - @param filename name of the opened video file (eg. video.avi) or image sequence (eg. - img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...) - - @param apiPreference preferred Capture API to use. Can be used to enforce a specific reader - implementation if multiple are available: e.g. CAP_FFMPEG or CAP_IMAGES - */ - CV_WRAP VideoCapture(const String& filename, int apiPreference); - - /** @overload - @param index = camera_id + domain_offset (CAP_*). id of the video capturing device to open. If there is a single - camera connected, just pass 0. Advanced Usage: to open Camera 1 using the MS Media Foundation API: index = 1 + CAP_MSMF - */ - CV_WRAP VideoCapture(int index); - - virtual ~VideoCapture(); - - /** @brief Open video file or a capturing device for video capturing - - @param filename name of the opened video file (eg. video.avi) or image sequence (eg. - img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...) - - The methods first call VideoCapture::release to close the already opened file or camera. - */ - CV_WRAP virtual bool open(const String& filename); - - /** @overload - @param index = camera_id + domain_offset (CAP_*). id of the video capturing device to open. If there is a single - camera connected, just pass 0. Advanced Usage: to open Camera 1 using the MS Media Foundation API: index = 1 + CAP_MSMF - */ - CV_WRAP virtual bool open(int index); - - /** @brief Returns true if video capturing has been initialized already. - - If the previous call to VideoCapture constructor or VideoCapture::open succeeded, the method returns - true. - */ - CV_WRAP virtual bool isOpened() const; - - /** @brief Closes video file or capturing device. - - The methods are automatically called by subsequent VideoCapture::open and by VideoCapture - destructor. - - The C function also deallocates memory and clears \*capture pointer. - */ - CV_WRAP virtual void release(); - - /** @brief Grabs the next frame from video file or capturing device. - - The methods/functions grab the next frame from video file or camera and return true (non-zero) in - the case of success. - - The primary use of the function is in multi-camera environments, especially when the cameras do not - have hardware synchronization. That is, you call VideoCapture::grab() for each camera and after that - call the slower method VideoCapture::retrieve() to decode and get frame from each camera. This way - the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames - from different cameras will be closer in time. - - Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the - correct way of retrieving data from it is to call VideoCapture::grab first and then call - VideoCapture::retrieve one or more times with different values of the channel parameter. See - - */ - CV_WRAP virtual bool grab(); - - /** @brief Decodes and returns the grabbed video frame. - - The methods/functions decode and return the just grabbed frame. If no frames has been grabbed - (camera has been disconnected, or there are no more frames in video file), the methods return false - and the functions return NULL pointer. - - @note OpenCV 1.x functions cvRetrieveFrame and cv.RetrieveFrame return image stored inside the video - capturing structure. It is not allowed to modify or release the image! You can copy the frame using - :ocvcvCloneImage and then do whatever you want with the copy. - */ - CV_WRAP virtual bool retrieve(OutputArray image, int flag = 0); - virtual VideoCapture& operator >> (CV_OUT Mat& image); - virtual VideoCapture& operator >> (CV_OUT UMat& image); - - /** @brief Grabs, decodes and returns the next video frame. - - The methods/functions combine VideoCapture::grab and VideoCapture::retrieve in one call. This is the - most convenient method for reading video files or capturing data from decode and return the just - grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more - frames in video file), the methods return false and the functions return NULL pointer. - - @note OpenCV 1.x functions cvRetrieveFrame and cv.RetrieveFrame return image stored inside the video - capturing structure. It is not allowed to modify or release the image! You can copy the frame using - :ocvcvCloneImage and then do whatever you want with the copy. - */ - CV_WRAP virtual bool read(OutputArray image); - - /** @brief Sets a property in the VideoCapture. - - @param propId Property identifier. It can be one of the following: - - **CAP_PROP_POS_MSEC** Current position of the video file in milliseconds. - - **CAP_PROP_POS_FRAMES** 0-based index of the frame to be decoded/captured next. - - **CAP_PROP_POS_AVI_RATIO** Relative position of the video file: 0 - start of the - film, 1 - end of the film. - - **CAP_PROP_FRAME_WIDTH** Width of the frames in the video stream. - - **CAP_PROP_FRAME_HEIGHT** Height of the frames in the video stream. - - **CAP_PROP_FPS** Frame rate. - - **CAP_PROP_FOURCC** 4-character code of codec. - - **CAP_PROP_FRAME_COUNT** Number of frames in the video file. - - **CAP_PROP_FORMAT** Format of the Mat objects returned by retrieve() . - - **CAP_PROP_MODE** Backend-specific value indicating the current capture mode. - - **CAP_PROP_BRIGHTNESS** Brightness of the image (only for cameras). - - **CAP_PROP_CONTRAST** Contrast of the image (only for cameras). - - **CAP_PROP_SATURATION** Saturation of the image (only for cameras). - - **CAP_PROP_HUE** Hue of the image (only for cameras). - - **CAP_PROP_GAIN** Gain of the image (only for cameras). - - **CAP_PROP_EXPOSURE** Exposure (only for cameras). - - **CAP_PROP_CONVERT_RGB** Boolean flags indicating whether images should be converted - to RGB. - - **CAP_PROP_WHITE_BALANCE** Currently unsupported - - **CAP_PROP_RECTIFICATION** Rectification flag for stereo cameras (note: only supported - by DC1394 v 2.x backend currently) - @param value Value of the property. - */ - CV_WRAP virtual bool set(int propId, double value); - - /** @brief Returns the specified VideoCapture property - - @param propId Property identifier. It can be one of the following: - - **CAP_PROP_POS_MSEC** Current position of the video file in milliseconds or video - capture timestamp. - - **CAP_PROP_POS_FRAMES** 0-based index of the frame to be decoded/captured next. - - **CAP_PROP_POS_AVI_RATIO** Relative position of the video file: 0 - start of the - film, 1 - end of the film. - - **CAP_PROP_FRAME_WIDTH** Width of the frames in the video stream. - - **CAP_PROP_FRAME_HEIGHT** Height of the frames in the video stream. - - **CAP_PROP_FPS** Frame rate. - - **CAP_PROP_FOURCC** 4-character code of codec. - - **CAP_PROP_FRAME_COUNT** Number of frames in the video file. - - **CAP_PROP_FORMAT** Format of the Mat objects returned by retrieve() . - - **CAP_PROP_MODE** Backend-specific value indicating the current capture mode. - - **CAP_PROP_BRIGHTNESS** Brightness of the image (only for cameras). - - **CAP_PROP_CONTRAST** Contrast of the image (only for cameras). - - **CAP_PROP_SATURATION** Saturation of the image (only for cameras). - - **CAP_PROP_HUE** Hue of the image (only for cameras). - - **CAP_PROP_GAIN** Gain of the image (only for cameras). - - **CAP_PROP_EXPOSURE** Exposure (only for cameras). - - **CAP_PROP_CONVERT_RGB** Boolean flags indicating whether images should be converted - to RGB. - - **CAP_PROP_WHITE_BALANCE** Currently not supported - - **CAP_PROP_RECTIFICATION** Rectification flag for stereo cameras (note: only supported - by DC1394 v 2.x backend currently) - - @note When querying a property that is not supported by the backend used by the VideoCapture - class, value 0 is returned. - */ - CV_WRAP virtual double get(int propId) const; - - /** @overload - - @param filename name of the opened video file (eg. video.avi) or image sequence (eg. - img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...) - - @param apiPreference preferred Capture API to use. Can be used to enforce a specific reader - implementation if multiple are available: e.g. CAP_FFMPEG or CAP_IMAGES - - The methods first call VideoCapture::release to close the already opened file or camera. - */ - CV_WRAP virtual bool open(const String& filename, int apiPreference); - -protected: - Ptr cap; - Ptr icap; -}; - -class IVideoWriter; - -/** @brief Video writer class. - */ -class CV_EXPORTS_W VideoWriter -{ -public: - /** @brief VideoWriter constructors - - The constructors/functions initialize video writers. On Linux FFMPEG is used to write videos; on - Windows FFMPEG or VFW is used; on MacOSX QTKit is used. - */ - CV_WRAP VideoWriter(); - - /** @overload - @param filename Name of the output video file. - @param fourcc 4-character code of codec used to compress the frames. For example, - VideoWriter::fourcc('P','I','M','1') is a MPEG-1 codec, VideoWriter::fourcc('M','J','P','G') is a - motion-jpeg codec etc. List of codes can be obtained at [Video Codecs by - FOURCC](http://www.fourcc.org/codecs.php) page. FFMPEG backend with MP4 container natively uses - other values as fourcc code: see [ObjectType](http://www.mp4ra.org/codecs.html), - so you may receive a warning message from OpenCV about fourcc code conversion. - @param fps Framerate of the created video stream. - @param frameSize Size of the video frames. - @param isColor If it is not zero, the encoder will expect and encode color frames, otherwise it - will work with grayscale frames (the flag is currently supported on Windows only). - */ - CV_WRAP VideoWriter(const String& filename, int fourcc, double fps, - Size frameSize, bool isColor = true); - - virtual ~VideoWriter(); - - /** @brief Initializes or reinitializes video writer. - - The method opens video writer. Parameters are the same as in the constructor - VideoWriter::VideoWriter. - */ - CV_WRAP virtual bool open(const String& filename, int fourcc, double fps, - Size frameSize, bool isColor = true); - - /** @brief Returns true if video writer has been successfully initialized. - */ - CV_WRAP virtual bool isOpened() const; - - /** @brief Closes the video writer. - - The methods are automatically called by subsequent VideoWriter::open and by the VideoWriter - destructor. - */ - CV_WRAP virtual void release(); - virtual VideoWriter& operator << (const Mat& image); - - /** @brief Writes the next video frame - - @param image The written frame - - The functions/methods write the specified image to video file. It must have the same size as has - been specified when opening the video writer. - */ - CV_WRAP virtual void write(const Mat& image); - - /** @brief Sets a property in the VideoWriter. - - @param propId Property identifier. It can be one of the following: - - **VIDEOWRITER_PROP_QUALITY** Quality (0..100%) of the videostream encoded. Can be adjusted dynamically in some codecs. - - **VIDEOWRITER_PROP_NSTRIPES** Number of stripes for parallel encoding - @param value Value of the property. - */ - CV_WRAP virtual bool set(int propId, double value); - - /** @brief Returns the specified VideoWriter property - - @param propId Property identifier. It can be one of the following: - - **VIDEOWRITER_PROP_QUALITY** Current quality of the encoded videostream. - - **VIDEOWRITER_PROP_FRAMEBYTES** (Read-only) Size of just encoded video frame; note that the encoding order may be different from representation order. - - **VIDEOWRITER_PROP_NSTRIPES** Number of stripes for parallel encoding - - @note When querying a property that is not supported by the backend used by the VideoWriter - class, value 0 is returned. - */ - CV_WRAP virtual double get(int propId) const; - - /** @brief Concatenates 4 chars to a fourcc code - - This static method constructs the fourcc code of the codec to be used in the constructor - VideoWriter::VideoWriter or VideoWriter::open. - */ - CV_WRAP static int fourcc(char c1, char c2, char c3, char c4); - -protected: - Ptr writer; - Ptr iwriter; - - static Ptr create(const String& filename, int fourcc, double fps, - Size frameSize, bool isColor = true); -}; - -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvCapture* obj) const; -template<> CV_EXPORTS void DefaultDeleter::operator ()(CvVideoWriter* obj) const; - -//! @} videoio - -} // cv - -#endif //__OPENCV_VIDEOIO_HPP__ diff --git a/lib/3rdParty/OpenCV3.1/x64/v140/lib/opencv_world310.lib b/lib/3rdParty/OpenCV3.1/x64/v140/lib/opencv_world310.lib deleted file mode 100644 index 7a20501e..00000000 Binary files a/lib/3rdParty/OpenCV3.1/x64/v140/lib/opencv_world310.lib and /dev/null differ diff --git a/lib/3rdParty/OpenCV3.1/x86/v140/bin/opencv_world310.dll b/lib/3rdParty/OpenCV3.1/x86/v140/bin/opencv_world310.dll deleted file mode 100644 index 681f0c9f..00000000 Binary files a/lib/3rdParty/OpenCV3.1/x86/v140/bin/opencv_world310.dll and /dev/null differ diff --git a/lib/3rdParty/OpenCV3.1/x86/v140/lib/opencv_world310.lib b/lib/3rdParty/OpenCV3.1/x86/v140/lib/opencv_world310.lib deleted file mode 100644 index 17c517af..00000000 Binary files a/lib/3rdParty/OpenCV3.1/x86/v140/lib/opencv_world310.lib and /dev/null differ diff --git a/lib/3rdParty/OpenCV3.1/bin/opencv_ffmpeg310_64.dll b/lib/3rdParty/OpenCV3.4/bin/opencv_ffmpeg340.dll similarity index 54% rename from lib/3rdParty/OpenCV3.1/bin/opencv_ffmpeg310_64.dll rename to lib/3rdParty/OpenCV3.4/bin/opencv_ffmpeg340.dll index 040198c5..2a9b7aa9 100644 Binary files a/lib/3rdParty/OpenCV3.1/bin/opencv_ffmpeg310_64.dll and b/lib/3rdParty/OpenCV3.4/bin/opencv_ffmpeg340.dll differ diff --git a/lib/3rdParty/OpenCV3.1/bin/opencv_ffmpeg310.dll b/lib/3rdParty/OpenCV3.4/bin/opencv_ffmpeg340_64.dll similarity index 51% rename from lib/3rdParty/OpenCV3.1/bin/opencv_ffmpeg310.dll rename to lib/3rdParty/OpenCV3.4/bin/opencv_ffmpeg340_64.dll index 4abb8ca9..45dc8391 100644 Binary files a/lib/3rdParty/OpenCV3.1/bin/opencv_ffmpeg310.dll and b/lib/3rdParty/OpenCV3.4/bin/opencv_ffmpeg340_64.dll differ diff --git a/lib/3rdParty/OpenCV3.1/classifiers/haarcascade_frontalface_alt.xml b/lib/3rdParty/OpenCV3.4/classifiers/haarcascade_frontalface_alt.xml similarity index 100% rename from lib/3rdParty/OpenCV3.1/classifiers/haarcascade_frontalface_alt.xml rename to lib/3rdParty/OpenCV3.4/classifiers/haarcascade_frontalface_alt.xml diff --git a/lib/3rdParty/OpenCV3.1/classifiers/haarcascade_frontalface_alt2.xml b/lib/3rdParty/OpenCV3.4/classifiers/haarcascade_frontalface_alt2.xml similarity index 100% rename from lib/3rdParty/OpenCV3.1/classifiers/haarcascade_frontalface_alt2.xml rename to lib/3rdParty/OpenCV3.4/classifiers/haarcascade_frontalface_alt2.xml diff --git a/lib/3rdParty/OpenCV3.1/classifiers/haarcascade_frontalface_alt_tree.xml b/lib/3rdParty/OpenCV3.4/classifiers/haarcascade_frontalface_alt_tree.xml similarity index 100% rename from lib/3rdParty/OpenCV3.1/classifiers/haarcascade_frontalface_alt_tree.xml rename to lib/3rdParty/OpenCV3.4/classifiers/haarcascade_frontalface_alt_tree.xml diff --git a/lib/3rdParty/OpenCV3.1/classifiers/haarcascade_frontalface_default.xml b/lib/3rdParty/OpenCV3.4/classifiers/haarcascade_frontalface_default.xml similarity index 100% rename from lib/3rdParty/OpenCV3.1/classifiers/haarcascade_frontalface_default.xml rename to lib/3rdParty/OpenCV3.4/classifiers/haarcascade_frontalface_default.xml diff --git a/lib/3rdParty/OpenCV3.1/classifiers/haarcascade_profileface.xml b/lib/3rdParty/OpenCV3.4/classifiers/haarcascade_profileface.xml similarity index 100% rename from lib/3rdParty/OpenCV3.1/classifiers/haarcascade_profileface.xml rename to lib/3rdParty/OpenCV3.4/classifiers/haarcascade_profileface.xml diff --git a/lib/3rdParty/OpenCV3.1/include/opencv/cv.h b/lib/3rdParty/OpenCV3.4/include/opencv/cv.h similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv/cv.h rename to lib/3rdParty/OpenCV3.4/include/opencv/cv.h index 0aefc6d2..19a74e29 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv/cv.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv/cv.h @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_OLD_CV_H__ -#define __OPENCV_OLD_CV_H__ +#ifndef OPENCV_OLD_CV_H +#define OPENCV_OLD_CV_H #if defined(_MSC_VER) #define CV_DO_PRAGMA(x) __pragma(x) diff --git a/lib/3rdParty/OpenCV3.1/include/opencv/cv.hpp b/lib/3rdParty/OpenCV3.4/include/opencv/cv.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv/cv.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv/cv.hpp index e498d7ac..86739564 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv/cv.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv/cv.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_OLD_CV_HPP__ -#define __OPENCV_OLD_CV_HPP__ +#ifndef OPENCV_OLD_CV_HPP +#define OPENCV_OLD_CV_HPP //#if defined(__GNUC__) //#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv/cvaux.h b/lib/3rdParty/OpenCV3.4/include/opencv/cvaux.h similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv/cvaux.h rename to lib/3rdParty/OpenCV3.4/include/opencv/cvaux.h index fe86c5d9..c0367cc2 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv/cvaux.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv/cvaux.h @@ -39,8 +39,8 @@ // //M*/ -#ifndef __OPENCV_OLD_AUX_H__ -#define __OPENCV_OLD_AUX_H__ +#ifndef OPENCV_OLD_AUX_H +#define OPENCV_OLD_AUX_H //#if defined(__GNUC__) //#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv/cvaux.hpp b/lib/3rdParty/OpenCV3.4/include/opencv/cvaux.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv/cvaux.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv/cvaux.hpp index b0e60a30..4888eef2 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv/cvaux.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv/cvaux.hpp @@ -39,8 +39,8 @@ // //M*/ -#ifndef __OPENCV_OLD_AUX_HPP__ -#define __OPENCV_OLD_AUX_HPP__ +#ifndef OPENCV_OLD_AUX_HPP +#define OPENCV_OLD_AUX_HPP //#if defined(__GNUC__) //#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv/cvwimage.h b/lib/3rdParty/OpenCV3.4/include/opencv/cvwimage.h similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv/cvwimage.h rename to lib/3rdParty/OpenCV3.4/include/opencv/cvwimage.h index de89c927..ec0ab141 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv/cvwimage.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv/cvwimage.h @@ -38,8 +38,8 @@ // the use of this software, even if advised of the possibility of such damage. -#ifndef __OPENCV_OLD_WIMAGE_HPP__ -#define __OPENCV_OLD_WIMAGE_HPP__ +#ifndef OPENCV_OLD_WIMAGE_HPP +#define OPENCV_OLD_WIMAGE_HPP #include "opencv2/core/wimage.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv/cxcore.h b/lib/3rdParty/OpenCV3.4/include/opencv/cxcore.h similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv/cxcore.h rename to lib/3rdParty/OpenCV3.4/include/opencv/cxcore.h index 0982bd75..dc070c77 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv/cxcore.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv/cxcore.h @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_OLD_CXCORE_H__ -#define __OPENCV_OLD_CXCORE_H__ +#ifndef OPENCV_OLD_CXCORE_H +#define OPENCV_OLD_CXCORE_H //#if defined(__GNUC__) //#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv/cxcore.hpp b/lib/3rdParty/OpenCV3.4/include/opencv/cxcore.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv/cxcore.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv/cxcore.hpp index 9af4ac74..c371677c 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv/cxcore.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv/cxcore.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_OLD_CXCORE_HPP__ -#define __OPENCV_OLD_CXCORE_HPP__ +#ifndef OPENCV_OLD_CXCORE_HPP +#define OPENCV_OLD_CXCORE_HPP //#if defined(__GNUC__) //#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv/cxeigen.hpp b/lib/3rdParty/OpenCV3.4/include/opencv/cxeigen.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv/cxeigen.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv/cxeigen.hpp index 1f04d1a3..1d3df914 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv/cxeigen.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv/cxeigen.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_OLD_EIGEN_HPP__ -#define __OPENCV_OLD_EIGEN_HPP__ +#ifndef OPENCV_OLD_EIGEN_HPP +#define OPENCV_OLD_EIGEN_HPP #include "opencv2/core/eigen.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv/cxmisc.h b/lib/3rdParty/OpenCV3.4/include/opencv/cxmisc.h similarity index 53% rename from lib/3rdParty/OpenCV3.1/include/opencv/cxmisc.h rename to lib/3rdParty/OpenCV3.4/include/opencv/cxmisc.h index 6c93a0cc..9b9bc820 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv/cxmisc.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv/cxmisc.h @@ -1,5 +1,5 @@ -#ifndef __OPENCV_OLD_CXMISC_H__ -#define __OPENCV_OLD_CXMISC_H__ +#ifndef OPENCV_OLD_CXMISC_H +#define OPENCV_OLD_CXMISC_H #ifdef __cplusplus # include "opencv2/core/utility.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv/highgui.h b/lib/3rdParty/OpenCV3.4/include/opencv/highgui.h similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv/highgui.h rename to lib/3rdParty/OpenCV3.4/include/opencv/highgui.h index 0261029c..69b394e0 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv/highgui.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv/highgui.h @@ -39,8 +39,8 @@ // //M*/ -#ifndef __OPENCV_OLD_HIGHGUI_H__ -#define __OPENCV_OLD_HIGHGUI_H__ +#ifndef OPENCV_OLD_HIGHGUI_H +#define OPENCV_OLD_HIGHGUI_H #include "opencv2/core/core_c.h" #include "opencv2/highgui/highgui_c.h" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv/ml.h b/lib/3rdParty/OpenCV3.4/include/opencv/ml.h similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv/ml.h rename to lib/3rdParty/OpenCV3.4/include/opencv/ml.h index d8e967f8..0c376bac 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv/ml.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv/ml.h @@ -38,8 +38,8 @@ // //M*/ -#ifndef __OPENCV_OLD_ML_H__ -#define __OPENCV_OLD_ML_H__ +#ifndef OPENCV_OLD_ML_H +#define OPENCV_OLD_ML_H #include "opencv2/core/core_c.h" #include "opencv2/ml.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/calib3d.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/calib3d.hpp similarity index 82% rename from lib/3rdParty/OpenCV3.1/include/opencv2/calib3d.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/calib3d.hpp index ddffffec..74b63c6c 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/calib3d.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/calib3d.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_CALIB3D_HPP__ -#define __OPENCV_CALIB3D_HPP__ +#ifndef OPENCV_CALIB3D_HPP +#define OPENCV_CALIB3D_HPP #include "opencv2/core.hpp" #include "opencv2/features2d.hpp" @@ -96,6 +96,10 @@ u = f_x*x' + c_x \\ v = f_y*y' + c_y \end{array}\f] +The following figure illustrates the pinhole camera model. + +![Pinhole camera model](pics/pinhole_camera_model.png) + Real lenses usually have some distortion, mostly radial distortion and slight tangential distortion. So, the above model is extended as: @@ -114,6 +118,10 @@ v = f_y*y'' + c_y tangential distortion coefficients. \f$s_1\f$, \f$s_2\f$, \f$s_3\f$, and \f$s_4\f$, are the thin prism distortion coefficients. Higher-order coefficients are not considered in OpenCV. +The next figure shows two common types of radial distortion: barrel distortion (typically \f$ k_1 > 0 \f$ and pincushion distortion (typically \f$ k_1 < 0 \f$). + +![](pics/distortion_examples.png) + In some cases the image sensor may be tilted in order to focus an oblique plane in front of the camera (Scheimpfug condition). This can be useful for particle image velocimetry (PIV) or triangulation with a laser fan. The tilt causes a perspective distortion of \f$x''\f$ and @@ -190,7 +198,7 @@ pattern (every view is described by several 3D-2D point correspondences). \f[x = Xc_1 \\ y = Xc_2 \\ z = Xc_3\f] - The pinehole projection coordinates of P is [a; b] where + The pinhole projection coordinates of P is [a; b] where \f[a = x / z \ and \ b = y / z \\ r^2 = a^2 + b^2 \\ \theta = atan(r)\f] @@ -200,12 +208,12 @@ pattern (every view is described by several 3D-2D point correspondences). The distorted point coordinates are [x'; y'] where - \f[x' = (\theta_d / r) x \\ y' = (\theta_d / r) y \f] + \f[x' = (\theta_d / r) a \\ y' = (\theta_d / r) b \f] Finally, conversion into pixel coordinates: The final pixel coordinates vector [u; v] where: \f[u = f_x (x' + \alpha y') + c_x \\ - v = f_y yy + c_y\f] + v = f_y y' + c_y\f] @defgroup calib3d_c C API @@ -228,8 +236,9 @@ enum { SOLVEPNP_ITERATIVE = 0, SOLVEPNP_EPNP = 1, //!< EPnP: Efficient Perspective-n-Point Camera Pose Estimation @cite lepetit2009epnp SOLVEPNP_P3P = 2, //!< Complete Solution Classification for the Perspective-Three-Point Problem @cite gao2003complete SOLVEPNP_DLS = 3, //!< A Direct Least-Squares (DLS) Method for PnP @cite hesch2011direct - SOLVEPNP_UPNP = 4 //!< Exhaustive Linearization for Robust Camera Pose and Focal Length Estimation @cite penate2013exhaustive - + SOLVEPNP_UPNP = 4, //!< Exhaustive Linearization for Robust Camera Pose and Focal Length Estimation @cite penate2013exhaustive + SOLVEPNP_AP3P = 5, //!< An Efficient Algebraic Solution to the Perspective-Three-Point Problem @cite Ke17 + SOLVEPNP_MAX_COUNT //!< Used for count }; enum { CALIB_CB_ADAPTIVE_THRESH = 1, @@ -259,6 +268,8 @@ enum { CALIB_USE_INTRINSIC_GUESS = 0x00001, CALIB_FIX_S1_S2_S3_S4 = 0x10000, CALIB_TILTED_MODEL = 0x40000, CALIB_FIX_TAUX_TAUY = 0x80000, + CALIB_USE_QR = 0x100000, //!< use QR instead of SVD decomposition for solving. Faster but potentially less precise + CALIB_FIX_TANGENT_DIST = 0x200000, // only for stereo CALIB_FIX_INTRINSIC = 0x00100, CALIB_SAME_FOCAL_LENGTH = 0x00200, @@ -295,6 +306,12 @@ optimization procedures like calibrateCamera, stereoCalibrate, or solvePnP . */ CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() ); +/** @example pose_from_homography.cpp + An example program about pose estimation from coplanar points + + Check @ref tutorial_homography "the corresponding tutorial" for more details + */ + /** @brief Finds a perspective transformation between two planes. @param srcPoints Coordinates of the points in the original plane, a matrix of the type CV_32FC2 @@ -316,7 +333,7 @@ mask values are ignored. @param maxIters The maximum number of RANSAC iterations, 2000 is the maximum it can be. @param confidence Confidence level, between 0 and 1. -The functions find and return the perspective transformation \f$H\f$ between the source and the +The function finds and returns the perspective transformation \f$H\f$ between the source and the destination planes: \f[s_i \vecthree{x'_i}{y'_i}{1} \sim H \vecthree{x_i}{y_i}{1}\f] @@ -351,13 +368,8 @@ determined up to a scale. Thus, it is normalized so that \f$h_{33}=1\f$. Note th cannot be estimated, an empty one will be returned. @sa - getAffineTransform, getPerspectiveTransform, estimateRigidTransform, warpPerspective, - perspectiveTransform - -@note - - A example on calculating a homography for image matching can be found at - opencv_source_code/samples/cpp/video_homography.cpp - +getAffineTransform, estimateAffine2D, estimateAffinePartial2D, getPerspectiveTransform, warpPerspective, +perspectiveTransform */ CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints, int method = 0, double ransacReprojThreshold = 3, @@ -383,8 +395,8 @@ and a rotation matrix. It optionally returns three rotation matrices, one for each axis, and the three Euler angles in degrees (as the return value) that could be used in OpenGL. Note, there is always more than one -sequence of rotations about the three principle axes that results in the same orientation of an -object, eg. see @cite Slabaugh . Returned tree rotation matrices and corresponding three Euler angules +sequence of rotations about the three principal axes that results in the same orientation of an +object, e.g. see @cite Slabaugh . Returned tree rotation matrices and corresponding three Euler angles are only one of the possible solutions. */ CV_EXPORTS_W Vec3d RQDecomp3x3( InputArray src, OutputArray mtxR, OutputArray mtxQ, @@ -409,8 +421,8 @@ matrix and the position of a camera. It optionally returns three rotation matrices, one for each axis, and three Euler angles that could be used in OpenGL. Note, there is always more than one sequence of rotations about the three -principle axes that results in the same orientation of an object, eg. see @cite Slabaugh . Returned -tree rotation matrices and corresponding three Euler angules are only one of the possible solutions. +principal axes that results in the same orientation of an object, e.g. see @cite Slabaugh . Returned +tree rotation matrices and corresponding three Euler angles are only one of the possible solutions. The function is based on RQDecomp3x3 . */ @@ -513,21 +525,27 @@ CV_EXPORTS_W void projectPoints( InputArray objectPoints, OutputArray jacobian = noArray(), double aspectRatio = 0 ); +/** @example homography_from_camera_displacement.cpp + An example program about homography from the camera displacement + + Check @ref tutorial_homography "the corresponding tutorial" for more details + */ + /** @brief Finds an object pose from 3D-2D point correspondences. -@param objectPoints Array of object points in the object coordinate space, 3xN/Nx3 1-channel or +@param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or 1xN/Nx1 3-channel, where N is the number of points. vector\ can be also passed here. -@param imagePoints Array of corresponding image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, +@param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, where N is the number of points. vector\ can be also passed here. @param cameraMatrix Input camera matrix \f$A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}\f$ . @param distCoeffs Input vector of distortion coefficients \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. -@param rvec Output rotation vector (see Rodrigues ) that, together with tvec , brings points from +@param rvec Output rotation vector (see @ref Rodrigues ) that, together with tvec , brings points from the model coordinate system to the camera coordinate system. @param tvec Output translation vector. -@param useExtrinsicGuess Parameter used for SOLVEPNP_ITERATIVE. If true (1), the function uses +@param useExtrinsicGuess Parameter used for #SOLVEPNP_ITERATIVE. If true (1), the function uses the provided rvec and tvec values as initial approximations of the rotation and translation vectors, respectively, and further optimizes them. @param flags Method for solving a PnP problem: @@ -536,20 +554,116 @@ this case the function finds such a pose that minimizes reprojection error, that of squared distances between the observed projections imagePoints and the projected (using projectPoints ) objectPoints . - **SOLVEPNP_P3P** Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang -"Complete Solution Classification for the Perspective-Three-Point Problem". In this case the -function requires exactly four object and image points. +"Complete Solution Classification for the Perspective-Three-Point Problem" (@cite gao2003complete). +In this case the function requires exactly four object and image points. +- **SOLVEPNP_AP3P** Method is based on the paper of T. Ke, S. Roumeliotis +"An Efficient Algebraic Solution to the Perspective-Three-Point Problem" (@cite Ke17). +In this case the function requires exactly four object and image points. - **SOLVEPNP_EPNP** Method has been introduced by F.Moreno-Noguer, V.Lepetit and P.Fua in the -paper "EPnP: Efficient Perspective-n-Point Camera Pose Estimation". +paper "EPnP: Efficient Perspective-n-Point Camera Pose Estimation" (@cite lepetit2009epnp). - **SOLVEPNP_DLS** Method is based on the paper of Joel A. Hesch and Stergios I. Roumeliotis. -"A Direct Least-Squares (DLS) Method for PnP". +"A Direct Least-Squares (DLS) Method for PnP" (@cite hesch2011direct). - **SOLVEPNP_UPNP** Method is based on the paper of A.Penate-Sanchez, J.Andrade-Cetto, F.Moreno-Noguer. "Exhaustive Linearization for Robust Camera Pose and Focal Length -Estimation". In this case the function also estimates the parameters \f$f_x\f$ and \f$f_y\f$ +Estimation" (@cite penate2013exhaustive). In this case the function also estimates the parameters \f$f_x\f$ and \f$f_y\f$ assuming that both have the same value. Then the cameraMatrix is updated with the estimated focal length. +- **SOLVEPNP_AP3P** Method is based on the paper of Tong Ke and Stergios I. Roumeliotis. +"An Efficient Algebraic Solution to the Perspective-Three-Point Problem" (@cite Ke17). In this case the +function requires exactly four object and image points. The function estimates the object pose given a set of object points, their corresponding image -projections, as well as the camera matrix and the distortion coefficients. +projections, as well as the camera matrix and the distortion coefficients, see the figure below +(more precisely, the X-axis of the camera frame is pointing to the right, the Y-axis downward +and the Z-axis forward). + +![](pnp.jpg) + +Points expressed in the world frame \f$ \bf{X}_w \f$ are projected into the image plane \f$ \left[ u, v \right] \f$ +using the perspective projection model \f$ \Pi \f$ and the camera intrinsic parameters matrix \f$ \bf{A} \f$: + +\f[ + \begin{align*} + \begin{bmatrix} + u \\ + v \\ + 1 + \end{bmatrix} &= + \bf{A} \hspace{0.1em} \Pi \hspace{0.2em} ^{c}\bf{M}_w + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} \\ + \begin{bmatrix} + u \\ + v \\ + 1 + \end{bmatrix} &= + \begin{bmatrix} + f_x & 0 & c_x \\ + 0 & f_y & c_y \\ + 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + 1 & 0 & 0 & 0 \\ + 0 & 1 & 0 & 0 \\ + 0 & 0 & 1 & 0 + \end{bmatrix} + \begin{bmatrix} + r_{11} & r_{12} & r_{13} & t_x \\ + r_{21} & r_{22} & r_{23} & t_y \\ + r_{31} & r_{32} & r_{33} & t_z \\ + 0 & 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} + \end{align*} +\f] + +The estimated pose is thus the rotation (`rvec`) and the translation (`tvec`) vectors that allow to transform +a 3D point expressed in the world frame into the camera frame: + +\f[ + \begin{align*} + \begin{bmatrix} + X_c \\ + Y_c \\ + Z_c \\ + 1 + \end{bmatrix} &= + \hspace{0.2em} ^{c}\bf{M}_w + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} \\ + \begin{bmatrix} + X_c \\ + Y_c \\ + Z_c \\ + 1 + \end{bmatrix} &= + \begin{bmatrix} + r_{11} & r_{12} & r_{13} & t_x \\ + r_{21} & r_{22} & r_{23} & t_y \\ + r_{31} & r_{32} & r_{33} & t_z \\ + 0 & 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} + \end{align*} +\f] @note - An example of how to use solvePnP for planar augmented reality can be found at @@ -564,6 +678,15 @@ projections, as well as the camera matrix and the distortion coefficients. - Thus, given some data D = np.array(...) where D.shape = (N,M), in order to use a subset of it as, e.g., imagePoints, one must effectively copy it into a new array: imagePoints = np.ascontiguousarray(D[:,:2]).reshape((N,1,2)) + - The methods **SOLVEPNP_DLS** and **SOLVEPNP_UPNP** cannot be used as the current implementations are + unstable and sometimes give completely wrong results. If you pass one of these two + flags, **SOLVEPNP_EPNP** method will be used instead. + - The minimum number of points is 4 in the general case. In the case of **SOLVEPNP_P3P** and **SOLVEPNP_AP3P** + methods, it is required to use exactly 4 points (the first 3 points are used to estimate all the solutions + of the P3P problem, the last one is used to retain the best solution that minimizes the reprojection error). + - With **SOLVEPNP_ITERATIVE** method and `useExtrinsicGuess=true`, the minimum number of points is 3 (3 points + are sufficient to compute a pose but there are up to 4 solutions). The initial solution should be close to the + global solution to converge. */ CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, @@ -572,9 +695,9 @@ CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints, /** @brief Finds an object pose from 3D-2D point correspondences using the RANSAC scheme. -@param objectPoints Array of object points in the object coordinate space, 3xN/Nx3 1-channel or +@param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or 1xN/Nx1 3-channel, where N is the number of points. vector\ can be also passed here. -@param imagePoints Array of corresponding image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, +@param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, where N is the number of points. vector\ can be also passed here. @param cameraMatrix Input camera matrix \f$A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}\f$ . @param distCoeffs Input vector of distortion coefficients @@ -604,6 +727,13 @@ makes the function resistant to outliers. @note - An example of how to use solvePNPRansac for object detection can be found at opencv_source_code/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/ + - The default method used to estimate the camera pose for the Minimal Sample Sets step + is #SOLVEPNP_EPNP. Exceptions are: + - if you choose #SOLVEPNP_P3P or #SOLVEPNP_AP3P, these methods will be used. + - if the number of input points is equal to 4, #SOLVEPNP_P3P is used. + - The method used to estimate the camera pose using all the inliers is defined by the + flags parameters unless it is equal to #SOLVEPNP_P3P or #SOLVEPNP_AP3P. In this case, + the method #SOLVEPNP_EPNP will be used instead. */ CV_EXPORTS_W bool solvePnPRansac( InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, @@ -611,6 +741,33 @@ CV_EXPORTS_W bool solvePnPRansac( InputArray objectPoints, InputArray imagePoint bool useExtrinsicGuess = false, int iterationsCount = 100, float reprojectionError = 8.0, double confidence = 0.99, OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE ); +/** @brief Finds an object pose from 3 3D-2D point correspondences. + +@param objectPoints Array of object points in the object coordinate space, 3x3 1-channel or +1x3/3x1 3-channel. vector\ can be also passed here. +@param imagePoints Array of corresponding image points, 3x2 1-channel or 1x3/3x1 2-channel. + vector\ can be also passed here. +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param rvecs Output rotation vectors (see Rodrigues ) that, together with tvecs , brings points from +the model coordinate system to the camera coordinate system. A P3P problem has up to 4 solutions. +@param tvecs Output translation vectors. +@param flags Method for solving a P3P problem: +- **SOLVEPNP_P3P** Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang +"Complete Solution Classification for the Perspective-Three-Point Problem" (@cite gao2003complete). +- **SOLVEPNP_AP3P** Method is based on the paper of Tong Ke and Stergios I. Roumeliotis. +"An Efficient Algebraic Solution to the Perspective-Three-Point Problem" (@cite Ke17). + +The function estimates the object pose given 3 object points, their corresponding image +projections, as well as the camera matrix and the distortion coefficients. + */ +CV_EXPORTS_W int solveP3P( InputArray objectPoints, InputArray imagePoints, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + int flags ); /** @brief Finds an initial camera matrix from 3D-2D point correspondences. @@ -638,11 +795,11 @@ CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints, ( patternSize = cvSize(points_per_row,points_per_colum) = cvSize(columns,rows) ). @param corners Output array of detected corners. @param flags Various operation flags that can be zero or a combination of the following values: -- **CV_CALIB_CB_ADAPTIVE_THRESH** Use adaptive thresholding to convert the image to black +- **CALIB_CB_ADAPTIVE_THRESH** Use adaptive thresholding to convert the image to black and white, rather than a fixed threshold level (computed from the average image brightness). -- **CV_CALIB_CB_NORMALIZE_IMAGE** Normalize the image gamma with equalizeHist before +- **CALIB_CB_NORMALIZE_IMAGE** Normalize the image gamma with equalizeHist before applying fixed or adaptive thresholding. -- **CV_CALIB_CB_FILTER_QUADS** Use additional criteria (like contour area, perimeter, +- **CALIB_CB_FILTER_QUADS** Use additional criteria (like contour area, perimeter, square-like shape) to filter out false quads extracted at the contour retrieval stage. - **CALIB_CB_FAST_CHECK** Run a fast check on the image that looks for chessboard corners, and shortcut the call if none is found. This can drastically speed up the call in the @@ -701,6 +858,38 @@ found, or as colored corners connected with lines if the board was found. CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSize, InputArray corners, bool patternWasFound ); +struct CV_EXPORTS_W_SIMPLE CirclesGridFinderParameters +{ + CV_WRAP CirclesGridFinderParameters(); + CV_PROP_RW cv::Size2f densityNeighborhoodSize; + CV_PROP_RW float minDensity; + CV_PROP_RW int kmeansAttempts; + CV_PROP_RW int minDistanceToAddKeypoint; + CV_PROP_RW int keypointScale; + CV_PROP_RW float minGraphConfidence; + CV_PROP_RW float vertexGain; + CV_PROP_RW float vertexPenalty; + CV_PROP_RW float existingVertexGain; + CV_PROP_RW float edgeGain; + CV_PROP_RW float edgePenalty; + CV_PROP_RW float convexHullFactor; + CV_PROP_RW float minRNGEdgeSwitchDist; + + enum GridType + { + SYMMETRIC_GRID, ASYMMETRIC_GRID + }; + GridType gridType; +}; + +struct CV_EXPORTS_W_SIMPLE CirclesGridFinderParameters2 : public CirclesGridFinderParameters +{ + CV_WRAP CirclesGridFinderParameters2(); + + CV_PROP_RW float squareSize; //!< Distance between two adjacent points. Used by CALIB_CB_CLUSTERING. + CV_PROP_RW float maxRectifiedDistance; //!< Max deviation from predicion. Used by CALIB_CB_CLUSTERING. +}; + /** @brief Finds centers in the grid of circles. @param image grid view of input circles; it must be an 8-bit grayscale or color image. @@ -713,6 +902,7 @@ CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSiz - **CALIB_CB_CLUSTERING** uses a special algorithm for grid detection. It is more robust to perspective distortions but much more sensitive to background clutter. @param blobDetector feature detector that finds blobs like dark circles on light background. +@param parameters struct for finding circles in a grid pattern. The function attempts to determine whether the input image contains a grid of circles. If it is, the function locates centers of the circles. The function returns a non-zero value if all of the centers @@ -732,6 +922,18 @@ Sample usage of detecting and drawing the centers of circles: : @note The function requires white space (like a square-thick border, the wider the better) around the board to make the detection more robust in various environments. */ +CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, + OutputArray centers, int flags, + const Ptr &blobDetector, + CirclesGridFinderParameters parameters); + +/** @overload */ +CV_EXPORTS_W bool findCirclesGrid2( InputArray image, Size patternSize, + OutputArray centers, int flags, + const Ptr &blobDetector, + CirclesGridFinderParameters2 parameters); + +/** @overload */ CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, OutputArray centers, int flags = CALIB_CB_SYMMETRIC_GRID, const Ptr &blobDetector = SimpleBlobDetector::create()); @@ -756,7 +958,7 @@ together. @param imageSize Size of the image used only to initialize the intrinsic camera matrix. @param cameraMatrix Output 3x3 floating-point camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS -and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be +and/or CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be initialized before calling the function. @param distCoeffs Output vector of distortion coefficients \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of @@ -767,25 +969,33 @@ k-th translation vector (see the next output parameter description) brings the c from the model coordinate space (in which object points are specified) to the world coordinate space, that is, a real position of the calibration pattern in the k-th pattern view (k=0.. *M* -1). @param tvecs Output vector of translation vectors estimated for each pattern view. +@param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. + Order of deviations values: +\f$(f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6 , s_1, s_2, s_3, + s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero. +@param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. + Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views, + \f$R_i, T_i\f$ are concatenated 1x3 vectors. + @param perViewErrors Output vector of the RMS re-projection error estimated for each pattern view. @param flags Different flags that may be zero or a combination of the following values: -- **CV_CALIB_USE_INTRINSIC_GUESS** cameraMatrix contains valid initial values of +- **CALIB_USE_INTRINSIC_GUESS** cameraMatrix contains valid initial values of fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image center ( imageSize is used), and focal distances are computed in a least-squares fashion. Note, that if intrinsic parameters are known, there is no need to use this function just to estimate extrinsic parameters. Use solvePnP instead. -- **CV_CALIB_FIX_PRINCIPAL_POINT** The principal point is not changed during the global +- **CALIB_FIX_PRINCIPAL_POINT** The principal point is not changed during the global optimization. It stays at the center or at a different location specified when -CV_CALIB_USE_INTRINSIC_GUESS is set too. -- **CV_CALIB_FIX_ASPECT_RATIO** The functions considers only fy as a free parameter. The +CALIB_USE_INTRINSIC_GUESS is set too. +- **CALIB_FIX_ASPECT_RATIO** The functions considers only fy as a free parameter. The ratio fx/fy stays the same as in the input cameraMatrix . When -CV_CALIB_USE_INTRINSIC_GUESS is not set, the actual input values of fx and fy are +CALIB_USE_INTRINSIC_GUESS is not set, the actual input values of fx and fy are ignored, only their ratio is computed and used further. -- **CV_CALIB_ZERO_TANGENT_DIST** Tangential distortion coefficients \f$(p_1, p_2)\f$ are set +- **CALIB_ZERO_TANGENT_DIST** Tangential distortion coefficients \f$(p_1, p_2)\f$ are set to zeros and stay zero. -- **CV_CALIB_FIX_K1,...,CV_CALIB_FIX_K6** The corresponding radial distortion -coefficient is not changed during the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is +- **CALIB_FIX_K1,...,CALIB_FIX_K6** The corresponding radial distortion +coefficient is not changed during the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. -- **CV_CALIB_RATIONAL_MODEL** Coefficients k4, k5, and k6 are enabled. To provide the +- **CALIB_RATIONAL_MODEL** Coefficients k4, k5, and k6 are enabled. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the rational model and return 8 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients. @@ -794,24 +1004,26 @@ backward compatibility, this extra flag should be explicitly specified to make t calibration function use the thin prism model and return 12 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients. - **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during -the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. - **CALIB_TILTED_MODEL** Coefficients tauX and tauY are enabled. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the tilted sensor model and return 14 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients. - **CALIB_FIX_TAUX_TAUY** The coefficients of the tilted sensor model are not changed during -the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. @param criteria Termination criteria for the iterative optimization algorithm. +@return the overall RMS re-projection error. + The function estimates the intrinsic camera parameters and extrinsic parameters for each of the views. The algorithm is based on @cite Zhang2000 and @cite BouguetMCT . The coordinates of 3D object points and their corresponding 2D projections in each view must be specified. That may be achieved by using an object with a known geometry and easily detectable feature points. Such an object is called a calibration rig or calibration pattern, and OpenCV has built-in support for a chessboard as a calibration rig (see findChessboardCorners ). Currently, initialization of intrinsic parameters -(when CV_CALIB_USE_INTRINSIC_GUESS is not set) is only implemented for planar calibration +(when CALIB_USE_INTRINSIC_GUESS is not set) is only implemented for planar calibration patterns (where Z-coordinates of the object points must be all zeros). 3D calibration rigs can also be used as long as initial cameraMatrix is provided. @@ -819,7 +1031,7 @@ The algorithm performs the following steps: - Compute the initial intrinsic parameters (the option only available for planar calibration patterns) or read them from the input parameters. The distortion coefficients are all set to - zeros initially unless some of CV_CALIB_FIX_K? are specified. + zeros initially unless some of CALIB_FIX_K? are specified. - Estimate the initial camera pose as if the intrinsic parameters have been already known. This is done using solvePnP . @@ -829,8 +1041,6 @@ The algorithm performs the following steps: the projected (using the current estimates for camera parameters and the poses) object points objectPoints. See projectPoints for details. -The function returns the final re-projection error. - @note If you use a non-square (=non-NxN) grid and findChessboardCorners for calibration, and calibrateCamera returns bad values (zero distortion coefficients, an image center very far from @@ -841,6 +1051,24 @@ The function returns the final re-projection error. @sa findChessboardCorners, solvePnP, initCameraMatrix2D, stereoCalibrate, undistort */ +CV_EXPORTS_AS(calibrateCameraExtended) double calibrateCamera( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, Size imageSize, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray stdDeviationsIntrinsics, + OutputArray stdDeviationsExtrinsics, + OutputArray perViewErrors, + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); + +/** @overload double calibrateCamera( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, Size imageSize, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray stdDeviations, OutputArray perViewErrors, + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ) + */ CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, @@ -883,8 +1111,8 @@ observed by the first camera. observed by the second camera. @param cameraMatrix1 Input/output first camera matrix: \f$\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}\f$ , \f$j = 0,\, 1\f$ . If -any of CV_CALIB_USE_INTRINSIC_GUESS , CV_CALIB_FIX_ASPECT_RATIO , -CV_CALIB_FIX_INTRINSIC , or CV_CALIB_FIX_FOCAL_LENGTH are specified, some or all of the +any of CALIB_USE_INTRINSIC_GUESS , CALIB_FIX_ASPECT_RATIO , +CALIB_FIX_INTRINSIC , or CALIB_FIX_FOCAL_LENGTH are specified, some or all of the matrix components must be initialized. See the flags description for details. @param distCoeffs1 Input/output vector of distortion coefficients \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of @@ -898,21 +1126,21 @@ is similar to distCoeffs1 . @param E Output essential matrix. @param F Output fundamental matrix. @param flags Different flags that may be zero or a combination of the following values: -- **CV_CALIB_FIX_INTRINSIC** Fix cameraMatrix? and distCoeffs? so that only R, T, E , and F +- **CALIB_FIX_INTRINSIC** Fix cameraMatrix? and distCoeffs? so that only R, T, E , and F matrices are estimated. -- **CV_CALIB_USE_INTRINSIC_GUESS** Optimize some or all of the intrinsic parameters +- **CALIB_USE_INTRINSIC_GUESS** Optimize some or all of the intrinsic parameters according to the specified flags. Initial values are provided by the user. -- **CV_CALIB_FIX_PRINCIPAL_POINT** Fix the principal points during the optimization. -- **CV_CALIB_FIX_FOCAL_LENGTH** Fix \f$f^{(j)}_x\f$ and \f$f^{(j)}_y\f$ . -- **CV_CALIB_FIX_ASPECT_RATIO** Optimize \f$f^{(j)}_y\f$ . Fix the ratio \f$f^{(j)}_x/f^{(j)}_y\f$ +- **CALIB_FIX_PRINCIPAL_POINT** Fix the principal points during the optimization. +- **CALIB_FIX_FOCAL_LENGTH** Fix \f$f^{(j)}_x\f$ and \f$f^{(j)}_y\f$ . +- **CALIB_FIX_ASPECT_RATIO** Optimize \f$f^{(j)}_y\f$ . Fix the ratio \f$f^{(j)}_x/f^{(j)}_y\f$ . -- **CV_CALIB_SAME_FOCAL_LENGTH** Enforce \f$f^{(0)}_x=f^{(1)}_x\f$ and \f$f^{(0)}_y=f^{(1)}_y\f$ . -- **CV_CALIB_ZERO_TANGENT_DIST** Set tangential distortion coefficients for each camera to +- **CALIB_SAME_FOCAL_LENGTH** Enforce \f$f^{(0)}_x=f^{(1)}_x\f$ and \f$f^{(0)}_y=f^{(1)}_y\f$ . +- **CALIB_ZERO_TANGENT_DIST** Set tangential distortion coefficients for each camera to zeros and fix there. -- **CV_CALIB_FIX_K1,...,CV_CALIB_FIX_K6** Do not change the corresponding radial -distortion coefficient during the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, +- **CALIB_FIX_K1,...,CALIB_FIX_K6** Do not change the corresponding radial +distortion coefficient during the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. -- **CV_CALIB_RATIONAL_MODEL** Enable coefficients k4, k5, and k6. To provide the backward +- **CALIB_RATIONAL_MODEL** Enable coefficients k4, k5, and k6. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the rational model and return 8 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients. @@ -921,14 +1149,14 @@ backward compatibility, this extra flag should be explicitly specified to make t calibration function use the thin prism model and return 12 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients. - **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during -the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. - **CALIB_TILTED_MODEL** Coefficients tauX and tauY are enabled. To provide the backward compatibility, this extra flag should be explicitly specified to make the calibration function use the tilted sensor model and return 14 coefficients. If the flag is not set, the function computes and returns only 5 distortion coefficients. - **CALIB_FIX_TAUX_TAUY** The coefficients of the tilted sensor model are not changed during -the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. @param criteria Termination criteria for the iterative optimization algorithm. @@ -940,8 +1168,8 @@ This means that, given ( \f$R_1\f$,\f$T_1\f$ ), it should be possible to compute need to know the position and orientation of the second camera relative to the first camera. This is what the described function does. It computes ( \f$R\f$,\f$T\f$ ) so that: -\f[R_2=R*R_1 -T_2=R*T_1 + T,\f] +\f[R_2=R*R_1\f] +\f[T_2=R*T_1 + T,\f] Optionally, it computes the essential matrix E: @@ -956,10 +1184,10 @@ Besides the stereo-related information, the function can also perform a full cal two cameras. However, due to the high dimensionality of the parameter space and noise in the input data, the function can diverge from the correct solution. If the intrinsic parameters can be estimated with high accuracy for each of the cameras individually (for example, using -calibrateCamera ), you are recommended to do so and then pass CV_CALIB_FIX_INTRINSIC flag to the +calibrateCamera ), you are recommended to do so and then pass CALIB_FIX_INTRINSIC flag to the function along with the computed intrinsic parameters. Otherwise, if all the parameters are estimated at once, it makes sense to restrict some parameters, for example, pass -CV_CALIB_SAME_FOCAL_LENGTH and CV_CALIB_ZERO_TANGENT_DIST flags, which is usually a +CALIB_SAME_FOCAL_LENGTH and CALIB_ZERO_TANGENT_DIST flags, which is usually a reasonable assumption. Similarly to calibrateCamera , the function minimizes the total re-projection error for all the @@ -991,7 +1219,7 @@ camera. @param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second camera. @param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ). -@param flags Operation flags that may be zero or CV_CALIB_ZERO_DISPARITY . If the flag is set, +@param flags Operation flags that may be zero or CALIB_ZERO_DISPARITY . If the flag is set, the function makes the principal points of each camera have the same pixel coordinates in the rectified views. And if the flag is not set, the function may still shift the images in the horizontal or vertical direction (depending on the orientation of epipolar lines) to maximize the @@ -1030,7 +1258,7 @@ coordinates. The function distinguishes the following two cases: \f[\texttt{P2} = \begin{bmatrix} f & 0 & cx_2 & T_x*f \\ 0 & f & cy & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix} ,\f] where \f$T_x\f$ is a horizontal shift between the cameras and \f$cx_1=cx_2\f$ if - CV_CALIB_ZERO_DISPARITY is set. + CALIB_ZERO_DISPARITY is set. - **Vertical stereo**: the first and the second camera views are shifted relative to each other mainly in vertical direction (and probably a bit in the horizontal direction too). The epipolar @@ -1076,7 +1304,7 @@ findFundamentalMat . @param threshold Optional threshold used to filter out the outliers. If the parameter is greater than zero, all the point pairs that do not comply with the epipolar geometry (that is, the points for which \f$|\texttt{points2[i]}^T*\texttt{F}*\texttt{points1[i]}|>\texttt{threshold}\f$ ) are -rejected prior to computing the homographies. Otherwise,all the points are considered inliers. +rejected prior to computing the homographies. Otherwise, all the points are considered inliers. The function computes the rectification transformations without knowing intrinsic parameters of the cameras and their relative position in the space, which explains the suffix "uncalibrated". Another @@ -1120,7 +1348,7 @@ assumed. @param alpha Free scaling parameter between 0 (when all the pixels in the undistorted image are valid) and 1 (when all the source image pixels are retained in the undistorted image). See stereoRectify for details. -@param newImgSize Image size after rectification. By default,it is set to imageSize . +@param newImgSize Image size after rectification. By default, it is set to imageSize . @param validPixROI Optional output rectangle that outlines all-good-pixels region in the undistorted image. See roi1, roi2 description in stereoRectify . @param centerPrincipalPoint Optional flag that indicates whether in the new camera matrix the @@ -1131,7 +1359,7 @@ best fit a subset of the source image (determined by alpha) to the corrected ima The function computes and returns the optimal new camera matrix based on the free scaling parameter. By varying this parameter, you may retrieve only sensible pixels alpha=0 , keep all the original image pixels if there is valuable information in the corners alpha=1 , or get something in between. -When alpha\>0 , the undistortion result is likely to have some black pixels corresponding to +When alpha\>0 , the undistorted result is likely to have some black pixels corresponding to "virtual" pixels outside of the captured distorted image. The original camera matrix, distortion coefficients, the computed new camera matrix, and newImageSize should be passed to initUndistortRectifyMap to produce the maps for remap . @@ -1242,15 +1470,15 @@ be floating-point (single or double precision). @param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . Note that this function assumes that points1 and points2 are feature points from cameras with the same camera matrix. -@param method Method for computing a fundamental matrix. +@param method Method for computing an essential matrix. - **RANSAC** for the RANSAC algorithm. -- **MEDS** for the LMedS algorithm. +- **LMEDS** for the LMedS algorithm. +@param prob Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of +confidence (probability) that the estimated matrix is correct. @param threshold Parameter used for RANSAC. It is the maximum distance from a point to an epipolar line in pixels, beyond which the point is considered an outlier and is not used for computing the final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the point localization, image resolution, and the image noise. -@param prob Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of -confidence (probability) that the estimated matrix is correct. @param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 for the other points. The array is computed only in the RANSAC and LMedS methods. @@ -1273,8 +1501,8 @@ CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, be floating-point (single or double precision). @param points2 Array of the second image points of the same size and format as points1 . @param focal focal length of the camera. Note that this function assumes that points1 and points2 -are feature points from cameras with same focal length and principle point. -@param pp principle point of the camera. +are feature points from cameras with same focal length and principal point. +@param pp principal point of the camera. @param method Method for computing a fundamental matrix. - **RANSAC** for the RANSAC algorithm. - **LMEDS** for the LMedS algorithm. @@ -1327,7 +1555,7 @@ floating-point (single or double precision). Note that this function assumes that points1 and points2 are feature points from cameras with the same camera matrix. @param R Recovered relative rotation. -@param t Recoverd relative translation. +@param t Recovered relative translation. @param mask Input/output mask for inliers in points1 and points2. : If it is not empty, then it marks inliers in points1 and points2 for then given essential matrix E. Only these inliers will be used to recover pose. In the output mask only inliers @@ -1370,10 +1598,10 @@ CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray point floating-point (single or double precision). @param points2 Array of the second image points of the same size and format as points1 . @param R Recovered relative rotation. -@param t Recoverd relative translation. +@param t Recovered relative translation. @param focal Focal length of the camera. Note that this function assumes that points1 and points2 -are feature points from cameras with same focal length and principle point. -@param pp Principle point of the camera. +are feature points from cameras with same focal length and principal point. +@param pp principal point of the camera. @param mask Input/output mask for inliers in points1 and points2. : If it is not empty, then it marks inliers in points1 and points2 for then given essential matrix E. Only these inliers will be used to recover pose. In the output mask only inliers @@ -1394,6 +1622,28 @@ CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray point double focal = 1.0, Point2d pp = Point2d(0, 0), InputOutputArray mask = noArray() ); +/** @overload +@param E The input essential matrix. +@param points1 Array of N 2D points from the first image. The point coordinates should be +floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1. +@param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +Note that this function assumes that points1 and points2 are feature points from cameras with the +same camera matrix. +@param R Recovered relative rotation. +@param t Recovered relative translation. +@param distanceThresh threshold distance which is used to filter out far away points (i.e. infinite points). +@param mask Input/output mask for inliers in points1 and points2. +: If it is not empty, then it marks inliers in points1 and points2 for then given essential +matrix E. Only these inliers will be used to recover pose. In the output mask only inliers +which pass the cheirality check. +@param triangulatedPoints 3d points which were reconstructed by triangulation. + */ + +CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2, + InputArray cameraMatrix, OutputArray R, OutputArray t, double distanceThresh, InputOutputArray mask = noArray(), + OutputArray triangulatedPoints = noArray()); + /** @brief For points in an image of a stereo pair, computes the corresponding epilines in the other image. @param points Input points. \f$N \times 1\f$ or \f$1 \times N\f$ matrix of type CV_32FC2 or @@ -1504,7 +1754,7 @@ to 3D points with a very large Z value (currently set to 10000). depth. ddepth can also be set to CV_16S, CV_32S or CV_32F. The function transforms a single-channel disparity map to a 3-channel image representing a 3D -surface. That is, for each pixel (x,y) andthe corresponding disparity d=disparity(x,y) , it +surface. That is, for each pixel (x,y) and the corresponding disparity d=disparity(x,y) , it computes: \f[\begin{array}{l} [X \; Y \; Z \; W]^T = \texttt{Q} *[x \; y \; \texttt{disparity} (x,y) \; 1]^T \\ \texttt{\_3dImage} (x,y) = (X/W, \; Y/W, \; Z/W) \end{array}\f] @@ -1548,6 +1798,99 @@ CV_EXPORTS_W int estimateAffine3D(InputArray src, InputArray dst, OutputArray out, OutputArray inliers, double ransacThreshold = 3, double confidence = 0.99); +/** @brief Computes an optimal affine transformation between two 2D point sets. + +@param from First input 2D point set. +@param to Second input 2D point set. +@param inliers Output vector indicating which points are inliers. +@param method Robust method used to compute transformation. The following methods are possible: +- cv::RANSAC - RANSAC-based robust method +- cv::LMEDS - Least-Median robust method +RANSAC is the default method. +@param ransacReprojThreshold Maximum reprojection error in the RANSAC algorithm to consider +a point as an inlier. Applies only to RANSAC. +@param maxIters The maximum number of robust method iterations, 2000 is the maximum it can be. +@param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything +between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation +significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. +@param refineIters Maximum number of iterations of refining algorithm (Levenberg-Marquardt). +Passing 0 will disable refining, so the output matrix will be output of robust method. + +@return Output 2D affine transformation matrix \f$2 \times 3\f$ or empty matrix if transformation +could not be estimated. + +The function estimates an optimal 2D affine transformation between two 2D point sets using the +selected robust algorithm. + +The computed transformation is then refined further (using only inliers) with the +Levenberg-Marquardt method to reduce the re-projection error even more. + +@note +The RANSAC method can handle practically any ratio of outliers but need a threshold to +distinguish inliers from outliers. The method LMeDS does not need any threshold but it works +correctly only when there are more than 50% of inliers. + +@sa estimateAffinePartial2D, getAffineTransform +*/ +CV_EXPORTS_W cv::Mat estimateAffine2D(InputArray from, InputArray to, OutputArray inliers = noArray(), + int method = RANSAC, double ransacReprojThreshold = 3, + size_t maxIters = 2000, double confidence = 0.99, + size_t refineIters = 10); + +/** @brief Computes an optimal limited affine transformation with 4 degrees of freedom between +two 2D point sets. + +@param from First input 2D point set. +@param to Second input 2D point set. +@param inliers Output vector indicating which points are inliers. +@param method Robust method used to compute transformation. The following methods are possible: +- cv::RANSAC - RANSAC-based robust method +- cv::LMEDS - Least-Median robust method +RANSAC is the default method. +@param ransacReprojThreshold Maximum reprojection error in the RANSAC algorithm to consider +a point as an inlier. Applies only to RANSAC. +@param maxIters The maximum number of robust method iterations, 2000 is the maximum it can be. +@param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything +between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation +significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. +@param refineIters Maximum number of iterations of refining algorithm (Levenberg-Marquardt). +Passing 0 will disable refining, so the output matrix will be output of robust method. + +@return Output 2D affine transformation (4 degrees of freedom) matrix \f$2 \times 3\f$ or +empty matrix if transformation could not be estimated. + +The function estimates an optimal 2D affine transformation with 4 degrees of freedom limited to +combinations of translation, rotation, and uniform scaling. Uses the selected algorithm for robust +estimation. + +The computed transformation is then refined further (using only inliers) with the +Levenberg-Marquardt method to reduce the re-projection error even more. + +Estimated transformation matrix is: +\f[ \begin{bmatrix} \cos(\theta)s & -\sin(\theta)s & tx \\ + \sin(\theta)s & \cos(\theta)s & ty +\end{bmatrix} \f] +Where \f$ \theta \f$ is the rotation angle, \f$ s \f$ the scaling factor and \f$ tx, ty \f$ are +translations in \f$ x, y \f$ axes respectively. + +@note +The RANSAC method can handle practically any ratio of outliers but need a threshold to +distinguish inliers from outliers. The method LMeDS does not need any threshold but it works +correctly only when there are more than 50% of inliers. + +@sa estimateAffine2D, getAffineTransform +*/ +CV_EXPORTS_W cv::Mat estimateAffinePartial2D(InputArray from, InputArray to, OutputArray inliers = noArray(), + int method = RANSAC, double ransacReprojThreshold = 3, + size_t maxIters = 2000, double confidence = 0.99, + size_t refineIters = 10); + +/** @example decompose_homography.cpp + An example program with homography decomposition. + + Check @ref tutorial_homography "the corresponding tutorial" for more details. + */ + /** @brief Decompose a homography matrix to rotation(s), translation(s) and plane normal(s). @param H The input homography matrix between two images. @@ -1683,7 +2026,8 @@ public: { MODE_SGBM = 0, MODE_HH = 1, - MODE_SGBM_3WAY = 2 + MODE_SGBM_3WAY = 2, + MODE_HH4 = 3 }; CV_WRAP virtual int getPreFilterCap() const = 0; @@ -1738,7 +2082,7 @@ public: set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter to a custom value. */ - CV_WRAP static Ptr create(int minDisparity, int numDisparities, int blockSize, + CV_WRAP static Ptr create(int minDisparity = 0, int numDisparities = 16, int blockSize = 3, int P1 = 0, int P2 = 0, int disp12MaxDiff = 0, int preFilterCap = 0, int uniquenessRatio = 0, int speckleWindowSize = 0, int speckleRange = 0, @@ -1756,15 +2100,16 @@ namespace fisheye //! @{ enum{ - CALIB_USE_INTRINSIC_GUESS = 1, - CALIB_RECOMPUTE_EXTRINSIC = 2, - CALIB_CHECK_COND = 4, - CALIB_FIX_SKEW = 8, - CALIB_FIX_K1 = 16, - CALIB_FIX_K2 = 32, - CALIB_FIX_K3 = 64, - CALIB_FIX_K4 = 128, - CALIB_FIX_INTRINSIC = 256 + CALIB_USE_INTRINSIC_GUESS = 1 << 0, + CALIB_RECOMPUTE_EXTRINSIC = 1 << 1, + CALIB_CHECK_COND = 1 << 2, + CALIB_FIX_SKEW = 1 << 3, + CALIB_FIX_K1 = 1 << 4, + CALIB_FIX_K2 = 1 << 5, + CALIB_FIX_K3 = 1 << 6, + CALIB_FIX_K4 = 1 << 7, + CALIB_FIX_INTRINSIC = 1 << 8, + CALIB_FIX_PRINCIPAL_POINT = 1 << 9 }; /** @brief Projects points using fisheye model @@ -1802,6 +2147,10 @@ namespace fisheye @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. @param alpha The skew coefficient. @param distorted Output array of image points, 1xN/Nx1 2-channel, or vector\ . + + Note that the function assumes the camera matrix of the undistorted points to be identity. + This means if you want to transform back points undistorted with undistortPoints() you have to + multiply them with \f$P^{-1}\f$. */ CV_EXPORTS_W void distortPoints(InputArray undistorted, OutputArray distorted, InputArray K, InputArray D, double alpha = 0); @@ -1910,8 +2259,10 @@ namespace fisheye of intrinsic optimization. - **fisheye::CALIB_CHECK_COND** The functions will check validity of condition number. - **fisheye::CALIB_FIX_SKEW** Skew coefficient (alpha) is set to zero and stay zero. - - **fisheye::CALIB_FIX_K1..4** Selected distortion coefficients are set to zeros and stay - zero. + - **fisheye::CALIB_FIX_K1..fisheye::CALIB_FIX_K4** Selected distortion coefficients + are set to zeros and stay zero. + - **fisheye::CALIB_FIX_PRINCIPAL_POINT** The principal point is not changed during the global +optimization. It stays at the center or at a different location specified when CALIB_USE_INTRINSIC_GUESS is set too. @param criteria Termination criteria for the iterative optimization algorithm. */ CV_EXPORTS_W double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, const Size& image_size, @@ -1935,7 +2286,7 @@ namespace fisheye @param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second camera. @param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ). - @param flags Operation flags that may be zero or CV_CALIB_ZERO_DISPARITY . If the flag is set, + @param flags Operation flags that may be zero or CALIB_ZERO_DISPARITY . If the flag is set, the function makes the principal points of each camera have the same pixel coordinates in the rectified views. And if the flag is not set, the function may still shift the images in the horizontal or vertical direction (depending on the orientation of epipolar lines) to maximize the @@ -1961,7 +2312,7 @@ namespace fisheye observed by the second camera. @param K1 Input/output first camera matrix: \f$\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}\f$ , \f$j = 0,\, 1\f$ . If - any of fisheye::CALIB_USE_INTRINSIC_GUESS , fisheye::CV_CALIB_FIX_INTRINSIC are specified, + any of fisheye::CALIB_USE_INTRINSIC_GUESS , fisheye::CALIB_FIX_INTRINSIC are specified, some or all of the matrix components must be initialized. @param D1 Input/output vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$ of 4 elements. @param K2 Input/output second camera matrix. The parameter is similar to K1 . @@ -1971,7 +2322,7 @@ namespace fisheye @param R Output rotation matrix between the 1st and the 2nd camera coordinate systems. @param T Output translation vector between the coordinate systems of the cameras. @param flags Different flags that may be zero or a combination of the following values: - - **fisheye::CV_CALIB_FIX_INTRINSIC** Fix K1, K2? and D1, D2? so that only R, T matrices + - **fisheye::CALIB_FIX_INTRINSIC** Fix K1, K2? and D1, D2? so that only R, T matrices are estimated. - **fisheye::CALIB_USE_INTRINSIC_GUESS** K1, K2 contains valid initial values of fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/calib3d/calib3d.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/calib3d/calib3d.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/calib3d/calib3d.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/calib3d/calib3d.hpp diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/calib3d/calib3d_c.h b/lib/3rdParty/OpenCV3.4/include/opencv2/calib3d/calib3d_c.h similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/calib3d/calib3d_c.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/calib3d/calib3d_c.h index 0e77aa88..8ec6390d 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/calib3d/calib3d_c.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/calib3d/calib3d_c.h @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_CALIB3D_C_H__ -#define __OPENCV_CALIB3D_C_H__ +#ifndef OPENCV_CALIB3D_C_H +#define OPENCV_CALIB3D_C_H #include "opencv2/core/core_c.h" @@ -245,7 +245,9 @@ CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size, #define CV_CALIB_FIX_S1_S2_S3_S4 65536 #define CV_CALIB_TILTED_MODEL 262144 #define CV_CALIB_FIX_TAUX_TAUY 524288 +#define CV_CALIB_FIX_TANGENT_DIST 2097152 +#define CV_CALIB_NINTRINSIC 18 /* Finds intrinsic and extrinsic camera parameters from a few views of known calibration pattern */ @@ -422,4 +424,4 @@ public: #endif -#endif /* __OPENCV_CALIB3D_C_H__ */ +#endif /* OPENCV_CALIB3D_C_H */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core.hpp similarity index 91% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core.hpp index 55922607..fe3af393 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core.hpp @@ -42,8 +42,8 @@ // //M*/ -#ifndef __OPENCV_CORE_HPP__ -#define __OPENCV_CORE_HPP__ +#ifndef OPENCV_CORE_HPP +#define OPENCV_CORE_HPP #ifndef __cplusplus # error core.hpp header must be compiled as C++ @@ -74,6 +74,7 @@ @{ @defgroup core_utils_sse SSE utilities @defgroup core_utils_neon NEON utilities + @defgroup core_utils_softfloat Softfloat support @} @defgroup core_opengl OpenGL interoperability @defgroup core_ipp Intel IPP Asynchronous C/C++ Converters @@ -114,7 +115,7 @@ public: */ Exception(); /*! - Full constructor. Normally the constuctor is not called explicitly. + Full constructor. Normally the constructor is not called explicitly. Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used. */ Exception(int _code, const String& _err, const String& _func, const String& _file, int _line); @@ -131,8 +132,8 @@ public: int code; ///< error code @see CVStatus String err; ///< error description String func; ///< function name. Available only when the compiler supports getting it - String file; ///< source file name where the error has occured - int line; ///< line number in the source file where the error has occured + String file; ///< source file name where the error has occurred + int line; ///< line number in the source file where the error has occurred }; /*! @brief Signals an error and raises the exception. @@ -273,6 +274,9 @@ of p and len. */ CV_EXPORTS_W int borderInterpolate(int p, int len, int borderType); +/** @example copyMakeBorder_demo.cpp +An example using copyMakeBorder function + */ /** @brief Forms a border around an image. The function copies the source image into the middle of the destination image. The areas to the @@ -426,7 +430,7 @@ CV_EXPORTS_W void multiply(InputArray src1, InputArray src2, /** @brief Performs per-element division of two arrays or a scalar by an array. -The functions divide divide one array by another: +The function cv::divide divides one array by another: \f[\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}\f] or a scalar by an array when there is no src1 : \f[\texttt{dst(I) = saturate(scale/src2(I))}\f] @@ -471,6 +475,9 @@ The function can also be emulated with a matrix expression, for example: */ CV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst); +/** @example AddingImagesTrackbar.cpp + + */ /** @brief Calculates the weighted sum of two arrays. The function addWeighted calculates the weighted sum of two arrays as follows: @@ -524,6 +531,17 @@ For example: CV_EXPORTS_W void convertScaleAbs(InputArray src, OutputArray dst, double alpha = 1, double beta = 0); +/** @brief Converts an array to half precision floating number. + +This function converts FP32 (single precision floating point) from/to FP16 (half precision floating point). The input array has to have type of CV_32F or +CV_16S to represent the bit depth. If the input array is neither of them, the function will raise an error. +The format of half precision floating point is defined in IEEE 754-2008. + +@param src input array. +@param dst output array. +*/ +CV_EXPORTS_W void convertFp16(InputArray src, OutputArray dst); + /** @brief Performs a look-up table transform of an array. The function LUT fills the output array with values from the look-up table. Indices of the entries @@ -542,7 +560,7 @@ CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst); /** @brief Calculates the sum of array elements. -The functions sum calculate and return the sum of array elements, +The function cv::sum calculates and returns the sum of array elements, independently for each channel. @param src input array that must have from 1 to 4 channels. @sa countNonZero, mean, meanStdDev, norm, minMaxLoc, reduce @@ -588,10 +606,10 @@ CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx ); /** @brief Calculates an average (mean) of array elements. -The function mean calculates the mean value M of array elements, +The function cv::mean calculates the mean value M of array elements, independently for each channel, and return it: \f[\begin{array}{l} N = \sum _{I: \; \texttt{mask} (I) \ne 0} 1 \\ M_c = \left ( \sum _{I: \; \texttt{mask} (I) \ne 0}{ \texttt{mtx} (I)_c} \right )/N \end{array}\f] -When all the mask elements are 0's, the functions return Scalar::all(0) +When all the mask elements are 0's, the function returns Scalar::all(0) @param src input array that should have from 1 to 4 channels so that the result can be stored in Scalar_ . @param mask optional operation mask. @@ -601,11 +619,11 @@ CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask = noArray()); /** Calculates a mean and standard deviation of array elements. -The function meanStdDev calculates the mean and the standard deviation M +The function cv::meanStdDev calculates the mean and the standard deviation M of array elements independently for each channel and returns it via the output parameters: \f[\begin{array}{l} N = \sum _{I, \texttt{mask} (I) \ne 0} 1 \\ \texttt{mean} _c = \frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \texttt{src} (I)_c}{N} \\ \texttt{stddev} _c = \sqrt{\frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \left ( \texttt{src} (I)_c - \texttt{mean} _c \right )^2}{N}} \end{array}\f] -When all the mask elements are 0's, the functions return +When all the mask elements are 0's, the function returns mean=stddev=Scalar::all(0). @note The calculated standard deviation is only the diagonal of the complete normalized covariance matrix. If the full matrix is needed, you @@ -615,50 +633,57 @@ then pass the matrix to calcCovarMatrix . @param src input array that should have from 1 to 4 channels so that the results can be stored in Scalar_ 's. @param mean output parameter: calculated mean value. -@param stddev output parameter: calculateded standard deviation. +@param stddev output parameter: calculated standard deviation. @param mask optional operation mask. @sa countNonZero, mean, norm, minMaxLoc, calcCovarMatrix */ CV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev, InputArray mask=noArray()); -/** @brief Calculates an absolute array norm, an absolute difference norm, or a -relative difference norm. +/** @brief Calculates the absolute norm of an array. -The functions norm calculate an absolute norm of src1 (when there is no -src2 ): +This version of cv::norm calculates the absolute norm of src1. The type of norm to calculate is specified using cv::NormTypes. -\f[norm = \forkthree{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } -{ \| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) } -{ \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f] - -or an absolute or relative difference norm if src2 is there: - -\f[norm = \forkthree{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } -{ \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) } -{ \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f] - -or - -\f[norm = \forkthree{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE_INF}\) } -{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE_L1}\) } -{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE_L2}\) }\f] - -The functions norm return the calculated norm. +As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$. +The \f$ L_{1}, L_{2} \f$ and \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$ +is calculated as follows +\f{align*} + \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\ + \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\ + \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2 +\f} +and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is +\f{align*} + \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\ + \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\ + \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5. +\f} +The following graphic shows all values for the three norm functions \f$\| r(x) \|_{L_1}, \| r(x) \|_{L_2}\f$ and \f$\| r(x) \|_{L_\infty}\f$. +It is notable that the \f$ L_{1} \f$ norm forms the upper and the \f$ L_{\infty} \f$ norm forms the lower border for the example function \f$ r(x) \f$. +![Graphs for the different norm functions from the above example](pics/NormTypes_OneArray_1-2-INF.png) When the mask parameter is specified and it is not empty, the norm is + +If normType is not specified, NORM_L2 is used. calculated only over the region specified by the mask. -A multi-channel input arrays are treated as a single-channel, that is, +Multi-channel input arrays are treated as single-channel arrays, that is, the results for all channels are combined. +Hamming norms can only be calculated with CV_8U depth arrays. + @param src1 first input array. @param normType type of the norm (see cv::NormTypes). @param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type. */ CV_EXPORTS_W double norm(InputArray src1, int normType = NORM_L2, InputArray mask = noArray()); -/** @overload +/** @brief Calculates an absolute difference norm or a relative difference norm. + +This version of cv::norm calculates the absolute difference norm +or the relative difference norm of arrays src1 and src2. +The type of norm to calculate is specified using cv::NormTypes. + @param src1 first input array. @param src2 second input array of the same size and the same type as src1. @param normType type of the norm (cv::NormTypes). @@ -672,10 +697,21 @@ CV_EXPORTS_W double norm(InputArray src1, InputArray src2, */ CV_EXPORTS double norm( const SparseMat& src, int normType ); -/** @brief computes PSNR image/video quality metric +/** @brief Computes the Peak Signal-to-Noise Ratio (PSNR) image quality metric. + +This function calculates the Peak Signal-to-Noise Ratio (PSNR) image quality metric in decibels (dB), between two input arrays src1 and src2. Arrays must have depth CV_8U. + +The PSNR is calculated as follows: + +\f[ +\texttt{PSNR} = 10 \cdot \log_{10}{\left( \frac{R^2}{MSE} \right) } +\f] + +where R is the maximum integer value of depth CV_8U (255) and MSE is the mean squared error between the two arrays. + +@param src1 first input array. +@param src2 second input array of the same size as src1. -see http://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio for details -@todo document */ CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2); @@ -692,7 +728,7 @@ CV_EXPORTS_W void batchDistance(InputArray src1, InputArray src2, /** @brief Normalizes the norm or value range of an array. -The functions normalize scale and shift the input array elements so that +The function cv::normalize normalizes scale and shift the input array elements so that \f[\| \texttt{dst} \| _{L_p}= \texttt{alpha}\f] (where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that \f[\min _I \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I \texttt{dst} (I)= \texttt{beta}\f] @@ -762,11 +798,11 @@ CV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, i /** @brief Finds the global minimum and maximum in an array. -The functions minMaxLoc find the minimum and maximum element values and their positions. The +The function cv::minMaxLoc finds the minimum and maximum element values and their positions. The extremums are searched across the whole array or, if mask is not an empty array, in the specified array region. -The functions do not work with multi-channel arrays. If you need to find minimum or maximum +The function do not work with multi-channel arrays. If you need to find minimum or maximum elements across all the channels, use Mat::reshape first to reinterpret the array as single-channel. Or you may extract the particular channel using either extractImageCOI , or mixChannels , or split . @@ -785,7 +821,7 @@ CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal, /** @brief Finds the global minimum and maximum in an array -The function minMaxIdx finds the minimum and maximum element values and their positions. The +The function cv::minMaxIdx finds the minimum and maximum element values and their positions. The extremums are searched across the whole array or, if mask is not an empty array, in the specified array region. The function does not work with multi-channel arrays. If you need to find minimum or maximum elements across all the channels, use Mat::reshape first to reinterpret the array as @@ -823,12 +859,19 @@ CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal, /** @brief Reduces a matrix to a vector. -The function reduce reduces the matrix to a vector by treating the matrix rows/columns as a set of +The function cv::reduce reduces the matrix to a vector by treating the matrix rows/columns as a set of 1D vectors and performing the specified operation on the vectors until a single row/column is obtained. For example, the function can be used to compute horizontal and vertical projections of a -raster image. In case of REDUCE_SUM and REDUCE_AVG , the output may have a larger element -bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction -modes. +raster image. In case of REDUCE_MAX and REDUCE_MIN , the output image should have the same type as the source one. +In case of REDUCE_SUM and REDUCE_AVG , the output may have a larger element bit-depth to preserve accuracy. +And multi-channel arrays are also supported in these two reduction modes. + +The following code demonstrates its usage for a single channel matrix. +@snippet snippets/core_reduce.cpp example + +And the following code demonstrates its usage for a two-channel matrix. +@snippet snippets/core_reduce.cpp example2 + @param src input 2D matrix. @param dst output vector. Its size and type is defined by dim and dtype parameters. @param dim dimension index along which the matrix is reduced. 0 means that the matrix is reduced to @@ -842,12 +885,16 @@ CV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, in /** @brief Creates one multi-channel array out of several single-channel ones. -The function merge merges several arrays to make a single multi-channel array. That is, each +The function cv::merge merges several arrays to make a single multi-channel array. That is, each element of the output array will be a concatenation of the elements of the input arrays, where elements of i-th input array are treated as mv[i].channels()-element vectors. The function cv::split does the reverse operation. If you need to shuffle channels in some other advanced way, use cv::mixChannels. + +The following example shows how to merge 3 single channel matrices into a single 3-channel matrix. +@snippet snippets/core_merge.cpp example + @param mv input array of matrices to be merged; all the matrices in mv must have the same size and the same depth. @param count number of input matrices when mv is a plain C array; it must be greater than zero. @@ -867,10 +914,14 @@ CV_EXPORTS_W void merge(InputArrayOfArrays mv, OutputArray dst); /** @brief Divides a multi-channel array into several single-channel arrays. -The functions split split a multi-channel array into separate single-channel arrays: +The function cv::split splits a multi-channel array into separate single-channel arrays: \f[\texttt{mv} [c](I) = \texttt{src} (I)_c\f] If you need to extract a single channel or do some other sophisticated channel permutation, use mixChannels . + +The following example demonstrates how to split a 3-channel matrix into 3 single channel matrices. +@snippet snippets/core_split.cpp example + @param src input multi-channel array. @param mvbegin output array; the number of arrays must match src.channels(); the arrays themselves are reallocated, if needed. @@ -889,7 +940,7 @@ output arrays. The function cv::mixChannels provides an advanced mechanism for shuffling image channels. -cv::split and cv::merge and some forms of cv::cvtColor are partial cases of cv::mixChannels . +cv::split,cv::merge,cv::extractChannel,cv::insertChannel and some forms of cv::cvtColor are partial cases of cv::mixChannels. In the example below, the code splits a 4-channel BGRA image into a 3-channel BGR (with B and R channels swapped) and a separate alpha-channel image: @@ -923,7 +974,7 @@ src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is filled with zero . @param npairs number of index pairs in `fromTo`. -@sa cv::split, cv::merge, cv::cvtColor +@sa split, merge, extractChannel, insertChannel, cvtColor */ CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, const int* fromTo, size_t npairs); @@ -961,19 +1012,25 @@ filled with zero . CV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst, const std::vector& fromTo); -/** @brief extracts a single channel from src (coi is 0-based index) -@todo document +/** @brief Extracts a single channel from src (coi is 0-based index) +@param src input array +@param dst output array +@param coi index of channel to extract +@sa mixChannels, split */ CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi); -/** @brief inserts a single channel to dst (coi is 0-based index) -@todo document +/** @brief Inserts a single channel to dst (coi is 0-based index) +@param src input array +@param dst output array +@param coi index of channel for insertion +@sa mixChannels, merge */ CV_EXPORTS_W void insertChannel(InputArray src, InputOutputArray dst, int coi); /** @brief Flips a 2D array around vertical, horizontal, or both axes. -The function flip flips the array in one of three different ways (row +The function cv::flip flips the array in one of three different ways (row and column indices are 0-based): \f[\texttt{dst} _{ij} = \left\{ @@ -1005,26 +1062,44 @@ around both axes. */ CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode); +enum RotateFlags { + ROTATE_90_CLOCKWISE = 0, //Rotate 90 degrees clockwise + ROTATE_180 = 1, //Rotate 180 degrees clockwise + ROTATE_90_COUNTERCLOCKWISE = 2, //Rotate 270 degrees clockwise +}; +/** @brief Rotates a 2D array in multiples of 90 degrees. +The function rotate rotates the array in one of three different ways: +* Rotate by 90 degrees clockwise (rotateCode = ROTATE_90). +* Rotate by 180 degrees clockwise (rotateCode = ROTATE_180). +* Rotate by 270 degrees clockwise (rotateCode = ROTATE_270). +@param src input array. +@param dst output array of the same type as src. The size is the same with ROTATE_180, +and the rows and cols are switched for ROTATE_90 and ROTATE_270. +@param rotateCode an enum to specify how to rotate the array; see the enum RotateFlags +@sa transpose , repeat , completeSymm, flip, RotateFlags +*/ +CV_EXPORTS_W void rotate(InputArray src, OutputArray dst, int rotateCode); + /** @brief Fills the output array with repeated copies of the input array. -The functions repeat duplicate the input array one or more times along each of the two axes: +The function cv::repeat duplicates the input array one or more times along each of the two axes: \f[\texttt{dst} _{ij}= \texttt{src} _{i\mod src.rows, \; j\mod src.cols }\f] The second variant of the function is more convenient to use with @ref MatrixExpressions. @param src input array to replicate. -@param dst output array of the same type as src. -@param ny Flag to specify how many times the src is repeated along the +@param ny Flag to specify how many times the `src` is repeated along the vertical axis. -@param nx Flag to specify how many times the src is repeated along the +@param nx Flag to specify how many times the `src` is repeated along the horizontal axis. -@sa reduce +@param dst output array of the same type as `src`. +@sa cv::reduce */ CV_EXPORTS_W void repeat(InputArray src, int ny, int nx, OutputArray dst); /** @overload @param src input array to replicate. -@param ny Flag to specify how many times the src is repeated along the +@param ny Flag to specify how many times the `src` is repeated along the vertical axis. -@param nx Flag to specify how many times the src is repeated along the +@param nx Flag to specify how many times the `src` is repeated along the horizontal axis. */ CV_EXPORTS Mat repeat(const Mat& src, int ny, int nx); @@ -1160,7 +1235,7 @@ CV_EXPORTS_W void vconcat(InputArrayOfArrays src, OutputArray dst); Calculates the per-element bit-wise conjunction of two arrays or an array and a scalar. -The function calculates the per-element bit-wise logical conjunction for: +The function cv::bitwise_and calculates the per-element bit-wise logical conjunction for: * Two arrays when src1 and src2 have the same size: \f[\texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] * An array and a scalar when src2 is constructed from Scalar or has @@ -1187,7 +1262,7 @@ CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2, /** @brief Calculates the per-element bit-wise disjunction of two arrays or an array and a scalar. -The function calculates the per-element bit-wise logical disjunction for: +The function cv::bitwise_or calculates the per-element bit-wise logical disjunction for: * Two arrays when src1 and src2 have the same size: \f[\texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] * An array and a scalar when src2 is constructed from Scalar or has @@ -1214,7 +1289,7 @@ CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, /** @brief Calculates the per-element bit-wise "exclusive or" operation on two arrays or an array and a scalar. -The function calculates the per-element bit-wise logical "exclusive-or" +The function cv::bitwise_xor calculates the per-element bit-wise logical "exclusive-or" operation for: * Two arrays when src1 and src2 have the same size: \f[\texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] @@ -1241,7 +1316,7 @@ CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2, /** @brief Inverts every bit of an array. -The function calculates per-element bit-wise inversion of the input +The function cv::bitwise_not calculates per-element bit-wise inversion of the input array: \f[\texttt{dst} (I) = \neg \texttt{src} (I)\f] In case of a floating-point input array, its machine-specific bit @@ -1258,7 +1333,7 @@ CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst, /** @brief Calculates the per-element absolute difference between two arrays or between an array and a scalar. -The function absdiff calculates: +The function cv::absdiff calculates: * Absolute difference between two arrays when they have the same size and type: \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2}(I)|)\f] @@ -1333,7 +1408,7 @@ CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int /** @brief Calculates per-element minimum of two arrays or an array and a scalar. -The functions min calculate the per-element minimum of two arrays: +The function cv::min calculates the per-element minimum of two arrays: \f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{src2} (I))\f] or array and a scalar: \f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{value} )\f] @@ -1354,7 +1429,7 @@ CV_EXPORTS void min(const UMat& src1, const UMat& src2, UMat& dst); /** @brief Calculates per-element maximum of two arrays or an array and a scalar. -The functions max calculate the per-element maximum of two arrays: +The function cv::max calculates the per-element maximum of two arrays: \f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{src2} (I))\f] or array and a scalar: \f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{value} )\f] @@ -1375,7 +1450,7 @@ CV_EXPORTS void max(const UMat& src1, const UMat& src2, UMat& dst); /** @brief Calculates a square root of array elements. -The functions sqrt calculate a square root of each input array element. +The function cv::sqrt calculates a square root of each input array element. In case of multi-channel arrays, each channel is processed independently. The accuracy is approximately the same as of the built-in std::sqrt . @@ -1386,7 +1461,7 @@ CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst); /** @brief Raises every array element to a power. -The function pow raises every element of the input array to power : +The function cv::pow raises every element of the input array to power : \f[\texttt{dst} (I) = \fork{\texttt{src}(I)^{power}}{if \(\texttt{power}\) is integer}{|\texttt{src}(I)|^{power}}{otherwise}\f] So, for a non-integer power exponent, the absolute values of input array @@ -1411,7 +1486,7 @@ CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst); /** @brief Calculates the exponent of every array element. -The function exp calculates the exponent of every element of the input +The function cv::exp calculates the exponent of every element of the input array: \f[\texttt{dst} [I] = e^{ src(I) }\f] @@ -1427,14 +1502,11 @@ CV_EXPORTS_W void exp(InputArray src, OutputArray dst); /** @brief Calculates the natural logarithm of every array element. -The function log calculates the natural logarithm of the absolute value -of every element of the input array: -\f[\texttt{dst} (I) = \fork{\log |\texttt{src}(I)|}{if \(\texttt{src}(I) \ne 0\) }{\texttt{C}}{otherwise}\f] +The function cv::log calculates the natural logarithm of every element of the input array: +\f[\texttt{dst} (I) = \log (\texttt{src}(I)) \f] + +Output on zero, negative and special (NaN, Inf) values is undefined. -where C is a large negative number (about -700 in the current -implementation). The maximum relative error is about 7e-6 for -single-precision input and less than 1e-10 for double-precision input. -Special values (NaN, Inf) are not handled. @param src input array. @param dst output array of the same size and type as src . @sa exp, cartToPolar, polarToCart, phase, pow, sqrt, magnitude @@ -1443,7 +1515,7 @@ CV_EXPORTS_W void log(InputArray src, OutputArray dst); /** @brief Calculates x and y coordinates of 2D vectors from their magnitude and angle. -The function polarToCart calculates the Cartesian coordinates of each 2D +The function cv::polarToCart calculates the Cartesian coordinates of each 2D vector represented by the corresponding elements of magnitude and angle: \f[\begin{array}{l} \texttt{x} (I) = \texttt{magnitude} (I) \cos ( \texttt{angle} (I)) \\ \texttt{y} (I) = \texttt{magnitude} (I) \sin ( \texttt{angle} (I)) \\ \end{array}\f] @@ -1466,7 +1538,7 @@ CV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle, /** @brief Calculates the magnitude and angle of 2D vectors. -The function cartToPolar calculates either the magnitude, angle, or both +The function cv::cartToPolar calculates either the magnitude, angle, or both for every 2D vector (x(I),y(I)): \f[\begin{array}{l} \texttt{magnitude} (I)= \sqrt{\texttt{x}(I)^2+\texttt{y}(I)^2} , \\ \texttt{angle} (I)= \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))[ \cdot180 / \pi ] \end{array}\f] @@ -1488,7 +1560,7 @@ CV_EXPORTS_W void cartToPolar(InputArray x, InputArray y, /** @brief Calculates the rotation angle of 2D vectors. -The function phase calculates the rotation angle of each 2D vector that +The function cv::phase calculates the rotation angle of each 2D vector that is formed from the corresponding elements of x and y : \f[\texttt{angle} (I) = \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))\f] @@ -1507,7 +1579,7 @@ CV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle, /** @brief Calculates the magnitude of 2D vectors. -The function magnitude calculates the magnitude of 2D vectors formed +The function cv::magnitude calculates the magnitude of 2D vectors formed from the corresponding elements of x and y arrays: \f[\texttt{dst} (I) = \sqrt{\texttt{x}(I)^2 + \texttt{y}(I)^2}\f] @param x floating-point array of x-coordinates of the vectors. @@ -1520,11 +1592,11 @@ CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude); /** @brief Checks every element of an input array for invalid values. -The functions checkRange check that every array element is neither NaN nor infinite. When minVal \> --DBL_MAX and maxVal \< DBL_MAX, the functions also check that each value is between minVal and +The function cv::checkRange checks that every array element is neither NaN nor infinite. When minVal \> +-DBL_MAX and maxVal \< DBL_MAX, the function also checks that each value is between minVal and maxVal. In case of multi-channel arrays, each channel is processed independently. If some values are out of range, position of the first outlier is stored in pos (when pos != NULL). Then, the -functions either return false (when quiet=true) or throw an exception. +function either returns false (when quiet=true) or throws an exception. @param a input array. @param quiet a flag, indicating whether the functions quietly return false when the array elements are out of range or they throw an exception. @@ -1542,7 +1614,7 @@ CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val = 0); /** @brief Performs generalized matrix multiplication. -The function performs generalized matrix multiplication similar to the +The function cv::gemm performs generalized matrix multiplication similar to the gemm functions in BLAS level 3. For example, `gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T)` corresponds to @@ -1573,7 +1645,7 @@ CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha, /** @brief Calculates the product of a matrix and its transposition. -The function mulTransposed calculates the product of src and its +The function cv::mulTransposed calculates the product of src and its transposition: \f[\texttt{dst} = \texttt{scale} ( \texttt{src} - \texttt{delta} )^T ( \texttt{src} - \texttt{delta} )\f] if aTa=true , and @@ -1605,9 +1677,9 @@ CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa, /** @brief Transposes a matrix. -The function transpose transposes the matrix src : +The function cv::transpose transposes the matrix src : \f[\texttt{dst} (i,j) = \texttt{src} (j,i)\f] -@note No complex conjugation is done in case of a complex matrix. It it +@note No complex conjugation is done in case of a complex matrix. It should be done separately if needed. @param src input array. @param dst output array of the same type as src. @@ -1616,7 +1688,7 @@ CV_EXPORTS_W void transpose(InputArray src, OutputArray dst); /** @brief Performs the matrix transformation of every array element. -The function transform performs the matrix transformation of every +The function cv::transform performs the matrix transformation of every element of the array src and stores the results in dst : \f[\texttt{dst} (I) = \texttt{m} \cdot \texttt{src} (I)\f] (when m.cols=src.channels() ), or @@ -1636,13 +1708,13 @@ m.cols or m.cols-1. @param dst output array of the same size and depth as src; it has as many channels as m.rows. @param m transformation 2x2 or 2x3 floating-point matrix. -@sa perspectiveTransform, getAffineTransform, estimateRigidTransform, warpAffine, warpPerspective +@sa perspectiveTransform, getAffineTransform, estimateAffine2D, warpAffine, warpPerspective */ CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m ); /** @brief Performs the perspective matrix transformation of vectors. -The function perspectiveTransform transforms every element of src by +The function cv::perspectiveTransform transforms every element of src by treating it as a 2D or 3D vector, in the following way: \f[(x, y, z) \rightarrow (x'/w, y'/w, z'/w)\f] where @@ -1669,7 +1741,7 @@ CV_EXPORTS_W void perspectiveTransform(InputArray src, OutputArray dst, InputArr /** @brief Copies the lower or the upper half of a square matrix to another half. -The function completeSymm copies the lower half of a square matrix to +The function cv::completeSymm copies the lower half of a square matrix to its another half. The matrix diagonal remains unchanged: * \f$\texttt{mtx}_{ij}=\texttt{mtx}_{ji}\f$ for \f$i > j\f$ if lowerToUpper=false @@ -1684,7 +1756,7 @@ CV_EXPORTS_W void completeSymm(InputOutputArray mtx, bool lowerToUpper = false); /** @brief Initializes a scaled identity matrix. -The function setIdentity initializes a scaled identity matrix: +The function cv::setIdentity initializes a scaled identity matrix: \f[\texttt{mtx} (i,j)= \fork{\texttt{value}}{ if \(i=j\)}{0}{otherwise}\f] The function can also be emulated using the matrix initializers and the @@ -1701,7 +1773,7 @@ CV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s = Scalar(1)) /** @brief Returns the determinant of a square floating-point matrix. -The function determinant calculates and returns the determinant of the +The function cv::determinant calculates and returns the determinant of the specified matrix. For small matrices ( mtx.cols=mtx.rows\<=3 ), the direct method is used. For larger matrices, the function uses LU factorization with partial pivoting. @@ -1716,7 +1788,7 @@ CV_EXPORTS_W double determinant(InputArray mtx); /** @brief Returns the trace of a matrix. -The function trace returns the sum of the diagonal elements of the +The function cv::trace returns the sum of the diagonal elements of the matrix mtx . \f[\mathrm{tr} ( \texttt{mtx} ) = \sum _i \texttt{mtx} (i,i)\f] @param mtx input matrix. @@ -1725,7 +1797,7 @@ CV_EXPORTS_W Scalar trace(InputArray mtx); /** @brief Finds the inverse or pseudo-inverse of a matrix. -The function invert inverts the matrix src and stores the result in dst +The function cv::invert inverts the matrix src and stores the result in dst . When the matrix src is singular or non-square, the function calculates the pseudo-inverse matrix (the dst matrix) so that norm(src\*dst - I) is minimal, where I is an identity matrix. @@ -1752,7 +1824,7 @@ CV_EXPORTS_W double invert(InputArray src, OutputArray dst, int flags = DECOMP_L /** @brief Solves one or more linear systems or least-squares problems. -The function solve solves a linear system or least-squares problem (the +The function cv::solve solves a linear system or least-squares problem (the latter is possible with SVD or QR methods, or by specifying the flag DECOMP_NORMAL ): \f[\texttt{dst} = \arg \min _X \| \texttt{src1} \cdot \texttt{X} - \texttt{src2} \|\f] @@ -1777,7 +1849,7 @@ CV_EXPORTS_W bool solve(InputArray src1, InputArray src2, /** @brief Sorts each row or each column of a matrix. -The function sort sorts each matrix row or each matrix column in +The function cv::sort sorts each matrix row or each matrix column in ascending or descending order. So you should pass two operation flags to get desired behaviour. If you want to sort matrix rows or columns lexicographically, you can use STL std::sort generic function with the @@ -1792,7 +1864,7 @@ CV_EXPORTS_W void sort(InputArray src, OutputArray dst, int flags); /** @brief Sorts each row or each column of a matrix. -The function sortIdx sorts each matrix row or each matrix column in the +The function cv::sortIdx sorts each matrix row or each matrix column in the ascending or descending order. So you should pass two operation flags to get desired behaviour. Instead of reordering the elements themselves, it stores the indices of sorted elements in the output array. For example: @@ -1826,7 +1898,7 @@ CV_EXPORTS_W int solveCubic(InputArray coeffs, OutputArray roots); /** @brief Finds the real or complex roots of a polynomial equation. -The function solvePoly finds real and complex roots of a polynomial equation: +The function cv::solvePoly finds real and complex roots of a polynomial equation: \f[\texttt{coeffs} [n] x^{n} + \texttt{coeffs} [n-1] x^{n-1} + ... + \texttt{coeffs} [1] x + \texttt{coeffs} [0] = 0\f] @param coeffs array of polynomial coefficients. @param roots output (complex) array of roots. @@ -1836,13 +1908,14 @@ CV_EXPORTS_W double solvePoly(InputArray coeffs, OutputArray roots, int maxIters /** @brief Calculates eigenvalues and eigenvectors of a symmetric matrix. -The functions eigen calculate just eigenvalues, or eigenvalues and eigenvectors of the symmetric +The function cv::eigen calculates just eigenvalues, or eigenvalues and eigenvectors of the symmetric matrix src: @code src*eigenvectors.row(i).t() = eigenvalues.at(i)*eigenvectors.row(i).t() @endcode -@note in the new and the old interfaces different ordering of eigenvalues and eigenvectors -parameters is used. + +@note Use cv::eigenNonSymmetric for calculation of real eigenvalues and eigenvectors of non-symmetric matrix. + @param src input matrix that must have CV_32FC1 or CV_64FC1 type, square size and be symmetrical (src ^T^ == src). @param eigenvalues output vector of eigenvalues of the same type as src; the eigenvalues are stored @@ -1850,14 +1923,31 @@ in the descending order. @param eigenvectors output matrix of eigenvectors; it has the same size and type as src; the eigenvectors are stored as subsequent matrix rows, in the same order as the corresponding eigenvalues. -@sa completeSymm , PCA +@sa eigenNonSymmetric, completeSymm , PCA */ CV_EXPORTS_W bool eigen(InputArray src, OutputArray eigenvalues, OutputArray eigenvectors = noArray()); +/** @brief Calculates eigenvalues and eigenvectors of a non-symmetric matrix (real eigenvalues only). + +@note Assumes real eigenvalues. + +The function calculates eigenvalues and eigenvectors (optional) of the square matrix src: +@code + src*eigenvectors.row(i).t() = eigenvalues.at(i)*eigenvectors.row(i).t() +@endcode + +@param src input matrix (CV_32FC1 or CV_64FC1 type). +@param eigenvalues output vector of eigenvalues (type is the same type as src). +@param eigenvectors output matrix of eigenvectors (type is the same type as src). The eigenvectors are stored as subsequent matrix rows, in the same order as the corresponding eigenvalues. +@sa eigen +*/ +CV_EXPORTS_W void eigenNonSymmetric(InputArray src, OutputArray eigenvalues, + OutputArray eigenvectors); + /** @brief Calculates the covariance matrix of a set of vectors. -The functions calcCovarMatrix calculate the covariance matrix and, optionally, the mean vector of +The function cv::calcCovarMatrix calculates the covariance matrix and, optionally, the mean vector of the set of input vectors. @param samples samples stored as separate matrices @param nsamples number of samples @@ -1907,7 +1997,7 @@ CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt, /** @brief Calculates the Mahalanobis distance between two vectors. -The function Mahalanobis calculates and returns the weighted distance between two vectors: +The function cv::Mahalanobis calculates and returns the weighted distance between two vectors: \f[d( \texttt{vec1} , \texttt{vec2} )= \sqrt{\sum_{i,j}{\texttt{icovar(i,j)}\cdot(\texttt{vec1}(I)-\texttt{vec2}(I))\cdot(\texttt{vec1(j)}-\texttt{vec2(j)})} }\f] The covariance matrix may be calculated using the cv::calcCovarMatrix function and then inverted using the invert function (preferably using the cv::DECOMP_SVD method, as the most accurate). @@ -1919,7 +2009,7 @@ CV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar) /** @brief Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floating-point array. -The function performs one of the following: +The function cv::dft performs one of the following: - Forward the Fourier transform of a 1D vector of N elements: \f[Y = F^{(N)} \cdot X,\f] where \f$F^{(N)}_{jk}=\exp(-2\pi i j k/N)\f$ and \f$i=\sqrt{-1}\f$ @@ -2067,7 +2157,7 @@ CV_EXPORTS_W void idft(InputArray src, OutputArray dst, int flags = 0, int nonze /** @brief Performs a forward or inverse discrete Cosine transform of 1D or 2D array. -The function dct performs a forward or inverse discrete Cosine transform (DCT) of a 1D or 2D +The function cv::dct performs a forward or inverse discrete Cosine transform (DCT) of a 1D or 2D floating-point array: - Forward Cosine transform of a 1D vector of N elements: \f[Y = C^{(N)} \cdot X\f] @@ -2118,7 +2208,7 @@ CV_EXPORTS_W void idct(InputArray src, OutputArray dst, int flags = 0); /** @brief Performs the per-element multiplication of two Fourier spectrums. -The function mulSpectrums performs the per-element multiplication of the two CCS-packed or complex +The function cv::mulSpectrums performs the per-element multiplication of the two CCS-packed or complex matrices that are results of a real or complex Fourier transform. The function, together with dft and idft , may be used to calculate convolution (pass conjB=false ) @@ -2145,7 +2235,7 @@ original one. Arrays whose size is a power-of-two (2, 4, 8, 16, 32, ...) are the Though, the arrays whose size is a product of 2's, 3's, and 5's (for example, 300 = 5\*5\*3\*2\*2) are also processed quite efficiently. -The function getOptimalDFTSize returns the minimum number N that is greater than or equal to vecsize +The function cv::getOptimalDFTSize returns the minimum number N that is greater than or equal to vecsize so that the DFT of a vector of size N can be processed efficiently. In the current implementation N = 2 ^p^ \* 3 ^q^ \* 5 ^r^ for some integer p, q, r. @@ -2161,7 +2251,7 @@ CV_EXPORTS_W int getOptimalDFTSize(int vecsize); /** @brief Returns the default random number generator. -The function theRNG returns the default random number generator. For each thread, there is a +The function cv::theRNG returns the default random number generator. For each thread, there is a separate random number generator, so you can use the function safely in multi-thread environments. If you just need to get a single random number using this generator or initialize an array, you can use randu or randn instead. But if you are going to generate many random numbers inside a loop, it @@ -2170,6 +2260,14 @@ is much faster to use this function to retrieve the generator and then use RNG:: */ CV_EXPORTS RNG& theRNG(); +/** @brief Sets state of default random number generator. + +The function cv::setRNGSeed sets state of default random number generator to custom value. +@param seed new state for default random number generator +@sa RNG, randu, randn +*/ +CV_EXPORTS_W void setRNGSeed(int seed); + /** @brief Generates a single uniformly-distributed random number or an array of random numbers. Non-template variant of the function fills the matrix dst with uniformly-distributed @@ -2184,7 +2282,7 @@ CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high); /** @brief Fills the array with normally distributed random numbers. -The function randn fills the matrix dst with normally distributed random numbers with the specified +The function cv::randn fills the matrix dst with normally distributed random numbers with the specified mean vector and the standard deviation matrix. The generated random numbers are clipped to fit the value range of the output array data type. @param dst output array of random numbers; the array must be pre-allocated and have 1 to 4 channels. @@ -2197,7 +2295,7 @@ CV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev /** @brief Shuffles the array elements randomly. -The function randShuffle shuffles the specified 1D array by randomly choosing pairs of elements and +The function cv::randShuffle shuffles the specified 1D array by randomly choosing pairs of elements and swapping them. The number of such swap operations will be dst.rows\*dst.cols\*iterFactor . @param dst input/output numerical 1D array. @param iterFactor scale factor that determines the number of random swap operations (see the details @@ -2316,11 +2414,11 @@ public: The operator performs %PCA of the supplied dataset. It is safe to reuse the same PCA structure for multiple datasets. That is, if the structure has been previously used with another dataset, the existing internal - data is reclaimed and the new eigenvalues, @ref eigenvectors , and @ref + data is reclaimed and the new @ref eigenvalues, @ref eigenvectors and @ref mean are allocated and computed. - The computed eigenvalues are sorted from the largest to the smallest and - the corresponding eigenvectors are stored as eigenvectors rows. + The computed @ref eigenvalues are sorted from the largest to the smallest and + the corresponding @ref eigenvectors are stored as eigenvectors rows. @param data input samples stored as the matrix rows or as the matrix columns. @@ -2400,11 +2498,17 @@ public: */ void backProject(InputArray vec, OutputArray result) const; - /** @brief write and load PCA matrix + /** @brief write PCA objects -*/ - void write(FileStorage& fs ) const; - void read(const FileNode& fs); + Writes @ref eigenvalues @ref eigenvectors and @ref mean to specified FileStorage + */ + void write(FileStorage& fs) const; + + /** @brief load PCA objects + + Loads @ref eigenvalues @ref eigenvectors and @ref mean from specified FileNode + */ + void read(const FileNode& fn); Mat eigenvectors; //!< eigenvectors of the covariation matrix Mat eigenvalues; //!< eigenvalues of the covariation matrix @@ -2716,7 +2820,7 @@ public: double a1 = rng.uniform((double)0, (double)1); // produces float from [0, 1) - double b = rng.uniform(0.f, 1.f); + float b = rng.uniform(0.f, 1.f); // produces double from [0, 1) double c = rng.uniform(0., 1.); @@ -2732,8 +2836,8 @@ public: want a floating-point random number, but the range boundaries are integer numbers, either put dots in the end, if they are constants, or use explicit type cast operators, as in the a1 initialization above. - @param a lower inclusive boundary of the returned random numbers. - @param b upper non-inclusive boundary of the returned random numbers. + @param a lower inclusive boundary of the returned random number. + @param b upper non-inclusive boundary of the returned random number. */ int uniform(int a, int b); /** @overload */ @@ -2788,6 +2892,8 @@ public: double gaussian(double sigma); uint64 state; + + bool operator ==(const RNG& other) const; }; /** @brief Mersenne Twister random number generator @@ -2987,19 +3093,25 @@ public: */ virtual void write(FileStorage& fs) const { (void)fs; } + /** @brief simplified API for language bindings + * @overload + */ + CV_WRAP void write(const Ptr& fs, const String& name = String()) const; + /** @brief Reads algorithm parameters from a file storage */ - virtual void read(const FileNode& fn) { (void)fn; } + CV_WRAP virtual void read(const FileNode& fn) { (void)fn; } /** @brief Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read */ - virtual bool empty() const { return false; } + CV_WRAP virtual bool empty() const { return false; } /** @brief Reads algorithm from the file node This is static template method of Algorithm. It's usage is following (in the case of SVM): @code - Ptr svm = Algorithm::read(fn); + cv::FileStorage fsRead("example.xml", FileStorage::READ); + Ptr svm = Algorithm::read(fsRead.root()); @endcode In order to make this method work, the derived class must overwrite Algorithm::read(const FileNode& fn) and also have static create() method without parameters @@ -3027,7 +3139,9 @@ public: template static Ptr<_Tp> load(const String& filename, const String& objname=String()) { FileStorage fs(filename, FileStorage::READ); + CV_Assert(fs.isOpened()); FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]; + if (fn.empty()) return Ptr<_Tp>(); Ptr<_Tp> obj = _Tp::create(); obj->read(fn); return !obj->empty() ? obj : Ptr<_Tp>(); @@ -3059,6 +3173,9 @@ public: /** Returns the algorithm string identifier. This string is used as top level xml/yml node tag when the object is saved to a file or string. */ CV_WRAP virtual String getDefaultName() const; + +protected: + void writeFormat(FileStorage& fs) const; }; struct Param { @@ -3164,5 +3281,6 @@ template<> struct ParamType #include "opencv2/core/cvstd.inl.hpp" #include "opencv2/core/utility.hpp" #include "opencv2/core/optim.hpp" +#include "opencv2/core/ovx.hpp" -#endif /*__OPENCV_CORE_HPP__*/ +#endif /*OPENCV_CORE_HPP*/ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/affine.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/affine.hpp similarity index 91% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/affine.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/affine.hpp index 2bce5b98..443097a5 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/affine.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/affine.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_CORE_AFFINE3_HPP__ -#define __OPENCV_CORE_AFFINE3_HPP__ +#ifndef OPENCV_CORE_AFFINE3_HPP +#define OPENCV_CORE_AFFINE3_HPP #ifdef __cplusplus @@ -153,15 +153,24 @@ namespace cv typedef _Tp channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 16, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; + namespace traits { + template + struct Depth< Affine3<_Tp> > { enum { value = Depth<_Tp>::value }; }; + template + struct Type< Affine3<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 16) }; }; + } // namespace + //! @} core } @@ -202,7 +211,7 @@ cv::Affine3::Affine3(const Vec3& _rvec, const Vec3& t) template inline cv::Affine3::Affine3(const cv::Mat& data, const Vec3& t) { - CV_Assert(data.type() == cv::DataType::type); + CV_Assert(data.type() == cv::traits::Type::value); if (data.cols == 4 && data.rows == 4) { @@ -213,11 +222,13 @@ cv::Affine3::Affine3(const cv::Mat& data, const Vec3& t) { rotation(data(Rect(0, 0, 3, 3))); translation(data(Rect(3, 0, 1, 3))); - return; + } + else + { + rotation(data); + translation(t); } - rotation(data); - translation(t); matrix.val[12] = matrix.val[13] = matrix.val[14] = 0; matrix.val[15] = 1; } @@ -241,30 +252,25 @@ void cv::Affine3::rotation(const Mat3& R) template inline void cv::Affine3::rotation(const Vec3& _rvec) { - double rx = _rvec[0], ry = _rvec[1], rz = _rvec[2]; - double theta = std::sqrt(rx*rx + ry*ry + rz*rz); + double theta = norm(_rvec); if (theta < DBL_EPSILON) rotation(Mat3::eye()); else { - const double I[] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; - double c = std::cos(theta); double s = std::sin(theta); double c1 = 1. - c; double itheta = (theta != 0) ? 1./theta : 0.; - rx *= itheta; ry *= itheta; rz *= itheta; + Point3_ r = _rvec*itheta; - double rrt[] = { rx*rx, rx*ry, rx*rz, rx*ry, ry*ry, ry*rz, rx*rz, ry*rz, rz*rz }; - double _r_x_[] = { 0, -rz, ry, rz, 0, -rx, -ry, rx, 0 }; - Mat3 R; + Mat3 rrt( r.x*r.x, r.x*r.y, r.x*r.z, r.x*r.y, r.y*r.y, r.y*r.z, r.x*r.z, r.y*r.z, r.z*r.z ); + Mat3 r_x( 0, -r.z, r.y, r.z, 0, -r.x, -r.y, r.x, 0 ); // R = cos(theta)*I + (1 - cos(theta))*r*rT + sin(theta)*[r_x] // where [r_x] is [0 -rz ry; rz 0 -rx; -ry rx 0] - for(int k = 0; k < 9; ++k) - R.val[k] = static_cast(c*I[k] + c1*rrt[k] + s*_r_x_[k]); + Mat3 R = c*Mat3::eye() + c1*rrt + s*r_x; rotation(R); } @@ -274,7 +280,7 @@ void cv::Affine3::rotation(const Vec3& _rvec) template inline void cv::Affine3::rotation(const cv::Mat& data) { - CV_Assert(data.type() == cv::DataType::type); + CV_Assert(data.type() == cv::traits::Type::value); if (data.cols == 3 && data.rows == 3) { @@ -488,21 +494,21 @@ cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v) template inline cv::Affine3::Affine3(const Eigen::Transform& affine) { - cv::Mat(4, 4, cv::DataType::type, affine.matrix().data()).copyTo(matrix); + cv::Mat(4, 4, cv::traits::Type::value, affine.matrix().data()).copyTo(matrix); } template inline cv::Affine3::Affine3(const Eigen::Transform& affine) { Eigen::Transform a = affine; - cv::Mat(4, 4, cv::DataType::type, a.matrix().data()).copyTo(matrix); + cv::Mat(4, 4, cv::traits::Type::value, a.matrix().data()).copyTo(matrix); } template inline cv::Affine3::operator Eigen::Transform() const { Eigen::Transform r; - cv::Mat hdr(4, 4, cv::DataType::type, r.matrix().data()); + cv::Mat hdr(4, 4, cv::traits::Type::value, r.matrix().data()); cv::Mat(matrix, false).copyTo(hdr); return r; } @@ -519,4 +525,4 @@ cv::Affine3::operator Eigen::Transform() const #endif /* __cplusplus */ -#endif /* __OPENCV_CORE_AFFINE3_HPP__ */ +#endif /* OPENCV_CORE_AFFINE3_HPP */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/base.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/base.hpp similarity index 73% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/base.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/base.hpp index ed633f5d..05190927 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/base.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/base.hpp @@ -42,13 +42,15 @@ // //M*/ -#ifndef __OPENCV_CORE_BASE_HPP__ -#define __OPENCV_CORE_BASE_HPP__ +#ifndef OPENCV_CORE_BASE_HPP +#define OPENCV_CORE_BASE_HPP #ifndef __cplusplus # error base.hpp header must be compiled as C++ #endif +#include "opencv2/opencv_modules.hpp" + #include #include @@ -64,38 +66,38 @@ namespace cv namespace Error { //! error codes enum Code { - StsOk= 0, //!< everithing is ok + StsOk= 0, //!< everything is ok StsBackTrace= -1, //!< pseudo error for back trace StsError= -2, //!< unknown /unspecified error StsInternal= -3, //!< internal error (bad state) StsNoMem= -4, //!< insufficient memory StsBadArg= -5, //!< function arg/param is bad StsBadFunc= -6, //!< unsupported function - StsNoConv= -7, //!< iter. didn't converge + StsNoConv= -7, //!< iteration didn't converge StsAutoTrace= -8, //!< tracing HeaderIsNull= -9, //!< image header is NULL BadImageSize= -10, //!< image size is invalid BadOffset= -11, //!< offset is invalid BadDataPtr= -12, //!< - BadStep= -13, //!< + BadStep= -13, //!< image step is wrong, this may happen for a non-continuous matrix. BadModelOrChSeq= -14, //!< - BadNumChannels= -15, //!< + BadNumChannels= -15, //!< bad number of channels, for example, some functions accept only single channel matrices. BadNumChannel1U= -16, //!< - BadDepth= -17, //!< + BadDepth= -17, //!< input image depth is not supported by the function BadAlphaChannel= -18, //!< - BadOrder= -19, //!< - BadOrigin= -20, //!< - BadAlign= -21, //!< + BadOrder= -19, //!< number of dimensions is out of range + BadOrigin= -20, //!< incorrect input origin + BadAlign= -21, //!< incorrect input align BadCallBack= -22, //!< BadTileSize= -23, //!< - BadCOI= -24, //!< - BadROISize= -25, //!< + BadCOI= -24, //!< input COI is not supported + BadROISize= -25, //!< incorrect input roi MaskIsTiled= -26, //!< StsNullPtr= -27, //!< null pointer StsVecLengthErr= -28, //!< incorrect vector length - StsFilterStructContentErr= -29, //!< incorr. filter structure content - StsKernelStructContentErr= -30, //!< incorr. transform kernel content - StsFilterOffsetErr= -31, //!< incorrect filter ofset value + StsFilterStructContentErr= -29, //!< incorrect filter structure content + StsKernelStructContentErr= -30, //!< incorrect transform kernel content + StsFilterOffsetErr= -31, //!< incorrect filter offset value StsBadSize= -201, //!< the input/output structure size is incorrect StsDivByZero= -202, //!< division by zero StsInplaceNotSupported= -203, //!< in-place operation is not supported @@ -111,13 +113,13 @@ enum Code { StsNotImplemented= -213, //!< the requested function/feature is not implemented StsBadMemBlock= -214, //!< an allocated block has been corrupted StsAssert= -215, //!< assertion failed - GpuNotSupported= -216, - GpuApiCallError= -217, - OpenGlNotSupported= -218, - OpenGlApiCallError= -219, - OpenCLApiCallError= -220, + GpuNotSupported= -216, //!< no CUDA support + GpuApiCallError= -217, //!< GPU API call error + OpenGlNotSupported= -218, //!< no OpenGL support + OpenGlApiCallError= -219, //!< OpenGL API call error + OpenCLApiCallError= -220, //!< OpenCL API call error OpenCLDoubleNotSupported= -221, - OpenCLInitError= -222, + OpenCLInitError= -222, //!< OpenCL initialization error OpenCLNoAMDBlasFft= -223 }; } //Error @@ -150,46 +152,57 @@ enum DecompTypes { }; /** norm types -- For one array: -\f[norm = \forkthree{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } -{ \| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) } -{ \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f] -- Absolute norm for two arrays -\f[norm = \forkthree{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } -{ \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) } -{ \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f] +src1 and src2 denote input arrays. +*/ -- Relative norm for two arrays -\f[norm = \forkthree{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE_INF}\) } -{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE_L1}\) } -{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE_L2}\) }\f] - -As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$. -The \f$ L_{1}, L_{2} \f$ and \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$ -is calculated as follows -\f{align*} - \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\ - \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\ - \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2 -\f} -and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is -\f{align*} - \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\ - \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\ - \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5. -\f} -The following graphic shows all values for the three norm functions \f$\| r(x) \|_{L_1}, \| r(x) \|_{L_2}\f$ and \f$\| r(x) \|_{L_\infty}\f$. -It is notable that the \f$ L_{1} \f$ norm forms the upper and the \f$ L_{\infty} \f$ norm forms the lower border for the example function \f$ r(x) \f$. -![Graphs for the different norm functions from the above example](pics/NormTypes_OneArray_1-2-INF.png) - */ -enum NormTypes { NORM_INF = 1, +enum NormTypes { + /** + \f[ + norm = \forkthree + {\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } + {\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } + {\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_INF}\) } + \f] + */ + NORM_INF = 1, + /** + \f[ + norm = \forkthree + {\| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\)} + { \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) } + { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L1}\) } + \f]*/ NORM_L1 = 2, + /** + \f[ + norm = \forkthree + { \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) } + { \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) } + { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) } + \f] + */ NORM_L2 = 4, + /** + \f[ + norm = \forkthree + { \| \texttt{src1} \| _{L_2} ^{2} = \sum_I \texttt{src1}(I)^2} {if \(\texttt{normType} = \texttt{NORM_L2SQR}\)} + { \| \texttt{src1} - \texttt{src2} \| _{L_2} ^{2} = \sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2 }{if \(\texttt{normType} = \texttt{NORM_L2SQR}\) } + { \left(\frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}}\right)^2 }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) } + \f] + */ NORM_L2SQR = 5, + /** + In the case of one input array, calculates the Hamming distance of the array from zero, + In the case of two input arrays, calculates the Hamming distance between the arrays. + */ NORM_HAMMING = 6, + /** + Similar to NORM_HAMMING, but in the calculation, each two bits of the input sequence will + be added and treated as a single bit to be used in the same calculation as NORM_HAMMING. + */ NORM_HAMMING2 = 7, - NORM_TYPE_MASK = 7, + NORM_TYPE_MASK = 7, //!< bit-mask which can be used to separate norm type from norm flags NORM_RELATIVE = 8, //!< flag NORM_MINMAX = 32 //!< flag }; @@ -237,6 +250,10 @@ enum DftFlags { into a real array and inverse transformation is executed, the function treats the input as a packed complex-conjugate symmetrical array, and the output will also be a real array). */ DFT_REAL_OUTPUT = 32, + /** specifies that input is complex input. If this flag is set, the input must have 2 channels. + On the other hand, for backwards compatibility reason, if input has 2 channels, input is + already considered complex. */ + DFT_COMPLEX_INPUT = 64, /** performs an inverse 1D or 2D transform instead of the default forward transform. */ DCT_INVERSE = DFT_INVERSE, /** performs a forward or inverse transform of every individual row of the input @@ -325,7 +342,23 @@ enum BorderTypes { #define CV_SUPPRESS_DEPRECATED_START #define CV_SUPPRESS_DEPRECATED_END #endif + #define CV_UNUSED(name) (void)name + +#if defined __GNUC__ && !defined __EXCEPTIONS +#define CV_TRY +#define CV_CATCH(A, B) for (A B; false; ) +#define CV_CATCH_ALL if (false) +#define CV_THROW(A) abort() +#define CV_RETHROW() abort() +#else +#define CV_TRY try +#define CV_CATCH(A, B) catch(const A & B) +#define CV_CATCH_ALL catch(...) +#define CV_THROW(A) throw A +#define CV_RETHROW() throw +#endif + //! @endcond /*! @brief Signals an error and raises the exception. @@ -336,8 +369,8 @@ It is possible to alternate error processing by using redirectError(). @param _code - error code (Error::Code) @param _err - error description @param _func - function name. Available only when the compiler supports getting it -@param _file - source file name where the error has occured -@param _line - line number in the source file where the error has occured +@param _file - source file name where the error has occurred +@param _line - line number in the source file where the error has occurred @see CV_Error, CV_Error_, CV_ErrorNoReturn, CV_ErrorNoReturn_, CV_Assert, CV_DbgAssert */ CV_EXPORTS void error(int _code, const String& _err, const char* _func, const char* _file, int _line); @@ -375,6 +408,17 @@ CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const ch #define CV_Func "" #endif +#ifdef CV_STATIC_ANALYSIS +// In practice, some macro are not processed correctly (noreturn is not detected). +// We need to use simplified definition for them. +#define CV_Error(...) do { abort(); } while (0) +#define CV_Error_(...) do { abort(); } while (0) +#define CV_Assert(cond) do { if (!(cond)) abort(); } while (0) +#define CV_ErrorNoReturn(...) do { abort(); } while (0) +#define CV_ErrorNoReturn_(...) do { abort(); } while (0) + +#else // CV_STATIC_ANALYSIS + /** @brief Call the error handler. Currently, the error handler prints the error code and the error message to the standard @@ -407,7 +451,22 @@ The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release configurations while CV_DbgAssert is only retained in the Debug configuration. */ -#define CV_Assert( expr ) if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ) + +#define CV_VA_NUM_ARGS_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N +#define CV_VA_NUM_ARGS(...) CV_VA_NUM_ARGS_HELPER(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) + +#define CV_Assert_1( expr ) if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ) +#define CV_Assert_2( expr1, expr2 ) CV_Assert_1(expr1); CV_Assert_1(expr2) +#define CV_Assert_3( expr1, expr2, expr3 ) CV_Assert_2(expr1, expr2); CV_Assert_1(expr3) +#define CV_Assert_4( expr1, expr2, expr3, expr4 ) CV_Assert_3(expr1, expr2, expr3); CV_Assert_1(expr4) +#define CV_Assert_5( expr1, expr2, expr3, expr4, expr5 ) CV_Assert_4(expr1, expr2, expr3, expr4); CV_Assert_1(expr5) +#define CV_Assert_6( expr1, expr2, expr3, expr4, expr5, expr6 ) CV_Assert_5(expr1, expr2, expr3, expr4, expr5); CV_Assert_1(expr6) +#define CV_Assert_7( expr1, expr2, expr3, expr4, expr5, expr6, expr7 ) CV_Assert_6(expr1, expr2, expr3, expr4, expr5, expr6 ); CV_Assert_1(expr7) +#define CV_Assert_8( expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8 ) CV_Assert_7(expr1, expr2, expr3, expr4, expr5, expr6, expr7 ); CV_Assert_1(expr8) +#define CV_Assert_9( expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9 ) CV_Assert_8(expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8 ); CV_Assert_1(expr9) +#define CV_Assert_10( expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9, expr10 ) CV_Assert_9(expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9 ); CV_Assert_1(expr10) + +#define CV_Assert(...) CVAUX_CONCAT(CV_Assert_, CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__) /** same as CV_Error(code,msg), but does not return */ #define CV_ErrorNoReturn( code, msg ) cv::errorNoReturn( code, msg, CV_Func, __FILE__, __LINE__ ) @@ -415,6 +474,8 @@ configurations while CV_DbgAssert is only retained in the Debug configuration. /** same as CV_Error_(code,args), but does not return */ #define CV_ErrorNoReturn_( code, args ) cv::errorNoReturn( code, cv::format args, CV_Func, __FILE__, __LINE__ ) +#endif // CV_STATIC_ANALYSIS + /** replaced with CV_Assert(expr) in Debug configuration */ #ifdef _DEBUG # define CV_DbgAssert(expr) CV_Assert(expr) @@ -665,13 +726,23 @@ namespace cudev namespace ipp { -CV_EXPORTS int getIppFeatures(); -CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL, +#if OPENCV_ABI_COMPATIBILITY > 300 +CV_EXPORTS unsigned long long getIppFeatures(); +#else +CV_EXPORTS int getIppFeatures(); +#endif +CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL, int line = 0); -CV_EXPORTS int getIppStatus(); -CV_EXPORTS String getIppErrorLocation(); -CV_EXPORTS bool useIPP(); -CV_EXPORTS void setUseIPP(bool flag); +CV_EXPORTS int getIppStatus(); +CV_EXPORTS String getIppErrorLocation(); +CV_EXPORTS_W bool useIPP(); +CV_EXPORTS_W void setUseIPP(bool flag); +CV_EXPORTS_W String getIppVersion(); + +// IPP Not-Exact mode. This function may force use of IPP then both IPP and OpenCV provide proper results +// but have internal accuracy differences which have to much direct or indirect impact on accuracy tests. +CV_EXPORTS_W bool useIPP_NE(); +CV_EXPORTS_W void setUseIPP_NE(bool flag); } // ipp @@ -685,5 +756,6 @@ CV_EXPORTS void setUseIPP(bool flag); } // cv #include "opencv2/core/neon_utils.hpp" +#include "opencv2/core/vsx_utils.hpp" -#endif //__OPENCV_CORE_BASE_HPP__ +#endif //OPENCV_CORE_BASE_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/bufferpool.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/bufferpool.hpp similarity index 72% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/bufferpool.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/bufferpool.hpp index 76df2d29..4698e5da 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/bufferpool.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/bufferpool.hpp @@ -4,8 +4,13 @@ // // Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved. -#ifndef __OPENCV_CORE_BUFFER_POOL_HPP__ -#define __OPENCV_CORE_BUFFER_POOL_HPP__ +#ifndef OPENCV_CORE_BUFFER_POOL_HPP +#define OPENCV_CORE_BUFFER_POOL_HPP + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4265) +#endif namespace cv { @@ -28,4 +33,8 @@ public: } -#endif // __OPENCV_CORE_BUFFER_POOL_HPP__ +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#endif // OPENCV_CORE_BUFFER_POOL_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/core.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/core.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/core.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/core.hpp diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/core_c.h b/lib/3rdParty/OpenCV3.4/include/opencv2/core/core_c.h similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/core_c.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/core_c.h index a0ed6326..754af2fc 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/core_c.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/core_c.h @@ -42,8 +42,8 @@ //M*/ -#ifndef __OPENCV_CORE_C_H__ -#define __OPENCV_CORE_C_H__ +#ifndef OPENCV_CORE_C_H +#define OPENCV_CORE_C_H #include "opencv2/core/types_c.h" @@ -359,7 +359,7 @@ CVAPI(CvMat*) cvGetSubRect( const CvArr* arr, CvMat* submat, CvRect rect ); /** @brief Returns array row or row span. -The functions return the header, corresponding to a specified row/row span of the input array. +The function returns the header, corresponding to a specified row/row span of the input array. cvGetRow(arr, submat, row) is a shortcut for cvGetRows(arr, submat, row, row+1). @param arr Input array @param submat Pointer to the resulting sub-array header @@ -385,7 +385,7 @@ CV_INLINE CvMat* cvGetRow( const CvArr* arr, CvMat* submat, int row ) /** @brief Returns one of more array columns. -The functions return the header, corresponding to a specified column span of the input array. That +The function returns the header, corresponding to a specified column span of the input array. That is, no data is copied. Therefore, any modifications of the submatrix will affect the original array. If you need to copy the columns, use cvCloneMat. cvGetCol(arr, submat, col) is a shortcut for @@ -1976,8 +1976,16 @@ CVAPI(void) cvSetIPLAllocators( Cv_iplCreateImageHeader create_header, The function opens file storage for reading or writing data. In the latter case, a new file is created or an existing file is rewritten. The type of the read or written file is determined by the -filename extension: .xml for XML and .yml or .yaml for YAML. The function returns a pointer to the -CvFileStorage structure. If the file cannot be opened then the function returns NULL. +filename extension: .xml for XML, .yml or .yaml for YAML and .json for JSON. + +At the same time, it also supports adding parameters like "example.xml?base64". The three ways +are the same: +@snippet samples/cpp/filestorage_base64.cpp suffix_in_file_name +@snippet samples/cpp/filestorage_base64.cpp flag_write_base64 +@snippet samples/cpp/filestorage_base64.cpp flag_write_and_flag_base64 + +The function returns a pointer to the CvFileStorage structure. +If the file cannot be opened then the function returns NULL. @param filename Name of the file associated with the storage @param memstorage Memory storage used for temporary data and for : storing dynamic structures, such as CvSeq or CvGraph . If it is NULL, a temporary memory @@ -1985,6 +1993,7 @@ CvFileStorage structure. If the file cannot be opened then the function returns @param flags Can be one of the following: > - **CV_STORAGE_READ** the storage is open for reading > - **CV_STORAGE_WRITE** the storage is open for writing + (use **CV_STORAGE_WRITE | CV_STORAGE_WRITE_BASE64** to write rawdata in Base64) @param encoding */ CVAPI(CvFileStorage*) cvOpenFileStorage( const char* filename, CvMemStorage* memstorage, @@ -2022,7 +2031,8 @@ One and only one of the two above flags must be specified @param type_name Optional parameter - the object type name. In case of XML it is written as a type_id attribute of the structure opening tag. In the case of YAML it is written after a colon following the structure name (see the example in - CvFileStorage description). Mainly it is used with user objects. When the storage is read, the + CvFileStorage description). In case of JSON it is written as a name/value pair. + Mainly it is used with user objects. When the storage is read, the encoded type name is used to determine the object type (see CvTypeInfo and cvFindType ). @param attributes This parameter is not used in the current implementation */ @@ -2162,7 +2172,7 @@ the file with multiple streams looks like this: @endcode The YAML file will look like this: @code{.yaml} - %YAML:1.0 + %YAML 1.0 # stream #1 data ... --- @@ -2187,6 +2197,28 @@ to a sequence rather than a map. CVAPI(void) cvWriteRawData( CvFileStorage* fs, const void* src, int len, const char* dt ); +/** @brief Writes multiple numbers in Base64. + +If either CV_STORAGE_WRITE_BASE64 or cv::FileStorage::WRITE_BASE64 is used, +this function will be the same as cvWriteRawData. If neither, the main +difference is that it outputs a sequence in Base64 encoding rather than +in plain text. + +This function can only be used to write a sequence with a type "binary". + +Consider the following two examples where their output is the same: +@snippet samples/cpp/filestorage_base64.cpp without_base64_flag +and +@snippet samples/cpp/filestorage_base64.cpp with_write_base64_flag + +@param fs File storage +@param src Pointer to the written array +@param len Number of the array elements to write +@param dt Specification of each array element, see @ref format_spec "format specification" +*/ +CVAPI(void) cvWriteRawDataBase64( CvFileStorage* fs, const void* src, + int len, const char* dt ); + /** @brief Returns a unique pointer for a given name. The function returns a unique pointer for each particular file node name. This pointer can be then @@ -2468,7 +2500,7 @@ CVAPI(void) cvReadRawData( const CvFileStorage* fs, const CvFileNode* src, /** @brief Writes a file node to another file storage. The function writes a copy of a file node to file storage. Possible applications of the function are -merging several file storages into one and conversion between XML and YAML formats. +merging several file storages into one and conversion between XML, YAML and JSON formats. @param fs Destination file storage @param new_node_name New name of the file node in the destination file storage. To keep the existing name, use cvcvGetFileNodeName @@ -2622,7 +2654,7 @@ CVAPI(int) cvGetErrMode( void ); /** Sets error processing mode, returns previously used mode */ CVAPI(int) cvSetErrMode( int mode ); -/** Sets error status and performs some additonal actions (displaying message box, +/** Sets error status and performs some additional actions (displaying message box, writing message to stderr, terminating application etc.) depending on the current error mode */ CVAPI(void) cvError( int status, const char* func_name, @@ -2631,7 +2663,7 @@ CVAPI(void) cvError( int status, const char* func_name, /** Retrieves textual description of the error given its code */ CVAPI(const char*) cvErrorStr( int status ); -/** Retrieves detailed information about the last error occured */ +/** Retrieves detailed information about the last error occurred */ CVAPI(int) cvGetErrInfo( const char** errcode_desc, const char** description, const char** filename, int* line ); diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda.hpp similarity index 93% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda.hpp index 64bc53ef..6dca2723 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_CORE_CUDA_HPP__ -#define __OPENCV_CORE_CUDA_HPP__ +#ifndef OPENCV_CORE_CUDA_HPP +#define OPENCV_CORE_CUDA_HPP #ifndef __cplusplus # error cuda.hpp header must be compiled as C++ @@ -327,6 +327,34 @@ The function does not reallocate memory if the matrix has proper attributes alre */ CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr); +/** @brief BufferPool for use with CUDA streams + + * BufferPool utilizes cuda::Stream's allocator to create new buffers. It is + * particularly useful when BufferPoolUsage is set to true, or a custom + * allocator is specified for the cuda::Stream, and you want to implement your + * own stream based functions utilizing the same underlying GPU memory + * management. + */ +class CV_EXPORTS BufferPool +{ +public: + + //! Gets the BufferPool for the given stream. + explicit BufferPool(Stream& stream); + + //! Allocates a new GpuMat of given size and type. + GpuMat getBuffer(int rows, int cols, int type); + + //! Allocates a new GpuMat of given size and type. + GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); } + + //! Returns the allocator associated with the stream. + Ptr getAllocator() const { return allocator_; } + +private: + Ptr allocator_; +}; + //! BufferPool management (must be called before Stream creation) CV_EXPORTS void setBufferPoolUsage(bool on); CV_EXPORTS void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount); @@ -447,7 +475,26 @@ CV_EXPORTS void unregisterPageLocked(Mat& m); functions use the constant GPU memory, and next call may update the memory before the previous one has been finished. But calling different operations asynchronously is safe because each operation has its own constant buffer. Memory copy/upload/download/set operations to the buffers you hold are -also safe. : +also safe. + +@note The Stream class is not thread-safe. Please use different Stream objects for different CPU threads. + +@code +void thread1() +{ + cv::cuda::Stream stream1; + cv::cuda::func1(..., stream1); +} + +void thread2() +{ + cv::cuda::Stream stream2; + cv::cuda::func2(..., stream2); +} +@endcode + +@note By default all CUDA routines are launched in Stream::Null() object, if the stream is not specified by user. +In multi-threading environment the stream objects must be passed explicitly (see previous note). */ class CV_EXPORTS Stream { @@ -460,6 +507,9 @@ public: //! creates a new asynchronous stream Stream(); + //! creates a new asynchronous stream with custom allocator + Stream(const Ptr& allocator); + /** @brief Returns true if the current stream queue is finished. Otherwise, it returns false. */ bool queryIfComplete() const; @@ -545,7 +595,8 @@ private: /** @brief Returns the number of installed CUDA-enabled devices. Use this function before any other CUDA functions calls. If OpenCV is compiled without CUDA support, -this function returns 0. +this function returns 0. If the CUDA driver is not installed, or is incompatible, this function +returns -1. */ CV_EXPORTS int getCudaEnabledDeviceCount(); @@ -836,6 +887,15 @@ private: CV_EXPORTS void printCudaDeviceInfo(int device); CV_EXPORTS void printShortCudaDeviceInfo(int device); +/** @brief Converts an array to half precision floating number. + +@param _src input array. +@param _dst output array. +@param stream Stream for the asynchronous version. +@sa convertFp16 +*/ +CV_EXPORTS void convertFp16(InputArray _src, OutputArray _dst, Stream& stream = Stream::Null()); + //! @} cudacore_init }} // namespace cv { namespace cuda { @@ -843,4 +903,4 @@ CV_EXPORTS void printShortCudaDeviceInfo(int device); #include "opencv2/core/cuda.inl.hpp" -#endif /* __OPENCV_CORE_CUDA_HPP__ */ +#endif /* OPENCV_CORE_CUDA_HPP */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda.inl.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda.inl.hpp similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda.inl.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda.inl.hpp index 01dc6d7c..35ae2e49 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda.inl.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda.inl.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_CORE_CUDAINL_HPP__ -#define __OPENCV_CORE_CUDAINL_HPP__ +#ifndef OPENCV_CORE_CUDAINL_HPP +#define OPENCV_CORE_CUDAINL_HPP #include "opencv2/core/cuda.hpp" @@ -628,4 +628,4 @@ Mat::Mat(const cuda::GpuMat& m) //! @endcond -#endif // __OPENCV_CORE_CUDAINL_HPP__ +#endif // OPENCV_CORE_CUDAINL_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda_stream_accessor.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda_stream_accessor.hpp similarity index 95% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda_stream_accessor.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda_stream_accessor.hpp index 0f8ee9b2..deaf356f 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda_stream_accessor.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda_stream_accessor.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP__ -#define __OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP__ +#ifndef OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP +#define OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP #ifndef __cplusplus # error cuda_stream_accessor.hpp header must be compiled as C++ @@ -83,4 +83,4 @@ namespace cv } } -#endif /* __OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP__ */ +#endif /* OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda_types.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda_types.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda_types.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda_types.hpp index 8df816e8..f13a8474 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cuda_types.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cuda_types.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_CORE_CUDA_TYPES_HPP__ -#define __OPENCV_CORE_CUDA_TYPES_HPP__ +#ifndef OPENCV_CORE_CUDA_TYPES_HPP +#define OPENCV_CORE_CUDA_TYPES_HPP #ifndef __cplusplus # error cuda_types.hpp header must be compiled as C++ @@ -132,4 +132,4 @@ namespace cv //! @endcond -#endif /* __OPENCV_CORE_CUDA_TYPES_HPP__ */ +#endif /* OPENCV_CORE_CUDA_TYPES_HPP */ diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/core/cv_cpu_dispatch.h b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cv_cpu_dispatch.h new file mode 100644 index 00000000..5261a414 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cv_cpu_dispatch.h @@ -0,0 +1,228 @@ +// 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. + +#if defined __OPENCV_BUILD \ + +#include "cv_cpu_config.h" +#include "cv_cpu_helper.h" + +#ifdef CV_CPU_DISPATCH_MODE +#define CV_CPU_OPTIMIZATION_NAMESPACE __CV_CAT(opt_, CV_CPU_DISPATCH_MODE) +#define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace __CV_CAT(opt_, CV_CPU_DISPATCH_MODE) { +#define CV_CPU_OPTIMIZATION_NAMESPACE_END } +#else +#define CV_CPU_OPTIMIZATION_NAMESPACE cpu_baseline +#define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace cpu_baseline { +#define CV_CPU_OPTIMIZATION_NAMESPACE_END } +#endif + + +#define __CV_CPU_DISPATCH_CHAIN_END(fn, args, mode, ...) /* done */ +#define __CV_CPU_DISPATCH(fn, args, mode, ...) __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) +#define __CV_CPU_DISPATCH_EXPAND(fn, args, ...) __CV_EXPAND(__CV_CPU_DISPATCH(fn, args, __VA_ARGS__)) +#define CV_CPU_DISPATCH(fn, args, ...) __CV_CPU_DISPATCH_EXPAND(fn, args, __VA_ARGS__, END) // expand macros + + +#if defined CV_ENABLE_INTRINSICS \ + && !defined CV_DISABLE_OPTIMIZATION \ + && !defined __CUDACC__ /* do not include SSE/AVX/NEON headers for NVCC compiler */ \ + +#ifdef CV_CPU_COMPILE_SSE2 +# include +# define CV_MMX 1 +# define CV_SSE 1 +# define CV_SSE2 1 +#endif +#ifdef CV_CPU_COMPILE_SSE3 +# include +# define CV_SSE3 1 +#endif +#ifdef CV_CPU_COMPILE_SSSE3 +# include +# define CV_SSSE3 1 +#endif +#ifdef CV_CPU_COMPILE_SSE4_1 +# include +# define CV_SSE4_1 1 +#endif +#ifdef CV_CPU_COMPILE_SSE4_2 +# include +# define CV_SSE4_2 1 +#endif +#ifdef CV_CPU_COMPILE_POPCNT +# ifdef _MSC_VER +# include +# if defined(_M_X64) +# define CV_POPCNT_U64 _mm_popcnt_u64 +# endif +# define CV_POPCNT_U32 _mm_popcnt_u32 +# else +# include +# if defined(__x86_64__) +# define CV_POPCNT_U64 __builtin_popcountll +# endif +# define CV_POPCNT_U32 __builtin_popcount +# endif +# define CV_POPCNT 1 +#endif +#ifdef CV_CPU_COMPILE_AVX +# include +# define CV_AVX 1 +#endif +#ifdef CV_CPU_COMPILE_FP16 +# if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) +# include +# else +# include +# endif +# define CV_FP16 1 +#endif +#ifdef CV_CPU_COMPILE_AVX2 +# include +# define CV_AVX2 1 +#endif +#ifdef CV_CPU_COMPILE_FMA3 +# define CV_FMA3 1 +#endif + +#if defined _WIN32 && defined(_M_ARM) +# include +# include +# define CV_NEON 1 +#elif defined(__ARM_NEON__) || (defined (__ARM_NEON) && defined(__aarch64__)) +# include +# define CV_NEON 1 +#endif + +#if defined(__ARM_NEON__) || defined(__aarch64__) +# include +#endif + +#if defined(__VSX__) && defined(__PPC64__) && defined(__LITTLE_ENDIAN__) +# include +# undef vector +# undef pixel +# undef bool +# define CV_VSX 1 +#endif + +#endif // CV_ENABLE_INTRINSICS && !CV_DISABLE_OPTIMIZATION && !__CUDACC__ + +#if defined CV_CPU_COMPILE_AVX && !defined CV_CPU_BASELINE_COMPILE_AVX +struct VZeroUpperGuard { +#ifdef __GNUC__ + __attribute__((always_inline)) +#endif + inline ~VZeroUpperGuard() { _mm256_zeroupper(); } +}; +#define __CV_AVX_GUARD VZeroUpperGuard __vzeroupper_guard; (void)__vzeroupper_guard; +#endif + +#ifdef __CV_AVX_GUARD +#define CV_AVX_GUARD __CV_AVX_GUARD +#else +#define CV_AVX_GUARD +#endif + +#endif // __OPENCV_BUILD + + + +#if !defined __OPENCV_BUILD /* Compatibility code */ \ + && !defined __CUDACC__ /* do not include SSE/AVX/NEON headers for NVCC compiler */ +#if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) +# include +# define CV_MMX 1 +# define CV_SSE 1 +# define CV_SSE2 1 +#elif defined _WIN32 && defined(_M_ARM) +# include +# include +# define CV_NEON 1 +#elif defined(__ARM_NEON__) || (defined (__ARM_NEON) && defined(__aarch64__)) +# include +# define CV_NEON 1 +#elif defined(__VSX__) && defined(__PPC64__) && defined(__LITTLE_ENDIAN__) +# include +# undef vector +# undef pixel +# undef bool +# define CV_VSX 1 +#endif + +#endif // !__OPENCV_BUILD && !__CUDACC (Compatibility code) + + + +#ifndef CV_MMX +# define CV_MMX 0 +#endif +#ifndef CV_SSE +# define CV_SSE 0 +#endif +#ifndef CV_SSE2 +# define CV_SSE2 0 +#endif +#ifndef CV_SSE3 +# define CV_SSE3 0 +#endif +#ifndef CV_SSSE3 +# define CV_SSSE3 0 +#endif +#ifndef CV_SSE4_1 +# define CV_SSE4_1 0 +#endif +#ifndef CV_SSE4_2 +# define CV_SSE4_2 0 +#endif +#ifndef CV_POPCNT +# define CV_POPCNT 0 +#endif +#ifndef CV_AVX +# define CV_AVX 0 +#endif +#ifndef CV_FP16 +# define CV_FP16 0 +#endif +#ifndef CV_AVX2 +# define CV_AVX2 0 +#endif +#ifndef CV_FMA3 +# define CV_FMA3 0 +#endif +#ifndef CV_AVX_512F +# define CV_AVX_512F 0 +#endif +#ifndef CV_AVX_512BW +# define CV_AVX_512BW 0 +#endif +#ifndef CV_AVX_512CD +# define CV_AVX_512CD 0 +#endif +#ifndef CV_AVX_512DQ +# define CV_AVX_512DQ 0 +#endif +#ifndef CV_AVX_512ER +# define CV_AVX_512ER 0 +#endif +#ifndef CV_AVX_512IFMA512 +# define CV_AVX_512IFMA512 0 +#endif +#ifndef CV_AVX_512PF +# define CV_AVX_512PF 0 +#endif +#ifndef CV_AVX_512VBMI +# define CV_AVX_512VBMI 0 +#endif +#ifndef CV_AVX_512VL +# define CV_AVX_512VL 0 +#endif + +#ifndef CV_NEON +# define CV_NEON 0 +#endif + +#ifndef CV_VSX +# define CV_VSX 0 +#endif diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/core/cv_cpu_helper.h b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cv_cpu_helper.h new file mode 100644 index 00000000..66a473f1 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cv_cpu_helper.h @@ -0,0 +1,199 @@ +// AUTOGENERATED, DO NOT EDIT + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE +# define CV_TRY_SSE 1 +# define CV_CPU_HAS_SUPPORT_SSE 1 +# define CV_CPU_CALL_SSE(fn, args) return (opt_SSE::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE +# define CV_TRY_SSE 1 +# define CV_CPU_HAS_SUPPORT_SSE (cv::checkHardwareSupport(CV_CPU_SSE)) +# define CV_CPU_CALL_SSE(fn, args) if (CV_CPU_HAS_SUPPORT_SSE) return (opt_SSE::fn args) +#else +# define CV_TRY_SSE 0 +# define CV_CPU_HAS_SUPPORT_SSE 0 +# define CV_CPU_CALL_SSE(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE(fn, args, mode, ...) CV_CPU_CALL_SSE(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE2 +# define CV_TRY_SSE2 1 +# define CV_CPU_HAS_SUPPORT_SSE2 1 +# define CV_CPU_CALL_SSE2(fn, args) return (opt_SSE2::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE2 +# define CV_TRY_SSE2 1 +# define CV_CPU_HAS_SUPPORT_SSE2 (cv::checkHardwareSupport(CV_CPU_SSE2)) +# define CV_CPU_CALL_SSE2(fn, args) if (CV_CPU_HAS_SUPPORT_SSE2) return (opt_SSE2::fn args) +#else +# define CV_TRY_SSE2 0 +# define CV_CPU_HAS_SUPPORT_SSE2 0 +# define CV_CPU_CALL_SSE2(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE2(fn, args, mode, ...) CV_CPU_CALL_SSE2(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE3 +# define CV_TRY_SSE3 1 +# define CV_CPU_HAS_SUPPORT_SSE3 1 +# define CV_CPU_CALL_SSE3(fn, args) return (opt_SSE3::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE3 +# define CV_TRY_SSE3 1 +# define CV_CPU_HAS_SUPPORT_SSE3 (cv::checkHardwareSupport(CV_CPU_SSE3)) +# define CV_CPU_CALL_SSE3(fn, args) if (CV_CPU_HAS_SUPPORT_SSE3) return (opt_SSE3::fn args) +#else +# define CV_TRY_SSE3 0 +# define CV_CPU_HAS_SUPPORT_SSE3 0 +# define CV_CPU_CALL_SSE3(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE3(fn, args, mode, ...) CV_CPU_CALL_SSE3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSSE3 +# define CV_TRY_SSSE3 1 +# define CV_CPU_HAS_SUPPORT_SSSE3 1 +# define CV_CPU_CALL_SSSE3(fn, args) return (opt_SSSE3::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSSE3 +# define CV_TRY_SSSE3 1 +# define CV_CPU_HAS_SUPPORT_SSSE3 (cv::checkHardwareSupport(CV_CPU_SSSE3)) +# define CV_CPU_CALL_SSSE3(fn, args) if (CV_CPU_HAS_SUPPORT_SSSE3) return (opt_SSSE3::fn args) +#else +# define CV_TRY_SSSE3 0 +# define CV_CPU_HAS_SUPPORT_SSSE3 0 +# define CV_CPU_CALL_SSSE3(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSSE3(fn, args, mode, ...) CV_CPU_CALL_SSSE3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE4_1 +# define CV_TRY_SSE4_1 1 +# define CV_CPU_HAS_SUPPORT_SSE4_1 1 +# define CV_CPU_CALL_SSE4_1(fn, args) return (opt_SSE4_1::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE4_1 +# define CV_TRY_SSE4_1 1 +# define CV_CPU_HAS_SUPPORT_SSE4_1 (cv::checkHardwareSupport(CV_CPU_SSE4_1)) +# define CV_CPU_CALL_SSE4_1(fn, args) if (CV_CPU_HAS_SUPPORT_SSE4_1) return (opt_SSE4_1::fn args) +#else +# define CV_TRY_SSE4_1 0 +# define CV_CPU_HAS_SUPPORT_SSE4_1 0 +# define CV_CPU_CALL_SSE4_1(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE4_1(fn, args, mode, ...) CV_CPU_CALL_SSE4_1(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE4_2 +# define CV_TRY_SSE4_2 1 +# define CV_CPU_HAS_SUPPORT_SSE4_2 1 +# define CV_CPU_CALL_SSE4_2(fn, args) return (opt_SSE4_2::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE4_2 +# define CV_TRY_SSE4_2 1 +# define CV_CPU_HAS_SUPPORT_SSE4_2 (cv::checkHardwareSupport(CV_CPU_SSE4_2)) +# define CV_CPU_CALL_SSE4_2(fn, args) if (CV_CPU_HAS_SUPPORT_SSE4_2) return (opt_SSE4_2::fn args) +#else +# define CV_TRY_SSE4_2 0 +# define CV_CPU_HAS_SUPPORT_SSE4_2 0 +# define CV_CPU_CALL_SSE4_2(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE4_2(fn, args, mode, ...) CV_CPU_CALL_SSE4_2(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_POPCNT +# define CV_TRY_POPCNT 1 +# define CV_CPU_HAS_SUPPORT_POPCNT 1 +# define CV_CPU_CALL_POPCNT(fn, args) return (opt_POPCNT::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_POPCNT +# define CV_TRY_POPCNT 1 +# define CV_CPU_HAS_SUPPORT_POPCNT (cv::checkHardwareSupport(CV_CPU_POPCNT)) +# define CV_CPU_CALL_POPCNT(fn, args) if (CV_CPU_HAS_SUPPORT_POPCNT) return (opt_POPCNT::fn args) +#else +# define CV_TRY_POPCNT 0 +# define CV_CPU_HAS_SUPPORT_POPCNT 0 +# define CV_CPU_CALL_POPCNT(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_POPCNT(fn, args, mode, ...) CV_CPU_CALL_POPCNT(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX +# define CV_TRY_AVX 1 +# define CV_CPU_HAS_SUPPORT_AVX 1 +# define CV_CPU_CALL_AVX(fn, args) return (opt_AVX::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX +# define CV_TRY_AVX 1 +# define CV_CPU_HAS_SUPPORT_AVX (cv::checkHardwareSupport(CV_CPU_AVX)) +# define CV_CPU_CALL_AVX(fn, args) if (CV_CPU_HAS_SUPPORT_AVX) return (opt_AVX::fn args) +#else +# define CV_TRY_AVX 0 +# define CV_CPU_HAS_SUPPORT_AVX 0 +# define CV_CPU_CALL_AVX(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX(fn, args, mode, ...) CV_CPU_CALL_AVX(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_FP16 +# define CV_TRY_FP16 1 +# define CV_CPU_HAS_SUPPORT_FP16 1 +# define CV_CPU_CALL_FP16(fn, args) return (opt_FP16::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_FP16 +# define CV_TRY_FP16 1 +# define CV_CPU_HAS_SUPPORT_FP16 (cv::checkHardwareSupport(CV_CPU_FP16)) +# define CV_CPU_CALL_FP16(fn, args) if (CV_CPU_HAS_SUPPORT_FP16) return (opt_FP16::fn args) +#else +# define CV_TRY_FP16 0 +# define CV_CPU_HAS_SUPPORT_FP16 0 +# define CV_CPU_CALL_FP16(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_FP16(fn, args, mode, ...) CV_CPU_CALL_FP16(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX2 +# define CV_TRY_AVX2 1 +# define CV_CPU_HAS_SUPPORT_AVX2 1 +# define CV_CPU_CALL_AVX2(fn, args) return (opt_AVX2::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX2 +# define CV_TRY_AVX2 1 +# define CV_CPU_HAS_SUPPORT_AVX2 (cv::checkHardwareSupport(CV_CPU_AVX2)) +# define CV_CPU_CALL_AVX2(fn, args) if (CV_CPU_HAS_SUPPORT_AVX2) return (opt_AVX2::fn args) +#else +# define CV_TRY_AVX2 0 +# define CV_CPU_HAS_SUPPORT_AVX2 0 +# define CV_CPU_CALL_AVX2(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX2(fn, args, mode, ...) CV_CPU_CALL_AVX2(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_FMA3 +# define CV_TRY_FMA3 1 +# define CV_CPU_HAS_SUPPORT_FMA3 1 +# define CV_CPU_CALL_FMA3(fn, args) return (opt_FMA3::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_FMA3 +# define CV_TRY_FMA3 1 +# define CV_CPU_HAS_SUPPORT_FMA3 (cv::checkHardwareSupport(CV_CPU_FMA3)) +# define CV_CPU_CALL_FMA3(fn, args) if (CV_CPU_HAS_SUPPORT_FMA3) return (opt_FMA3::fn args) +#else +# define CV_TRY_FMA3 0 +# define CV_CPU_HAS_SUPPORT_FMA3 0 +# define CV_CPU_CALL_FMA3(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_FMA3(fn, args, mode, ...) CV_CPU_CALL_FMA3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_NEON +# define CV_TRY_NEON 1 +# define CV_CPU_HAS_SUPPORT_NEON 1 +# define CV_CPU_CALL_NEON(fn, args) return (opt_NEON::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_NEON +# define CV_TRY_NEON 1 +# define CV_CPU_HAS_SUPPORT_NEON (cv::checkHardwareSupport(CV_CPU_NEON)) +# define CV_CPU_CALL_NEON(fn, args) if (CV_CPU_HAS_SUPPORT_NEON) return (opt_NEON::fn args) +#else +# define CV_TRY_NEON 0 +# define CV_CPU_HAS_SUPPORT_NEON 0 +# define CV_CPU_CALL_NEON(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_NEON(fn, args, mode, ...) CV_CPU_CALL_NEON(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_VSX +# define CV_TRY_VSX 1 +# define CV_CPU_HAS_SUPPORT_VSX 1 +# define CV_CPU_CALL_VSX(fn, args) return (opt_VSX::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_VSX +# define CV_TRY_VSX 1 +# define CV_CPU_HAS_SUPPORT_VSX (cv::checkHardwareSupport(CV_CPU_VSX)) +# define CV_CPU_CALL_VSX(fn, args) if (CV_CPU_HAS_SUPPORT_VSX) return (opt_VSX::fn args) +#else +# define CV_TRY_VSX 0 +# define CV_CPU_HAS_SUPPORT_VSX 0 +# define CV_CPU_CALL_VSX(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_VSX(fn, args, mode, ...) CV_CPU_CALL_VSX(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#define CV_CPU_CALL_BASELINE(fn, args) return (cpu_baseline::fn args) +#define __CV_CPU_DISPATCH_CHAIN_BASELINE(fn, args, mode, ...) CV_CPU_CALL_BASELINE(fn, args) /* last in sequence */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cvdef.h b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cvdef.h similarity index 61% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/cvdef.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/cvdef.h index af2abfbb..c1fcc6a1 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cvdef.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cvdef.h @@ -42,15 +42,43 @@ // //M*/ -#ifndef __OPENCV_CORE_CVDEF_H__ -#define __OPENCV_CORE_CVDEF_H__ +#ifndef OPENCV_CORE_CVDEF_H +#define OPENCV_CORE_CVDEF_H //! @addtogroup core_utils //! @{ -#if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER && _MSC_VER > 1300 -# define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio warnings */ +#if !defined CV_DOXYGEN && !defined CV_IGNORE_DEBUG_BUILD_GUARD +#if (defined(_MSC_VER) && (defined(DEBUG) || defined(_DEBUG))) || \ + (defined(_GLIBCXX_DEBUG) || defined(_GLIBCXX_DEBUG_PEDANTIC)) +// Guard to prevent using of binary incompatible binaries / runtimes +// https://github.com/opencv/opencv/pull/9161 +#define CV__DEBUG_NS_BEGIN namespace debug_build_guard { +#define CV__DEBUG_NS_END } +namespace cv { namespace debug_build_guard { } using namespace debug_build_guard; } #endif +#endif + +#ifndef CV__DEBUG_NS_BEGIN +#define CV__DEBUG_NS_BEGIN +#define CV__DEBUG_NS_END +#endif + + +#ifdef __OPENCV_BUILD +#include "cvconfig.h" +#endif + +#ifndef __CV_EXPAND +#define __CV_EXPAND(x) x +#endif + +#ifndef __CV_CAT +#define __CV_CAT__(x, y) x ## y +#define __CV_CAT_(x, y) __CV_CAT__(x, y) +#define __CV_CAT(x, y) __CV_CAT_(x, y) +#endif + // undef problematic defines sometimes defined by system headers (windows.h in particular) #undef small @@ -59,10 +87,6 @@ #undef abs #undef Complex -#if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER && _MSC_VER > 1300 -# define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio warnings */ -#endif - #include #include "opencv2/core/hal/interface.h" @@ -88,7 +112,7 @@ # endif #endif -#if defined CV_ICC && !defined CV_ENABLE_UNROLLED +#if defined CV_DISABLE_OPTIMIZATION || (defined CV_ICC && !defined CV_ENABLE_UNROLLED) # define CV_ENABLE_UNROLLED 0 #else # define CV_ENABLE_UNROLLED 1 @@ -112,7 +136,7 @@ #define CV_CPU_SSE4_1 6 #define CV_CPU_SSE4_2 7 #define CV_CPU_POPCNT 8 - +#define CV_CPU_FP16 9 #define CV_CPU_AVX 10 #define CV_CPU_AVX2 11 #define CV_CPU_FMA3 12 @@ -129,6 +153,8 @@ #define CV_CPU_NEON 100 +#define CV_CPU_VSX 200 + // when adding to this list remember to update the following enum #define CV_HARDWARE_MAX_FEATURE 255 @@ -143,7 +169,7 @@ enum CpuFeatures { CPU_SSE4_1 = 6, CPU_SSE4_2 = 7, CPU_POPCNT = 8, - + CPU_FP16 = 9, CPU_AVX = 10, CPU_AVX2 = 11, CPU_FMA3 = 12, @@ -158,156 +184,53 @@ enum CpuFeatures { CPU_AVX_512VBMI = 20, CPU_AVX_512VL = 21, - CPU_NEON = 100 + CPU_NEON = 100, + + CPU_VSX = 200 }; -// do not include SSE/AVX/NEON headers for NVCC compiler -#ifndef __CUDACC__ -#if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) -# include -# define CV_MMX 1 -# define CV_SSE 1 -# define CV_SSE2 1 -# if defined __SSE3__ || (defined _MSC_VER && _MSC_VER >= 1500) -# include -# define CV_SSE3 1 -# endif -# if defined __SSSE3__ || (defined _MSC_VER && _MSC_VER >= 1500) -# include -# define CV_SSSE3 1 -# endif -# if defined __SSE4_1__ || (defined _MSC_VER && _MSC_VER >= 1500) -# include -# define CV_SSE4_1 1 -# endif -# if defined __SSE4_2__ || (defined _MSC_VER && _MSC_VER >= 1500) -# include -# define CV_SSE4_2 1 -# endif -# if defined __POPCNT__ || (defined _MSC_VER && _MSC_VER >= 1500) -# ifdef _MSC_VER -# include -# else -# include -# endif -# define CV_POPCNT 1 -# endif -# if defined __AVX__ || (defined _MSC_VER && _MSC_VER >= 1600 && 0) -// MS Visual Studio 2010 (2012?) has no macro pre-defined to identify the use of /arch:AVX -// See: http://connect.microsoft.com/VisualStudio/feedback/details/605858/arch-avx-should-define-a-predefined-macro-in-x64-and-set-a-unique-value-for-m-ix86-fp-in-win32 -# include -# define CV_AVX 1 -# if defined(_XCR_XFEATURE_ENABLED_MASK) -# define __xgetbv() _xgetbv(_XCR_XFEATURE_ENABLED_MASK) -# else -# define __xgetbv() 0 -# endif -# endif -# if defined __AVX2__ || (defined _MSC_VER && _MSC_VER >= 1800 && 0) -# include -# define CV_AVX2 1 -# if defined __FMA__ -# define CV_FMA3 1 -# endif -# endif -#endif +#include "cv_cpu_dispatch.h" -#if (defined WIN32 || defined _WIN32) && defined(_M_ARM) -# include -# include "arm_neon.h" -# define CV_NEON 1 -# define CPU_HAS_NEON_FEATURE (true) -#elif defined(__ARM_NEON__) || (defined (__ARM_NEON) && defined(__aarch64__)) -# include -# define CV_NEON 1 -#endif - -#if defined __GNUC__ && defined __arm__ && (defined __ARM_PCS_VFP || defined __ARM_VFPV3__ || defined __ARM_NEON__) && !defined __SOFTFP__ -# define CV_VFP 1 -#endif - -#endif // __CUDACC__ - -#ifndef CV_POPCNT -#define CV_POPCNT 0 -#endif -#ifndef CV_MMX -# define CV_MMX 0 -#endif -#ifndef CV_SSE -# define CV_SSE 0 -#endif -#ifndef CV_SSE2 -# define CV_SSE2 0 -#endif -#ifndef CV_SSE3 -# define CV_SSE3 0 -#endif -#ifndef CV_SSSE3 -# define CV_SSSE3 0 -#endif -#ifndef CV_SSE4_1 -# define CV_SSE4_1 0 -#endif -#ifndef CV_SSE4_2 -# define CV_SSE4_2 0 -#endif -#ifndef CV_AVX -# define CV_AVX 0 -#endif -#ifndef CV_AVX2 -# define CV_AVX2 0 -#endif -#ifndef CV_FMA3 -# define CV_FMA3 0 -#endif -#ifndef CV_AVX_512F -# define CV_AVX_512F 0 -#endif -#ifndef CV_AVX_512BW -# define CV_AVX_512BW 0 -#endif -#ifndef CV_AVX_512CD -# define CV_AVX_512CD 0 -#endif -#ifndef CV_AVX_512DQ -# define CV_AVX_512DQ 0 -#endif -#ifndef CV_AVX_512ER -# define CV_AVX_512ER 0 -#endif -#ifndef CV_AVX_512IFMA512 -# define CV_AVX_512IFMA512 0 -#endif -#ifndef CV_AVX_512PF -# define CV_AVX_512PF 0 -#endif -#ifndef CV_AVX_512VBMI -# define CV_AVX_512VBMI 0 -#endif -#ifndef CV_AVX_512VL -# define CV_AVX_512VL 0 -#endif - -#ifndef CV_NEON -# define CV_NEON 0 -#endif - -#ifndef CV_VFP -# define CV_VFP 0 -#endif /* fundamental constants */ #define CV_PI 3.1415926535897932384626433832795 -#define CV_2PI 6.283185307179586476925286766559 +#define CV_2PI 6.283185307179586476925286766559 #define CV_LOG2 0.69314718055994530941723212145818 +#if defined __ARM_FP16_FORMAT_IEEE \ + && !defined __CUDACC__ +# define CV_FP16_TYPE 1 +#else +# define CV_FP16_TYPE 0 +#endif + +typedef union Cv16suf +{ + short i; +#if CV_FP16_TYPE + __fp16 h; +#endif + struct _fp16Format + { + unsigned int significand : 10; + unsigned int exponent : 5; + unsigned int sign : 1; + } fmt; +} +Cv16suf; + typedef union Cv32suf { int i; unsigned u; float f; + struct _fp32Format + { + unsigned int significand : 23; + unsigned int exponent : 8; + unsigned int sign : 1; + } fmt; } Cv32suf; @@ -325,12 +248,32 @@ Cv64suf; # define DISABLE_OPENCV_24_COMPATIBILITY #endif -#if (defined WIN32 || defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined CVAPI_EXPORTS -# define CV_EXPORTS __declspec(dllexport) -#elif defined __GNUC__ && __GNUC__ >= 4 -# define CV_EXPORTS __attribute__ ((visibility ("default"))) +#ifdef CVAPI_EXPORTS +# if (defined _WIN32 || defined WINCE || defined __CYGWIN__) +# define CV_EXPORTS __declspec(dllexport) +# elif defined __GNUC__ && __GNUC__ >= 4 +# define CV_EXPORTS __attribute__ ((visibility ("default"))) +# endif +#endif + +#ifndef CV_EXPORTS +# define CV_EXPORTS +#endif + +#ifdef _MSC_VER +# define CV_EXPORTS_TEMPLATE #else -# define CV_EXPORTS +# define CV_EXPORTS_TEMPLATE CV_EXPORTS +#endif + +#ifndef CV_DEPRECATED +# if defined(__GNUC__) +# define CV_DEPRECATED __attribute__ ((deprecated)) +# elif defined(_MSC_VER) +# define CV_DEPRECATED __declspec(deprecated) +# else +# define CV_DEPRECATED +# endif #endif #ifndef CV_EXTERN_C @@ -357,67 +300,6 @@ Cv64suf; * Matrix type (Mat) * \****************************************************************************************/ -#define CV_CN_MAX 512 -#define CV_CN_SHIFT 3 -#define CV_DEPTH_MAX (1 << CV_CN_SHIFT) - -#define CV_8U 0 -#define CV_8S 1 -#define CV_16U 2 -#define CV_16S 3 -#define CV_32S 4 -#define CV_32F 5 -#define CV_64F 6 -#define CV_USRTYPE1 7 - -#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1) -#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK) - -#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)) -#define CV_MAKE_TYPE CV_MAKETYPE - -#define CV_8UC1 CV_MAKETYPE(CV_8U,1) -#define CV_8UC2 CV_MAKETYPE(CV_8U,2) -#define CV_8UC3 CV_MAKETYPE(CV_8U,3) -#define CV_8UC4 CV_MAKETYPE(CV_8U,4) -#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n)) - -#define CV_8SC1 CV_MAKETYPE(CV_8S,1) -#define CV_8SC2 CV_MAKETYPE(CV_8S,2) -#define CV_8SC3 CV_MAKETYPE(CV_8S,3) -#define CV_8SC4 CV_MAKETYPE(CV_8S,4) -#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n)) - -#define CV_16UC1 CV_MAKETYPE(CV_16U,1) -#define CV_16UC2 CV_MAKETYPE(CV_16U,2) -#define CV_16UC3 CV_MAKETYPE(CV_16U,3) -#define CV_16UC4 CV_MAKETYPE(CV_16U,4) -#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n)) - -#define CV_16SC1 CV_MAKETYPE(CV_16S,1) -#define CV_16SC2 CV_MAKETYPE(CV_16S,2) -#define CV_16SC3 CV_MAKETYPE(CV_16S,3) -#define CV_16SC4 CV_MAKETYPE(CV_16S,4) -#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n)) - -#define CV_32SC1 CV_MAKETYPE(CV_32S,1) -#define CV_32SC2 CV_MAKETYPE(CV_32S,2) -#define CV_32SC3 CV_MAKETYPE(CV_32S,3) -#define CV_32SC4 CV_MAKETYPE(CV_32S,4) -#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n)) - -#define CV_32FC1 CV_MAKETYPE(CV_32F,1) -#define CV_32FC2 CV_MAKETYPE(CV_32F,2) -#define CV_32FC3 CV_MAKETYPE(CV_32F,3) -#define CV_32FC4 CV_MAKETYPE(CV_32F,4) -#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n)) - -#define CV_64FC1 CV_MAKETYPE(CV_64F,1) -#define CV_64FC2 CV_MAKETYPE(CV_64F,2) -#define CV_64FC3 CV_MAKETYPE(CV_64F,3) -#define CV_64FC4 CV_MAKETYPE(CV_64F,4) -#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n)) - #define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT) #define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1) #define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1) @@ -431,7 +313,7 @@ Cv64suf; #define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG) /** Size of each channel item, - 0x124489 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */ + 0x8442211 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */ #define CV_ELEM_SIZE1(type) \ ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15) @@ -447,14 +329,36 @@ Cv64suf; # define MAX(a,b) ((a) < (b) ? (b) : (a)) #endif +/****************************************************************************************\ +* static analysys * +\****************************************************************************************/ + +// In practice, some macro are not processed correctly (noreturn is not detected). +// We need to use simplified definition for them. +#ifndef CV_STATIC_ANALYSIS +# if defined(__KLOCWORK__) || defined(__clang_analyzer__) || defined(__COVERITY__) +# define CV_STATIC_ANALYSIS +# endif +#endif + +/****************************************************************************************\ +* Thread sanitizer * +\****************************************************************************************/ +#ifndef CV_THREAD_SANITIZER +# if defined(__has_feature) +# if __has_feature(thread_sanitizer) +# define CV_THREAD_SANITIZER +# endif +# endif +#endif + /****************************************************************************************\ * exchange-add operation for atomic operations on reference counters * \****************************************************************************************/ -#if defined __INTEL_COMPILER && !(defined WIN32 || defined _WIN32) - // atomic increment on the linux version of the Intel(tm) compiler -# define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd(const_cast(reinterpret_cast(addr)), delta) -#elif defined __GNUC__ +#ifdef CV_XADD + // allow to use user-defined macro +#elif defined __GNUC__ || defined __clang__ # if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__) # ifdef __ATOMIC_ACQ_REL # define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL) @@ -492,12 +396,26 @@ Cv64suf; #endif +/****************************************************************************************\ +* C++ 11 * +\****************************************************************************************/ +#ifndef CV_CXX11 +# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) +# define CV_CXX11 1 +# endif +#else +# if CV_CXX11 == 0 +# undef CV_CXX11 +# endif +#endif + + /****************************************************************************************\ * C++ Move semantics * \****************************************************************************************/ #ifndef CV_CXX_MOVE_SEMANTICS -# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(_MSC_VER) && _MSC_VER >= 1600 +# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(_MSC_VER) && _MSC_VER >= 1600) # define CV_CXX_MOVE_SEMANTICS 1 # elif defined(__clang) # if __has_feature(cxx_rvalue_references) @@ -510,6 +428,21 @@ Cv64suf; # endif #endif +/****************************************************************************************\ +* C++11 std::array * +\****************************************************************************************/ + +#ifndef CV_CXX_STD_ARRAY +# if __cplusplus >= 201103L +# define CV_CXX_STD_ARRAY 1 +# include +# endif +#else +# if CV_CXX_STD_ARRAY == 0 +# undef CV_CXX_STD_ARRAY +# endif +#endif + //! @} -#endif // __OPENCV_CORE_CVDEF_H__ +#endif // OPENCV_CORE_CVDEF_H diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cvstd.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cvstd.hpp similarity index 95% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/cvstd.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/cvstd.hpp index edae954f..0a3f553a 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cvstd.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cvstd.hpp @@ -41,25 +41,21 @@ // //M*/ -#ifndef __OPENCV_CORE_CVSTD_HPP__ -#define __OPENCV_CORE_CVSTD_HPP__ +#ifndef OPENCV_CORE_CVSTD_HPP +#define OPENCV_CORE_CVSTD_HPP #ifndef __cplusplus # error cvstd.hpp header must be compiled as C++ #endif #include "opencv2/core/cvdef.h" - #include #include #include -#ifndef OPENCV_NOSTL -# include -#endif +#include // import useful primitives from stl -#ifndef OPENCV_NOSTL_TRANSITIONAL # include # include # include //for abs(int) @@ -67,6 +63,11 @@ namespace cv { + static inline uchar abs(uchar a) { return a; } + static inline ushort abs(ushort a) { return a; } + static inline unsigned abs(unsigned a) { return a; } + static inline uint64 abs(uint64 a) { return a; } + using std::min; using std::max; using std::abs; @@ -77,29 +78,6 @@ namespace cv using std::log; } -namespace std -{ - static inline uchar abs(uchar a) { return a; } - static inline ushort abs(ushort a) { return a; } - static inline unsigned abs(unsigned a) { return a; } - static inline uint64 abs(uint64 a) { return a; } -} - -#else -namespace cv -{ - template static inline T min(T a, T b) { return a < b ? a : b; } - template static inline T max(T a, T b) { return a > b ? a : b; } - template static inline T abs(T a) { return a < 0 ? -a : a; } - template static inline void swap(T& a, T& b) { T tmp = a; a = b; b = tmp; } - - template<> inline uchar abs(uchar a) { return a; } - template<> inline ushort abs(ushort a) { return a; } - template<> inline unsigned abs(unsigned a) { return a; } - template<> inline uint64 abs(uint64 a) { return a; } -} -#endif - namespace cv { //! @addtogroup core_utils @@ -492,7 +470,7 @@ public: static const size_t npos = size_t(-1); - explicit String(); + String(); String(const String& str); String(const String& str, size_t pos, size_t len = npos); String(const char* s); @@ -559,7 +537,6 @@ public: String toLowerCase() const; -#ifndef OPENCV_NOSTL String(const std::string& str); String(const std::string& str, size_t pos, size_t len = npos); String& operator=(const std::string& str); @@ -568,7 +545,6 @@ public: friend String operator+ (const String& lhs, const std::string& rhs); friend String operator+ (const std::string& lhs, const String& rhs); -#endif private: char* cstr_; @@ -622,6 +598,7 @@ String::String(const char* s) { if (!s) return; size_t len = strlen(s); + if (!len) return; memcpy(allocate(len), s, len); } @@ -630,6 +607,7 @@ String::String(const char* s, size_t n) : cstr_(0), len_(0) { if (!n) return; + if (!s) return; memcpy(allocate(n), s, n); } @@ -637,6 +615,7 @@ inline String::String(size_t n, char c) : cstr_(0), len_(0) { + if (!n) return; memset(allocate(n), c, n); } @@ -645,6 +624,7 @@ String::String(const char* first, const char* last) : cstr_(0), len_(0) { size_t len = (size_t)(last - first); + if (!len) return; memcpy(allocate(len), first, len); } @@ -653,6 +633,7 @@ String::String(Iterator first, Iterator last) : cstr_(0), len_(0) { size_t len = (size_t)(last - first); + if (!len) return; char* str = allocate(len); while (first != last) { @@ -685,7 +666,7 @@ String& String::operator=(const char* s) deallocate(); if (!s) return *this; size_t len = strlen(s); - memcpy(allocate(len), s, len); + if (len) memcpy(allocate(len), s, len); return *this; } @@ -751,7 +732,7 @@ const char* String::begin() const inline const char* String::end() const { - return len_ ? cstr_ + 1 : 0; + return len_ ? cstr_ + len_ : NULL; } inline @@ -958,8 +939,9 @@ size_t String::find_last_of(const char* s, size_t pos) const inline String String::toLowerCase() const { + if (!cstr_) + return String(); String res(cstr_, len_); - for (size_t i = 0; i < len_; ++i) res.cstr_[i] = (char) ::tolower(cstr_[i]); @@ -978,8 +960,8 @@ String operator + (const String& lhs, const String& rhs) { String s; s.allocate(lhs.len_ + rhs.len_); - memcpy(s.cstr_, lhs.cstr_, lhs.len_); - memcpy(s.cstr_ + lhs.len_, rhs.cstr_, rhs.len_); + if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); + if (rhs.len_) memcpy(s.cstr_ + lhs.len_, rhs.cstr_, rhs.len_); return s; } @@ -989,8 +971,8 @@ String operator + (const String& lhs, const char* rhs) String s; size_t rhslen = strlen(rhs); s.allocate(lhs.len_ + rhslen); - memcpy(s.cstr_, lhs.cstr_, lhs.len_); - memcpy(s.cstr_ + lhs.len_, rhs, rhslen); + if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); + if (rhslen) memcpy(s.cstr_ + lhs.len_, rhs, rhslen); return s; } @@ -1000,8 +982,8 @@ String operator + (const char* lhs, const String& rhs) String s; size_t lhslen = strlen(lhs); s.allocate(lhslen + rhs.len_); - memcpy(s.cstr_, lhs, lhslen); - memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_); + if (lhslen) memcpy(s.cstr_, lhs, lhslen); + if (rhs.len_) memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_); return s; } @@ -1010,7 +992,7 @@ String operator + (const String& lhs, char rhs) { String s; s.allocate(lhs.len_ + 1); - memcpy(s.cstr_, lhs.cstr_, lhs.len_); + if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); s.cstr_[lhs.len_] = rhs; return s; } @@ -1021,7 +1003,7 @@ String operator + (char lhs, const String& rhs) String s; s.allocate(rhs.len_ + 1); s.cstr_[0] = lhs; - memcpy(s.cstr_ + 1, rhs.cstr_, rhs.len_); + if (rhs.len_) memcpy(s.cstr_ + 1, rhs.cstr_, rhs.len_); return s; } @@ -1048,22 +1030,11 @@ static inline bool operator>= (const String& lhs, const char* rhs) { return lh } // cv -#ifndef OPENCV_NOSTL_TRANSITIONAL namespace std { static inline void swap(cv::String& a, cv::String& b) { a.swap(b); } } -#else -namespace cv -{ - template<> inline - void swap(cv::String& a, cv::String& b) - { - a.swap(b); - } -} -#endif #include "opencv2/core/ptr.inl.hpp" -#endif //__OPENCV_CORE_CVSTD_HPP__ +#endif //OPENCV_CORE_CVSTD_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cvstd.inl.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cvstd.inl.hpp similarity index 85% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/cvstd.inl.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/cvstd.inl.hpp index ad154061..85230f59 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/cvstd.inl.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/cvstd.inl.hpp @@ -41,19 +41,21 @@ // //M*/ -#ifndef __OPENCV_CORE_CVSTDINL_HPP__ -#define __OPENCV_CORE_CVSTDINL_HPP__ +#ifndef OPENCV_CORE_CVSTDINL_HPP +#define OPENCV_CORE_CVSTDINL_HPP -#ifndef OPENCV_NOSTL -# include -# include -#endif +#include +#include //! @cond IGNORED +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4127 ) +#endif + namespace cv { -#ifndef OPENCV_NOSTL template class DataType< std::complex<_Tp> > { @@ -78,7 +80,7 @@ String::String(const std::string& str) if (!str.empty()) { size_t len = str.size(); - memcpy(allocate(len), str.c_str(), len); + if (len) memcpy(allocate(len), str.c_str(), len); } } @@ -100,7 +102,7 @@ String& String::operator = (const std::string& str) if (!str.empty()) { size_t len = str.size(); - memcpy(allocate(len), str.c_str(), len); + if (len) memcpy(allocate(len), str.c_str(), len); } return *this; } @@ -124,8 +126,8 @@ String operator + (const String& lhs, const std::string& rhs) String s; size_t rhslen = rhs.size(); s.allocate(lhs.len_ + rhslen); - memcpy(s.cstr_, lhs.cstr_, lhs.len_); - memcpy(s.cstr_ + lhs.len_, rhs.c_str(), rhslen); + if (lhs.len_) memcpy(s.cstr_, lhs.cstr_, lhs.len_); + if (rhslen) memcpy(s.cstr_ + lhs.len_, rhs.c_str(), rhslen); return s; } @@ -135,8 +137,8 @@ String operator + (const std::string& lhs, const String& rhs) String s; size_t lhslen = lhs.size(); s.allocate(lhslen + rhs.len_); - memcpy(s.cstr_, lhs.c_str(), lhslen); - memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_); + if (lhslen) memcpy(s.cstr_, lhs.c_str(), lhslen); + if (rhs.len_) memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_); return s; } @@ -151,9 +153,7 @@ FileNode::operator std::string() const template<> inline void operator >> (const FileNode& n, std::string& value) { - String val; - read(n, val, val); - value = val; + read(n, value, std::string()); } template<> inline @@ -183,6 +183,18 @@ std::ostream& operator << (std::ostream& out, const Mat& mtx) return out << Formatter::get()->format(mtx); } +static inline +std::ostream& operator << (std::ostream& out, const UMat& m) +{ + return out << m.getMat(ACCESS_READ); +} + +template static inline +std::ostream& operator << (std::ostream& out, const Complex<_Tp>& c) +{ + return out << "(" << c.re << "," << c.im << ")"; +} + template static inline std::ostream& operator << (std::ostream& out, const std::vector >& vec) { @@ -221,14 +233,7 @@ template static inline std::ostream& operator << (std::ostream& out, const Vec<_Tp, n>& vec) { out << "["; -#ifdef _MSC_VER -#pragma warning( push ) -#pragma warning( disable: 4127 ) -#endif - if(Vec<_Tp, n>::depth < CV_32F) -#ifdef _MSC_VER -#pragma warning( pop ) -#endif + if (cv::traits::Depth<_Tp>::value <= CV_32S) { for (int i = 0; i < n - 1; ++i) { out << (int)vec[i] << ", "; @@ -258,10 +263,24 @@ std::ostream& operator << (std::ostream& out, const Rect_<_Tp>& rect) return out << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]"; } +static inline std::ostream& operator << (std::ostream& out, const MatSize& msize) +{ + int i, dims = msize.p[-1]; + for( i = 0; i < dims; i++ ) + { + out << msize.p[i]; + if( i < dims-1 ) + out << " x "; + } + return out; +} -#endif // OPENCV_NOSTL } // cv +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + //! @endcond -#endif // __OPENCV_CORE_CVSTDINL_HPP__ +#endif // OPENCV_CORE_CVSTDINL_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/directx.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/directx.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/directx.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/directx.hpp index 764af74d..056a85a1 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/directx.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/directx.hpp @@ -39,8 +39,8 @@ // //M*/ -#ifndef __OPENCV_CORE_DIRECTX_HPP__ -#define __OPENCV_CORE_DIRECTX_HPP__ +#ifndef OPENCV_CORE_DIRECTX_HPP +#define OPENCV_CORE_DIRECTX_HPP #include "mat.hpp" #include "ocl.hpp" @@ -181,4 +181,4 @@ CV_EXPORTS int getTypeFromD3DFORMAT(const int iD3DFORMAT); // enum D3DTYPE for D } } // namespace cv::directx -#endif // __OPENCV_CORE_DIRECTX_HPP__ +#endif // OPENCV_CORE_DIRECTX_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/eigen.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/eigen.hpp similarity index 73% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/eigen.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/eigen.hpp index 44df04c5..c8603aca 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/eigen.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/eigen.hpp @@ -42,8 +42,8 @@ //M*/ -#ifndef __OPENCV_CORE_EIGEN_HPP__ -#define __OPENCV_CORE_EIGEN_HPP__ +#ifndef OPENCV_CORE_EIGEN_HPP +#define OPENCV_CORE_EIGEN_HPP #include "opencv2/core.hpp" @@ -64,14 +64,14 @@ void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCo { if( !(src.Flags & Eigen::RowMajorBit) ) { - Mat _src(src.cols(), src.rows(), DataType<_Tp>::type, - (void*)src.data(), src.stride()*sizeof(_Tp)); + Mat _src(src.cols(), src.rows(), traits::Type<_Tp>::value, + (void*)src.data(), src.outerStride()*sizeof(_Tp)); transpose(_src, dst); } else { - Mat _src(src.rows(), src.cols(), DataType<_Tp>::type, - (void*)src.data(), src.stride()*sizeof(_Tp)); + Mat _src(src.rows(), src.cols(), traits::Type<_Tp>::value, + (void*)src.data(), src.outerStride()*sizeof(_Tp)); _src.copyTo(dst); } } @@ -98,8 +98,8 @@ void cv2eigen( const Mat& src, CV_DbgAssert(src.rows == _rows && src.cols == _cols); if( !(dst.Flags & Eigen::RowMajorBit) ) { - const Mat _dst(src.cols, src.rows, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); if( src.type() == _dst.type() ) transpose(src, _dst); else if( src.cols == src.rows ) @@ -112,8 +112,8 @@ void cv2eigen( const Mat& src, } else { - const Mat _dst(src.rows, src.cols, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); src.convertTo(_dst, _dst.type()); } } @@ -125,14 +125,14 @@ void cv2eigen( const Matx<_Tp, _rows, _cols>& src, { if( !(dst.Flags & Eigen::RowMajorBit) ) { - const Mat _dst(_cols, _rows, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(_cols, _rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); transpose(src, _dst); } else { - const Mat _dst(_rows, _cols, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(_rows, _cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); Mat(src).copyTo(_dst); } } @@ -144,8 +144,8 @@ void cv2eigen( const Mat& src, dst.resize(src.rows, src.cols); if( !(dst.Flags & Eigen::RowMajorBit) ) { - const Mat _dst(src.cols, src.rows, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); if( src.type() == _dst.type() ) transpose(src, _dst); else if( src.cols == src.rows ) @@ -158,8 +158,8 @@ void cv2eigen( const Mat& src, } else { - const Mat _dst(src.rows, src.cols, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); src.convertTo(_dst, _dst.type()); } } @@ -172,14 +172,14 @@ void cv2eigen( const Matx<_Tp, _rows, _cols>& src, dst.resize(_rows, _cols); if( !(dst.Flags & Eigen::RowMajorBit) ) { - const Mat _dst(_cols, _rows, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(_cols, _rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); transpose(src, _dst); } else { - const Mat _dst(_rows, _cols, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(_rows, _cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); Mat(src).copyTo(_dst); } } @@ -193,8 +193,8 @@ void cv2eigen( const Mat& src, if( !(dst.Flags & Eigen::RowMajorBit) ) { - const Mat _dst(src.cols, src.rows, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); if( src.type() == _dst.type() ) transpose(src, _dst); else @@ -202,8 +202,8 @@ void cv2eigen( const Mat& src, } else { - const Mat _dst(src.rows, src.cols, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); src.convertTo(_dst, _dst.type()); } } @@ -217,14 +217,14 @@ void cv2eigen( const Matx<_Tp, _rows, 1>& src, if( !(dst.Flags & Eigen::RowMajorBit) ) { - const Mat _dst(1, _rows, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(1, _rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); transpose(src, _dst); } else { - const Mat _dst(_rows, 1, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(_rows, 1, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); src.copyTo(_dst); } } @@ -238,8 +238,8 @@ void cv2eigen( const Mat& src, dst.resize(src.cols); if( !(dst.Flags & Eigen::RowMajorBit) ) { - const Mat _dst(src.cols, src.rows, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); if( src.type() == _dst.type() ) transpose(src, _dst); else @@ -247,8 +247,8 @@ void cv2eigen( const Mat& src, } else { - const Mat _dst(src.rows, src.cols, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); src.convertTo(_dst, _dst.type()); } } @@ -261,14 +261,14 @@ void cv2eigen( const Matx<_Tp, 1, _cols>& src, dst.resize(_cols); if( !(dst.Flags & Eigen::RowMajorBit) ) { - const Mat _dst(_cols, 1, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(_cols, 1, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); transpose(src, _dst); } else { - const Mat _dst(1, _cols, DataType<_Tp>::type, - dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); + const Mat _dst(1, _cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); Mat(src).copyTo(_dst); } } diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/fast_math.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/fast_math.hpp similarity index 79% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/fast_math.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/fast_math.hpp index b8b241b0..7858d404 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/fast_math.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/fast_math.hpp @@ -42,11 +42,17 @@ // //M*/ -#ifndef __OPENCV_CORE_FAST_MATH_HPP__ -#define __OPENCV_CORE_FAST_MATH_HPP__ +#ifndef OPENCV_CORE_FAST_MATH_HPP +#define OPENCV_CORE_FAST_MATH_HPP #include "opencv2/core/cvdef.h" +#if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ + && defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__) +#include +#endif + + //! @addtogroup core_utils //! @{ @@ -54,24 +60,27 @@ * fast math * \****************************************************************************************/ -#if defined __BORLANDC__ -# include -#elif defined __cplusplus +#ifdef __cplusplus # include #else -# include +# ifdef __BORLANDC__ +# include +# else +# include +# endif #endif #ifdef HAVE_TEGRA_OPTIMIZATION # include "tegra_round.hpp" #endif -#if CV_VFP +#if defined __GNUC__ && defined __arm__ && (defined __ARM_PCS_VFP || defined __ARM_VFPV3__ || defined __ARM_NEON__) && !defined __SOFTFP__ && !defined(__CUDACC__) // 1. general scheme #define ARM_ROUND(_value, _asm_string) \ int res; \ float temp; \ - asm(_asm_string : [res] "=r" (res), [temp] "=w" (temp) : [value] "w" (_value)); \ + (void)temp; \ + __asm__(_asm_string : [res] "=r" (res), [temp] "=w" (temp) : [value] "w" (_value)); \ return res // 2. version for double #ifdef __clang__ @@ -81,7 +90,7 @@ #endif // 3. version for float #define ARM_ROUND_FLT(value) ARM_ROUND(value, "vcvtr.s32.f32 %[temp], %[value]\n vmov %[res], %[temp]") -#endif // CV_VFP +#endif /** @brief Rounds floating-point number to the nearest integer @@ -92,7 +101,7 @@ CV_INLINE int cvRound( double value ) { #if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ - && defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__) + && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) && !defined(__CUDACC__) __m128d t = _mm_set_sd( value ); return _mm_cvtsd_si32(t); #elif defined _MSC_VER && defined _M_IX86 @@ -107,7 +116,7 @@ cvRound( double value ) defined __GNUC__) && defined HAVE_TEGRA_OPTIMIZATION TEGRA_ROUND_DBL(value); #elif defined CV_ICC || defined __GNUC__ -# if CV_VFP +# if defined ARM_ROUND_DBL ARM_ROUND_DBL(value); # else return (int)lrint(value); @@ -129,18 +138,8 @@ cvRound( double value ) */ CV_INLINE int cvFloor( double value ) { -#if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__) - __m128d t = _mm_set_sd( value ); - int i = _mm_cvtsd_si32(t); - return i - _mm_movemask_pd(_mm_cmplt_sd(t, _mm_cvtsi32_sd(t,i))); -#elif defined __GNUC__ int i = (int)value; return i - (i > value); -#else - int i = cvRound(value); - float diff = (float)(value - i); - return i - (diff < 0); -#endif } /** @brief Rounds floating-point number to the nearest integer not smaller than the original. @@ -152,18 +151,8 @@ CV_INLINE int cvFloor( double value ) */ CV_INLINE int cvCeil( double value ) { -#if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__&& !defined __APPLE__)) && !defined(__CUDACC__) - __m128d t = _mm_set_sd( value ); - int i = _mm_cvtsd_si32(t); - return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i), t)); -#elif defined __GNUC__ int i = (int)value; return i + (i < value); -#else - int i = cvRound(value); - float diff = (float)(i - value); - return i + (diff < 0); -#endif } /** @brief Determines if the argument is Not A Number. @@ -199,8 +188,8 @@ CV_INLINE int cvIsInf( double value ) /** @overload */ CV_INLINE int cvRound(float value) { -#if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ && \ - defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__) +#if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ + && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) && !defined(__CUDACC__) __m128 t = _mm_set_ss( value ); return _mm_cvtss_si32(t); #elif defined _MSC_VER && defined _M_IX86 @@ -215,7 +204,7 @@ CV_INLINE int cvRound(float value) defined __GNUC__) && defined HAVE_TEGRA_OPTIMIZATION TEGRA_ROUND_FLT(value); #elif defined CV_ICC || defined __GNUC__ -# if CV_VFP +# if defined ARM_ROUND_FLT ARM_ROUND_FLT(value); # else return (int)lrintf(value); @@ -236,18 +225,8 @@ CV_INLINE int cvRound( int value ) /** @overload */ CV_INLINE int cvFloor( float value ) { -#if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__) - __m128 t = _mm_set_ss( value ); - int i = _mm_cvtss_si32(t); - return i - _mm_movemask_ps(_mm_cmplt_ss(t, _mm_cvtsi32_ss(t,i))); -#elif defined __GNUC__ int i = (int)value; return i - (i > value); -#else - int i = cvRound(value); - float diff = (float)(value - i); - return i - (diff < 0); -#endif } /** @overload */ @@ -259,18 +238,8 @@ CV_INLINE int cvFloor( int value ) /** @overload */ CV_INLINE int cvCeil( float value ) { -#if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__&& !defined __APPLE__)) && !defined(__CUDACC__) - __m128 t = _mm_set_ss( value ); - int i = _mm_cvtss_si32(t); - return i + _mm_movemask_ps(_mm_cmplt_ss(_mm_cvtsi32_ss(t,i), t)); -#elif defined __GNUC__ int i = (int)value; return i + (i < value); -#else - int i = cvRound(value); - float diff = (float)(i - value); - return i + (diff < 0); -#endif } /** @overload */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/hal.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/hal.hpp similarity index 81% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/hal.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/hal.hpp index 118913eb..68900ec4 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/hal.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/hal.hpp @@ -42,23 +42,13 @@ // //M*/ -#ifndef __OPENCV_HAL_HPP__ -#define __OPENCV_HAL_HPP__ +#ifndef OPENCV_HAL_HPP +#define OPENCV_HAL_HPP #include "opencv2/core/cvdef.h" +#include "opencv2/core/cvstd.hpp" #include "opencv2/core/hal/interface.h" -//! @cond IGNORED -#define CALL_HAL(name, fun, ...) \ - int res = fun(__VA_ARGS__); \ - if (res == CV_HAL_ERROR_OK) \ - return; \ - else if (res != CV_HAL_ERROR_NOT_IMPLEMENTED) \ - CV_Error_(cv::Error::StsInternal, \ - ("HAL implementation " CVAUX_STR(name) " ==> " CVAUX_STR(fun) " returned %d (0x%08x)", res, res)); -//! @endcond - - namespace cv { namespace hal { //! @addtogroup core_hal_functions @@ -74,6 +64,23 @@ CV_EXPORTS int LU32f(float* A, size_t astep, int m, float* b, size_t bstep, int CV_EXPORTS int LU64f(double* A, size_t astep, int m, double* b, size_t bstep, int n); CV_EXPORTS bool Cholesky32f(float* A, size_t astep, int m, float* b, size_t bstep, int n); CV_EXPORTS bool Cholesky64f(double* A, size_t astep, int m, double* b, size_t bstep, int n); +CV_EXPORTS void SVD32f(float* At, size_t astep, float* W, float* U, size_t ustep, float* Vt, size_t vstep, int m, int n, int flags); +CV_EXPORTS void SVD64f(double* At, size_t astep, double* W, double* U, size_t ustep, double* Vt, size_t vstep, int m, int n, int flags); +CV_EXPORTS int QR32f(float* A, size_t astep, int m, int n, int k, float* b, size_t bstep, float* hFactors); +CV_EXPORTS int QR64f(double* A, size_t astep, int m, int n, int k, double* b, size_t bstep, double* hFactors); + +CV_EXPORTS void gemm32f(const float* src1, size_t src1_step, const float* src2, size_t src2_step, + float alpha, const float* src3, size_t src3_step, float beta, float* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); +CV_EXPORTS void gemm64f(const double* src1, size_t src1_step, const double* src2, size_t src2_step, + double alpha, const double* src3, size_t src3_step, double beta, double* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); +CV_EXPORTS void gemm32fc(const float* src1, size_t src1_step, const float* src2, size_t src2_step, + float alpha, const float* src3, size_t src3_step, float beta, float* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); +CV_EXPORTS void gemm64fc(const double* src1, size_t src1_step, const double* src2, size_t src2_step, + double alpha, const double* src3, size_t src3_step, double beta, double* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); CV_EXPORTS int normL1_(const uchar* a, const uchar* b, int n); CV_EXPORTS float normL1_(const float* a, const float* b, int n); @@ -84,7 +91,8 @@ CV_EXPORTS void exp64f(const double* src, double* dst, int n); CV_EXPORTS void log32f(const float* src, float* dst, int n); CV_EXPORTS void log64f(const double* src, double* dst, int n); -CV_EXPORTS void fastAtan2(const float* y, const float* x, float* dst, int n, bool angleInDegrees); +CV_EXPORTS void fastAtan32f(const float* y, const float* x, float* dst, int n, bool angleInDegrees); +CV_EXPORTS void fastAtan64f(const double* y, const double* x, double* dst, int n, bool angleInDegrees); CV_EXPORTS void magnitude32f(const float* x, const float* y, float* dst, int n); CV_EXPORTS void magnitude64f(const double* x, const double* y, double* dst, int n); CV_EXPORTS void sqrt32f(const float* src, float* dst, int len); @@ -171,13 +179,13 @@ CV_EXPORTS void div32s( const int* src1, size_t step1, const int* src2, size_t s CV_EXPORTS void div32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scale); CV_EXPORTS void div64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scale); -CV_EXPORTS void recip8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* scale); -CV_EXPORTS void recip8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* scale); -CV_EXPORTS void recip16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scale); -CV_EXPORTS void recip16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* scale); -CV_EXPORTS void recip32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* scale); -CV_EXPORTS void recip32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scale); -CV_EXPORTS void recip64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip8u( const uchar *, size_t, const uchar * src2, size_t step2, uchar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip8s( const schar *, size_t, const schar * src2, size_t step2, schar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip16u( const ushort *, size_t, const ushort * src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip16s( const short *, size_t, const short * src2, size_t step2, short* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip32s( const int *, size_t, const int * src2, size_t step2, int* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip32f( const float *, size_t, const float * src2, size_t step2, float* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip64f( const double *, size_t, const double * src2, size_t step2, double* dst, size_t step, int width, int height, void* scale); CV_EXPORTS void addWeighted8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _scalars ); CV_EXPORTS void addWeighted8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* scalars ); @@ -187,6 +195,29 @@ CV_EXPORTS void addWeighted32s( const int* src1, size_t step1, const int* src2, CV_EXPORTS void addWeighted32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scalars ); CV_EXPORTS void addWeighted64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scalars ); +struct CV_EXPORTS DFT1D +{ + static Ptr create(int len, int count, int depth, int flags, bool * useBuffer = 0); + virtual void apply(const uchar *src, uchar *dst) = 0; + virtual ~DFT1D() {} +}; + +struct CV_EXPORTS DFT2D +{ + static Ptr create(int width, int height, int depth, + int src_channels, int dst_channels, + int flags, int nonzero_rows = 0); + virtual void apply(const uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step) = 0; + virtual ~DFT2D() {} +}; + +struct CV_EXPORTS DCT2D +{ + static Ptr create(int width, int height, int depth, int flags); + virtual void apply(const uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step) = 0; + virtual ~DCT2D() {} +}; + //! @} core_hal //============================================================================= @@ -204,6 +235,7 @@ CV_EXPORTS void exp(const double* src, double* dst, int n); CV_EXPORTS void log(const float* src, float* dst, int n); CV_EXPORTS void log(const double* src, double* dst, int n); +CV_EXPORTS void fastAtan2(const float* y, const float* x, float* dst, int n, bool angleInDegrees); CV_EXPORTS void magnitude(const float* x, const float* y, float* dst, int n); CV_EXPORTS void magnitude(const double* x, const double* y, double* dst, int n); CV_EXPORTS void sqrt(const float* src, float* dst, int len); @@ -215,4 +247,4 @@ CV_EXPORTS void invSqrt(const double* src, double* dst, int len); }} //cv::hal -#endif //__OPENCV_HAL_HPP__ +#endif //OPENCV_HAL_HPP diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/interface.h b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/interface.h new file mode 100644 index 00000000..8f640254 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/interface.h @@ -0,0 +1,182 @@ +#ifndef OPENCV_CORE_HAL_INTERFACE_H +#define OPENCV_CORE_HAL_INTERFACE_H + +//! @addtogroup core_hal_interface +//! @{ + +//! @name Return codes +//! @{ +#define CV_HAL_ERROR_OK 0 +#define CV_HAL_ERROR_NOT_IMPLEMENTED 1 +#define CV_HAL_ERROR_UNKNOWN -1 +//! @} + +#ifdef __cplusplus +#include +#else +#include +#include +#endif + +//! @name Data types +//! primitive types +//! - schar - signed 1 byte integer +//! - uchar - unsigned 1 byte integer +//! - short - signed 2 byte integer +//! - ushort - unsigned 2 byte integer +//! - int - signed 4 byte integer +//! - uint - unsigned 4 byte integer +//! - int64 - signed 8 byte integer +//! - uint64 - unsigned 8 byte integer +//! @{ +#if !defined _MSC_VER && !defined __BORLANDC__ +# if defined __cplusplus && __cplusplus >= 201103L && !defined __APPLE__ +# include +# ifdef __NEWLIB__ + typedef unsigned int uint; +# else + typedef std::uint32_t uint; +# endif +# else +# include + typedef uint32_t uint; +# endif +#else + typedef unsigned uint; +#endif + +typedef signed char schar; + +#ifndef __IPL_H__ + typedef unsigned char uchar; + typedef unsigned short ushort; +#endif + +#if defined _MSC_VER || defined __BORLANDC__ + typedef __int64 int64; + typedef unsigned __int64 uint64; +# define CV_BIG_INT(n) n##I64 +# define CV_BIG_UINT(n) n##UI64 +#else + typedef int64_t int64; + typedef uint64_t uint64; +# define CV_BIG_INT(n) n##LL +# define CV_BIG_UINT(n) n##ULL +#endif + +#define CV_CN_MAX 512 +#define CV_CN_SHIFT 3 +#define CV_DEPTH_MAX (1 << CV_CN_SHIFT) + +#define CV_8U 0 +#define CV_8S 1 +#define CV_16U 2 +#define CV_16S 3 +#define CV_32S 4 +#define CV_32F 5 +#define CV_64F 6 +#define CV_USRTYPE1 7 + +#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1) +#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK) + +#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)) +#define CV_MAKE_TYPE CV_MAKETYPE + +#define CV_8UC1 CV_MAKETYPE(CV_8U,1) +#define CV_8UC2 CV_MAKETYPE(CV_8U,2) +#define CV_8UC3 CV_MAKETYPE(CV_8U,3) +#define CV_8UC4 CV_MAKETYPE(CV_8U,4) +#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n)) + +#define CV_8SC1 CV_MAKETYPE(CV_8S,1) +#define CV_8SC2 CV_MAKETYPE(CV_8S,2) +#define CV_8SC3 CV_MAKETYPE(CV_8S,3) +#define CV_8SC4 CV_MAKETYPE(CV_8S,4) +#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n)) + +#define CV_16UC1 CV_MAKETYPE(CV_16U,1) +#define CV_16UC2 CV_MAKETYPE(CV_16U,2) +#define CV_16UC3 CV_MAKETYPE(CV_16U,3) +#define CV_16UC4 CV_MAKETYPE(CV_16U,4) +#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n)) + +#define CV_16SC1 CV_MAKETYPE(CV_16S,1) +#define CV_16SC2 CV_MAKETYPE(CV_16S,2) +#define CV_16SC3 CV_MAKETYPE(CV_16S,3) +#define CV_16SC4 CV_MAKETYPE(CV_16S,4) +#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n)) + +#define CV_32SC1 CV_MAKETYPE(CV_32S,1) +#define CV_32SC2 CV_MAKETYPE(CV_32S,2) +#define CV_32SC3 CV_MAKETYPE(CV_32S,3) +#define CV_32SC4 CV_MAKETYPE(CV_32S,4) +#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n)) + +#define CV_32FC1 CV_MAKETYPE(CV_32F,1) +#define CV_32FC2 CV_MAKETYPE(CV_32F,2) +#define CV_32FC3 CV_MAKETYPE(CV_32F,3) +#define CV_32FC4 CV_MAKETYPE(CV_32F,4) +#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n)) + +#define CV_64FC1 CV_MAKETYPE(CV_64F,1) +#define CV_64FC2 CV_MAKETYPE(CV_64F,2) +#define CV_64FC3 CV_MAKETYPE(CV_64F,3) +#define CV_64FC4 CV_MAKETYPE(CV_64F,4) +#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n)) +//! @} + +//! @name Comparison operation +//! @sa cv::CmpTypes +//! @{ +#define CV_HAL_CMP_EQ 0 +#define CV_HAL_CMP_GT 1 +#define CV_HAL_CMP_GE 2 +#define CV_HAL_CMP_LT 3 +#define CV_HAL_CMP_LE 4 +#define CV_HAL_CMP_NE 5 +//! @} + +//! @name Border processing modes +//! @sa cv::BorderTypes +//! @{ +#define CV_HAL_BORDER_CONSTANT 0 +#define CV_HAL_BORDER_REPLICATE 1 +#define CV_HAL_BORDER_REFLECT 2 +#define CV_HAL_BORDER_WRAP 3 +#define CV_HAL_BORDER_REFLECT_101 4 +#define CV_HAL_BORDER_TRANSPARENT 5 +#define CV_HAL_BORDER_ISOLATED 16 +//! @} + +//! @name DFT flags +//! @{ +#define CV_HAL_DFT_INVERSE 1 +#define CV_HAL_DFT_SCALE 2 +#define CV_HAL_DFT_ROWS 4 +#define CV_HAL_DFT_COMPLEX_OUTPUT 16 +#define CV_HAL_DFT_REAL_OUTPUT 32 +#define CV_HAL_DFT_TWO_STAGE 64 +#define CV_HAL_DFT_STAGE_COLS 128 +#define CV_HAL_DFT_IS_CONTINUOUS 512 +#define CV_HAL_DFT_IS_INPLACE 1024 +//! @} + +//! @name SVD flags +//! @{ +#define CV_HAL_SVD_NO_UV 1 +#define CV_HAL_SVD_SHORT_UV 2 +#define CV_HAL_SVD_MODIFY_A 4 +#define CV_HAL_SVD_FULL_UV 8 +//! @} + +//! @name Gemm flags +//! @{ +#define CV_HAL_GEMM_1_T 1 +#define CV_HAL_GEMM_2_T 2 +#define CV_HAL_GEMM_3_T 4 +//! @} + +//! @} + +#endif diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin.hpp similarity index 65% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin.hpp index 33e14b48..9dcfc562 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin.hpp @@ -42,8 +42,8 @@ // //M*/ -#ifndef __OPENCV_HAL_INTRIN_HPP__ -#define __OPENCV_HAL_INTRIN_HPP__ +#ifndef OPENCV_HAL_INTRIN_HPP +#define OPENCV_HAL_INTRIN_HPP #include #include @@ -60,6 +60,25 @@ // access from within opencv code more accessible namespace cv { +#ifndef CV_DOXYGEN + +#ifdef CV_CPU_DISPATCH_MODE +#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE __CV_CAT(hal_, CV_CPU_DISPATCH_MODE) +#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN namespace __CV_CAT(hal_, CV_CPU_DISPATCH_MODE) { +#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END } +#else +#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE hal_baseline +#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN namespace hal_baseline { +#define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END } +#endif + + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END +using namespace CV_CPU_OPTIMIZATION_HAL_NAMESPACE; +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN +#endif + //! @addtogroup core_hal_intrin //! @{ @@ -281,11 +300,15 @@ template struct V_SIMD128Traits //! @} +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END +#endif } #ifdef CV_DOXYGEN # undef CV_SSE2 # undef CV_NEON +# undef CV_VSX #endif #if CV_SSE2 @@ -296,6 +319,10 @@ template struct V_SIMD128Traits #include "opencv2/core/hal/intrin_neon.hpp" +#elif CV_VSX + +#include "opencv2/core/hal/intrin_vsx.hpp" + #else #include "opencv2/core/hal/intrin_cpp.hpp" @@ -317,4 +344,129 @@ template struct V_SIMD128Traits //! @} +//================================================================================================== + +//! @cond IGNORED + +namespace cv { + +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN +#endif + +template struct V_RegTrait128; + +template <> struct V_RegTrait128 { + typedef v_uint8x16 reg; + typedef v_uint16x8 w_reg; + typedef v_uint32x4 q_reg; + typedef v_uint8x16 u_reg; + static v_uint8x16 zero() { return v_setzero_u8(); } + static v_uint8x16 all(uchar val) { return v_setall_u8(val); } +}; + +template <> struct V_RegTrait128 { + typedef v_int8x16 reg; + typedef v_int16x8 w_reg; + typedef v_int32x4 q_reg; + typedef v_uint8x16 u_reg; + static v_int8x16 zero() { return v_setzero_s8(); } + static v_int8x16 all(schar val) { return v_setall_s8(val); } +}; + +template <> struct V_RegTrait128 { + typedef v_uint16x8 reg; + typedef v_uint32x4 w_reg; + typedef v_int16x8 int_reg; + typedef v_uint16x8 u_reg; + static v_uint16x8 zero() { return v_setzero_u16(); } + static v_uint16x8 all(ushort val) { return v_setall_u16(val); } +}; + +template <> struct V_RegTrait128 { + typedef v_int16x8 reg; + typedef v_int32x4 w_reg; + typedef v_uint16x8 u_reg; + static v_int16x8 zero() { return v_setzero_s16(); } + static v_int16x8 all(short val) { return v_setall_s16(val); } +}; + +template <> struct V_RegTrait128 { + typedef v_uint32x4 reg; + typedef v_uint64x2 w_reg; + typedef v_int32x4 int_reg; + typedef v_uint32x4 u_reg; + static v_uint32x4 zero() { return v_setzero_u32(); } + static v_uint32x4 all(unsigned val) { return v_setall_u32(val); } +}; + +template <> struct V_RegTrait128 { + typedef v_int32x4 reg; + typedef v_int64x2 w_reg; + typedef v_uint32x4 u_reg; + static v_int32x4 zero() { return v_setzero_s32(); } + static v_int32x4 all(int val) { return v_setall_s32(val); } +}; + +template <> struct V_RegTrait128 { + typedef v_uint64x2 reg; + static v_uint64x2 zero() { return v_setzero_u64(); } + static v_uint64x2 all(uint64 val) { return v_setall_u64(val); } +}; + +template <> struct V_RegTrait128 { + typedef v_int64x2 reg; + static v_int64x2 zero() { return v_setzero_s64(); } + static v_int64x2 all(int64 val) { return v_setall_s64(val); } +}; + +template <> struct V_RegTrait128 { + typedef v_float32x4 reg; + typedef v_int32x4 int_reg; + typedef v_float32x4 u_reg; + static v_float32x4 zero() { return v_setzero_f32(); } + static v_float32x4 all(float val) { return v_setall_f32(val); } +}; + +#if CV_SIMD128_64F +template <> struct V_RegTrait128 { + typedef v_float64x2 reg; + typedef v_int32x4 int_reg; + typedef v_float64x2 u_reg; + static v_float64x2 zero() { return v_setzero_f64(); } + static v_float64x2 all(double val) { return v_setall_f64(val); } +}; +#endif + +inline unsigned int trailingZeros32(unsigned int value) { +#if defined(_MSC_VER) +#if (_MSC_VER < 1700) || defined(_M_ARM) + unsigned long index = 0; + _BitScanForward(&index, value); + return (unsigned int)index; +#else + return _tzcnt_u32(value); +#endif +#elif defined(__GNUC__) || defined(__GNUG__) + return __builtin_ctz(value); +#elif defined(__ICC) || defined(__INTEL_COMPILER) + return _bit_scan_forward(value); +#elif defined(__clang__) + return llvm.cttz.i32(value, true); +#else + static const int MultiplyDeBruijnBitPosition[32] = { + 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, + 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 }; + return MultiplyDeBruijnBitPosition[((uint32_t)((value & -value) * 0x077CB531U)) >> 27]; +#endif +} + +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END +#endif + +} // cv:: + +//! @endcond + #endif diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin_cpp.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_cpp.hpp similarity index 84% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin_cpp.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_cpp.hpp index 3929e0d0..e7ea899b 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin_cpp.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_cpp.hpp @@ -42,8 +42,8 @@ // //M*/ -#ifndef __OPENCV_HAL_INTRIN_CPP_HPP__ -#define __OPENCV_HAL_INTRIN_CPP_HPP__ +#ifndef OPENCV_HAL_INTRIN_CPP_HPP +#define OPENCV_HAL_INTRIN_CPP_HPP #include #include @@ -53,6 +53,10 @@ namespace cv { +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN +#endif + /** @addtogroup core_hal_intrin "Universal intrinsics" is a types and functions set intended to simplify vectorization of code on @@ -95,7 +99,7 @@ block and to save contents of the register to memory block. @ref v_setall_s8, @ref v_setall_u8, ..., @ref v_setzero_u8, @ref v_setzero_s8, ... - Memory operations: -@ref v_load, @ref v_load_aligned, @ref v_load_halves, +@ref v_load, @ref v_load_aligned, @ref v_load_low, @ref v_load_halves, @ref v_store, @ref v_store_aligned, @ref v_store_high, @ref v_store_low @@ -103,7 +107,7 @@ block and to save contents of the register to memory block. These operations allow to reorder or recombine elements in one or multiple vectors. -- Interleave, deinterleave (3 and 4 channels): @ref v_load_deinterleave, @ref v_store_interleave +- Interleave, deinterleave (2, 3 and 4 channels): @ref v_load_deinterleave, @ref v_store_interleave - Expand: @ref v_load_expand, @ref v_load_expand_q, @ref v_expand - Pack: @ref v_pack, @ref v_pack_u, @ref v_rshr_pack, @ref v_rshr_pack_u, @ref v_pack_store, @ref v_pack_u_store, @ref v_rshr_pack_store, @ref v_rshr_pack_u_store @@ -116,32 +120,32 @@ These operations allow to reorder or recombine elements in one or multiple vecto Element-wise binary and unary operations. - Arithmetics: -@ref operator+(const v_reg &a, const v_reg &b) "+", -@ref operator-(const v_reg &a, const v_reg &b) "-", -@ref operator*(const v_reg &a, const v_reg &b) "*", -@ref operator/(const v_reg &a, const v_reg &b) "/", +@ref operator +(const v_reg &a, const v_reg &b) "+", +@ref operator -(const v_reg &a, const v_reg &b) "-", +@ref operator *(const v_reg &a, const v_reg &b) "*", +@ref operator /(const v_reg &a, const v_reg &b) "/", @ref v_mul_expand - Non-saturating arithmetics: @ref v_add_wrap, @ref v_sub_wrap - Bitwise shifts: -@ref operator<<(const v_reg &a, int s) "<<", -@ref operator>>(const v_reg &a, int s) ">>", +@ref operator <<(const v_reg &a, int s) "<<", +@ref operator >>(const v_reg &a, int s) ">>", @ref v_shl, @ref v_shr - Bitwise logic: @ref operator&(const v_reg &a, const v_reg &b) "&", -@ref operator|(const v_reg &a, const v_reg &b) "|", -@ref operator^(const v_reg &a, const v_reg &b) "^", -@ref operator~(const v_reg &a) "~" +@ref operator |(const v_reg &a, const v_reg &b) "|", +@ref operator ^(const v_reg &a, const v_reg &b) "^", +@ref operator ~(const v_reg &a) "~" - Comparison: -@ref operator>(const v_reg &a, const v_reg &b) ">", -@ref operator>=(const v_reg &a, const v_reg &b) ">=", -@ref operator<(const v_reg &a, const v_reg &b) "<", -@ref operator<=(const v_reg &a, const v_reg &b) "<=", +@ref operator >(const v_reg &a, const v_reg &b) ">", +@ref operator >=(const v_reg &a, const v_reg &b) ">=", +@ref operator <(const v_reg &a, const v_reg &b) "<", +@ref operator <=(const v_reg &a, const v_reg &b) "<=", @ref operator==(const v_reg &a, const v_reg &b) "==", -@ref operator!=(const v_reg &a, const v_reg &b) "!=" +@ref operator !=(const v_reg &a, const v_reg &b) "!=" - min/max: @ref v_min, @ref v_max @@ -149,7 +153,7 @@ Element-wise binary and unary operations. Most of these operations return only one value. -- Reduce: @ref v_reduce_min, @ref v_reduce_max, @ref v_reduce_sum +- Reduce: @ref v_reduce_min, @ref v_reduce_max, @ref v_reduce_sum, @ref v_popcount - Mask: @ref v_signmask, @ref v_check_all, @ref v_check_any, @ref v_select ### Other math @@ -455,8 +459,10 @@ template inline v_reg<_Tp, n> operator ~ (const v_reg<_Tp, { v_reg<_Tp, n> c; for( int i = 0; i < n; i++ ) + { c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int(~V_TypeTraits<_Tp>::reinterpret_int(a.s[i])); - return c; + } + return c; } //! @brief Helper macro @@ -572,6 +578,49 @@ Scheme: For 32-bit integer and 32-bit floating point types. */ OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(v_reduce_max, std::max) +static const unsigned char popCountTable[] = +{ + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, +}; +/** @brief Count the 1 bits in the vector and return 4 values + +Scheme: +@code +{A1 A2 A3 ...} => popcount(A1) +@endcode +Any types but result will be in v_uint32x4*/ +template inline v_uint32x4 v_popcount(const v_reg<_Tp, n>& a) +{ + v_uint8x16 b; + b = v_reinterpret_as_u8(a); + for( int i = 0; i < v_uint8x16::nlanes; i++ ) + { + b.s[i] = popCountTable[b.s[i]]; + } + v_uint32x4 c; + for( int i = 0; i < v_uint32x4::nlanes; i++ ) + { + c.s[i] = b.s[i*4] + b.s[i*4+1] + b.s[i*4+2] + b.s[i*4+3]; + } + return c; +} + + //! @cond IGNORED template inline void v_minmax( const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, @@ -672,7 +721,7 @@ inline v_reg::abs_type, n> v_absdiff(const v_reg<_Tp, { typedef typename V_TypeTraits<_Tp>::abs_type rtype; v_reg c; - const rtype mask = std::numeric_limits<_Tp>::is_signed ? (1 << (sizeof(rtype)*8 - 1)) : 0; + const rtype mask = (rtype)(std::numeric_limits<_Tp>::is_signed ? (1 << (sizeof(rtype)*8 - 1)) : 0); for( int i = 0; i < n; i++ ) { rtype ua = a.s[i] ^ mask; @@ -836,12 +885,59 @@ template inline v_reg<_Tp, n> operator shift_op(const v_reg /** @brief Bitwise shift left For 16-, 32- and 64-bit integer values. */ -OPENCV_HAL_IMPL_SHIFT_OP(<<) +OPENCV_HAL_IMPL_SHIFT_OP(<< ) /** @brief Bitwise shift right For 16-, 32- and 64-bit integer values. */ -OPENCV_HAL_IMPL_SHIFT_OP(>>) +OPENCV_HAL_IMPL_SHIFT_OP(>> ) + +/** @brief Element shift left among vector + +For all type */ +#define OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(suffix,opA,opB) \ +template inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a) \ +{ \ + v_reg<_Tp, n> b; \ + for (int i = 0; i < n; i++) \ + { \ + int sIndex = i opA imm; \ + if (0 <= sIndex && sIndex < n) \ + { \ + b.s[i] = a.s[sIndex]; \ + } \ + else \ + { \ + b.s[i] = 0; \ + } \ + } \ + return b; \ +} \ +template inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + for (int i = 0; i < n; i++) \ + { \ + int aIndex = i opA imm; \ + int bIndex = i opA imm opB n; \ + if (0 <= bIndex && bIndex < n) \ + { \ + c.s[i] = b.s[bIndex]; \ + } \ + else if (0 <= aIndex && aIndex < n) \ + { \ + c.s[i] = a.s[aIndex]; \ + } \ + else \ + { \ + c.s[i] = 0; \ + } \ + } \ + return c; \ +} + +OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(left, -, +) +OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(right, +, -) /** @brief Sum packed values @@ -858,6 +954,27 @@ template inline typename V_TypeTraits<_Tp>::sum_type v_redu return c; } +/** @brief Sums all elements of each input vector, returns the vector of sums + + Scheme: + @code + result[0] = a[0] + a[1] + a[2] + a[3] + result[1] = b[0] + b[1] + b[2] + b[3] + result[2] = c[0] + c[1] + c[2] + c[3] + result[3] = d[0] + d[1] + d[2] + d[3] + @endcode +*/ +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + v_float32x4 r; + r.s[0] = a.s[0] + a.s[1] + a.s[2] + a.s[3]; + r.s[1] = b.s[0] + b.s[1] + b.s[2] + b.s[3]; + r.s[2] = c.s[0] + c.s[1] + c.s[2] + c.s[3]; + r.s[3] = d.s[0] + d.s[1] + d.s[2] + d.s[3]; + return r; +} + /** @brief Get negative values mask Returned value is a bit mask with bits set to 1 on places corresponding to negative packed values indexes. @@ -1010,6 +1127,26 @@ inline v_reg<_Tp, V_SIMD128Traits<_Tp>::nlanes> v_load_aligned(const _Tp* ptr) return v_reg<_Tp, V_SIMD128Traits<_Tp>::nlanes>(ptr); } +/** @brief Load 64-bits of data to lower part (high part is undefined). + +@param ptr memory block containing data for first half (0..n/2) + +@code{.cpp} +int lo[2] = { 1, 2 }; +v_int32x4 r = v_load_low(lo); +@endcode + */ +template +inline v_reg<_Tp, V_SIMD128Traits<_Tp>::nlanes> v_load_low(const _Tp* ptr) +{ + v_reg<_Tp, V_SIMD128Traits<_Tp>::nlanes> c; + for( int i = 0; i < c.nlanes/2; i++ ) + { + c.s[i] = ptr[i]; + } + return c; +} + /** @brief Load register contents from two memory blocks @param loptr memory block containing data for first half (0..n/2) @@ -1075,12 +1212,31 @@ v_load_expand_q(const _Tp* ptr) return c; } -/** @brief Load and deinterleave (4 channels) +/** @brief Load and deinterleave (2 channels) -Load data from memory deinterleave and store to 4 registers. +Load data from memory deinterleave and store to 2 registers. Scheme: @code -{A1 B1 C1 D1 A2 B2 C2 D2 ...} ==> {A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...}, {D1 D2 ...} +{A1 B1 A2 B2 ...} ==> {A1 A2 ...}, {B1 B2 ...} +@endcode +For all types except 64-bit. */ +template inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, + v_reg<_Tp, n>& b) +{ + int i, i2; + for( i = i2 = 0; i < n; i++, i2 += 2 ) + { + a.s[i] = ptr[i2]; + b.s[i] = ptr[i2+1]; + } +} + +/** @brief Load and deinterleave (3 channels) + +Load data from memory deinterleave and store to 3 registers. +Scheme: +@code +{A1 B1 C1 A2 B2 C2 ...} ==> {A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...} @endcode For all types except 64-bit. */ template inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, @@ -1095,12 +1251,12 @@ template inline void v_load_deinterleave(const _Tp* ptr, v_ } } -/** @brief Load and deinterleave (3 channels) +/** @brief Load and deinterleave (4 channels) -Load data from memory deinterleave and store to 3 registers. +Load data from memory deinterleave and store to 4 registers. Scheme: @code -{A1 B1 C1 A2 B2 C2 ...} ==> {A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...} +{A1 B1 C1 D1 A2 B2 C2 D2 ...} ==> {A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...}, {D1 D2 ...} @endcode For all types except 64-bit. */ template @@ -1118,12 +1274,32 @@ inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, } } +/** @brief Interleave and store (2 channels) + +Interleave and store data from 2 registers to memory. +Scheme: +@code +{A1 A2 ...}, {B1 B2 ...} ==> {A1 B1 A2 B2 ...} +@endcode +For all types except 64-bit. */ +template +inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, + const v_reg<_Tp, n>& b) +{ + int i, i2; + for( i = i2 = 0; i < n; i++, i2 += 2 ) + { + ptr[i2] = a.s[i]; + ptr[i2+1] = b.s[i]; + } +} + /** @brief Interleave and store (3 channels) Interleave and store data from 3 registers to memory. Scheme: @code -{A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...}, {D1 D2 ...} ==> {A1 B1 C1 D1 A2 B2 C2 D2 ...} +{A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...} ==> {A1 B1 C1 A2 B2 C2 ...} @endcode For all types except 64-bit. */ template @@ -1586,14 +1762,14 @@ OPENCV_HAL_IMPL_C_RSHIFTR(v_int64x2, int64) //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_PACK(_Tpvec, _Tpnvec, _Tpn, pack_suffix) \ +#define OPENCV_HAL_IMPL_C_PACK(_Tpvec, _Tpnvec, _Tpn, pack_suffix, cast) \ inline _Tpnvec v_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ { \ _Tpnvec c; \ for( int i = 0; i < _Tpvec::nlanes; i++ ) \ { \ - c.s[i] = saturate_cast<_Tpn>(a.s[i]); \ - c.s[i+_Tpvec::nlanes] = saturate_cast<_Tpn>(b.s[i]); \ + c.s[i] = cast<_Tpn>(a.s[i]); \ + c.s[i+_Tpvec::nlanes] = cast<_Tpn>(b.s[i]); \ } \ return c; \ } @@ -1607,26 +1783,28 @@ inline _Tpnvec v_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ //! //! - pack: for 16-, 32- and 64-bit integer input types //! - pack_u: for 16- and 32-bit signed integer input types -OPENCV_HAL_IMPL_C_PACK(v_uint16x8, v_uint8x16, uchar, pack) -OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_int8x16, schar, pack) -OPENCV_HAL_IMPL_C_PACK(v_uint32x4, v_uint16x8, ushort, pack) -OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_int16x8, short, pack) -OPENCV_HAL_IMPL_C_PACK(v_uint64x2, v_uint32x4, unsigned, pack) -OPENCV_HAL_IMPL_C_PACK(v_int64x2, v_int32x4, int, pack) -OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_uint8x16, uchar, pack_u) -OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_uint16x8, ushort, pack_u) +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_PACK(v_uint16x8, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_uint32x4, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_uint64x2, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK(v_int64x2, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_uint16x8, ushort, pack_u, saturate_cast) //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_RSHR_PACK(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix) \ +#define OPENCV_HAL_IMPL_C_RSHR_PACK(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ template inline _Tpnvec v_rshr_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ { \ _Tpnvec c; \ for( int i = 0; i < _Tpvec::nlanes; i++ ) \ { \ - c.s[i] = saturate_cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ - c.s[i+_Tpvec::nlanes] = saturate_cast<_Tpn>((b.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + c.s[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + c.s[i+_Tpvec::nlanes] = cast<_Tpn>((b.s[i] + ((_Tp)1 << (n - 1))) >> n); \ } \ return c; \ } @@ -1640,51 +1818,55 @@ template inline _Tpnvec v_rshr_##pack_suffix(const _Tpvec& a, const _Tpve //! //! - pack: for 16-, 32- and 64-bit integer input types //! - pack_u: for 16- and 32-bit signed integer input types -OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint16x8, ushort, v_uint8x16, uchar, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_int8x16, schar, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint32x4, unsigned, v_uint16x8, ushort, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_int16x8, short, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint64x2, uint64, v_uint32x4, unsigned, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int64x2, int64, v_int32x4, int, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_uint8x16, uchar, pack_u) -OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_uint16x8, ushort, pack_u) +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix) \ +#define OPENCV_HAL_IMPL_C_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ inline void v_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ { \ for( int i = 0; i < _Tpvec::nlanes; i++ ) \ - ptr[i] = saturate_cast<_Tpn>(a.s[i]); \ + ptr[i] = cast<_Tpn>(a.s[i]); \ } //! @name Pack and store //! @{ //! @brief Store values from the input vector into memory with pack //! -//! Values will be stored into memory with saturating conversion to narrower type. +//! Values will be stored into memory with conversion to narrower type. //! Variant with _u_ suffix converts to corresponding unsigned type. //! //! - pack: for 16-, 32- and 64-bit integer input types //! - pack_u: for 16- and 32-bit signed integer input types -OPENCV_HAL_IMPL_C_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack) -OPENCV_HAL_IMPL_C_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_int16x8, short, pack) -OPENCV_HAL_IMPL_C_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u) -OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u) +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) //! @} //! @brief Helper macro //! @ingroup core_hal_intrin_impl -#define OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix) \ +#define OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ template inline void v_rshr_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ { \ for( int i = 0; i < _Tpvec::nlanes; i++ ) \ - ptr[i] = saturate_cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + ptr[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ } //! @name Pack and store with rounding shift @@ -1696,14 +1878,16 @@ template inline void v_rshr_##pack_suffix##_store(_Tpn* ptr, const _Tpvec //! //! - pack: for 16-, 32- and 64-bit integer input types //! - pack_u: for 16- and 32-bit signed integer input types -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_int16x8, short, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u) -OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u) +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) //! @} /** @brief Matrix multiplication @@ -1731,8 +1915,45 @@ inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + v.s[3]*m3.s[3]); } +/** @brief Matrix multiplication and add + +Scheme: +@code +{A0 A1 A2 } |V0| |D0| +{B0 B1 B2 } |V1| |D1| +{C0 C1 C2 } x |V2| + |D2| +==================== +{R0 R1 R2 R3}, where: +R0 = A0V0 + A1V1 + A2V2 + D0, +R1 = B0V0 + B1V1 + B2V2 + D1 +... +@endcode +*/ +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + m3.s[0], + v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + m3.s[1], + v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + m3.s[2], + v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + m3.s[3]); +} + //! @} +//! @name Check SIMD support +//! @{ +//! @brief Check CPU capability of SIMD operation +static inline bool hasSIMD128() +{ + return false; +} + +//! @} + +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END +#endif } #endif diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin_neon.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_neon.hpp similarity index 65% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin_neon.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_neon.hpp index f3e47ca8..c3c49c90 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin_neon.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_neon.hpp @@ -42,17 +42,42 @@ // //M*/ -#ifndef __OPENCV_HAL_INTRIN_NEON_HPP__ -#define __OPENCV_HAL_INTRIN_NEON_HPP__ +#ifndef OPENCV_HAL_INTRIN_NEON_HPP +#define OPENCV_HAL_INTRIN_NEON_HPP #include +#include "opencv2/core/utility.hpp" namespace cv { //! @cond IGNORED +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + #define CV_SIMD128 1 +#if defined(__aarch64__) +#define CV_SIMD128_64F 1 +#else +#define CV_SIMD128_64F 0 +#endif + +#if CV_SIMD128_64F +#define OPENCV_HAL_IMPL_NEON_REINTERPRET(_Tpv, suffix) \ +template static inline \ +_Tpv vreinterpretq_##suffix##_f64(T a) { return (_Tpv) a; } \ +template static inline \ +float64x2_t vreinterpretq_f64_##suffix(T a) { return (float64x2_t) a; } +OPENCV_HAL_IMPL_NEON_REINTERPRET(uint8x16_t, u8) +OPENCV_HAL_IMPL_NEON_REINTERPRET(int8x16_t, s8) +OPENCV_HAL_IMPL_NEON_REINTERPRET(uint16x8_t, u16) +OPENCV_HAL_IMPL_NEON_REINTERPRET(int16x8_t, s16) +OPENCV_HAL_IMPL_NEON_REINTERPRET(uint32x4_t, u32) +OPENCV_HAL_IMPL_NEON_REINTERPRET(int32x4_t, s32) +OPENCV_HAL_IMPL_NEON_REINTERPRET(uint64x2_t, u64) +OPENCV_HAL_IMPL_NEON_REINTERPRET(int64x2_t, s64) +OPENCV_HAL_IMPL_NEON_REINTERPRET(float32x4_t, f32) +#endif struct v_uint8x16 { @@ -201,7 +226,7 @@ struct v_uint64x2 v_uint64x2() {} explicit v_uint64x2(uint64x2_t v) : val(v) {} - v_uint64x2(unsigned v0, unsigned v1) + v_uint64x2(uint64 v0, uint64 v1) { uint64 v[] = {v0, v1}; val = vld1q_u64(v); @@ -220,7 +245,7 @@ struct v_int64x2 v_int64x2() {} explicit v_int64x2(int64x2_t v) : val(v) {} - v_int64x2(int v0, int v1) + v_int64x2(int64 v0, int64 v1) { int64 v[] = {v0, v1}; val = vld1q_s64(v); @@ -232,6 +257,70 @@ struct v_int64x2 int64x2_t val; }; +#if CV_SIMD128_64F +struct v_float64x2 +{ + typedef double lane_type; + enum { nlanes = 2 }; + + v_float64x2() {} + explicit v_float64x2(float64x2_t v) : val(v) {} + v_float64x2(double v0, double v1) + { + double v[] = {v0, v1}; + val = vld1q_f64(v); + } + double get0() const + { + return vgetq_lane_f64(val, 0); + } + float64x2_t val; +}; +#endif + +#if CV_FP16 +// Workaround for old compilers +template static inline int16x4_t vreinterpret_s16_f16(T a) +{ return (int16x4_t)a; } +template static inline float16x4_t vreinterpret_f16_s16(T a) +{ return (float16x4_t)a; } +template static inline float16x4_t cv_vld1_f16(const T* ptr) +{ +#ifndef vld1_f16 // APPLE compiler defines vld1_f16 as macro + return vreinterpret_f16_s16(vld1_s16((const short*)ptr)); +#else + return vld1_f16((const __fp16*)ptr); +#endif +} +template static inline void cv_vst1_f16(T* ptr, float16x4_t a) +{ +#ifndef vst1_f16 // APPLE compiler defines vst1_f16 as macro + vst1_s16((short*)ptr, vreinterpret_s16_f16(a)); +#else + vst1_f16((__fp16*)ptr, a); +#endif +} + +struct v_float16x4 +{ + typedef short lane_type; + enum { nlanes = 4 }; + + v_float16x4() {} + explicit v_float16x4(float16x4_t v) : val(v) {} + v_float16x4(short v0, short v1, short v2, short v3) + { + short v[] = {v0, v1, v2, v3}; + val = cv_vld1_f16(v); + } + short get0() const + { + return vget_lane_s16(vreinterpret_s16_f16(val), 0); + } + float16x4_t val; +}; +#endif + #define OPENCV_HAL_IMPL_NEON_INIT(_Tpv, _Tp, suffix) \ inline v_##_Tpv v_setzero_##suffix() { return v_##_Tpv(vdupq_n_##suffix((_Tp)0)); } \ inline v_##_Tpv v_setall_##suffix(_Tp v) { return v_##_Tpv(vdupq_n_##suffix(v)); } \ @@ -255,41 +344,56 @@ OPENCV_HAL_IMPL_NEON_INIT(int32x4, int, s32) OPENCV_HAL_IMPL_NEON_INIT(uint64x2, uint64, u64) OPENCV_HAL_IMPL_NEON_INIT(int64x2, int64, s64) OPENCV_HAL_IMPL_NEON_INIT(float32x4, float, f32) +#if CV_SIMD128_64F +#define OPENCV_HAL_IMPL_NEON_INIT_64(_Tpv, suffix) \ +inline v_float64x2 v_reinterpret_as_f64(const v_##_Tpv& v) { return v_float64x2(vreinterpretq_f64_##suffix(v.val)); } +OPENCV_HAL_IMPL_NEON_INIT(float64x2, double, f64) +OPENCV_HAL_IMPL_NEON_INIT_64(uint8x16, u8) +OPENCV_HAL_IMPL_NEON_INIT_64(int8x16, s8) +OPENCV_HAL_IMPL_NEON_INIT_64(uint16x8, u16) +OPENCV_HAL_IMPL_NEON_INIT_64(int16x8, s16) +OPENCV_HAL_IMPL_NEON_INIT_64(uint32x4, u32) +OPENCV_HAL_IMPL_NEON_INIT_64(int32x4, s32) +OPENCV_HAL_IMPL_NEON_INIT_64(uint64x2, u64) +OPENCV_HAL_IMPL_NEON_INIT_64(int64x2, s64) +OPENCV_HAL_IMPL_NEON_INIT_64(float32x4, f32) +OPENCV_HAL_IMPL_NEON_INIT_64(float64x2, f64) +#endif -#define OPENCV_HAL_IMPL_NEON_PACK(_Tpvec, _Tp, hreg, suffix, _Tpwvec, wsuffix, pack, op) \ +#define OPENCV_HAL_IMPL_NEON_PACK(_Tpvec, _Tp, hreg, suffix, _Tpwvec, pack, mov, rshr) \ inline _Tpvec v_##pack(const _Tpwvec& a, const _Tpwvec& b) \ { \ - hreg a1 = vqmov##op##_##wsuffix(a.val), b1 = vqmov##op##_##wsuffix(b.val); \ + hreg a1 = mov(a.val), b1 = mov(b.val); \ return _Tpvec(vcombine_##suffix(a1, b1)); \ } \ inline void v_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ { \ - hreg a1 = vqmov##op##_##wsuffix(a.val); \ + hreg a1 = mov(a.val); \ vst1_##suffix(ptr, a1); \ } \ template inline \ _Tpvec v_rshr_##pack(const _Tpwvec& a, const _Tpwvec& b) \ { \ - hreg a1 = vqrshr##op##_n_##wsuffix(a.val, n); \ - hreg b1 = vqrshr##op##_n_##wsuffix(b.val, n); \ + hreg a1 = rshr(a.val, n); \ + hreg b1 = rshr(b.val, n); \ return _Tpvec(vcombine_##suffix(a1, b1)); \ } \ template inline \ void v_rshr_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ { \ - hreg a1 = vqrshr##op##_n_##wsuffix(a.val, n); \ + hreg a1 = rshr(a.val, n); \ vst1_##suffix(ptr, a1); \ } -OPENCV_HAL_IMPL_NEON_PACK(v_uint8x16, uchar, uint8x8_t, u8, v_uint16x8, u16, pack, n) -OPENCV_HAL_IMPL_NEON_PACK(v_int8x16, schar, int8x8_t, s8, v_int16x8, s16, pack, n) -OPENCV_HAL_IMPL_NEON_PACK(v_uint16x8, ushort, uint16x4_t, u16, v_uint32x4, u32, pack, n) -OPENCV_HAL_IMPL_NEON_PACK(v_int16x8, short, int16x4_t, s16, v_int32x4, s32, pack, n) -OPENCV_HAL_IMPL_NEON_PACK(v_uint32x4, unsigned, uint32x2_t, u32, v_uint64x2, u64, pack, n) -OPENCV_HAL_IMPL_NEON_PACK(v_int32x4, int, int32x2_t, s32, v_int64x2, s64, pack, n) +OPENCV_HAL_IMPL_NEON_PACK(v_uint8x16, uchar, uint8x8_t, u8, v_uint16x8, pack, vqmovn_u16, vqrshrn_n_u16) +OPENCV_HAL_IMPL_NEON_PACK(v_int8x16, schar, int8x8_t, s8, v_int16x8, pack, vqmovn_s16, vqrshrn_n_s16) +OPENCV_HAL_IMPL_NEON_PACK(v_uint16x8, ushort, uint16x4_t, u16, v_uint32x4, pack, vqmovn_u32, vqrshrn_n_u32) +OPENCV_HAL_IMPL_NEON_PACK(v_int16x8, short, int16x4_t, s16, v_int32x4, pack, vqmovn_s32, vqrshrn_n_s32) +OPENCV_HAL_IMPL_NEON_PACK(v_uint32x4, unsigned, uint32x2_t, u32, v_uint64x2, pack, vmovn_u64, vrshrn_n_u64) +OPENCV_HAL_IMPL_NEON_PACK(v_int32x4, int, int32x2_t, s32, v_int64x2, pack, vmovn_s64, vrshrn_n_s64) -OPENCV_HAL_IMPL_NEON_PACK(v_uint8x16, uchar, uint8x8_t, u8, v_int16x8, s16, pack_u, un) -OPENCV_HAL_IMPL_NEON_PACK(v_uint16x8, ushort, uint16x4_t, u16, v_int32x4, s32, pack_u, un) +OPENCV_HAL_IMPL_NEON_PACK(v_uint8x16, uchar, uint8x8_t, u8, v_int16x8, pack_u, vqmovun_s16, vqrshrun_n_s16) +OPENCV_HAL_IMPL_NEON_PACK(v_uint16x8, ushort, uint16x4_t, u16, v_int32x4, pack_u, vqmovun_s32, vqrshrun_n_s32) inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, const v_float32x4& m1, const v_float32x4& m2, @@ -303,6 +407,18 @@ inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, return v_float32x4(res); } +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + float32x2_t vl = vget_low_f32(v.val), vh = vget_high_f32(v.val); + float32x4_t res = vmulq_lane_f32(m0.val, vl, 0); + res = vmlaq_lane_f32(res, m1.val, vl, 1); + res = vmlaq_lane_f32(res, m2.val, vh, 0); + res = vaddq_f32(res, a.val); + return v_float32x4(res); +} + #define OPENCV_HAL_IMPL_NEON_BIN_OP(bin_op, _Tpvec, intrin) \ inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ { \ @@ -337,7 +453,13 @@ OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int64x2, vaddq_s64) OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int64x2, vsubq_s64) OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint64x2, vaddq_u64) OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint64x2, vsubq_u64) - +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_BIN_OP(/, v_float32x4, vdivq_f32) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_float64x2, vaddq_f64) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_float64x2, vsubq_f64) +OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_float64x2, vmulq_f64) +OPENCV_HAL_IMPL_NEON_BIN_OP(/, v_float64x2, vdivq_f64) +#else inline v_float32x4 operator / (const v_float32x4& a, const v_float32x4& b) { float32x4_t reciprocal = vrecpeq_f32(b.val); @@ -353,6 +475,7 @@ inline v_float32x4& operator /= (v_float32x4& a, const v_float32x4& b) a.val = vmulq_f32(a.val, reciprocal); return a; } +#endif inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b, v_int32x4& c, v_int32x4& d) @@ -421,6 +544,18 @@ inline v_float32x4 operator ~ (const v_float32x4& a) return v_float32x4(vreinterpretq_f32_s32(vmvnq_s32(vreinterpretq_s32_f32(a.val)))); } +#if CV_SIMD128_64F +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ + return v_float32x4(vsqrtq_f32(x.val)); +} + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ + v_float32x4 one = v_setall_f32(1.0f); + return one / v_sqrt(x); +} +#else inline v_float32x4 v_sqrt(const v_float32x4& x) { float32x4_t x1 = vmaxq_f32(x.val, vdupq_n_f32(FLT_MIN)); @@ -437,10 +572,54 @@ inline v_float32x4 v_invsqrt(const v_float32x4& x) e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x.val, e), e), e); return v_float32x4(e); } +#endif + +#define OPENCV_HAL_IMPL_NEON_ABS(_Tpuvec, _Tpsvec, usuffix, ssuffix) \ +inline _Tpuvec v_abs(const _Tpsvec& a) { return v_reinterpret_as_##usuffix(_Tpsvec(vabsq_##ssuffix(a.val))); } + +OPENCV_HAL_IMPL_NEON_ABS(v_uint8x16, v_int8x16, u8, s8) +OPENCV_HAL_IMPL_NEON_ABS(v_uint16x8, v_int16x8, u16, s16) +OPENCV_HAL_IMPL_NEON_ABS(v_uint32x4, v_int32x4, u32, s32) inline v_float32x4 v_abs(v_float32x4 x) { return v_float32x4(vabsq_f32(x.val)); } +#if CV_SIMD128_64F +#define OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(bin_op, intrin) \ +inline v_float64x2 operator bin_op (const v_float64x2& a, const v_float64x2& b) \ +{ \ + return v_float64x2(vreinterpretq_f64_s64(intrin(vreinterpretq_s64_f64(a.val), vreinterpretq_s64_f64(b.val)))); \ +} \ +inline v_float64x2& operator bin_op##= (v_float64x2& a, const v_float64x2& b) \ +{ \ + a.val = vreinterpretq_f64_s64(intrin(vreinterpretq_s64_f64(a.val), vreinterpretq_s64_f64(b.val))); \ + return a; \ +} + +OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(&, vandq_s64) +OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(|, vorrq_s64) +OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(^, veorq_s64) + +inline v_float64x2 operator ~ (const v_float64x2& a) +{ + return v_float64x2(vreinterpretq_f64_s32(vmvnq_s32(vreinterpretq_s32_f64(a.val)))); +} + +inline v_float64x2 v_sqrt(const v_float64x2& x) +{ + return v_float64x2(vsqrtq_f64(x.val)); +} + +inline v_float64x2 v_invsqrt(const v_float64x2& x) +{ + v_float64x2 one = v_setall_f64(1.0f); + return one / v_sqrt(x); +} + +inline v_float64x2 v_abs(v_float64x2 x) +{ return v_float64x2(vabsq_f64(x.val)); } +#endif + // TODO: exp, log, sin, cos #define OPENCV_HAL_IMPL_NEON_BIN_FUNC(_Tpvec, func, intrin) \ @@ -463,8 +642,23 @@ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int32x4, v_min, vminq_s32) OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int32x4, v_max, vmaxq_s32) OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_min, vminq_f32) OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_max, vmaxq_f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_min, vminq_f64) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_max, vmaxq_f64) +#endif - +#if CV_SIMD128_64F +inline int64x2_t vmvnq_s64(int64x2_t a) +{ + int64x2_t vx = vreinterpretq_s64_u32(vdupq_n_u32(0xFFFFFFFF)); + return veorq_s64(a, vx); +} +inline uint64x2_t vmvnq_u64(uint64x2_t a) +{ + uint64x2_t vx = vreinterpretq_u64_u32(vdupq_n_u32(0xFFFFFFFF)); + return veorq_u64(a, vx); +} +#endif #define OPENCV_HAL_IMPL_NEON_INT_CMP_OP(_Tpvec, cast, suffix, not_suffix) \ inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ { return _Tpvec(cast(vceqq_##suffix(a.val, b.val))); } \ @@ -486,6 +680,11 @@ OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int16x8, vreinterpretq_s16_u16, s16, u16) OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint32x4, OPENCV_HAL_NOP, u32, u32) OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int32x4, vreinterpretq_s32_u32, s32, u32) OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_float32x4, vreinterpretq_f32_u32, f32, u32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint64x2, OPENCV_HAL_NOP, u64, u64) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int64x2, vreinterpretq_s64_u64, s64, u64) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_float64x2, vreinterpretq_f64_u64, f64, u64) +#endif OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_add_wrap, vaddq_u8) OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_add_wrap, vaddq_s8) @@ -501,6 +700,9 @@ OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_absdiff, vabdq_u8) OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_absdiff, vabdq_u16) OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint32x4, v_absdiff, vabdq_u32) OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_absdiff, vabdq_f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_absdiff, vabdq_f64) +#endif #define OPENCV_HAL_IMPL_NEON_BIN_FUNC2(_Tpvec, _Tpvec2, cast, func, intrin) \ inline _Tpvec2 func(const _Tpvec& a, const _Tpvec& b) \ @@ -528,6 +730,24 @@ inline v_float32x4 v_muladd(const v_float32x4& a, const v_float32x4& b, const v_ return v_float32x4(vmlaq_f32(c.val, a.val, b.val)); } +#if CV_SIMD128_64F +inline v_float64x2 v_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + v_float64x2 x(vaddq_f64(vmulq_f64(a.val, a.val), vmulq_f64(b.val, b.val))); + return v_sqrt(x); +} + +inline v_float64x2 v_sqr_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + return v_float64x2(vaddq_f64(vmulq_f64(a.val, a.val), vmulq_f64(b.val, b.val))); +} + +inline v_float64x2 v_muladd(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + return v_float64x2(vaddq_f64(c.val, vmulq_f64(a.val, b.val))); +} +#endif + // trade efficiency for convenience #define OPENCV_HAL_IMPL_NEON_SHIFT_OP(_Tpvec, suffix, _Tps, ssuffix) \ inline _Tpvec operator << (const _Tpvec& a, int n) \ @@ -539,7 +759,15 @@ template inline _Tpvec v_shl(const _Tpvec& a) \ template inline _Tpvec v_shr(const _Tpvec& a) \ { return _Tpvec(vshrq_n_##suffix(a.val, n)); } \ template inline _Tpvec v_rshr(const _Tpvec& a) \ -{ return _Tpvec(vrshrq_n_##suffix(a.val, n)); } +{ return _Tpvec(vrshrq_n_##suffix(a.val, n)); } \ +template inline _Tpvec v_rotate_right(const _Tpvec& a) \ +{ return _Tpvec(vextq_##suffix(a.val, vdupq_n_##suffix(0), n)); } \ +template inline _Tpvec v_rotate_left(const _Tpvec& a) \ +{ return _Tpvec(vextq_##suffix(vdupq_n_##suffix(0), a.val, _Tpvec::nlanes - n)); } \ +template inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vextq_##suffix(a.val, b.val, n)); } \ +template inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vextq_##suffix(b.val, a.val, _Tpvec::nlanes - n)); } OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint8x16, u8, schar, s8) OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int8x16, s8, schar, s8) @@ -555,6 +783,8 @@ inline _Tpvec v_load(const _Tp* ptr) \ { return _Tpvec(vld1q_##suffix(ptr)); } \ inline _Tpvec v_load_aligned(const _Tp* ptr) \ { return _Tpvec(vld1q_##suffix(ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(vcombine_##suffix(vld1_##suffix(ptr), vdup_n_##suffix((_Tp)0))); } \ inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ { return _Tpvec(vcombine_##suffix(vld1_##suffix(ptr0), vld1_##suffix(ptr1))); } \ inline void v_store(_Tp* ptr, const _Tpvec& a) \ @@ -575,26 +805,80 @@ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int32x4, int, s32) OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint64x2, uint64, u64) OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int64x2, int64, s64) OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float32x4, float, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float64x2, double, f64) +#endif -#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(_Tpvec, scalartype, func, scalar_func) \ +#if CV_FP16 +// Workaround for old comiplers +inline v_float16x4 v_load_f16(const short* ptr) +{ return v_float16x4(cv_vld1_f16(ptr)); } +inline void v_store_f16(short* ptr, v_float16x4& a) +{ cv_vst1_f16(ptr, a.val); } +#endif + +#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ inline scalartype v_reduce_##func(const _Tpvec& a) \ { \ - scalartype CV_DECL_ALIGNED(16) buf[4]; \ - v_store_aligned(buf, a); \ - scalartype s0 = scalar_func(buf[0], buf[1]); \ - scalartype s1 = scalar_func(buf[2], buf[3]); \ - return scalar_func(s0, s1); \ + _Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \ + a0 = vp##vectorfunc##_##suffix(a0, a0); \ + return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, a0),0); \ } -OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, unsigned, sum, OPENCV_HAL_ADD) -OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, unsigned, max, std::max) -OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, unsigned, min, std::min) -OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int, sum, OPENCV_HAL_ADD) -OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int, max, std::max) -OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int, min, std::min) -OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float, sum, OPENCV_HAL_ADD) -OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float, max, std::max) -OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float, min, std::min) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, unsigned short, sum, add, u16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, unsigned short, max, max, u16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, unsigned short, min, min, u16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, sum, add, s16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, max, max, s16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, short, min, min, s16) + +#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + _Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \ + return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, vget_high_##suffix(a.val)),0); \ +} + +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, sum, add, u32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, max, max, u32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, min, min, u32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, sum, add, s32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, max, max, s32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, min, min, s32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, sum, add, f32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, max, max, f32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, min, min, f32) + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + float32x4x2_t ab = vtrnq_f32(a.val, b.val); + float32x4x2_t cd = vtrnq_f32(c.val, d.val); + + float32x4_t u0 = vaddq_f32(ab.val[0], ab.val[1]); // a0+a1 b0+b1 a2+a3 b2+b3 + float32x4_t u1 = vaddq_f32(cd.val[0], cd.val[1]); // c0+c1 d0+d1 c2+c3 d2+d3 + + float32x4_t v0 = vcombine_f32(vget_low_f32(u0), vget_low_f32(u1)); + float32x4_t v1 = vcombine_f32(vget_high_f32(u0), vget_high_f32(u1)); + + return v_float32x4(vaddq_f32(v0, v1)); +} + +#define OPENCV_HAL_IMPL_NEON_POPCOUNT(_Tpvec, cast) \ +inline v_uint32x4 v_popcount(const _Tpvec& a) \ +{ \ + uint8x16_t t = vcntq_u8(cast(a.val)); \ + uint16x8_t t0 = vpaddlq_u8(t); /* 16 -> 8 */ \ + uint32x4_t t1 = vpaddlq_u16(t0); /* 8 -> 4 */ \ + return v_uint32x4(t1); \ +} + +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_uint8x16, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_uint16x8, vreinterpretq_u8_u16) +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_uint32x4, vreinterpretq_u8_u32) +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_int8x16, vreinterpretq_u8_s8) +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_int16x8, vreinterpretq_u8_s16) +OPENCV_HAL_IMPL_NEON_POPCOUNT(v_int32x4, vreinterpretq_u8_s32) inline int v_signmask(const v_uint8x16& a) { @@ -627,6 +911,16 @@ inline int v_signmask(const v_int32x4& a) { return v_signmask(v_reinterpret_as_u32(a)); } inline int v_signmask(const v_float32x4& a) { return v_signmask(v_reinterpret_as_u32(a)); } +#if CV_SIMD128_64F +inline int v_signmask(const v_uint64x2& a) +{ + int64x1_t m0 = vdup_n_s64(0); + uint64x2_t v0 = vshlq_u64(vshrq_n_u64(a.val, 63), vcombine_s64(m0, m0)); + return (int)vgetq_lane_u64(v0, 0) + ((int)vgetq_lane_u64(v0, 1) << 1); +} +inline int v_signmask(const v_float64x2& a) +{ return v_signmask(v_reinterpret_as_u64(a)); } +#endif #define OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(_Tpvec, suffix, shift) \ inline bool v_check_all(const v_##_Tpvec& a) \ @@ -645,6 +939,9 @@ inline bool v_check_any(const v_##_Tpvec& a) \ OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint8x16, u8, 7) OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint16x8, u16, 15) OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint32x4, u32, 31) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint64x2, u64, 63) +#endif inline bool v_check_all(const v_int8x16& a) { return v_check_all(v_reinterpret_as_u8(a)); } @@ -664,6 +961,17 @@ inline bool v_check_any(const v_int32x4& a) inline bool v_check_any(const v_float32x4& a) { return v_check_any(v_reinterpret_as_u32(a)); } +#if CV_SIMD128_64F +inline bool v_check_all(const v_int64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } +inline bool v_check_all(const v_float64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } +inline bool v_check_any(const v_int64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } +inline bool v_check_any(const v_float64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } +#endif + #define OPENCV_HAL_IMPL_NEON_SELECT(_Tpvec, suffix, usuffix) \ inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ { \ @@ -677,6 +985,9 @@ OPENCV_HAL_IMPL_NEON_SELECT(v_int16x8, s16, u16) OPENCV_HAL_IMPL_NEON_SELECT(v_uint32x4, u32, u32) OPENCV_HAL_IMPL_NEON_SELECT(v_int32x4, s32, u32) OPENCV_HAL_IMPL_NEON_SELECT(v_float32x4, f32, u32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_SELECT(v_float64x2, f64, u64) +#endif #define OPENCV_HAL_IMPL_NEON_EXPAND(_Tpvec, _Tpwvec, _Tp, suffix) \ inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ @@ -710,6 +1021,27 @@ inline v_int32x4 v_load_expand_q(const schar* ptr) return v_int32x4(vmovl_s16(v1)); } +#if defined(__aarch64__) +#define OPENCV_HAL_IMPL_NEON_UNPACKS(_Tpvec, suffix) \ +inline void v_zip(const v_##_Tpvec& a0, const v_##_Tpvec& a1, v_##_Tpvec& b0, v_##_Tpvec& b1) \ +{ \ + b0.val = vzip1q_##suffix(a0.val, a1.val); \ + b1.val = vzip2q_##suffix(a0.val, a1.val); \ +} \ +inline v_##_Tpvec v_combine_low(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val))); \ +} \ +inline v_##_Tpvec v_combine_high(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val))); \ +} \ +inline void v_recombine(const v_##_Tpvec& a, const v_##_Tpvec& b, v_##_Tpvec& c, v_##_Tpvec& d) \ +{ \ + c.val = vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val)); \ + d.val = vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val)); \ +} +#else #define OPENCV_HAL_IMPL_NEON_UNPACKS(_Tpvec, suffix) \ inline void v_zip(const v_##_Tpvec& a0, const v_##_Tpvec& a1, v_##_Tpvec& b0, v_##_Tpvec& b1) \ { \ @@ -730,6 +1062,7 @@ inline void v_recombine(const v_##_Tpvec& a, const v_##_Tpvec& b, v_##_Tpvec& c, c.val = vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val)); \ d.val = vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val)); \ } +#endif OPENCV_HAL_IMPL_NEON_UNPACKS(uint8x16, u8) OPENCV_HAL_IMPL_NEON_UNPACKS(int8x16, s8) @@ -738,6 +1071,9 @@ OPENCV_HAL_IMPL_NEON_UNPACKS(int16x8, s16) OPENCV_HAL_IMPL_NEON_UNPACKS(uint32x4, u32) OPENCV_HAL_IMPL_NEON_UNPACKS(int32x4, s32) OPENCV_HAL_IMPL_NEON_UNPACKS(float32x4, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_UNPACKS(float64x2, f64) +#endif #define OPENCV_HAL_IMPL_NEON_EXTRACT(_Tpvec, suffix) \ template \ @@ -755,6 +1091,9 @@ OPENCV_HAL_IMPL_NEON_EXTRACT(int32x4, s32) OPENCV_HAL_IMPL_NEON_EXTRACT(uint64x2, u64) OPENCV_HAL_IMPL_NEON_EXTRACT(int64x2, s64) OPENCV_HAL_IMPL_NEON_EXTRACT(float32x4, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_EXTRACT(float64x2, f64) +#endif inline v_int32x4 v_round(const v_float32x4& a) { @@ -782,6 +1121,38 @@ inline v_int32x4 v_ceil(const v_float32x4& a) inline v_int32x4 v_trunc(const v_float32x4& a) { return v_int32x4(vcvtq_s32_f32(a.val)); } +#if CV_SIMD128_64F +inline v_int32x4 v_round(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), zero)); +} + +inline v_int32x4 v_floor(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + int64x2_t a1 = vcvtq_s64_f64(a.val); + uint64x2_t mask = vcgtq_f64(vcvtq_f64_s64(a1), a.val); + a1 = vaddq_s64(a1, vreinterpretq_s64_u64(mask)); + return v_int32x4(vcombine_s32(vmovn_s64(a1), zero)); +} + +inline v_int32x4 v_ceil(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + int64x2_t a1 = vcvtq_s64_f64(a.val); + uint64x2_t mask = vcgtq_f64(a.val, vcvtq_f64_s64(a1)); + a1 = vsubq_s64(a1, vreinterpretq_s64_u64(mask)); + return v_int32x4(vcombine_s32(vmovn_s64(a1), zero)); +} + +inline v_int32x4 v_trunc(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), zero)); +} +#endif + #define OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(_Tpvec, suffix) \ inline void v_transpose4x4(const v_##_Tpvec& a0, const v_##_Tpvec& a1, \ const v_##_Tpvec& a2, const v_##_Tpvec& a3, \ @@ -809,6 +1180,12 @@ OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(int32x4, s32) OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(float32x4, f32) #define OPENCV_HAL_IMPL_NEON_INTERLEAVED(_Tpvec, _Tp, suffix) \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b) \ +{ \ + _Tpvec##x2_t v = vld2q_##suffix(ptr); \ + a.val = v.val[0]; \ + b.val = v.val[1]; \ +} \ inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, v_##_Tpvec& c) \ { \ _Tpvec##x3_t v = vld3q_##suffix(ptr); \ @@ -825,6 +1202,13 @@ inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, \ c.val = v.val[2]; \ d.val = v.val[3]; \ } \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + _Tpvec##x2_t v; \ + v.val[0] = a.val; \ + v.val[1] = b.val; \ + vst2q_##suffix(ptr, v); \ +} \ inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, const v_##_Tpvec& c) \ { \ _Tpvec##x3_t v; \ @@ -851,12 +1235,67 @@ OPENCV_HAL_IMPL_NEON_INTERLEAVED(int16x8, short, s16) OPENCV_HAL_IMPL_NEON_INTERLEAVED(uint32x4, unsigned, u32) OPENCV_HAL_IMPL_NEON_INTERLEAVED(int32x4, int, s32) OPENCV_HAL_IMPL_NEON_INTERLEAVED(float32x4, float, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_INTERLEAVED(float64x2, double, f64) +#endif inline v_float32x4 v_cvt_f32(const v_int32x4& a) { return v_float32x4(vcvtq_f32_s32(a.val)); } +#if CV_SIMD128_64F +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ + float32x2_t zero = vdup_n_f32(0.0f); + return v_float32x4(vcombine_f32(vcvt_f32_f64(a.val), zero)); +} + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vcvt_f32_s32(vget_low_s32(a.val)))); +} + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vcvt_f32_s32(vget_high_s32(a.val)))); +} + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vget_low_f32(a.val))); +} + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vget_high_f32(a.val))); +} +#endif + +#if CV_FP16 +inline v_float32x4 v_cvt_f32(const v_float16x4& a) +{ + return v_float32x4(vcvt_f32_f16(a.val)); +} + +inline v_float16x4 v_cvt_f16(const v_float32x4& a) +{ + return v_float16x4(vcvt_f16_f32(a.val)); +} +#endif + +//! @name Check SIMD support +//! @{ +//! @brief Check CPU capability of SIMD operation +static inline bool hasSIMD128() +{ + return (CV_CPU_HAS_SUPPORT_NEON) ? true : false; +} + +//! @} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + //! @endcond } diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin_sse.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_sse.hpp similarity index 83% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin_sse.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_sse.hpp index 1840e030..0e740f64 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/hal/intrin_sse.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_sse.hpp @@ -42,10 +42,11 @@ // //M*/ -#ifndef __OPENCV_HAL_SSE_HPP__ -#define __OPENCV_HAL_SSE_HPP__ +#ifndef OPENCV_HAL_SSE_HPP +#define OPENCV_HAL_SSE_HPP #include +#include "opencv2/core/utility.hpp" #define CV_SIMD128 1 #define CV_SIMD128_64F 1 @@ -55,12 +56,14 @@ namespace cv //! @cond IGNORED +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + struct v_uint8x16 { typedef uchar lane_type; enum { nlanes = 16 }; - v_uint8x16() {} + v_uint8x16() : val(_mm_setzero_si128()) {} explicit v_uint8x16(__m128i v) : val(v) {} v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) @@ -83,7 +86,7 @@ struct v_int8x16 typedef schar lane_type; enum { nlanes = 16 }; - v_int8x16() {} + v_int8x16() : val(_mm_setzero_si128()) {} explicit v_int8x16(__m128i v) : val(v) {} v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) @@ -106,7 +109,7 @@ struct v_uint16x8 typedef ushort lane_type; enum { nlanes = 8 }; - v_uint16x8() {} + v_uint16x8() : val(_mm_setzero_si128()) {} explicit v_uint16x8(__m128i v) : val(v) {} v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) { @@ -126,7 +129,7 @@ struct v_int16x8 typedef short lane_type; enum { nlanes = 8 }; - v_int16x8() {} + v_int16x8() : val(_mm_setzero_si128()) {} explicit v_int16x8(__m128i v) : val(v) {} v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) { @@ -145,7 +148,7 @@ struct v_uint32x4 typedef unsigned lane_type; enum { nlanes = 4 }; - v_uint32x4() {} + v_uint32x4() : val(_mm_setzero_si128()) {} explicit v_uint32x4(__m128i v) : val(v) {} v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) { @@ -163,7 +166,7 @@ struct v_int32x4 typedef int lane_type; enum { nlanes = 4 }; - v_int32x4() {} + v_int32x4() : val(_mm_setzero_si128()) {} explicit v_int32x4(__m128i v) : val(v) {} v_int32x4(int v0, int v1, int v2, int v3) { @@ -181,7 +184,7 @@ struct v_float32x4 typedef float lane_type; enum { nlanes = 4 }; - v_float32x4() {} + v_float32x4() : val(_mm_setzero_ps()) {} explicit v_float32x4(__m128 v) : val(v) {} v_float32x4(float v0, float v1, float v2, float v3) { @@ -199,7 +202,7 @@ struct v_uint64x2 typedef uint64 lane_type; enum { nlanes = 2 }; - v_uint64x2() {} + v_uint64x2() : val(_mm_setzero_si128()) {} explicit v_uint64x2(__m128i v) : val(v) {} v_uint64x2(uint64 v0, uint64 v1) { @@ -219,7 +222,7 @@ struct v_int64x2 typedef int64 lane_type; enum { nlanes = 2 }; - v_int64x2() {} + v_int64x2() : val(_mm_setzero_si128()) {} explicit v_int64x2(__m128i v) : val(v) {} v_int64x2(int64 v0, int64 v1) { @@ -239,7 +242,7 @@ struct v_float64x2 typedef double lane_type; enum { nlanes = 2 }; - v_float64x2() {} + v_float64x2() : val(_mm_setzero_pd()) {} explicit v_float64x2(__m128d v) : val(v) {} v_float64x2(double v0, double v1) { @@ -252,6 +255,26 @@ struct v_float64x2 __m128d val; }; +#if CV_FP16 +struct v_float16x4 +{ + typedef short lane_type; + enum { nlanes = 4 }; + + v_float16x4() : val(_mm_setzero_si128()) {} + explicit v_float16x4(__m128i v) : val(v) {} + v_float16x4(short v0, short v1, short v2, short v3) + { + val = _mm_setr_epi16(v0, v1, v2, v3, 0, 0, 0, 0); + } + short get0() const + { + return (short)_mm_cvtsi128_si32(val); + } + __m128i val; +}; +#endif + #define OPENCV_HAL_IMPL_SSE_INITVEC(_Tpvec, _Tp, suffix, zsuffix, ssuffix, _Tps, cast) \ inline _Tpvec v_setzero_##suffix() { return _Tpvec(_mm_setzero_##zsuffix()); } \ inline _Tpvec v_setall_##suffix(_Tp v) { return _Tpvec(_mm_set1_##ssuffix((_Tps)v)); } \ @@ -579,6 +602,16 @@ inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, return v_float32x4(_mm_add_ps(_mm_add_ps(v0, v1), _mm_add_ps(v2, v3))); } +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + __m128 v0 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(0, 0, 0, 0)), m0.val); + __m128 v1 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(1, 1, 1, 1)), m1.val); + __m128 v2 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(2, 2, 2, 2)), m2.val); + + return v_float32x4(_mm_add_ps(_mm_add_ps(v0, v1), _mm_add_ps(v2, a.val))); +} #define OPENCV_HAL_IMPL_SSE_BIN_OP(bin_op, _Tpvec, intrin) \ inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ @@ -719,6 +752,18 @@ inline v_float64x2 v_invsqrt(const v_float64x2& x) return v_float64x2(_mm_div_pd(v_1, _mm_sqrt_pd(x.val))); } +#define OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(_Tpuvec, _Tpsvec, func, suffix, subWidth) \ +inline _Tpuvec v_abs(const _Tpsvec& x) \ +{ return _Tpuvec(_mm_##func##_ep##suffix(x.val, _mm_sub_ep##subWidth(_mm_setzero_si128(), x.val))); } + +OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(v_uint8x16, v_int8x16, min, u8, i8) +OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(v_uint16x8, v_int16x8, max, i16, i16) +inline v_uint32x4 v_abs(const v_int32x4& x) +{ + __m128i s = _mm_srli_epi32(x.val, 31); + __m128i f = _mm_srai_epi32(x.val, 31); + return v_uint32x4(_mm_add_epi32(_mm_xor_si128(x.val, f), s)); +} inline v_float32x4 v_abs(const v_float32x4& x) { return v_float32x4(_mm_and_ps(x.val, _mm_castsi128_ps(_mm_set1_epi32(0x7fffffff)))); } inline v_float64x2 v_abs(const v_float64x2& x) @@ -864,6 +909,15 @@ inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ OPENCV_HAL_IMPL_SSE_FLT_CMP_OP(v_float32x4, ps) OPENCV_HAL_IMPL_SSE_FLT_CMP_OP(v_float64x2, pd) +#define OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(_Tpvec, cast) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return cast(v_reinterpret_as_f64(a) == v_reinterpret_as_f64(b)); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return cast(v_reinterpret_as_f64(a) != v_reinterpret_as_f64(b)); } + +OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(v_uint64x2, v_reinterpret_as_u64); +OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(v_int64x2, v_reinterpret_as_s64); + OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_add_wrap, _mm_add_epi8) OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int8x16, v_add_wrap, _mm_add_epi8) OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint16x8, v_add_wrap, _mm_add_epi16) @@ -967,11 +1021,40 @@ OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint16x8, v_int16x8, epi16, _mm_srai_epi16) OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint32x4, v_int32x4, epi32, _mm_srai_epi32) OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint64x2, v_int64x2, epi64, v_srai_epi64) +template +inline _Tpvec v_rotate_right(const _Tpvec &a) +{ + enum { CV_SHIFT = imm*(sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(_mm_srli_si128(a.val, CV_SHIFT)); +} +template +inline _Tpvec v_rotate_left(const _Tpvec &a) +{ + enum { CV_SHIFT = imm*(sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(_mm_slli_si128(a.val, CV_SHIFT)); +} +template +inline _Tpvec v_rotate_right(const _Tpvec &a, const _Tpvec &b) +{ + enum { CV_SHIFT1 = imm*(sizeof(typename _Tpvec::lane_type)) }; + enum { CV_SHIFT2 = 16 - imm*(sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(_mm_or_si128(_mm_srli_si128(a.val, CV_SHIFT1), _mm_slli_si128(b.val, CV_SHIFT2))); +} +template +inline _Tpvec v_rotate_left(const _Tpvec &a, const _Tpvec &b) +{ + enum { CV_SHIFT1 = imm*(sizeof(typename _Tpvec::lane_type)) }; + enum { CV_SHIFT2 = 16 - imm*(sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(_mm_or_si128(_mm_slli_si128(a.val, CV_SHIFT1), _mm_srli_si128(b.val, CV_SHIFT2))); +} + #define OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(_Tpvec, _Tp) \ inline _Tpvec v_load(const _Tp* ptr) \ { return _Tpvec(_mm_loadu_si128((const __m128i*)ptr)); } \ inline _Tpvec v_load_aligned(const _Tp* ptr) \ { return _Tpvec(_mm_load_si128((const __m128i*)ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(_mm_loadl_epi64((const __m128i*)ptr)); } \ inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ { \ return _Tpvec(_mm_unpacklo_epi64(_mm_loadl_epi64((const __m128i*)ptr0), \ @@ -1000,6 +1083,8 @@ inline _Tpvec v_load(const _Tp* ptr) \ { return _Tpvec(_mm_loadu_##suffix(ptr)); } \ inline _Tpvec v_load_aligned(const _Tp* ptr) \ { return _Tpvec(_mm_load_##suffix(ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(_mm_castsi128_##suffix(_mm_loadl_epi64((const __m128i*)ptr))); } \ inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ { \ return _Tpvec(_mm_castsi128_##suffix( \ @@ -1021,6 +1106,62 @@ inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ OPENCV_HAL_IMPL_SSE_LOADSTORE_FLT_OP(v_float32x4, float, ps) OPENCV_HAL_IMPL_SSE_LOADSTORE_FLT_OP(v_float64x2, double, pd) +#if CV_FP16 +inline v_float16x4 v_load_f16(const short* ptr) +{ return v_float16x4(_mm_loadl_epi64((const __m128i*)ptr)); } +inline void v_store_f16(short* ptr, v_float16x4& a) +{ _mm_storel_epi64((__m128i*)ptr, a.val); } +#endif + +#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(_Tpvec, scalartype, func, suffix, sbit) \ +inline scalartype v_reduce_##func(const v_##_Tpvec& a) \ +{ \ + __m128i val = a.val; \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,8)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,4)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,2)); \ + return (scalartype)_mm_cvtsi128_si32(val); \ +} \ +inline unsigned scalartype v_reduce_##func(const v_u##_Tpvec& a) \ +{ \ + __m128i val = a.val; \ + __m128i smask = _mm_set1_epi16(sbit); \ + val = _mm_xor_si128(val, smask); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,8)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,4)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,2)); \ + return (unsigned scalartype)(_mm_cvtsi128_si32(val) ^ sbit); \ +} +#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_8_SUM(_Tpvec, scalartype, suffix) \ +inline scalartype v_reduce_sum(const v_##_Tpvec& a) \ +{ \ + __m128i val = a.val; \ + val = _mm_adds_epi##suffix(val, _mm_srli_si128(val, 8)); \ + val = _mm_adds_epi##suffix(val, _mm_srli_si128(val, 4)); \ + val = _mm_adds_epi##suffix(val, _mm_srli_si128(val, 2)); \ + return (scalartype)_mm_cvtsi128_si32(val); \ +} \ +inline unsigned scalartype v_reduce_sum(const v_u##_Tpvec& a) \ +{ \ + __m128i val = a.val; \ + val = _mm_adds_epu##suffix(val, _mm_srli_si128(val, 8)); \ + val = _mm_adds_epu##suffix(val, _mm_srli_si128(val, 4)); \ + val = _mm_adds_epu##suffix(val, _mm_srli_si128(val, 2)); \ + return (unsigned scalartype)_mm_cvtsi128_si32(val); \ +} +OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(int16x8, short, max, epi16, (short)-32768) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(int16x8, short, min, epi16, (short)-32768) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_8_SUM(int16x8, short, 16) + +#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(_Tpvec, scalartype, regtype, suffix, cast_from, cast_to, extract) \ +inline scalartype v_reduce_sum(const _Tpvec& a) \ +{ \ + regtype val = a.val; \ + val = _mm_add_##suffix(val, cast_to(_mm_srli_si128(cast_from(val), 8))); \ + val = _mm_add_##suffix(val, cast_to(_mm_srli_si128(cast_from(val), 4))); \ + return (scalartype)_mm_cvt##extract(val); \ +} + #define OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(_Tpvec, scalartype, func, scalar_func) \ inline scalartype v_reduce_##func(const _Tpvec& a) \ { \ @@ -1031,16 +1172,53 @@ inline scalartype v_reduce_##func(const _Tpvec& a) \ return scalar_func(s0, s1); \ } -OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_uint32x4, unsigned, sum, OPENCV_HAL_ADD) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_uint32x4, unsigned, __m128i, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP, si128_si32) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_int32x4, int, __m128i, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP, si128_si32) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_float32x4, float, __m128, ps, _mm_castps_si128, _mm_castsi128_ps, ss_f32) + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ +#if CV_SSE3 + __m128 ab = _mm_hadd_ps(a.val, b.val); + __m128 cd = _mm_hadd_ps(c.val, d.val); + return v_float32x4(_mm_hadd_ps(ab, cd)); +#else + __m128 ac = _mm_add_ps(_mm_unpacklo_ps(a.val, c.val), _mm_unpackhi_ps(a.val, c.val)); + __m128 bd = _mm_add_ps(_mm_unpacklo_ps(b.val, d.val), _mm_unpackhi_ps(b.val, d.val)); + return v_float32x4(_mm_add_ps(_mm_unpacklo_ps(ac, bd), _mm_unpackhi_ps(ac, bd))); +#endif +} + OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_uint32x4, unsigned, max, std::max) OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_uint32x4, unsigned, min, std::min) -OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_int32x4, int, sum, OPENCV_HAL_ADD) OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_int32x4, int, max, std::max) OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_int32x4, int, min, std::min) -OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_float32x4, float, sum, OPENCV_HAL_ADD) OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_float32x4, float, max, std::max) OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_float32x4, float, min, std::min) +#define OPENCV_HAL_IMPL_SSE_POPCOUNT(_Tpvec) \ +inline v_uint32x4 v_popcount(const _Tpvec& a) \ +{ \ + __m128i m1 = _mm_set1_epi32(0x55555555); \ + __m128i m2 = _mm_set1_epi32(0x33333333); \ + __m128i m4 = _mm_set1_epi32(0x0f0f0f0f); \ + __m128i p = a.val; \ + p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 1), m1), _mm_and_si128(p, m1)); \ + p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 2), m2), _mm_and_si128(p, m2)); \ + p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 4), m4), _mm_and_si128(p, m4)); \ + p = _mm_adds_epi8(p, _mm_srli_si128(p, 1)); \ + p = _mm_adds_epi8(p, _mm_srli_si128(p, 2)); \ + return v_uint32x4(_mm_and_si128(p, _mm_set1_epi32(0x000000ff))); \ +} + +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_uint8x16) +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_uint16x8) +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_uint32x4) +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_int8x16) +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_int16x8) +OPENCV_HAL_IMPL_SSE_POPCOUNT(v_int32x4) + #define OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(_Tpvec, suffix, pack_op, and_op, signmask, allmask) \ inline int v_signmask(const _Tpvec& a) \ { \ @@ -1256,6 +1434,24 @@ OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(v_int32x4, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NO OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(v_float32x4, ps, _mm_castps_si128, _mm_castsi128_ps) // adopted from sse_utils.hpp +inline void v_load_deinterleave(const uchar* ptr, v_uint8x16& a, v_uint8x16& b) +{ + __m128i t00 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t01 = _mm_loadu_si128((const __m128i*)(ptr + 16)); + + __m128i t10 = _mm_unpacklo_epi8(t00, t01); + __m128i t11 = _mm_unpackhi_epi8(t00, t01); + + __m128i t20 = _mm_unpacklo_epi8(t10, t11); + __m128i t21 = _mm_unpackhi_epi8(t10, t11); + + __m128i t30 = _mm_unpacklo_epi8(t20, t21); + __m128i t31 = _mm_unpackhi_epi8(t20, t21); + + a.val = _mm_unpacklo_epi8(t30, t31); + b.val = _mm_unpackhi_epi8(t30, t31); +} + inline void v_load_deinterleave(const uchar* ptr, v_uint8x16& a, v_uint8x16& b, v_uint8x16& c) { __m128i t00 = _mm_loadu_si128((const __m128i*)ptr); @@ -1374,6 +1570,65 @@ inline void v_load_deinterleave(const unsigned* ptr, v_uint32x4& a, v_uint32x4& v_transpose4x4(u0, u1, u2, u3, a, b, c, d); } +inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2& a, v_uint64x2& b, v_uint64x2& c) +{ + __m128i t0 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t1 = _mm_loadu_si128((const __m128i*)(ptr + 2)); + __m128i t2 = _mm_loadu_si128((const __m128i*)(ptr + 4)); + + a = v_uint64x2(_mm_unpacklo_epi64(t0, _mm_unpackhi_epi64(t1, t1))); + b = v_uint64x2(_mm_unpacklo_epi64(_mm_unpackhi_epi64(t0, t0), t2)); + c = v_uint64x2(_mm_unpacklo_epi64(t1, _mm_unpackhi_epi64(t2, t2))); +} + +inline void v_load_deinterleave(const int64 *ptr, v_int64x2& a, v_int64x2& b, v_int64x2& c) +{ + v_uint64x2 t0, t1, t2; + v_load_deinterleave((const uint64*)ptr, t0, t1, t2); + a = v_reinterpret_as_s64(t0); + b = v_reinterpret_as_s64(t1); + c = v_reinterpret_as_s64(t2); +} + +inline void v_load_deinterleave(const double *ptr, v_float64x2& a, v_float64x2& b, v_float64x2& c) +{ + v_uint64x2 t0, t1, t2; + v_load_deinterleave((const uint64*)ptr, t0, t1, t2); + a = v_reinterpret_as_f64(t0); + b = v_reinterpret_as_f64(t1); + c = v_reinterpret_as_f64(t2); +} + +// 2-channel, float only +inline void v_load_deinterleave(const float* ptr, v_float32x4& a, v_float32x4& b) +{ + const int mask_lo = _MM_SHUFFLE(2, 0, 2, 0), mask_hi = _MM_SHUFFLE(3, 1, 3, 1); + + __m128 u0 = _mm_loadu_ps(ptr); // a0 b0 a1 b1 + __m128 u1 = _mm_loadu_ps((ptr + 4)); // a2 b2 a3 b3 + + a.val = _mm_shuffle_ps(u0, u1, mask_lo); // a0 a1 a2 a3 + b.val = _mm_shuffle_ps(u0, u1, mask_hi); // b0 b1 ab b3 +} + +inline void v_store_interleave( short* ptr, const v_int16x8& a, const v_int16x8& b ) +{ + __m128i t0, t1; + t0 = _mm_unpacklo_epi16(a.val, b.val); + t1 = _mm_unpackhi_epi16(a.val, b.val); + _mm_storeu_si128((__m128i*)(ptr), t0); + _mm_storeu_si128((__m128i*)(ptr + 8), t1); +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x16& a, const v_uint8x16& b) +{ + __m128i v0 = _mm_unpacklo_epi8(a.val, b.val); + __m128i v1 = _mm_unpackhi_epi8(a.val, b.val); + + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 16), v1); +} + inline void v_store_interleave( uchar* ptr, const v_uint8x16& a, const v_uint8x16& b, const v_uint8x16& c ) { @@ -1529,6 +1784,39 @@ inline void v_store_interleave(unsigned* ptr, const v_uint32x4& a, const v_uint3 v_store(ptr + 12, t3); } +// 2-channel, float only +inline void v_store_interleave(float* ptr, const v_float32x4& a, const v_float32x4& b) +{ + // a0 a1 a2 a3 ... + // b0 b1 b2 b3 ... + __m128 u0 = _mm_unpacklo_ps(a.val, b.val); // a0 b0 a1 b1 + __m128 u1 = _mm_unpackhi_ps(a.val, b.val); // a2 b2 a3 b3 + + _mm_storeu_ps(ptr, u0); + _mm_storeu_ps((ptr + 4), u1); +} + +inline void v_store_interleave(uint64 *ptr, const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c) +{ + __m128i t0 = _mm_unpacklo_epi64(a.val, b.val); + __m128i t1 = _mm_unpacklo_epi64(c.val, _mm_unpackhi_epi64(a.val, a.val)); + __m128i t2 = _mm_unpackhi_epi64(b.val, c.val); + + _mm_storeu_si128((__m128i*)ptr, t0); + _mm_storeu_si128((__m128i*)(ptr + 2), t1); + _mm_storeu_si128((__m128i*)(ptr + 4), t2); +} + +inline void v_store_interleave(int64 *ptr, const v_int64x2& a, const v_int64x2& b, const v_int64x2& c) +{ + v_store_interleave((uint64*)ptr, v_reinterpret_as_u64(a), v_reinterpret_as_u64(b), v_reinterpret_as_u64(c)); +} + +inline void v_store_interleave(double *ptr, const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + v_store_interleave((uint64*)ptr, v_reinterpret_as_u64(a), v_reinterpret_as_u64(b), v_reinterpret_as_u64(c)); +} + #define OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(_Tpvec, _Tp, suffix, _Tpuvec, _Tpu, usuffix) \ inline void v_load_deinterleave( const _Tp* ptr, _Tpvec& a0, \ _Tpvec& b0, _Tpvec& c0 ) \ @@ -1587,11 +1875,45 @@ inline v_float64x2 v_cvt_f64(const v_int32x4& a) return v_float64x2(_mm_cvtepi32_pd(a.val)); } +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ + return v_float64x2(_mm_cvtepi32_pd(_mm_srli_si128(a.val,8))); +} + inline v_float64x2 v_cvt_f64(const v_float32x4& a) { return v_float64x2(_mm_cvtps_pd(a.val)); } +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ + return v_float64x2(_mm_cvtps_pd(_mm_castsi128_ps(_mm_srli_si128(_mm_castps_si128(a.val),8)))); +} + +#if CV_FP16 +inline v_float32x4 v_cvt_f32(const v_float16x4& a) +{ + return v_float32x4(_mm_cvtph_ps(a.val)); +} + +inline v_float16x4 v_cvt_f16(const v_float32x4& a) +{ + return v_float16x4(_mm_cvtps_ph(a.val, 0)); +} +#endif + +//! @name Check SIMD support +//! @{ +//! @brief Check CPU capability of SIMD operation +static inline bool hasSIMD128() +{ + return (CV_CPU_HAS_SUPPORT_SSE2) ? true : false; +} + +//! @} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + //! @endcond } diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_vsx.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_vsx.hpp new file mode 100644 index 00000000..9f050f7c --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/hal/intrin_vsx.hpp @@ -0,0 +1,962 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_HAL_VSX_HPP +#define OPENCV_HAL_VSX_HPP + +#include +#include "opencv2/core/utility.hpp" + +#define CV_SIMD128 1 +#define CV_SIMD128_64F 1 + +/** + * todo: supporting half precision for power9 + * convert instractions xvcvhpsp, xvcvsphp +**/ + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +///////// Types //////////// + +struct v_uint8x16 +{ + typedef uchar lane_type; + enum { nlanes = 16 }; + vec_uchar16 val; + + explicit v_uint8x16(const vec_uchar16& v) : val(v) + {} + v_uint8x16() : val(vec_uchar16_z) + {} + v_uint8x16(vec_bchar16 v) : val(vec_uchar16_c(v)) + {} + v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) + : val(vec_uchar16_set(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)) + {} + uchar get0() const + { return vec_extract(val, 0); } +}; + +struct v_int8x16 +{ + typedef schar lane_type; + enum { nlanes = 16 }; + vec_char16 val; + + explicit v_int8x16(const vec_char16& v) : val(v) + {} + v_int8x16() : val(vec_char16_z) + {} + v_int8x16(vec_bchar16 v) : val(vec_char16_c(v)) + {} + v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) + : val(vec_char16_set(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)) + {} + schar get0() const + { return vec_extract(val, 0); } +}; + +struct v_uint16x8 +{ + typedef ushort lane_type; + enum { nlanes = 8 }; + vec_ushort8 val; + + explicit v_uint16x8(const vec_ushort8& v) : val(v) + {} + v_uint16x8() : val(vec_ushort8_z) + {} + v_uint16x8(vec_bshort8 v) : val(vec_ushort8_c(v)) + {} + v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) + : val(vec_ushort8_set(v0, v1, v2, v3, v4, v5, v6, v7)) + {} + ushort get0() const + { return vec_extract(val, 0); } +}; + +struct v_int16x8 +{ + typedef short lane_type; + enum { nlanes = 8 }; + vec_short8 val; + + explicit v_int16x8(const vec_short8& v) : val(v) + {} + v_int16x8() : val(vec_short8_z) + {} + v_int16x8(vec_bshort8 v) : val(vec_short8_c(v)) + {} + v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) + : val(vec_short8_set(v0, v1, v2, v3, v4, v5, v6, v7)) + {} + short get0() const + { return vec_extract(val, 0); } +}; + +struct v_uint32x4 +{ + typedef unsigned lane_type; + enum { nlanes = 4 }; + vec_uint4 val; + + explicit v_uint32x4(const vec_uint4& v) : val(v) + {} + v_uint32x4() : val(vec_uint4_z) + {} + v_uint32x4(vec_bint4 v) : val(vec_uint4_c(v)) + {} + v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) : val(vec_uint4_set(v0, v1, v2, v3)) + {} + uint get0() const + { return vec_extract(val, 0); } +}; + +struct v_int32x4 +{ + typedef int lane_type; + enum { nlanes = 4 }; + vec_int4 val; + + explicit v_int32x4(const vec_int4& v) : val(v) + {} + v_int32x4() : val(vec_int4_z) + {} + v_int32x4(vec_bint4 v) : val(vec_int4_c(v)) + {} + v_int32x4(int v0, int v1, int v2, int v3) : val(vec_int4_set(v0, v1, v2, v3)) + {} + int get0() const + { return vec_extract(val, 0); } +}; + +struct v_float32x4 +{ + typedef float lane_type; + enum { nlanes = 4 }; + vec_float4 val; + + explicit v_float32x4(const vec_float4& v) : val(v) + {} + v_float32x4() : val(vec_float4_z) + {} + v_float32x4(vec_bint4 v) : val(vec_float4_c(v)) + {} + v_float32x4(float v0, float v1, float v2, float v3) : val(vec_float4_set(v0, v1, v2, v3)) + {} + float get0() const + { return vec_extract(val, 0); } +}; + +struct v_uint64x2 +{ + typedef uint64 lane_type; + enum { nlanes = 2 }; + vec_udword2 val; + + explicit v_uint64x2(const vec_udword2& v) : val(v) + {} + v_uint64x2() : val(vec_udword2_z) + {} + v_uint64x2(vec_bdword2 v) : val(vec_udword2_c(v)) + {} + v_uint64x2(uint64 v0, uint64 v1) : val(vec_udword2_set(v0, v1)) + {} + uint64 get0() const + { return vec_extract(val, 0); } +}; + +struct v_int64x2 +{ + typedef int64 lane_type; + enum { nlanes = 2 }; + vec_dword2 val; + + explicit v_int64x2(const vec_dword2& v) : val(v) + {} + v_int64x2() : val(vec_dword2_z) + {} + v_int64x2(vec_bdword2 v) : val(vec_dword2_c(v)) + {} + v_int64x2(int64 v0, int64 v1) : val(vec_dword2_set(v0, v1)) + {} + int64 get0() const + { return vec_extract(val, 0); } +}; + +struct v_float64x2 +{ + typedef double lane_type; + enum { nlanes = 2 }; + vec_double2 val; + + explicit v_float64x2(const vec_double2& v) : val(v) + {} + v_float64x2() : val(vec_double2_z) + {} + v_float64x2(vec_bdword2 v) : val(vec_double2_c(v)) + {} + v_float64x2(double v0, double v1) : val(vec_double2_set(v0, v1)) + {} + double get0() const + { return vec_extract(val, 0); } +}; + +//////////////// Load and store operations /////////////// + +/* + * clang-5 aborted during parse "vec_xxx_c" only if it's + * inside a function template which is defined by preprocessor macro. + * + * if vec_xxx_c defined as C++ cast, clang-5 will pass it +*/ +#define OPENCV_HAL_IMPL_VSX_INITVEC(_Tpvec, _Tp, suffix, cast) \ +inline _Tpvec v_setzero_##suffix() { return _Tpvec(); } \ +inline _Tpvec v_setall_##suffix(_Tp v) { return _Tpvec(vec_splats((_Tp)v));} \ +template inline _Tpvec v_reinterpret_as_##suffix(const _Tpvec0 &a) \ +{ return _Tpvec((cast)a.val); } + +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint8x16, uchar, u8, vec_uchar16) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int8x16, schar, s8, vec_char16) +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint16x8, ushort, u16, vec_ushort8) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int16x8, short, s16, vec_short8) +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint32x4, uint, u32, vec_uint4) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int32x4, int, s32, vec_int4) +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint64x2, uint64, u64, vec_udword2) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int64x2, int64, s64, vec_dword2) +OPENCV_HAL_IMPL_VSX_INITVEC(v_float32x4, float, f32, vec_float4) +OPENCV_HAL_IMPL_VSX_INITVEC(v_float64x2, double, f64, vec_double2) + +#define OPENCV_HAL_IMPL_VSX_LOADSTORE_INT_OP(_Tpvec, _Tp, ld_func, st_func) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec(ld_func(0, ptr)); } \ +inline _Tpvec v_load_aligned(const _Tp* ptr) \ +{ return _Tpvec(ld_func(0, ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(vec_ld_l8(ptr)); } \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ return _Tpvec(vec_mergesqh(vec_ld_l8(ptr0), vec_ld_l8(ptr1))); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ st_func(a.val, 0, ptr); } \ +inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ +{ st_func(a.val, 0, ptr); } \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ vec_st_l8(a.val, ptr); } \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ vec_st_h8(a.val, ptr); } + +OPENCV_HAL_IMPL_VSX_LOADSTORE_INT_OP(v_uint8x16, uchar, vsx_ld, vsx_st) +OPENCV_HAL_IMPL_VSX_LOADSTORE_INT_OP(v_int8x16, schar, vsx_ld, vsx_st) +OPENCV_HAL_IMPL_VSX_LOADSTORE_INT_OP(v_uint16x8, ushort, vsx_ld, vsx_st) +OPENCV_HAL_IMPL_VSX_LOADSTORE_INT_OP(v_int16x8, short, vsx_ld, vsx_st) +OPENCV_HAL_IMPL_VSX_LOADSTORE_INT_OP(v_uint32x4, uint, vsx_ld, vsx_st) +OPENCV_HAL_IMPL_VSX_LOADSTORE_INT_OP(v_int32x4, int, vsx_ld, vsx_st) +OPENCV_HAL_IMPL_VSX_LOADSTORE_INT_OP(v_float32x4, float, vsx_ld, vsx_st) +OPENCV_HAL_IMPL_VSX_LOADSTORE_INT_OP(v_float64x2, double, vsx_ld, vsx_st) +OPENCV_HAL_IMPL_VSX_LOADSTORE_INT_OP(v_uint64x2, uint64, vsx_ld2, vsx_st2) +OPENCV_HAL_IMPL_VSX_LOADSTORE_INT_OP(v_int64x2, int64, vsx_ld2, vsx_st2) + +//////////////// Value reordering /////////////// + +/* de&interleave */ +#define OPENCV_HAL_IMPL_VSX_INTERLEAVE(_Tp, _Tpvec) \ +inline void v_load_deinterleave(const _Tp* ptr, _Tpvec& a, _Tpvec& b) \ +{ vec_ld_deinterleave(ptr, a.val, b.val);} \ +inline void v_load_deinterleave(const _Tp* ptr, _Tpvec& a, \ + _Tpvec& b, _Tpvec& c) \ +{ vec_ld_deinterleave(ptr, a.val, b.val, c.val); } \ +inline void v_load_deinterleave(const _Tp* ptr, _Tpvec& a, _Tpvec& b, \ + _Tpvec& c, _Tpvec& d) \ +{ vec_ld_deinterleave(ptr, a.val, b.val, c.val, d.val); } \ +inline void v_store_interleave(_Tp* ptr, const _Tpvec& a, const _Tpvec& b) \ +{ vec_st_interleave(a.val, b.val, ptr); } \ +inline void v_store_interleave(_Tp* ptr, const _Tpvec& a, \ + const _Tpvec& b, const _Tpvec& c) \ +{ vec_st_interleave(a.val, b.val, c.val, ptr); } \ +inline void v_store_interleave(_Tp* ptr, const _Tpvec& a, const _Tpvec& b, \ + const _Tpvec& c, const _Tpvec& d) \ +{ vec_st_interleave(a.val, b.val, c.val, d.val, ptr); } + +OPENCV_HAL_IMPL_VSX_INTERLEAVE(uchar, v_uint8x16) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(schar, v_int8x16) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(ushort, v_uint16x8) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(short, v_int16x8) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(uint, v_uint32x4) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(int, v_int32x4) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(float, v_float32x4) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(double, v_float64x2) + +/* Expand */ +#define OPENCV_HAL_IMPL_VSX_EXPAND(_Tpvec, _Tpwvec, _Tp, fl, fh) \ +inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ +{ \ + b0.val = fh(a.val); \ + b1.val = fl(a.val); \ +} \ +inline _Tpwvec v_load_expand(const _Tp* ptr) \ +{ return _Tpwvec(fh(vsx_ld(0, ptr))); } + +OPENCV_HAL_IMPL_VSX_EXPAND(v_uint8x16, v_uint16x8, uchar, vec_unpacklu, vec_unpackhu) +OPENCV_HAL_IMPL_VSX_EXPAND(v_int8x16, v_int16x8, schar, vec_unpackl, vec_unpackh) +OPENCV_HAL_IMPL_VSX_EXPAND(v_uint16x8, v_uint32x4, ushort, vec_unpacklu, vec_unpackhu) +OPENCV_HAL_IMPL_VSX_EXPAND(v_int16x8, v_int32x4, short, vec_unpackl, vec_unpackh) +OPENCV_HAL_IMPL_VSX_EXPAND(v_uint32x4, v_uint64x2, uint, vec_unpacklu, vec_unpackhu) +OPENCV_HAL_IMPL_VSX_EXPAND(v_int32x4, v_int64x2, int, vec_unpackl, vec_unpackh) + +inline v_uint32x4 v_load_expand_q(const uchar* ptr) +{ return v_uint32x4(vec_ld_buw(ptr)); } + +inline v_int32x4 v_load_expand_q(const schar* ptr) +{ return v_int32x4(vec_ld_bsw(ptr)); } + +/* pack */ +#define OPENCV_HAL_IMPL_VSX_PACK(_Tpvec, _Tp, _Tpwvec, _Tpvn, _Tpdel, sfnc, pkfnc, addfnc, pack) \ +inline _Tpvec v_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + return _Tpvec(pkfnc(a.val, b.val)); \ +} \ +inline void v_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + vec_st_l8(pkfnc(a.val, a.val), ptr); \ +} \ +template \ +inline _Tpvec v_rshr_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + const __vector _Tpvn vn = vec_splats((_Tpvn)n); \ + const __vector _Tpdel delta = vec_splats((_Tpdel)((_Tpdel)1 << (n-1))); \ + return _Tpvec(pkfnc(sfnc(addfnc(a.val, delta), vn), sfnc(addfnc(b.val, delta), vn))); \ +} \ +template \ +inline void v_rshr_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + const __vector _Tpvn vn = vec_splats((_Tpvn)n); \ + const __vector _Tpdel delta = vec_splats((_Tpdel)((_Tpdel)1 << (n-1))); \ + vec_st_l8(pkfnc(sfnc(addfnc(a.val, delta), vn), delta), ptr); \ +} + +OPENCV_HAL_IMPL_VSX_PACK(v_uint8x16, uchar, v_uint16x8, unsigned short, unsigned short, + vec_sr, vec_packs, vec_adds, pack) +OPENCV_HAL_IMPL_VSX_PACK(v_int8x16, schar, v_int16x8, unsigned short, short, + vec_sra, vec_packs, vec_adds, pack) + +OPENCV_HAL_IMPL_VSX_PACK(v_uint16x8, ushort, v_uint32x4, unsigned int, unsigned int, + vec_sr, vec_packs, vec_add, pack) +OPENCV_HAL_IMPL_VSX_PACK(v_int16x8, short, v_int32x4, unsigned int, int, + vec_sra, vec_packs, vec_add, pack) + +OPENCV_HAL_IMPL_VSX_PACK(v_uint32x4, uint, v_uint64x2, unsigned long long, unsigned long long, + vec_sr, vec_pack, vec_add, pack) +OPENCV_HAL_IMPL_VSX_PACK(v_int32x4, int, v_int64x2, unsigned long long, long long, + vec_sra, vec_pack, vec_add, pack) + +OPENCV_HAL_IMPL_VSX_PACK(v_uint8x16, uchar, v_int16x8, unsigned short, short, + vec_sra, vec_packsu, vec_adds, pack_u) +OPENCV_HAL_IMPL_VSX_PACK(v_uint16x8, ushort, v_int32x4, unsigned int, int, + vec_sra, vec_packsu, vec_add, pack_u) +// Following variant is not implemented on other platforms: +//OPENCV_HAL_IMPL_VSX_PACK(v_uint32x4, uint, v_int64x2, unsigned long long, long long, +// vec_sra, vec_packsu, vec_add, pack_u) + +/* Recombine */ +template +inline void v_zip(const _Tpvec& a0, const _Tpvec& a1, _Tpvec& b0, _Tpvec& b1) +{ + b0.val = vec_mergeh(a0.val, a1.val); + b1.val = vec_mergel(a0.val, a1.val); +} + +template +inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(vec_mergesql(a.val, b.val)); } + +template +inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(vec_mergesqh(a.val, b.val)); } + +template +inline void v_recombine(const _Tpvec& a, const _Tpvec& b, _Tpvec& c, _Tpvec& d) +{ + c.val = vec_mergesqh(a.val, b.val); + d.val = vec_mergesql(a.val, b.val); +} + +/* Extract */ +template +inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) +{ + const int w = sizeof(typename _Tpvec::lane_type); + const int n = _Tpvec::nlanes; + const unsigned int sf = ((w * n) - (s * w)); + if (s == 0) + return _Tpvec(a.val); + else if (sf > 15) + return _Tpvec(); + // bitwise it just to make xlc happy + return _Tpvec(vec_sld(b.val, a.val, sf & 15)); +} + +#define OPENCV_HAL_IMPL_VSX_EXTRACT_2(_Tpvec) \ +template \ +inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) \ +{ \ + switch(s) { \ + case 0: return _Tpvec(a.val); \ + case 2: return _Tpvec(b.val); \ + case 1: return _Tpvec(vec_sldw(b.val, a.val, 2)); \ + default: return _Tpvec(); \ + } \ +} +OPENCV_HAL_IMPL_VSX_EXTRACT_2(v_uint64x2) +OPENCV_HAL_IMPL_VSX_EXTRACT_2(v_int64x2) + + +////////// Arithmetic, bitwise and comparison operations ///////// + +/* Element-wise binary and unary operations */ +/** Arithmetics **/ +#define OPENCV_HAL_IMPL_VSX_BIN_OP(bin_op, _Tpvec, intrin) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(intrin(a.val, b.val)); } \ +inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ +{ a.val = intrin(a.val, b.val); return a; } + +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint8x16, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint8x16, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int8x16, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int8x16, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint16x8, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint16x8, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_uint16x8, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int16x8, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int16x8, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_int16x8, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint32x4, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint32x4, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_uint32x4, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int32x4, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int32x4, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_int32x4, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_float32x4, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_float32x4, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_float32x4, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(/, v_float32x4, vec_div) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_float64x2, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_float64x2, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_float64x2, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(/, v_float64x2, vec_div) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint64x2, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint64x2, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int64x2, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int64x2, vec_sub) + +inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b, v_int32x4& c, v_int32x4& d) +{ + c.val = vec_mul(vec_unpackh(a.val), vec_unpackh(b.val)); + d.val = vec_mul(vec_unpackl(a.val), vec_unpackl(b.val)); +} +inline void v_mul_expand(const v_uint16x8& a, const v_uint16x8& b, v_uint32x4& c, v_uint32x4& d) +{ + c.val = vec_mul(vec_unpackhu(a.val), vec_unpackhu(b.val)); + d.val = vec_mul(vec_unpacklu(a.val), vec_unpacklu(b.val)); +} +inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b, v_uint64x2& c, v_uint64x2& d) +{ + c.val = vec_mul(vec_unpackhu(a.val), vec_unpackhu(b.val)); + d.val = vec_mul(vec_unpacklu(a.val), vec_unpacklu(b.val)); +} + +/** Non-saturating arithmetics **/ +#define OPENCV_HAL_IMPL_VSX_BIN_FUNC(func, intrin) \ +template \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(intrin(a.val, b.val)); } + +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_add_wrap, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_sub_wrap, vec_sub) + +/** Bitwise shifts **/ +#define OPENCV_HAL_IMPL_VSX_SHIFT_OP(_Tpvec, shr, splfunc) \ +inline _Tpvec operator << (const _Tpvec& a, int imm) \ +{ return _Tpvec(vec_sl(a.val, splfunc(imm))); } \ +inline _Tpvec operator >> (const _Tpvec& a, int imm) \ +{ return _Tpvec(shr(a.val, splfunc(imm))); } \ +template inline _Tpvec v_shl(const _Tpvec& a) \ +{ return _Tpvec(vec_sl(a.val, splfunc(imm))); } \ +template inline _Tpvec v_shr(const _Tpvec& a) \ +{ return _Tpvec(shr(a.val, splfunc(imm))); } + +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint8x16, vec_sr, vec_uchar16_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint16x8, vec_sr, vec_ushort8_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint32x4, vec_sr, vec_uint4_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint64x2, vec_sr, vec_udword2_sp) +// algebraic right shift +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int8x16, vec_sra, vec_uchar16_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int16x8, vec_sra, vec_ushort8_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int32x4, vec_sra, vec_uint4_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int64x2, vec_sra, vec_udword2_sp) + +/** Bitwise logic **/ +#define OPENCV_HAL_IMPL_VSX_LOGIC_OP(_Tpvec) \ +OPENCV_HAL_IMPL_VSX_BIN_OP(&, _Tpvec, vec_and) \ +OPENCV_HAL_IMPL_VSX_BIN_OP(|, _Tpvec, vec_or) \ +OPENCV_HAL_IMPL_VSX_BIN_OP(^, _Tpvec, vec_xor) \ +inline _Tpvec operator ~ (const _Tpvec& a) \ +{ return _Tpvec(vec_not(a.val)); } + +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint8x16) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int8x16) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint16x8) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int16x8) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint32x4) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int32x4) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint64x2) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int64x2) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_float32x4) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_float64x2) + +/** Bitwise select **/ +#define OPENCV_HAL_IMPL_VSX_SELECT(_Tpvec, cast) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_sel(b.val, a.val, cast(mask.val))); } + +OPENCV_HAL_IMPL_VSX_SELECT(v_uint8x16, vec_bchar16_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_int8x16, vec_bchar16_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_uint16x8, vec_bshort8_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_int16x8, vec_bshort8_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_uint32x4, vec_bint4_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_int32x4, vec_bint4_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_float32x4, vec_bint4_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_float64x2, vec_bdword2_c) + +/** Comparison **/ +#define OPENCV_HAL_IMPL_VSX_INT_CMP_OP(_Tpvec) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpeq(a.val, b.val)); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpne(a.val, b.val)); } \ +inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmplt(a.val, b.val)); } \ +inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpgt(a.val, b.val)); } \ +inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmple(a.val, b.val)); } \ +inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpge(a.val, b.val)); } + +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint8x16) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int8x16) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint16x8) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int16x8) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint32x4) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int32x4) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_float32x4) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_float64x2) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint64x2) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int64x2) + +/** min/max **/ +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_min, vec_min) +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_max, vec_max) + +/** Rotate **/ +#define OPENCV_IMPL_VSX_ROTATE(_Tpvec, suffix, shf, cast) \ +template \ +inline _Tpvec v_rotate_##suffix(const _Tpvec& a) \ +{ \ + const int wd = imm * sizeof(typename _Tpvec::lane_type); \ + if (wd > 15) \ + return _Tpvec(); \ + return _Tpvec((cast)shf(vec_uchar16_c(a.val), vec_uchar16_sp(wd << 3))); \ +} + +#define OPENCV_IMPL_VSX_ROTATE_LR(_Tpvec, cast) \ +OPENCV_IMPL_VSX_ROTATE(_Tpvec, left, vec_slo, cast) \ +OPENCV_IMPL_VSX_ROTATE(_Tpvec, right, vec_sro, cast) + +OPENCV_IMPL_VSX_ROTATE_LR(v_uint8x16, vec_uchar16) +OPENCV_IMPL_VSX_ROTATE_LR(v_int8x16, vec_char16) +OPENCV_IMPL_VSX_ROTATE_LR(v_uint16x8, vec_ushort8) +OPENCV_IMPL_VSX_ROTATE_LR(v_int16x8, vec_short8) +OPENCV_IMPL_VSX_ROTATE_LR(v_uint32x4, vec_uint4) +OPENCV_IMPL_VSX_ROTATE_LR(v_int32x4, vec_int4) +OPENCV_IMPL_VSX_ROTATE_LR(v_uint64x2, vec_udword2) +OPENCV_IMPL_VSX_ROTATE_LR(v_int64x2, vec_dword2) + + +template +inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) +{ + enum { CV_SHIFT = 16 - imm * (sizeof(typename _Tpvec::lane_type)) }; + if (CV_SHIFT == 16) + return a; +#ifdef __IBMCPP__ + return _Tpvec(vec_sld(b.val, a.val, CV_SHIFT & 15)); +#else + return _Tpvec(vec_sld(b.val, a.val, CV_SHIFT)); +#endif +} + +template +inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) +{ + enum { CV_SHIFT = imm * (sizeof(typename _Tpvec::lane_type)) }; + if (CV_SHIFT == 16) + return b; + return _Tpvec(vec_sld(a.val, b.val, CV_SHIFT)); +} + +#define OPENCV_IMPL_VSX_ROTATE_64(_Tpvec, suffix, rg1, rg2) \ +template \ +inline _Tpvec v_rotate_##suffix(const _Tpvec& a, const _Tpvec& b) \ +{ \ + if (imm == 1) \ + return _Tpvec(vec_permi(rg1.val, rg2.val, 2)); \ + return imm ? b : a; \ +} + +OPENCV_IMPL_VSX_ROTATE_64(v_int64x2, right, a, b) +OPENCV_IMPL_VSX_ROTATE_64(v_uint64x2, right, a, b) + +OPENCV_IMPL_VSX_ROTATE_64(v_int64x2, left, b, a) +OPENCV_IMPL_VSX_ROTATE_64(v_uint64x2, left, b, a) + +////////// Reduce and mask ///////// + +/** Reduce **/ +inline short v_reduce_sum(const v_int16x8& a) +{ + const vec_int4 zero = vec_int4_z; + return saturate_cast(vec_extract(vec_sums(vec_sum4s(a.val, zero), zero), 3)); +} +inline ushort v_reduce_sum(const v_uint16x8& a) +{ + const vec_int4 v4 = vec_int4_c(vec_unpackhu(vec_adds(a.val, vec_sld(a.val, a.val, 8)))); + return saturate_cast(vec_extract(vec_sums(v4, vec_int4_z), 3)); +} + +#define OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(_Tpvec, _Tpvec2, scalartype, suffix, func) \ +inline scalartype v_reduce_##suffix(const _Tpvec& a) \ +{ \ + const _Tpvec2 rs = func(a.val, vec_sld(a.val, a.val, 8)); \ + return vec_extract(func(rs, vec_sld(rs, rs, 4)), 0); \ +} +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_uint32x4, vec_uint4, uint, sum, vec_add) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_uint32x4, vec_uint4, uint, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_uint32x4, vec_uint4, uint, min, vec_min) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_int32x4, vec_int4, int, sum, vec_add) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_int32x4, vec_int4, int, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_int32x4, vec_int4, int, min, vec_min) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_float32x4, vec_float4, float, sum, vec_add) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_float32x4, vec_float4, float, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_float32x4, vec_float4, float, min, vec_min) + +#define OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(_Tpvec, _Tpvec2, scalartype, suffix, func) \ +inline scalartype v_reduce_##suffix(const _Tpvec& a) \ +{ \ + _Tpvec2 rs = func(a.val, vec_sld(a.val, a.val, 8)); \ + rs = func(rs, vec_sld(rs, rs, 4)); \ + return vec_extract(func(rs, vec_sld(rs, rs, 2)), 0); \ +} +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_uint16x8, vec_ushort8, ushort, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_uint16x8, vec_ushort8, ushort, min, vec_min) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_int16x8, vec_short8, short, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_int16x8, vec_short8, short, min, vec_min) + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + vec_float4 ac = vec_add(vec_mergel(a.val, c.val), vec_mergeh(a.val, c.val)); + ac = vec_add(ac, vec_sld(ac, ac, 8)); + + vec_float4 bd = vec_add(vec_mergel(b.val, d.val), vec_mergeh(b.val, d.val)); + bd = vec_add(bd, vec_sld(bd, bd, 8)); + return v_float32x4(vec_mergeh(ac, bd)); +} + +/** Popcount **/ +template +inline v_uint32x4 v_popcount(const _Tpvec& a) +{ return v_uint32x4(vec_popcntu(vec_uint4_c(a.val))); } + +/** Mask **/ +inline int v_signmask(const v_uint8x16& a) +{ + vec_uchar16 sv = vec_sr(a.val, vec_uchar16_sp(7)); + static const vec_uchar16 slm = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7}; + sv = vec_sl(sv, slm); + vec_uint4 sv4 = vec_sum4s(sv, vec_uint4_z); + static const vec_uint4 slm4 = {0, 0, 8, 8}; + sv4 = vec_sl(sv4, slm4); + return vec_extract(vec_sums((vec_int4) sv4, vec_int4_z), 3); +} +inline int v_signmask(const v_int8x16& a) +{ return v_signmask(v_reinterpret_as_u8(a)); } + +inline int v_signmask(const v_int16x8& a) +{ + static const vec_ushort8 slm = {0, 1, 2, 3, 4, 5, 6, 7}; + vec_short8 sv = vec_sr(a.val, vec_ushort8_sp(15)); + sv = vec_sl(sv, slm); + vec_int4 svi = vec_int4_z; + svi = vec_sums(vec_sum4s(sv, svi), svi); + return vec_extract(svi, 3); +} +inline int v_signmask(const v_uint16x8& a) +{ return v_signmask(v_reinterpret_as_s16(a)); } + +inline int v_signmask(const v_int32x4& a) +{ + static const vec_uint4 slm = {0, 1, 2, 3}; + vec_int4 sv = vec_sr(a.val, vec_uint4_sp(31)); + sv = vec_sl(sv, slm); + sv = vec_sums(sv, vec_int4_z); + return vec_extract(sv, 3); +} +inline int v_signmask(const v_uint32x4& a) +{ return v_signmask(v_reinterpret_as_s32(a)); } +inline int v_signmask(const v_float32x4& a) +{ return v_signmask(v_reinterpret_as_s32(a)); } + +inline int v_signmask(const v_int64x2& a) +{ + VSX_UNUSED(const vec_dword2) sv = vec_sr(a.val, vec_udword2_sp(63)); + return (int)vec_extract(sv, 0) | (int)vec_extract(sv, 1) << 1; +} +inline int v_signmask(const v_uint64x2& a) +{ return v_signmask(v_reinterpret_as_s64(a)); } +inline int v_signmask(const v_float64x2& a) +{ return v_signmask(v_reinterpret_as_s64(a)); } + + +template +inline bool v_check_all(const _Tpvec& a) +{ return vec_all_lt(a.val, _Tpvec().val);} +inline bool v_check_all(const v_uint8x16 &a) +{ return v_check_all(v_reinterpret_as_s8(a)); } +inline bool v_check_all(const v_uint16x8 &a) +{ return v_check_all(v_reinterpret_as_s16(a)); } +inline bool v_check_all(const v_uint32x4 &a) +{ return v_check_all(v_reinterpret_as_s32(a)); } + +template +inline bool v_check_any(const _Tpvec& a) +{ return vec_any_lt(a.val, _Tpvec().val);} +inline bool v_check_any(const v_uint8x16 &a) +{ return v_check_any(v_reinterpret_as_s8(a)); } +inline bool v_check_any(const v_uint16x8 &a) +{ return v_check_any(v_reinterpret_as_s16(a)); } +inline bool v_check_any(const v_uint32x4 &a) +{ return v_check_any(v_reinterpret_as_s32(a)); } + +////////// Other math ///////// + +/** Some frequent operations **/ +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ return v_float32x4(vec_sqrt(x.val)); } +inline v_float64x2 v_sqrt(const v_float64x2& x) +{ return v_float64x2(vec_sqrt(x.val)); } + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ return v_float32x4(vec_rsqrt(x.val)); } +inline v_float64x2 v_invsqrt(const v_float64x2& x) +{ return v_float64x2(vec_rsqrt(x.val)); } + +#define OPENCV_HAL_IMPL_VSX_MULADD(_Tpvec) \ +inline _Tpvec v_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_sqrt(vec_madd(a.val, a.val, vec_mul(b.val, b.val)))); } \ +inline _Tpvec v_sqr_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_madd(a.val, a.val, vec_mul(b.val, b.val))); } \ +inline _Tpvec v_muladd(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ +{ return _Tpvec(vec_madd(a.val, b.val, c.val)); } + +OPENCV_HAL_IMPL_VSX_MULADD(v_float32x4) +OPENCV_HAL_IMPL_VSX_MULADD(v_float64x2) + +// TODO: exp, log, sin, cos + +/** Absolute values **/ +inline v_uint8x16 v_abs(const v_int8x16& x) +{ return v_uint8x16(vec_uchar16_c(vec_abs(x.val))); } + +inline v_uint16x8 v_abs(const v_int16x8& x) +{ return v_uint16x8(vec_ushort8_c(vec_abs(x.val))); } + +inline v_uint32x4 v_abs(const v_int32x4& x) +{ return v_uint32x4(vec_uint4_c(vec_abs(x.val))); } + +inline v_float32x4 v_abs(const v_float32x4& x) +{ return v_float32x4(vec_abs(x.val)); } + +inline v_float64x2 v_abs(const v_float64x2& x) +{ return v_float64x2(vec_abs(x.val)); } + +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_absdiff, vec_absd) + +#define OPENCV_HAL_IMPL_VSX_BIN_FUNC2(_Tpvec, _Tpvec2, cast, func, intrin) \ +inline _Tpvec2 func(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec2(cast(intrin(a.val, b.val))); } + +OPENCV_HAL_IMPL_VSX_BIN_FUNC2(v_int8x16, v_uint8x16, vec_uchar16_c, v_absdiff, vec_absd) +OPENCV_HAL_IMPL_VSX_BIN_FUNC2(v_int16x8, v_uint16x8, vec_ushort8_c, v_absdiff, vec_absd) +OPENCV_HAL_IMPL_VSX_BIN_FUNC2(v_int32x4, v_uint32x4, vec_uint4_c, v_absdiff, vec_absd) +OPENCV_HAL_IMPL_VSX_BIN_FUNC2(v_int64x2, v_uint64x2, vec_udword2_c, v_absdiff, vec_absd) + +////////// Conversions ///////// + +/** Rounding **/ +inline v_int32x4 v_round(const v_float32x4& a) +{ return v_int32x4(vec_cts(vec_round(a.val))); } + +inline v_int32x4 v_round(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(vec_round(a.val)), vec_int4_z)); } + +inline v_int32x4 v_floor(const v_float32x4& a) +{ return v_int32x4(vec_cts(vec_floor(a.val))); } + +inline v_int32x4 v_floor(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(vec_floor(a.val)), vec_int4_z)); } + +inline v_int32x4 v_ceil(const v_float32x4& a) +{ return v_int32x4(vec_cts(vec_ceil(a.val))); } + +inline v_int32x4 v_ceil(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(vec_ceil(a.val)), vec_int4_z)); } + +inline v_int32x4 v_trunc(const v_float32x4& a) +{ return v_int32x4(vec_cts(a.val)); } + +inline v_int32x4 v_trunc(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(a.val), vec_int4_z)); } + +/** To float **/ +inline v_float32x4 v_cvt_f32(const v_int32x4& a) +{ return v_float32x4(vec_ctf(a.val)); } + +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ return v_float32x4(vec_mergesqo(vec_cvfo(a.val), vec_float4_z)); } + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ return v_float64x2(vec_ctdo(vec_mergeh(a.val, a.val))); } + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ return v_float64x2(vec_ctdo(vec_mergel(a.val, a.val))); } + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ return v_float64x2(vec_cvfo(vec_mergeh(a.val, a.val))); } + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ return v_float64x2(vec_cvfo(vec_mergel(a.val, a.val))); } + +/** Reinterpret **/ +/** its up there with load and store operations **/ + +////////// Matrix operations ///////// + +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b) +{ return v_int32x4(vec_msum(a.val, b.val, vec_int4_z)); } + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + const vec_float4 v0 = vec_splat(v.val, 0); + const vec_float4 v1 = vec_splat(v.val, 1); + const vec_float4 v2 = vec_splat(v.val, 2); + VSX_UNUSED(const vec_float4) v3 = vec_splat(v.val, 3); + return v_float32x4(vec_madd(v0, m0.val, vec_madd(v1, m1.val, vec_madd(v2, m2.val, vec_mul(v3, m3.val))))); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + const vec_float4 v0 = vec_splat(v.val, 0); + const vec_float4 v1 = vec_splat(v.val, 1); + const vec_float4 v2 = vec_splat(v.val, 2); + return v_float32x4(vec_madd(v0, m0.val, vec_madd(v1, m1.val, vec_madd(v2, m2.val, a.val)))); +} + +#define OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(_Tpvec, _Tpvec2) \ +inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \ + const _Tpvec& a2, const _Tpvec& a3, \ + _Tpvec& b0, _Tpvec& b1, _Tpvec& b2, _Tpvec& b3) \ +{ \ + _Tpvec2 a02 = vec_mergeh(a0.val, a2.val); \ + _Tpvec2 a13 = vec_mergeh(a1.val, a3.val); \ + b0.val = vec_mergeh(a02, a13); \ + b1.val = vec_mergel(a02, a13); \ + a02 = vec_mergel(a0.val, a2.val); \ + a13 = vec_mergel(a1.val, a3.val); \ + b2.val = vec_mergeh(a02, a13); \ + b3.val = vec_mergel(a02, a13); \ +} +OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(v_uint32x4, vec_uint4) +OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(v_int32x4, vec_int4) +OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(v_float32x4, vec_float4) + +//! @name Check SIMD support +//! @{ +//! @brief Check CPU capability of SIMD operation +static inline bool hasSIMD128() +{ + return (CV_CPU_HAS_SUPPORT_VSX) ? true : false; +} + +//! @} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} + +#endif // OPENCV_HAL_VSX_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/ippasync.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/ippasync.hpp similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/ippasync.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/ippasync.hpp index 4de8611d..0ed8264e 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/ippasync.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/ippasync.hpp @@ -42,8 +42,8 @@ // //M*/ -#ifndef __OPENCV_CORE_IPPASYNC_HPP__ -#define __OPENCV_CORE_IPPASYNC_HPP__ +#ifndef OPENCV_CORE_IPPASYNC_HPP +#define OPENCV_CORE_IPPASYNC_HPP #ifdef HAVE_IPP_A diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/mat.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/mat.hpp similarity index 91% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/mat.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/mat.hpp index ffec5386..65408d5e 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/mat.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/mat.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_CORE_MAT_HPP__ -#define __OPENCV_CORE_MAT_HPP__ +#ifndef OPENCV_CORE_MAT_HPP +#define OPENCV_CORE_MAT_HPP #ifndef __cplusplus # error mat.hpp header must be compiled as C++ @@ -53,6 +53,10 @@ #include "opencv2/core/bufferpool.hpp" +#ifdef CV_CXX11 +#include +#endif + namespace cv { @@ -62,6 +66,8 @@ namespace cv enum { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25, ACCESS_RW=3<<24, ACCESS_MASK=ACCESS_RW, ACCESS_FAST=1<<26 }; +CV__DEBUG_NS_BEGIN + class CV_EXPORTS _OutputArray; //////////////////////// Input/Output Array Arguments ///////////////////////////////// @@ -73,8 +79,8 @@ It is defined as: typedef const _InputArray& InputArray; @endcode where _InputArray is a class that can be constructed from `Mat`, `Mat_`, `Matx`, -`std::vector`, `std::vector >` or `std::vector`. It can also be constructed -from a matrix expression. +`std::vector`, `std::vector >`, `std::vector`, `std::vector >`, +`UMat`, `std::vector` or `double`. It can also be constructed from a matrix expression. Since this is mostly implementation-level class, and its interface may change in future versions, we do not describe it in details. There are a few key things, though, that should be kept in mind: @@ -165,7 +171,9 @@ public: UMAT =10 << KIND_SHIFT, STD_VECTOR_UMAT =11 << KIND_SHIFT, STD_BOOL_VECTOR =12 << KIND_SHIFT, - STD_VECTOR_CUDA_GPU_MAT = 13 << KIND_SHIFT + STD_VECTOR_CUDA_GPU_MAT = 13 << KIND_SHIFT, + STD_ARRAY =14 << KIND_SHIFT, + STD_ARRAY_MAT =15 << KIND_SHIFT }; _InputArray(); @@ -177,6 +185,7 @@ public: template _InputArray(const std::vector<_Tp>& vec); _InputArray(const std::vector& vec); template _InputArray(const std::vector >& vec); + _InputArray(const std::vector >&); template _InputArray(const std::vector >& vec); template _InputArray(const _Tp* vec, int n); template _InputArray(const Matx<_Tp, m, n>& matx); @@ -189,6 +198,11 @@ public: _InputArray(const UMat& um); _InputArray(const std::vector& umv); +#ifdef CV_CXX_STD_ARRAY + template _InputArray(const std::array<_Tp, _Nm>& arr); + template _InputArray(const std::array& arr); +#endif + Mat getMat(int idx=-1) const; Mat getMat_(int idx=-1) const; UMat getUMat(int idx=-1) const; @@ -293,6 +307,7 @@ public: template _OutputArray(std::vector<_Tp>& vec); _OutputArray(std::vector& vec); template _OutputArray(std::vector >& vec); + _OutputArray(std::vector >&); template _OutputArray(std::vector >& vec); template _OutputArray(Mat_<_Tp>& m); template _OutputArray(_Tp* vec, int n); @@ -316,6 +331,13 @@ public: _OutputArray(const UMat& m); _OutputArray(const std::vector& vec); +#ifdef CV_CXX_STD_ARRAY + template _OutputArray(std::array<_Tp, _Nm>& arr); + template _OutputArray(const std::array<_Tp, _Nm>& arr); + template _OutputArray(std::array& arr); + template _OutputArray(const std::array& arr); +#endif + bool fixedSize() const; bool fixedType() const; bool needed() const; @@ -335,6 +357,9 @@ public: void assign(const UMat& u) const; void assign(const Mat& m) const; + + void assign(const std::vector& v) const; + void assign(const std::vector& v) const; }; @@ -374,8 +399,18 @@ public: template _InputOutputArray(const Matx<_Tp, m, n>& matx); _InputOutputArray(const UMat& m); _InputOutputArray(const std::vector& vec); + +#ifdef CV_CXX_STD_ARRAY + template _InputOutputArray(std::array<_Tp, _Nm>& arr); + template _InputOutputArray(const std::array<_Tp, _Nm>& arr); + template _InputOutputArray(std::array& arr); + template _InputOutputArray(const std::array& arr); +#endif + }; +CV__DEBUG_NS_END + typedef const _InputArray& InputArray; typedef InputArray InputArrayOfArrays; typedef const _OutputArray& OutputArray; @@ -473,7 +508,9 @@ struct CV_EXPORTS UMatData { enum { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2, DEVICE_COPY_OBSOLETE=4, TEMP_UMAT=8, TEMP_COPIED_UMAT=24, - USER_ALLOCATED=32, DEVICE_MEM_MAPPED=64}; + USER_ALLOCATED=32, DEVICE_MEM_MAPPED=64, + ASYNC_CLEANUP=128 + }; UMatData(const MatAllocator* allocator); ~UMatData(); @@ -548,7 +585,7 @@ protected: An example demonstrating the serial out capabilities of cv::Mat */ - /** @brief n-dimensional dense array class + /** @brief n-dimensional dense array class \anchor CVMat_Details The class Mat represents an n-dimensional dense numerical single-channel or multi-channel array. It can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel @@ -660,7 +697,7 @@ sub-matrices. - Use MATLAB-style array initializers, zeros(), ones(), eye(), for example: @code - // create a double-precision identity martix and add it to M. + // create a double-precision identity matrix and add it to M. M += Mat::eye(M.rows, M.cols, CV_64F); @endcode @@ -693,7 +730,7 @@ If you need to process a whole row of a 2D array, the most efficient way is to g the row first, and then just use the plain C operator [] : @code // compute sum of positive matrix elements - // (assuming that M isa double-precision matrix) + // (assuming that M is a double-precision matrix) double sum=0; for(int i = 0; i < M.rows; i++) { @@ -736,6 +773,8 @@ Finally, there are STL-style iterators that are smart enough to skip gaps betwee @endcode The matrix iterators are random-access iterators, so they can be passed to any STL algorithm, including std::sort(). + +@note Matrix Expressions and arithmetic see MatExpr */ class CV_EXPORTS Mat { @@ -794,6 +833,13 @@ public: */ Mat(int ndims, const int* sizes, int type); + /** @overload + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + */ + Mat(const std::vector& sizes, int type); + /** @overload @param ndims Array dimensionality. @param sizes Array of integers specifying an n-dimensional array shape. @@ -805,6 +851,17 @@ public: */ Mat(int ndims, const int* sizes, int type, const Scalar& s); + /** @overload + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param s An optional value to initialize each matrix element with. To set all the matrix elements to + the particular value after the construction, use the assignment operator + Mat::operator=(const Scalar& value) . + */ + Mat(const std::vector& sizes, int type, const Scalar& s); + + /** @overload @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its sub-array is constructed and @@ -861,6 +918,20 @@ public: */ Mat(int ndims, const int* sizes, int type, void* data, const size_t* steps=0); + /** @overload + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always + set to the element size). If not specified, the matrix is assumed to be continuous. + */ + Mat(const std::vector& sizes, int type, void* data, const size_t* steps=0); + /** @overload @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its sub-array is constructed and @@ -893,6 +964,16 @@ public: */ Mat(const Mat& m, const Range* ranges); + /** @overload + @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied + by these constructors. Instead, the header pointing to m data or its sub-array is constructed and + associated with it. The reference counter, if any, is incremented. So, when you modify the matrix + formed using such a constructor, you also modify the corresponding elements of m . If you want to + have an independent copy of the sub-array, use Mat::clone() . + @param ranges Array of selected ranges of m along each dimensionality. + */ + Mat(const Mat& m, const std::vector& ranges); + /** @overload @param vec STL vector whose elements form the matrix. The matrix has a single column and the number of rows equal to the number of vector elements. Type of the matrix matches the type of vector @@ -911,6 +992,19 @@ public: */ template explicit Mat(const std::vector<_Tp>& vec, bool copyData=false); +#ifdef CV_CXX11 + /** @overload + */ + template::value>::type> + explicit Mat(const std::initializer_list<_Tp> list); +#endif + +#ifdef CV_CXX_STD_ARRAY + /** @overload + */ + template explicit Mat(const std::array<_Tp, _Nm>& arr, bool copyData=false); +#endif + /** @overload */ template explicit Mat(const Vec<_Tp, n>& vec, bool copyData=true); @@ -1037,18 +1131,40 @@ public: single-column matrix. Similarly to Mat::row and Mat::col, this is an O(1) operation. @param d index of the diagonal, with the following values: - `d=0` is the main diagonal. - - `d>0` is a diagonal from the lower half. For example, d=1 means the diagonal is set + - `d<0` is a diagonal from the lower half. For example, d=-1 means the diagonal is set immediately below the main one. - - `d<0` is a diagonal from the upper half. For example, d=-1 means the diagonal is set + - `d>0` is a diagonal from the upper half. For example, d=1 means the diagonal is set immediately above the main one. + For example: + @code + Mat m = (Mat_(3,3) << + 1,2,3, + 4,5,6, + 7,8,9); + Mat d0 = m.diag(0); + Mat d1 = m.diag(1); + Mat d_1 = m.diag(-1); + @endcode + The resulting matrices are + @code + d0 = + [1; + 5; + 9] + d1 = + [2; + 6] + d_1 = + [4; + 8] + @endcode */ Mat diag(int d=0) const; /** @brief creates a diagonal matrix - The method makes a new header for the specified matrix diagonal. The new matrix is represented as a - single-column matrix. Similarly to Mat::row and Mat::col, this is an O(1) operation. - @param d Single-column matrix that forms a diagonal matrix + The method creates a square diagonal matrix from specified main diagonal. + @param d One-dimensional matrix that represents the main diagonal. */ static Mat diag(const Mat& d); @@ -1079,8 +1195,8 @@ public: /** @overload @param m Destination matrix. If it does not have a proper size or type before the operation, it is reallocated. - @param mask Operation mask. Its non-zero elements indicate which matrix elements need to be copied. - The mask has to be of type CV_8U and can have 1 or multiple channels. + @param mask Operation mask of the same size as \*this. Its non-zero elements indicate which matrix + elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels. */ void copyTo( OutputArray m, InputArray mask ) const; @@ -1116,7 +1232,8 @@ public: This is an advanced variant of the Mat::operator=(const Scalar& s) operator. @param value Assigned scalar converted to the actual array type. - @param mask Operation mask of the same size as \*this. + @param mask Operation mask of the same size as \*this. Its non-zero elements indicate which matrix + elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels */ Mat& setTo(InputArray value, InputArray mask=noArray()); @@ -1149,6 +1266,9 @@ public: /** @overload */ Mat reshape(int cn, int newndims, const int* newsz) const; + /** @overload */ + Mat reshape(int cn, const std::vector& newshape) const; + /** @brief Transposes a matrix. The method performs matrix transposition by means of matrix expressions. It does not perform the @@ -1329,6 +1449,12 @@ public: */ void create(int ndims, const int* sizes, int type); + /** @overload + @param sizes Array of integers specifying a new array shape. + @param type New matrix type. + */ + void create(const std::vector& sizes, int type); + /** @brief Increments the reference counter. The method increments the reference counter associated with the matrix data. If the matrix header @@ -1355,7 +1481,7 @@ public: */ void release(); - //! deallocates the matrix data + //! internal use function, consider to use 'release' method instead; deallocates the matrix data void deallocate(); //! internal use function; properly re-allocates _size, _step arrays void copySize(const Mat& m); @@ -1369,6 +1495,14 @@ public: */ void reserve(size_t sz); + /** @brief Reserves space for the certain number of bytes. + + The method reserves space for sz bytes. If the matrix already has enough space to store sz bytes, + nothing happens. If matrix has to be reallocated its previous content could be lost. + @param sz Number of bytes. + */ + void reserveBuffer(size_t sz); + /** @brief Changes the number of matrix rows. The methods change the number of matrix rows. If the matrix is reallocated, the first @@ -1401,6 +1535,11 @@ public: */ template void push_back(const Mat_<_Tp>& elem); + /** @overload + @param elem Added element(s). + */ + template void push_back(const std::vector<_Tp>& elem); + /** @overload @param m Added line(s). */ @@ -1479,6 +1618,11 @@ public: */ Mat operator()( const Range* ranges ) const; + /** @overload + @param ranges Array of selected ranges along each array dimension. + */ + Mat operator()(const std::vector& ranges) const; + // //! converts header to CvMat; no data is copied // operator CvMat() const; // //! converts header to CvMatND; no data is copied @@ -1490,6 +1634,10 @@ public: template operator Vec<_Tp, n>() const; template operator Matx<_Tp, m, n>() const; +#ifdef CV_CXX_STD_ARRAY + template operator std::array<_Tp, _Nm>() const; +#endif + /** @brief Reports whether the matrix is continuous or not. The method returns true if the matrix elements are stored continuously without gaps at the end of @@ -1522,7 +1670,7 @@ public: inv_scale = 1.f/alpha_scale; CV_Assert( src1.type() == src2.type() && - src1.type() == CV_MAKETYPE(DataType::depth, 4) && + src1.type() == CV_MAKETYPE(traits::Depth::value, 4) && src1.size() == src2.size()); Size size = src1.size(); dst.create(size, src1.type()); @@ -1632,6 +1780,12 @@ public: */ size_t total() const; + /** @brief Returns the total number of array elements. + + The method returns the number of elements within a certain sub-array slice with startDim <= dim < endDim + */ + size_t total(int startDim, int endDim=INT_MAX) const; + //! returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const; @@ -1645,10 +1799,16 @@ public: /** @overload */ const uchar* ptr(int i0=0) const; - /** @overload */ - uchar* ptr(int i0, int i1); - /** @overload */ - const uchar* ptr(int i0, int i1) const; + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + uchar* ptr(int row, int col); + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + const uchar* ptr(int row, int col) const; /** @overload */ uchar* ptr(int i0, int i1, int i2); @@ -1668,10 +1828,16 @@ public: template _Tp* ptr(int i0=0); /** @overload */ template const _Tp* ptr(int i0=0) const; - /** @overload */ - template _Tp* ptr(int i0, int i1); - /** @overload */ - template const _Tp* ptr(int i0, int i1) const; + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + template _Tp* ptr(int row, int col); + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + template const _Tp* ptr(int row, int col) const; /** @overload */ template _Tp* ptr(int i0, int i1, int i2); /** @overload */ @@ -1702,6 +1868,17 @@ public: for(int j = 0; j < H.cols; j++) H.at(i,j)=1./(i+j+1); @endcode + + Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends + on the image from which you are trying to retrieve the data. The table below gives a better insight in this: + - If matrix is of type `CV_8U` then use `Mat.at(y,x)`. + - If matrix is of type `CV_8S` then use `Mat.at(y,x)`. + - If matrix is of type `CV_16U` then use `Mat.at(y,x)`. + - If matrix is of type `CV_16S` then use `Mat.at(y,x)`. + - If matrix is of type `CV_32S` then use `Mat.at(y,x)`. + - If matrix is of type `CV_32F` then use `Mat.at(y,x)`. + - If matrix is of type `CV_64F` then use `Mat.at(y,x)`. + @param i0 Index along the dimension 0 */ template _Tp& at(int i0=0); @@ -1710,15 +1887,15 @@ public: */ template const _Tp& at(int i0=0) const; /** @overload - @param i0 Index along the dimension 0 - @param i1 Index along the dimension 1 + @param row Index along the dimension 0 + @param col Index along the dimension 1 */ - template _Tp& at(int i0, int i1); + template _Tp& at(int row, int col); /** @overload - @param i0 Index along the dimension 0 - @param i1 Index along the dimension 1 + @param row Index along the dimension 0 + @param col Index along the dimension 1 */ - template const _Tp& at(int i0, int i1) const; + template const _Tp& at(int row, int col) const; /** @overload @param i0 Index along the dimension 0 @@ -1773,7 +1950,7 @@ public: inv_scale = 1.f/alpha_scale; CV_Assert( src1.type() == src2.type() && - src1.type() == DataType::type && + src1.type() == traits::Type::value && src1.size() == src2.size()); Size size = src1.size(); dst.create(size, src1.type()); @@ -1805,19 +1982,18 @@ public: template MatIterator_<_Tp> end(); template MatConstIterator_<_Tp> end() const; - /** @brief Invoke with arguments functor, and runs the functor over all matrix element. + /** @brief Runs the given functor over all matrix elements in parallel. - The methods runs operation in parallel. Operation is passed by arguments. Operation have to be a - function pointer, a function object or a lambda(C++11). + The operation passed as argument has to be a function pointer, a function object or a lambda(C++11). - All of below operation is equal. Put 0xFF to first channel of all matrix elements: + Example 1. All of the operations below put 0xFF the first channel of all matrix elements: @code Mat image(1920, 1080, CV_8UC3); typedef cv::Point3_ Pixel; // first. raw pointer access. for (int r = 0; r < image.rows; ++r) { - Pixel* ptr = image.ptr(0, r); + Pixel* ptr = image.ptr(r, 0); const Pixel* ptr_end = ptr + image.cols; for (; ptr != ptr_end; ++ptr) { ptr->x = 255; @@ -1842,18 +2018,18 @@ public: p.x = 255; }); @endcode - position parameter is index of current pixel: + Example 2. Using the pixel's position: @code - // Creating 3D matrix (255 x 255 x 255) typed uint8_t, - // and initialize all elements by the value which equals elements position. - // i.e. pixels (x,y,z) = (1,2,3) is (b,g,r) = (1,2,3). + // Creating 3D matrix (255 x 255 x 255) typed uint8_t + // and initialize all elements by the value which equals elements position. + // i.e. pixels (x,y,z) = (1,2,3) is (b,g,r) = (1,2,3). int sizes[] = { 255, 255, 255 }; typedef cv::Point3_ Pixel; Mat_ image = Mat::zeros(3, sizes, CV_8UC3); - image.forEachWithPosition([&](Pixel& pixel, const int position[]) -> void{ + image.forEach([&](Pixel& pixel, const int position[]) -> void { pixel.x = position[0]; pixel.y = position[1]; pixel.z = position[2]; @@ -1913,7 +2089,7 @@ protected: /** @brief Template matrix class derived from Mat -@code +@code{.cpp} template class Mat_ : public Mat { public: @@ -1925,7 +2101,7 @@ protected: The class `Mat_<_Tp>` is a *thin* template wrapper on top of the Mat class. It does not have any extra data fields. Nor this class nor Mat has any virtual methods. Thus, references or pointers to these two classes can be freely but carefully converted one to another. For example: -@code +@code{.cpp} // create a 100x100 8-bit matrix Mat M(100,100,CV_8U); // this will be compiled fine. no any data conversion will be done. @@ -1937,7 +2113,7 @@ While Mat is sufficient in most cases, Mat_ can be more convenient if you use a access operations and if you know matrix type at the compilation time. Note that `Mat::at(int y,int x)` and `Mat_::operator()(int y,int x)` do absolutely the same and run at the same speed, but the latter is certainly shorter: -@code +@code{.cpp} Mat_ M(20,20); for(int i = 0; i < M.rows; i++) for(int j = 0; j < M.cols; j++) @@ -1947,7 +2123,7 @@ and run at the same speed, but the latter is certainly shorter: cout << E.at(0,0)/E.at(M.rows-1,0); @endcode To use Mat_ for multi-channel images/matrices, pass Vec as a Mat_ parameter: -@code +@code{.cpp} // allocate a 320x240 color image and fill it with green (in RGB space) Mat_ img(240, 320, Vec3b(0,255,0)); // now draw a diagonal white line @@ -1957,6 +2133,17 @@ To use Mat_ for multi-channel images/matrices, pass Vec as a Mat_ parameter: for(int i = 0; i < img.rows; i++) for(int j = 0; j < img.cols; j++) img(i,j)[2] ^= (uchar)(i ^ j); +@endcode +Mat_ is fully compatible with C++11 range-based for loop. For example such loop +can be used to safely apply look-up table: +@code{.cpp} +void applyTable(Mat_& I, const uchar* const table) +{ + for(auto& pixel : I) + { + pixel = table[pixel]; + } +} @endcode */ template class Mat_ : public Mat @@ -1995,6 +2182,8 @@ public: Mat_(const Mat_& m, const Rect& roi); //! selects a submatrix, n-dim version Mat_(const Mat_& m, const Range* ranges); + //! selects a submatrix, n-dim version + Mat_(const Mat_& m, const std::vector& ranges); //! from a matrix expression explicit Mat_(const MatExpr& e); //! makes a matrix out of Vec, std::vector, Point_ or Point3_. The matrix will have a single column @@ -2005,6 +2194,14 @@ public: explicit Mat_(const Point3_::channel_type>& pt, bool copyData=true); explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer); +#ifdef CV_CXX11 + Mat_(std::initializer_list<_Tp> values); +#endif + +#ifdef CV_CXX_STD_ARRAY + template explicit Mat_(const std::array<_Tp, _Nm>& arr, bool copyData=false); +#endif + Mat_& operator = (const Mat& m); Mat_& operator = (const Mat_& m); //! set all the elements to s. @@ -2029,6 +2226,8 @@ public: void create(Size _size); //! equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type) void create(int _ndims, const int* _sizes); + //! equivalent to Mat::release() + void release(); //! cross-product Mat_ cross(const Mat_& m) const; //! data type conversion @@ -2064,6 +2263,7 @@ public: Mat_ operator()( const Range& rowRange, const Range& colRange ) const; Mat_ operator()( const Rect& roi ) const; Mat_ operator()( const Range* ranges ) const; + Mat_ operator()(const std::vector& ranges) const; //! more convenient forms of row and element access operators _Tp* operator [](int y); @@ -2084,9 +2284,9 @@ public: //! returns read-only reference to the specified element (1D case) const _Tp& operator ()(int idx0) const; //! returns reference to the specified element (2D case) - _Tp& operator ()(int idx0, int idx1); + _Tp& operator ()(int row, int col); //! returns read-only reference to the specified element (2D case) - const _Tp& operator ()(int idx0, int idx1) const; + const _Tp& operator ()(int row, int col) const; //! returns reference to the specified element (3D case) _Tp& operator ()(int idx0, int idx1, int idx2); //! returns read-only reference to the specified element (3D case) @@ -2097,6 +2297,12 @@ public: //! conversion to vector. operator std::vector<_Tp>() const; + +#ifdef CV_CXX_STD_ARRAY + //! conversion to array. + template operator std::array<_Tp, _Nm>() const; +#endif + //! conversion to Vec template operator Vec::channel_type, n>() const; //! conversion to Matx @@ -2168,8 +2374,10 @@ public: UMat(const UMat& m, const Range& rowRange, const Range& colRange=Range::all()); UMat(const UMat& m, const Rect& roi); UMat(const UMat& m, const Range* ranges); + UMat(const UMat& m, const std::vector& ranges); //! builds matrix from std::vector with or without copying the data template explicit UMat(const std::vector<_Tp>& vec, bool copyData=false); + //! builds matrix from cv::Vec; the data is copied by default template explicit UMat(const Vec<_Tp, n>& vec, bool copyData=true); //! builds matrix from cv::Matx; the data is copied by default @@ -2199,9 +2407,9 @@ public: UMat colRange(int startcol, int endcol) const; UMat colRange(const Range& r) const; //! ... for the specified diagonal - // (d=0 - the main diagonal, - // >0 - a diagonal from the lower half, - // <0 - a diagonal from the upper half) + //! (d=0 - the main diagonal, + //! >0 - a diagonal from the upper half, + //! <0 - a diagonal from the lower half) UMat diag(int d=0) const; //! constructs a square diagonal matrix which main diagonal is vector "d" static UMat diag(const UMat& d); @@ -2213,7 +2421,7 @@ public: void copyTo( OutputArray m ) const; //! copies those matrix elements to "m" that are marked with non-zero mask elements. void copyTo( OutputArray m, InputArray mask ) const; - //! converts matrix to another datatype with optional scalng. See cvConvertScale. + //! converts matrix to another datatype with optional scaling. See cvConvertScale. void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const; void assignTo( UMat& m, int type=-1 ) const; @@ -2252,6 +2460,7 @@ public: void create(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); void create(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); void create(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + void create(const std::vector& sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); //! increases the reference counter; use with care to avoid memleaks void addref(); @@ -2273,6 +2482,7 @@ public: UMat operator()( Range rowRange, Range colRange ) const; UMat operator()( const Rect& roi ) const; UMat operator()( const Range* ranges ) const; + UMat operator()(const std::vector& ranges) const; //! returns true iff the matrix data is continuous // (i.e. when there are no gaps between successive rows). @@ -2308,6 +2518,10 @@ public: UMat& operator = (UMat&& m); #endif + /*! Returns the OpenCL buffer handle on which UMat operates on. + The UMat instance should be kept alive during the use of the handle to prevent the buffer to be + returned to the OpenCV buffer pool. + */ void* handle(int accessFlags) const; void ndoffset(size_t* ofs) const; @@ -2359,15 +2573,16 @@ Elements can be accessed using the following methods: SparseMat::find), for example: @code const int dims = 5; - int size[] = {10, 10, 10, 10, 10}; + int size[5] = {10, 10, 10, 10, 10}; SparseMat sparse_mat(dims, size, CV_32F); for(int i = 0; i < 1000; i++) { int idx[dims]; for(int k = 0; k < dims; k++) - idx[k] = rand() + idx[k] = rand() % size[k]; sparse_mat.ref(idx) += 1.f; } + cout << "nnz = " << sparse_mat.nzcount() << endl; @endcode - Sparse matrix iterators. They are similar to MatIterator but different from NAryMatIterator. That is, the iteration loop is familiar to STL users: @@ -2504,11 +2719,11 @@ public: /*! @param [out] m - output matrix; if it does not have a proper size or type before the operation, it is reallocated - @param [in] rtype – desired output matrix type or, rather, the depth since the number of channels + @param [in] rtype - desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input. - @param [in] alpha – optional scale factor - @param [in] beta – optional delta added to the scaled values + @param [in] alpha - optional scale factor + @param [in] beta - optional delta added to the scaled values */ void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const; @@ -2782,9 +2997,7 @@ public: typedef const uchar** pointer; typedef uchar* reference; -#ifndef OPENCV_NOSTL typedef std::random_access_iterator_tag iterator_category; -#endif //! default constructor MatConstIterator(); @@ -2849,9 +3062,7 @@ public: typedef const _Tp* pointer; typedef const _Tp& reference; -#ifndef OPENCV_NOSTL typedef std::random_access_iterator_tag iterator_category; -#endif //! default constructor MatConstIterator_(); @@ -2869,9 +3080,9 @@ public: //! copy operator MatConstIterator_& operator = (const MatConstIterator_& it); //! returns the current matrix element - _Tp operator *() const; + const _Tp& operator *() const; //! returns the i-th matrix element, relative to the current - _Tp operator [](ptrdiff_t i) const; + const _Tp& operator [](ptrdiff_t i) const; //! shifts the iterator forward by the specified number of elements MatConstIterator_& operator += (ptrdiff_t ofs); @@ -2902,9 +3113,7 @@ public: typedef _Tp* pointer; typedef _Tp& reference; -#ifndef OPENCV_NOSTL typedef std::random_access_iterator_tag iterator_category; -#endif //! the default constructor MatIterator_(); @@ -3038,9 +3247,7 @@ template class SparseMatConstIterator_ : public SparseMatConstIter { public: -#ifndef OPENCV_NOSTL typedef std::forward_iterator_tag iterator_category; -#endif //! the default constructor SparseMatConstIterator_(); @@ -3074,9 +3281,7 @@ template class SparseMatIterator_ : public SparseMatConstIterator_ { public: -#ifndef OPENCV_NOSTL typedef std::forward_iterator_tag iterator_category; -#endif //! the default constructor SparseMatIterator_(); @@ -3135,21 +3340,29 @@ The example below illustrates how you can compute a normalized and threshold 3D } minProb *= image.rows*image.cols; - Mat plane; - NAryMatIterator it(&hist, &plane, 1); + + // initialize iterator (the style is different from STL). + // after initialization the iterator will contain + // the number of slices or planes the iterator will go through. + // it simultaneously increments iterators for several matrices + // supplied as a null terminated list of pointers + const Mat* arrays[] = {&hist, 0}; + Mat planes[1]; + NAryMatIterator itNAry(arrays, planes, 1); double s = 0; // iterate through the matrix. on each iteration - // it.planes[*] (of type Mat) will be set to the current plane. - for(int p = 0; p < it.nplanes; p++, ++it) + // itNAry.planes[i] (of type Mat) will be set to the current plane + // of the i-th n-dim matrix passed to the iterator constructor. + for(int p = 0; p < itNAry.nplanes; p++, ++itNAry) { - threshold(it.planes[0], it.planes[0], minProb, 0, THRESH_TOZERO); - s += sum(it.planes[0])[0]; + threshold(itNAry.planes[0], itNAry.planes[0], minProb, 0, THRESH_TOZERO); + s += sum(itNAry.planes[0])[0]; } s = 1./s; - it = NAryMatIterator(&hist, &plane, 1); - for(int p = 0; p < it.nplanes; p++, ++it) - it.planes[0] *= s; + itNAry = NAryMatIterator(arrays, planes, 1); + for(int p = 0; p < itNAry.nplanes; p++, ++itNAry) + itNAry.planes[0] *= s; } @endcode */ @@ -3428,4 +3641,4 @@ CV_EXPORTS MatExpr abs(const MatExpr& e); #include "opencv2/core/mat.inl.hpp" -#endif // __OPENCV_CORE_MAT_HPP__ +#endif // OPENCV_CORE_MAT_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/mat.inl.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/mat.inl.hpp similarity index 83% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/mat.inl.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/mat.inl.hpp index 54103401..dbd9584a 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/mat.inl.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/mat.inl.hpp @@ -42,15 +42,22 @@ // //M*/ -#ifndef __OPENCV_CORE_MATRIX_OPERATIONS_HPP__ -#define __OPENCV_CORE_MATRIX_OPERATIONS_HPP__ +#ifndef OPENCV_CORE_MATRIX_OPERATIONS_HPP +#define OPENCV_CORE_MATRIX_OPERATIONS_HPP #ifndef __cplusplus # error mat.inl.hpp header must be compiled as C++ #endif +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4127 ) +#endif + namespace cv { +CV__DEBUG_NS_BEGIN + //! @cond IGNORED @@ -75,31 +82,45 @@ inline _InputArray::_InputArray(const std::vector& vec) { init(STD_VECTOR_ template inline _InputArray::_InputArray(const std::vector<_Tp>& vec) -{ init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_READ, &vec); } +{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); } + +#ifdef CV_CXX_STD_ARRAY +template inline +_InputArray::_InputArray(const std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); } + +template inline +_InputArray::_InputArray(const std::array& arr) +{ init(STD_ARRAY_MAT + ACCESS_READ, arr.data(), Size(1, _Nm)); } +#endif inline _InputArray::_InputArray(const std::vector& vec) -{ init(FIXED_TYPE + STD_BOOL_VECTOR + DataType::type + ACCESS_READ, &vec); } +{ init(FIXED_TYPE + STD_BOOL_VECTOR + traits::Type::value + ACCESS_READ, &vec); } template inline _InputArray::_InputArray(const std::vector >& vec) -{ init(FIXED_TYPE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_READ, &vec); } +{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); } + +inline +_InputArray::_InputArray(const std::vector >&) +{ CV_Error(Error::StsUnsupportedFormat, "std::vector > is not supported!\n"); } template inline _InputArray::_InputArray(const std::vector >& vec) -{ init(FIXED_TYPE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_READ, &vec); } +{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_READ, &vec); } template inline _InputArray::_InputArray(const Matx<_Tp, m, n>& mtx) -{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_READ, &mtx, Size(n, m)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, &mtx, Size(n, m)); } template inline _InputArray::_InputArray(const _Tp* vec, int n) -{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_READ, vec, Size(n, 1)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, vec, Size(n, 1)); } template inline _InputArray::_InputArray(const Mat_<_Tp>& m) -{ init(FIXED_TYPE + MAT + DataType<_Tp>::type + ACCESS_READ, &m); } +{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_READ, &m); } inline _InputArray::_InputArray(const double& val) { init(FIXED_TYPE + FIXED_SIZE + MATX + CV_64F + ACCESS_READ, &val, Size(1,1)); } @@ -133,7 +154,9 @@ inline bool _InputArray::isUMat() const { return kind() == _InputArray::UMAT; } inline bool _InputArray::isMatVector() const { return kind() == _InputArray::STD_VECTOR_MAT; } inline bool _InputArray::isUMatVector() const { return kind() == _InputArray::STD_VECTOR_UMAT; } inline bool _InputArray::isMatx() const { return kind() == _InputArray::MATX; } -inline bool _InputArray::isVector() const { return kind() == _InputArray::STD_VECTOR || kind() == _InputArray::STD_BOOL_VECTOR; } +inline bool _InputArray::isVector() const { return kind() == _InputArray::STD_VECTOR || + kind() == _InputArray::STD_BOOL_VECTOR || + kind() == _InputArray::STD_ARRAY; } inline bool _InputArray::isGpuMatVector() const { return kind() == _InputArray::STD_VECTOR_CUDA_GPU_MAT; } //////////////////////////////////////////////////////////////////////////////////////// @@ -147,7 +170,17 @@ inline _OutputArray::_OutputArray(std::vector& vec) { init(STD_VECTOR_UMAT template inline _OutputArray::_OutputArray(std::vector<_Tp>& vec) -{ init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); } +{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +#ifdef CV_CXX_STD_ARRAY +template inline +_OutputArray::_OutputArray(std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } + +template inline +_OutputArray::_OutputArray(std::array& arr) +{ init(STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } +#endif inline _OutputArray::_OutputArray(std::vector&) @@ -155,47 +188,61 @@ _OutputArray::_OutputArray(std::vector&) template inline _OutputArray::_OutputArray(std::vector >& vec) -{ init(FIXED_TYPE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); } +{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +inline +_OutputArray::_OutputArray(std::vector >&) +{ CV_Error(Error::StsUnsupportedFormat, "std::vector > cannot be an output array\n"); } template inline _OutputArray::_OutputArray(std::vector >& vec) -{ init(FIXED_TYPE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_WRITE, &vec); } +{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } template inline _OutputArray::_OutputArray(Mat_<_Tp>& m) -{ init(FIXED_TYPE + MAT + DataType<_Tp>::type + ACCESS_WRITE, &m); } +{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); } template inline _OutputArray::_OutputArray(Matx<_Tp, m, n>& mtx) -{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, &mtx, Size(n, m)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); } template inline _OutputArray::_OutputArray(_Tp* vec, int n) -{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, vec, Size(n, 1)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); } template inline _OutputArray::_OutputArray(const std::vector<_Tp>& vec) -{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); } +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +#ifdef CV_CXX_STD_ARRAY +template inline +_OutputArray::_OutputArray(const std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } + +template inline +_OutputArray::_OutputArray(const std::array& arr) +{ init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } +#endif template inline _OutputArray::_OutputArray(const std::vector >& vec) -{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); } +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } template inline _OutputArray::_OutputArray(const std::vector >& vec) -{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_WRITE, &vec); } +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } template inline _OutputArray::_OutputArray(const Mat_<_Tp>& m) -{ init(FIXED_TYPE + FIXED_SIZE + MAT + DataType<_Tp>::type + ACCESS_WRITE, &m); } +{ init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); } template inline _OutputArray::_OutputArray(const Matx<_Tp, m, n>& mtx) -{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, &mtx, Size(n, m)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); } template inline _OutputArray::_OutputArray(const _Tp* vec, int n) -{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, vec, Size(n, 1)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); } inline _OutputArray::_OutputArray(cuda::GpuMat& d_mat) { init(CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); } @@ -242,54 +289,74 @@ inline _InputOutputArray::_InputOutputArray(std::vector& vec) { init(STD_V template inline _InputOutputArray::_InputOutputArray(std::vector<_Tp>& vec) -{ init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); } +{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +#ifdef CV_CXX_STD_ARRAY +template inline +_InputOutputArray::_InputOutputArray(std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } + +template inline +_InputOutputArray::_InputOutputArray(std::array& arr) +{ init(STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); } +#endif inline _InputOutputArray::_InputOutputArray(std::vector&) { CV_Error(Error::StsUnsupportedFormat, "std::vector cannot be an input/output array\n"); } template inline _InputOutputArray::_InputOutputArray(std::vector >& vec) -{ init(FIXED_TYPE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); } +{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } template inline _InputOutputArray::_InputOutputArray(std::vector >& vec) -{ init(FIXED_TYPE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_RW, &vec); } +{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); } template inline _InputOutputArray::_InputOutputArray(Mat_<_Tp>& m) -{ init(FIXED_TYPE + MAT + DataType<_Tp>::type + ACCESS_RW, &m); } +{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); } template inline _InputOutputArray::_InputOutputArray(Matx<_Tp, m, n>& mtx) -{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, &mtx, Size(n, m)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); } template inline _InputOutputArray::_InputOutputArray(_Tp* vec, int n) -{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, vec, Size(n, 1)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); } template inline _InputOutputArray::_InputOutputArray(const std::vector<_Tp>& vec) -{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); } +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +#ifdef CV_CXX_STD_ARRAY +template inline +_InputOutputArray::_InputOutputArray(const std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } + +template inline +_InputOutputArray::_InputOutputArray(const std::array& arr) +{ init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); } +#endif template inline _InputOutputArray::_InputOutputArray(const std::vector >& vec) -{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); } +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } template inline _InputOutputArray::_InputOutputArray(const std::vector >& vec) -{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_RW, &vec); } +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); } template inline _InputOutputArray::_InputOutputArray(const Mat_<_Tp>& m) -{ init(FIXED_TYPE + FIXED_SIZE + MAT + DataType<_Tp>::type + ACCESS_RW, &m); } +{ init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); } template inline _InputOutputArray::_InputOutputArray(const Matx<_Tp, m, n>& mtx) -{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, &mtx, Size(n, m)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); } template inline _InputOutputArray::_InputOutputArray(const _Tp* vec, int n) -{ init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, vec, Size(n, 1)); } +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); } inline _InputOutputArray::_InputOutputArray(cuda::GpuMat& d_mat) { init(CUDA_GPU_MAT + ACCESS_RW, &d_mat); } @@ -314,8 +381,12 @@ inline _InputOutputArray::_InputOutputArray(const std::vector& vec) inline _InputOutputArray::_InputOutputArray(const cuda::GpuMat& d_mat) { init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_RW, &d_mat); } + inline _InputOutputArray::_InputOutputArray(const std::vector& d_mat) -{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);} +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);} + +template<> inline _InputOutputArray::_InputOutputArray(std::vector& d_mat) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);} inline _InputOutputArray::_InputOutputArray(const ogl::Buffer& buf) { init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_RW, &buf); } @@ -323,18 +394,20 @@ inline _InputOutputArray::_InputOutputArray(const ogl::Buffer& buf) inline _InputOutputArray::_InputOutputArray(const cuda::HostMem& cuda_mem) { init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); } +CV__DEBUG_NS_END + //////////////////////////////////////////// Mat ////////////////////////////////////////// inline Mat::Mat() : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0), size(&rows), step(0) {} inline Mat::Mat(int _rows, int _cols, int _type) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0), size(&rows), step(0) { create(_rows, _cols, _type); } @@ -342,7 +415,7 @@ Mat::Mat(int _rows, int _cols, int _type) inline Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0), size(&rows), step(0) { create(_rows, _cols, _type); *this = _s; @@ -351,7 +424,7 @@ Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s) inline Mat::Mat(Size _sz, int _type) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0), size(&rows), step(0) { create( _sz.height, _sz.width, _type ); } @@ -359,7 +432,7 @@ Mat::Mat(Size _sz, int _type) inline Mat::Mat(Size _sz, int _type, const Scalar& _s) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0), size(&rows), step(0) { create(_sz.height, _sz.width, _type); *this = _s; @@ -368,7 +441,7 @@ Mat::Mat(Size _sz, int _type, const Scalar& _s) inline Mat::Mat(int _dims, const int* _sz, int _type) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0), size(&rows), step(0) { create(_dims, _sz, _type); } @@ -376,17 +449,34 @@ Mat::Mat(int _dims, const int* _sz, int _type) inline Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0), size(&rows), step(0) { create(_dims, _sz, _type); *this = _s; } +inline +Mat::Mat(const std::vector& _sz, int _type) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_sz, _type); +} + +inline +Mat::Mat(const std::vector& _sz, int _type, const Scalar& _s) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_sz, _type); + *this = _s; +} + inline Mat::Mat(const Mat& m) : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator), - u(m.u), size(&rows) + u(m.u), size(&rows), step(0) { if( u ) CV_XADD(&u->refcount, 1); @@ -418,7 +508,6 @@ Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step) } else { - if( rows == 1 ) _step = minstep; CV_DbgAssert( _step >= minstep ); if (_step % esz1 != 0) @@ -426,7 +515,8 @@ Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step) CV_Error(Error::BadStep, "Step must be a multiple of esz1"); } - flags |= _step == minstep ? CONTINUOUS_FLAG : 0; + if (_step == minstep || rows == 1) + flags |= CONTINUOUS_FLAG; } step[0] = _step; step[1] = esz; @@ -451,7 +541,6 @@ Mat::Mat(Size _sz, int _type, void* _data, size_t _step) } else { - if( rows == 1 ) _step = minstep; CV_DbgAssert( _step >= minstep ); if (_step % esz1 != 0) @@ -459,7 +548,8 @@ Mat::Mat(Size _sz, int _type, void* _data, size_t _step) CV_Error(Error::BadStep, "Step must be a multiple of esz1"); } - flags |= _step == minstep ? CONTINUOUS_FLAG : 0; + if (_step == minstep || rows == 1) + flags |= CONTINUOUS_FLAG; } step[0] = _step; step[1] = esz; @@ -469,8 +559,8 @@ Mat::Mat(Size _sz, int _type, void* _data, size_t _step) template inline Mat::Mat(const std::vector<_Tp>& vec, bool copyData) - : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), - cols(1), data(0), datastart(0), dataend(0), allocator(0), u(0), size(&rows) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), + cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if(vec.empty()) return; @@ -481,13 +571,44 @@ Mat::Mat(const std::vector<_Tp>& vec, bool copyData) datalimit = dataend = datastart + rows * step[0]; } else - Mat((int)vec.size(), 1, DataType<_Tp>::type, (uchar*)&vec[0]).copyTo(*this); + Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this); } +#ifdef CV_CXX11 +template inline +Mat::Mat(const std::initializer_list<_Tp> list) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)list.size()), + cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if(list.size() == 0) + return; + Mat((int)list.size(), 1, traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this); +} +#endif + +#ifdef CV_CXX_STD_ARRAY +template inline +Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)arr.size()), + cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if(arr.empty()) + return; + if( !copyData ) + { + step[0] = step[1] = sizeof(_Tp); + datastart = data = (uchar*)arr.data(); + datalimit = dataend = datastart + rows * step[0]; + } + else + Mat((int)arr.size(), 1, traits::Type<_Tp>::value, (uchar*)arr.data()).copyTo(*this); +} +#endif + template inline Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) - : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0), - datastart(0), dataend(0), allocator(0), u(0), size(&rows) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if( !copyData ) { @@ -496,14 +617,14 @@ Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) datalimit = dataend = datastart + rows * step[0]; } else - Mat(n, 1, DataType<_Tp>::type, (void*)vec.val).copyTo(*this); + Mat(n, 1, traits::Type<_Tp>::value, (void*)vec.val).copyTo(*this); } template inline Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData) - : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0), - datastart(0), dataend(0), allocator(0), u(0), size(&rows) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if( !copyData ) { @@ -513,13 +634,13 @@ Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData) datalimit = dataend = datastart + rows * step[0]; } else - Mat(m, n, DataType<_Tp>::type, (uchar*)M.val).copyTo(*this); + Mat(m, n, traits::Type<_Tp>::value, (uchar*)M.val).copyTo(*this); } template inline Mat::Mat(const Point_<_Tp>& pt, bool copyData) - : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0), - datastart(0), dataend(0), allocator(0), u(0), size(&rows) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if( !copyData ) { @@ -529,7 +650,7 @@ Mat::Mat(const Point_<_Tp>& pt, bool copyData) } else { - create(2, 1, DataType<_Tp>::type); + create(2, 1, traits::Type<_Tp>::value); ((_Tp*)data)[0] = pt.x; ((_Tp*)data)[1] = pt.y; } @@ -537,8 +658,8 @@ Mat::Mat(const Point_<_Tp>& pt, bool copyData) template inline Mat::Mat(const Point3_<_Tp>& pt, bool copyData) - : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0), - datastart(0), dataend(0), allocator(0), u(0), size(&rows) + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if( !copyData ) { @@ -548,7 +669,7 @@ Mat::Mat(const Point3_<_Tp>& pt, bool copyData) } else { - create(3, 1, DataType<_Tp>::type); + create(3, 1, traits::Type<_Tp>::value); ((_Tp*)data)[0] = pt.x; ((_Tp*)data)[1] = pt.y; ((_Tp*)data)[2] = pt.z; @@ -557,7 +678,7 @@ Mat::Mat(const Point3_<_Tp>& pt, bool copyData) template inline Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer) - : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0), + : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), allocator(0), u(0), size(&rows) { *this = commaInitializer.operator Mat_<_Tp>(); @@ -676,7 +797,8 @@ void Mat::addref() CV_XADD(&u->refcount, 1); } -inline void Mat::release() +inline +void Mat::release() { if( u && CV_XADD(&u->refcount, -1) == 1 ) deallocate(); @@ -684,6 +806,16 @@ inline void Mat::release() datastart = dataend = datalimit = data = 0; for(int i = 0; i < dims; i++) size.p[i] = 0; +#ifdef _DEBUG + flags = MAGIC_VAL; + dims = rows = cols = 0; + if(step.p != step.buf) + { + fastFree(step.p); + step.p = step.buf; + size.p = &rows; + } +#endif } inline @@ -704,6 +836,12 @@ Mat Mat::operator()(const Range* ranges) const return Mat(*this, ranges); } +inline +Mat Mat::operator()(const std::vector& ranges) const +{ + return Mat(*this, ranges); +} + inline bool Mat::isContinuous() const { @@ -755,7 +893,7 @@ size_t Mat::step1(int i) const inline bool Mat::empty() const { - return data == 0 || total() == 0; + return data == 0 || total() == 0 || dims == 0; } inline @@ -769,6 +907,17 @@ size_t Mat::total() const return p; } +inline +size_t Mat::total(int startDim, int endDim) const +{ + CV_Assert( 0 <= startDim && startDim <= endDim); + size_t p = 1; + int endDim_ = endDim <= dims ? endDim : dims; + for( int i = startDim; i < endDim_; i++ ) + p *= size[i]; + return p; +} + inline uchar* Mat::ptr(int y) { @@ -909,6 +1058,34 @@ const uchar* Mat::ptr(const int* idx) const return p; } +template inline +_Tp* Mat::ptr(const int* idx) +{ + int i, d = dims; + uchar* p = data; + CV_DbgAssert( d >= 1 && p ); + for( i = 0; i < d; i++ ) + { + CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); + p += idx[i] * step.p[i]; + } + return (_Tp*)p; +} + +template inline +const _Tp* Mat::ptr(const int* idx) const +{ + int i, d = dims; + uchar* p = data; + CV_DbgAssert( d >= 1 && p ); + for( i = 0; i < d; i++ ) + { + CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); + p += idx[i] * step.p[i]; + } + return (const _Tp*)p; +} + template inline _Tp& Mat::at(int i0, int i1) { @@ -916,7 +1093,7 @@ _Tp& Mat::at(int i0, int i1) CV_DbgAssert(data); CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); - CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1()); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); return ((_Tp*)(data + step.p[0] * i0))[i1]; } @@ -927,7 +1104,7 @@ const _Tp& Mat::at(int i0, int i1) const CV_DbgAssert(data); CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); - CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1()); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); return ((const _Tp*)(data + step.p[0] * i0))[i1]; } @@ -938,7 +1115,7 @@ _Tp& Mat::at(Point pt) CV_DbgAssert(data); CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); - CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1()); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); return ((_Tp*)(data + step.p[0] * pt.y))[pt.x]; } @@ -949,7 +1126,7 @@ const _Tp& Mat::at(Point pt) const CV_DbgAssert(data); CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); - CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1()); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x]; } @@ -959,7 +1136,7 @@ _Tp& Mat::at(int i0) CV_DbgAssert(dims <= 2); CV_DbgAssert(data); CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1])); - CV_DbgAssert(elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type)); + CV_DbgAssert(elemSize() == sizeof(_Tp)); if( isContinuous() || size.p[0] == 1 ) return ((_Tp*)data)[i0]; if( size.p[1] == 1 ) @@ -974,7 +1151,7 @@ const _Tp& Mat::at(int i0) const CV_DbgAssert(dims <= 2); CV_DbgAssert(data); CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1])); - CV_DbgAssert(elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type)); + CV_DbgAssert(elemSize() == sizeof(_Tp)); if( isContinuous() || size.p[0] == 1 ) return ((const _Tp*)data)[i0]; if( size.p[1] == 1 ) @@ -986,42 +1163,42 @@ const _Tp& Mat::at(int i0) const template inline _Tp& Mat::at(int i0, int i1, int i2) { - CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); + CV_DbgAssert( elemSize() == sizeof(_Tp) ); return *(_Tp*)ptr(i0, i1, i2); } template inline const _Tp& Mat::at(int i0, int i1, int i2) const { - CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); + CV_DbgAssert( elemSize() == sizeof(_Tp) ); return *(const _Tp*)ptr(i0, i1, i2); } template inline _Tp& Mat::at(const int* idx) { - CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); + CV_DbgAssert( elemSize() == sizeof(_Tp) ); return *(_Tp*)ptr(idx); } template inline const _Tp& Mat::at(const int* idx) const { - CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); + CV_DbgAssert( elemSize() == sizeof(_Tp) ); return *(const _Tp*)ptr(idx); } template inline _Tp& Mat::at(const Vec& idx) { - CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); + CV_DbgAssert( elemSize() == sizeof(_Tp) ); return *(_Tp*)ptr(idx.val); } template inline const _Tp& Mat::at(const Vec& idx) const { - CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); + CV_DbgAssert( elemSize() == sizeof(_Tp) ); return *(const _Tp*)ptr(idx.val); } @@ -1065,7 +1242,7 @@ void Mat::forEach(const Functor& operation) { template inline void Mat::forEach(const Functor& operation) const { // call as not const - (const_cast(this))->forEach(operation); + (const_cast(this))->forEach<_Tp>(operation); } template inline @@ -1076,16 +1253,26 @@ Mat::operator std::vector<_Tp>() const return v; } +#ifdef CV_CXX_STD_ARRAY +template inline +Mat::operator std::array<_Tp, _Nm>() const +{ + std::array<_Tp, _Nm> v; + copyTo(v); + return v; +} +#endif + template inline Mat::operator Vec<_Tp, n>() const { CV_Assert( data && dims <= 2 && (rows == 1 || cols == 1) && rows + cols - 1 == n && channels() == 1 ); - if( isContinuous() && type() == DataType<_Tp>::type ) + if( isContinuous() && type() == traits::Type<_Tp>::value ) return Vec<_Tp, n>((_Tp*)data); Vec<_Tp, n> v; - Mat tmp(rows, cols, DataType<_Tp>::type, v.val); + Mat tmp(rows, cols, traits::Type<_Tp>::value, v.val); convertTo(tmp, tmp.type()); return v; } @@ -1095,10 +1282,10 @@ Mat::operator Matx<_Tp, m, n>() const { CV_Assert( data && dims <= 2 && rows == m && cols == n && channels() == 1 ); - if( isContinuous() && type() == DataType<_Tp>::type ) + if( isContinuous() && type() == traits::Type<_Tp>::value ) return Matx<_Tp, m, n>((_Tp*)data); Matx<_Tp, m, n> mtx; - Mat tmp(rows, cols, DataType<_Tp>::type, mtx.val); + Mat tmp(rows, cols, traits::Type<_Tp>::value, mtx.val); convertTo(tmp, tmp.type()); return mtx; } @@ -1108,10 +1295,10 @@ void Mat::push_back(const _Tp& elem) { if( !data ) { - *this = Mat(1, 1, DataType<_Tp>::type, (void*)&elem).clone(); + *this = Mat(1, 1, traits::Type<_Tp>::value, (void*)&elem).clone(); return; } - CV_Assert(DataType<_Tp>::type == type() && cols == 1 + CV_Assert(traits::Type<_Tp>::value == type() && cols == 1 /* && dims == 2 (cols == 1 implies dims == 2) */); const uchar* tmp = dataend + step[0]; if( !isSubmatrix() && isContinuous() && tmp <= datalimit ) @@ -1135,6 +1322,13 @@ void Mat::push_back(const MatExpr& expr) push_back(static_cast(expr)); } + +template inline +void Mat::push_back(const std::vector<_Tp>& v) +{ + push_back(Mat(v)); +} + #ifdef CV_CXX_MOVE_SEMANTICS inline @@ -1165,6 +1359,9 @@ Mat::Mat(Mat&& m) inline Mat& Mat::operator = (Mat&& m) { + if (this == &m) + return *this; + release(); flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; data = m.data; datastart = m.datastart; dataend = m.dataend; datalimit = m.datalimit; allocator = m.allocator; @@ -1300,42 +1497,47 @@ template inline Mat_<_Tp>::Mat_() : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; + flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; } template inline Mat_<_Tp>::Mat_(int _rows, int _cols) - : Mat(_rows, _cols, DataType<_Tp>::type) + : Mat(_rows, _cols, traits::Type<_Tp>::value) { } template inline Mat_<_Tp>::Mat_(int _rows, int _cols, const _Tp& value) - : Mat(_rows, _cols, DataType<_Tp>::type) + : Mat(_rows, _cols, traits::Type<_Tp>::value) { *this = value; } template inline Mat_<_Tp>::Mat_(Size _sz) - : Mat(_sz.height, _sz.width, DataType<_Tp>::type) + : Mat(_sz.height, _sz.width, traits::Type<_Tp>::value) {} template inline Mat_<_Tp>::Mat_(Size _sz, const _Tp& value) - : Mat(_sz.height, _sz.width, DataType<_Tp>::type) + : Mat(_sz.height, _sz.width, traits::Type<_Tp>::value) { *this = value; } template inline Mat_<_Tp>::Mat_(int _dims, const int* _sz) - : Mat(_dims, _sz, DataType<_Tp>::type) + : Mat(_dims, _sz, traits::Type<_Tp>::value) {} template inline Mat_<_Tp>::Mat_(int _dims, const int* _sz, const _Tp& _s) - : Mat(_dims, _sz, DataType<_Tp>::type, Scalar(_s)) + : Mat(_dims, _sz, traits::Type<_Tp>::value, Scalar(_s)) +{} + +template inline +Mat_<_Tp>::Mat_(int _dims, const int* _sz, _Tp* _data, const size_t* _steps) + : Mat(_dims, _sz, traits::Type<_Tp>::value, _data, _steps) {} template inline @@ -1343,11 +1545,16 @@ Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const Range* ranges) : Mat(m, ranges) {} +template inline +Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const std::vector& ranges) + : Mat(m, ranges) +{} + template inline Mat_<_Tp>::Mat_(const Mat& m) : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; + flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; *this = m; } @@ -1358,7 +1565,7 @@ Mat_<_Tp>::Mat_(const Mat_& m) template inline Mat_<_Tp>::Mat_(int _rows, int _cols, _Tp* _data, size_t steps) - : Mat(_rows, _cols, DataType<_Tp>::type, _data, steps) + : Mat(_rows, _cols, traits::Type<_Tp>::value, _data, steps) {} template inline @@ -1373,7 +1580,7 @@ Mat_<_Tp>::Mat_(const Mat_& m, const Rect& roi) template template inline Mat_<_Tp>::Mat_(const Vec::channel_type, n>& vec, bool copyData) - : Mat(n / DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&vec) + : Mat(n / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&vec) { CV_Assert(n%DataType<_Tp>::channels == 0); if( copyData ) @@ -1382,7 +1589,7 @@ Mat_<_Tp>::Mat_(const Vec::channel_type, n>& vec, bool co template template inline Mat_<_Tp>::Mat_(const Matx::channel_type, m, n>& M, bool copyData) - : Mat(m, n / DataType<_Tp>::channels, DataType<_Tp>::type, (void*)&M) + : Mat(m, n / DataType<_Tp>::channels, traits::Type<_Tp>::value, (void*)&M) { CV_Assert(n % DataType<_Tp>::channels == 0); if( copyData ) @@ -1391,7 +1598,7 @@ Mat_<_Tp>::Mat_(const Matx::channel_type, m, n>& M, bool template inline Mat_<_Tp>::Mat_(const Point_::channel_type>& pt, bool copyData) - : Mat(2 / DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&pt) + : Mat(2 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt) { CV_Assert(2 % DataType<_Tp>::channels == 0); if( copyData ) @@ -1400,7 +1607,7 @@ Mat_<_Tp>::Mat_(const Point_::channel_type>& pt, bool cop template inline Mat_<_Tp>::Mat_(const Point3_::channel_type>& pt, bool copyData) - : Mat(3 / DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&pt) + : Mat(3 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt) { CV_Assert(3 % DataType<_Tp>::channels == 0); if( copyData ) @@ -1417,15 +1624,29 @@ Mat_<_Tp>::Mat_(const std::vector<_Tp>& vec, bool copyData) : Mat(vec, copyData) {} +#ifdef CV_CXX11 +template inline +Mat_<_Tp>::Mat_(std::initializer_list<_Tp> list) + : Mat(list) +{} +#endif + +#ifdef CV_CXX_STD_ARRAY +template template inline +Mat_<_Tp>::Mat_(const std::array<_Tp, _Nm>& arr, bool copyData) + : Mat(arr, copyData) +{} +#endif + template inline Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m) { - if( DataType<_Tp>::type == m.type() ) + if( traits::Type<_Tp>::value == m.type() ) { Mat::operator = (m); return *this; } - if( DataType<_Tp>::depth == m.depth() ) + if( traits::Depth<_Tp>::value == m.depth() ) { return (*this = m.reshape(DataType<_Tp>::channels, m.dims, 0)); } @@ -1452,19 +1673,28 @@ Mat_<_Tp>& Mat_<_Tp>::operator = (const _Tp& s) template inline void Mat_<_Tp>::create(int _rows, int _cols) { - Mat::create(_rows, _cols, DataType<_Tp>::type); + Mat::create(_rows, _cols, traits::Type<_Tp>::value); } template inline void Mat_<_Tp>::create(Size _sz) { - Mat::create(_sz, DataType<_Tp>::type); + Mat::create(_sz, traits::Type<_Tp>::value); } template inline void Mat_<_Tp>::create(int _dims, const int* _sz) { - Mat::create(_dims, _sz, DataType<_Tp>::type); + Mat::create(_dims, _sz, traits::Type<_Tp>::value); +} + +template inline +void Mat_<_Tp>::release() +{ + Mat::release(); +#ifdef _DEBUG + flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; +#endif } template inline @@ -1520,15 +1750,15 @@ size_t Mat_<_Tp>::elemSize1() const template inline int Mat_<_Tp>::type() const { - CV_DbgAssert( Mat::type() == DataType<_Tp>::type ); - return DataType<_Tp>::type; + CV_DbgAssert( Mat::type() == traits::Type<_Tp>::value ); + return traits::Type<_Tp>::value; } template inline int Mat_<_Tp>::depth() const { - CV_DbgAssert( Mat::depth() == DataType<_Tp>::depth ); - return DataType<_Tp>::depth; + CV_DbgAssert( Mat::depth() == traits::Depth<_Tp>::value ); + return traits::Depth<_Tp>::value; } template inline @@ -1574,17 +1804,23 @@ Mat_<_Tp> Mat_<_Tp>::operator()( const Range* ranges ) const return Mat_<_Tp>(*this, ranges); } +template inline +Mat_<_Tp> Mat_<_Tp>::operator()(const std::vector& ranges) const +{ + return Mat_<_Tp>(*this, ranges); +} + template inline _Tp* Mat_<_Tp>::operator [](int y) { - CV_DbgAssert( 0 <= y && y < rows ); + CV_DbgAssert( 0 <= y && y < size.p[0] ); return (_Tp*)(data + y*step.p[0]); } template inline const _Tp* Mat_<_Tp>::operator [](int y) const { - CV_DbgAssert( 0 <= y && y < rows ); + CV_DbgAssert( 0 <= y && y < size.p[0] ); return (const _Tp*)(data + y*step.p[0]); } @@ -1595,7 +1831,7 @@ _Tp& Mat_<_Tp>::operator ()(int i0, int i1) CV_DbgAssert(data); CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); - CV_DbgAssert(type() == DataType<_Tp>::type); + CV_DbgAssert(type() == traits::Type<_Tp>::value); return ((_Tp*)(data + step.p[0] * i0))[i1]; } @@ -1606,7 +1842,7 @@ const _Tp& Mat_<_Tp>::operator ()(int i0, int i1) const CV_DbgAssert(data); CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); - CV_DbgAssert(type() == DataType<_Tp>::type); + CV_DbgAssert(type() == traits::Type<_Tp>::value); return ((const _Tp*)(data + step.p[0] * i0))[i1]; } @@ -1617,7 +1853,7 @@ _Tp& Mat_<_Tp>::operator ()(Point pt) CV_DbgAssert(data); CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]); - CV_DbgAssert(type() == DataType<_Tp>::type); + CV_DbgAssert(type() == traits::Type<_Tp>::value); return ((_Tp*)(data + step.p[0] * pt.y))[pt.x]; } @@ -1628,7 +1864,7 @@ const _Tp& Mat_<_Tp>::operator ()(Point pt) const CV_DbgAssert(data); CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]); - CV_DbgAssert(type() == DataType<_Tp>::type); + CV_DbgAssert(type() == traits::Type<_Tp>::value); return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x]; } @@ -1688,6 +1924,16 @@ Mat_<_Tp>::operator std::vector<_Tp>() const return v; } +#ifdef CV_CXX_STD_ARRAY +template template inline +Mat_<_Tp>::operator std::array<_Tp, _Nm>() const +{ + std::array<_Tp, _Nm> a; + copyTo(a); + return a; +} +#endif + template template inline Mat_<_Tp>::operator Vec::channel_type, n>() const { @@ -1761,7 +2007,7 @@ Mat_<_Tp>::Mat_(Mat_&& m) template inline Mat_<_Tp>& Mat_<_Tp>::operator = (Mat_&& m) { - Mat::operator = (m); + Mat::operator = (std::move(m)); return *this; } @@ -1769,19 +2015,19 @@ template inline Mat_<_Tp>::Mat_(Mat&& m) : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; + flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; *this = m; } template inline Mat_<_Tp>& Mat_<_Tp>::operator = (Mat&& m) { - if( DataType<_Tp>::type == m.type() ) + if( traits::Type<_Tp>::value == m.type() ) { Mat::operator = ((Mat&&)m); return *this; } - if( DataType<_Tp>::depth == m.depth() ) + if( traits::Depth<_Tp>::value == m.depth() ) { Mat::operator = ((Mat&&)m.reshape(DataType<_Tp>::channels, m.dims, 0)); return *this; @@ -1795,7 +2041,7 @@ template inline Mat_<_Tp>::Mat_(MatExpr&& e) : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; + flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; *this = Mat(e); } @@ -2132,21 +2378,21 @@ SparseMatConstIterator_<_Tp> SparseMat::end() const template inline SparseMat_<_Tp>::SparseMat_() { - flags = MAGIC_VAL | DataType<_Tp>::type; + flags = MAGIC_VAL | traits::Type<_Tp>::value; } template inline SparseMat_<_Tp>::SparseMat_(int _dims, const int* _sizes) - : SparseMat(_dims, _sizes, DataType<_Tp>::type) + : SparseMat(_dims, _sizes, traits::Type<_Tp>::value) {} template inline SparseMat_<_Tp>::SparseMat_(const SparseMat& m) { - if( m.type() == DataType<_Tp>::type ) + if( m.type() == traits::Type<_Tp>::value ) *this = (const SparseMat_<_Tp>&)m; else - m.convertTo(*this, DataType<_Tp>::type); + m.convertTo(*this, traits::Type<_Tp>::value); } template inline @@ -2181,9 +2427,9 @@ SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat_<_Tp>& m) template inline SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat& m) { - if( m.type() == DataType<_Tp>::type ) + if( m.type() == traits::Type<_Tp>::value ) return (*this = (const SparseMat_<_Tp>&)m); - m.convertTo(*this, DataType<_Tp>::type); + m.convertTo(*this, traits::Type<_Tp>::value); return *this; } @@ -2204,19 +2450,19 @@ SparseMat_<_Tp> SparseMat_<_Tp>::clone() const template inline void SparseMat_<_Tp>::create(int _dims, const int* _sizes) { - SparseMat::create(_dims, _sizes, DataType<_Tp>::type); + SparseMat::create(_dims, _sizes, traits::Type<_Tp>::value); } template inline int SparseMat_<_Tp>::type() const { - return DataType<_Tp>::type; + return traits::Type<_Tp>::value; } template inline int SparseMat_<_Tp>::depth() const { - return DataType<_Tp>::depth; + return traits::Depth<_Tp>::value; } template inline @@ -2469,7 +2715,7 @@ ptrdiff_t operator - (const MatConstIterator& b, const MatConstIterator& a) if( a.m != b.m ) return ((size_t)(-1) >> 1); if( a.sliceEnd == b.sliceEnd ) - return (b.ptr - a.ptr)/b.elemSize; + return (b.ptr - a.ptr)/static_cast(b.elemSize); return b.lpos() - a.lpos(); } @@ -2538,7 +2784,7 @@ MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator = (const MatConstIterat } template inline -_Tp MatConstIterator_<_Tp>::operator *() const +const _Tp& MatConstIterator_<_Tp>::operator *() const { return *(_Tp*)(this->ptr); } @@ -2644,7 +2890,7 @@ MatConstIterator_<_Tp> operator - (const MatConstIterator_<_Tp>& a, ptrdiff_t of } template inline -_Tp MatConstIterator_<_Tp>::operator [](ptrdiff_t i) const +const _Tp& MatConstIterator_<_Tp>::operator [](ptrdiff_t i) const { return *(_Tp*)MatConstIterator::operator [](i); } @@ -2917,7 +3163,7 @@ template inline SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat* _m) : SparseMatConstIterator(_m) { - CV_Assert( _m->type() == DataType<_Tp>::type ); + CV_Assert( _m->type() == traits::Type<_Tp>::value ); } template inline @@ -3053,50 +3299,50 @@ Mat& Mat::operator = (const MatExpr& e) template inline Mat_<_Tp>::Mat_(const MatExpr& e) { - e.op->assign(e, *this, DataType<_Tp>::type); + e.op->assign(e, *this, traits::Type<_Tp>::value); } template inline Mat_<_Tp>& Mat_<_Tp>::operator = (const MatExpr& e) { - e.op->assign(e, *this, DataType<_Tp>::type); + e.op->assign(e, *this, traits::Type<_Tp>::value); return *this; } template inline MatExpr Mat_<_Tp>::zeros(int rows, int cols) { - return Mat::zeros(rows, cols, DataType<_Tp>::type); + return Mat::zeros(rows, cols, traits::Type<_Tp>::value); } template inline MatExpr Mat_<_Tp>::zeros(Size sz) { - return Mat::zeros(sz, DataType<_Tp>::type); + return Mat::zeros(sz, traits::Type<_Tp>::value); } template inline MatExpr Mat_<_Tp>::ones(int rows, int cols) { - return Mat::ones(rows, cols, DataType<_Tp>::type); + return Mat::ones(rows, cols, traits::Type<_Tp>::value); } template inline MatExpr Mat_<_Tp>::ones(Size sz) { - return Mat::ones(sz, DataType<_Tp>::type); + return Mat::ones(sz, traits::Type<_Tp>::value); } template inline MatExpr Mat_<_Tp>::eye(int rows, int cols) { - return Mat::eye(rows, cols, DataType<_Tp>::type); + return Mat::eye(rows, cols, traits::Type<_Tp>::value); } template inline MatExpr Mat_<_Tp>::eye(Size sz) { - return Mat::eye(sz, DataType<_Tp>::type); + return Mat::eye(sz, traits::Type<_Tp>::value); } inline @@ -3122,7 +3368,7 @@ template inline MatExpr::operator Mat_<_Tp>() const { Mat_<_Tp> m; - op->assign(*this, m, DataType<_Tp>::type); + op->assign(*this, m, traits::Type<_Tp>::value); return m; } @@ -3355,7 +3601,7 @@ UMat::UMat(const UMat& m) template inline UMat::UMat(const std::vector<_Tp>& vec, bool copyData) -: flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), +: flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) { if(vec.empty()) @@ -3366,10 +3612,9 @@ cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) CV_Error(Error::StsNotImplemented, ""); } else - Mat((int)vec.size(), 1, DataType<_Tp>::type, (uchar*)&vec[0]).copyTo(*this); + Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this); } - inline UMat& UMat::operator = (const UMat& m) { @@ -3500,6 +3745,12 @@ UMat UMat::operator()(const Range* ranges) const return UMat(*this, ranges); } +inline +UMat UMat::operator()(const std::vector& ranges) const +{ + return UMat(*this, ranges); +} + inline bool UMat::isContinuous() const { @@ -3551,7 +3802,7 @@ size_t UMat::step1(int i) const inline bool UMat::empty() const { - return u == 0 || total() == 0; + return u == 0 || total() == 0 || dims == 0; } inline @@ -3594,6 +3845,8 @@ UMat::UMat(UMat&& m) inline UMat& UMat::operator = (UMat&& m) { + if (this == &m) + return *this; release(); flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; allocator = m.allocator; usageFlags = m.usageFlags; @@ -3665,4 +3918,8 @@ inline UMatDataAutoLock::~UMatDataAutoLock() { u->unlock(); } } //cv +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + #endif diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/matx.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/matx.hpp similarity index 93% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/matx.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/matx.hpp index ca5f2619..1d1ab4a4 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/matx.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/matx.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_CORE_MATX_HPP__ -#define __OPENCV_CORE_MATX_HPP__ +#ifndef OPENCV_CORE_MATX_HPP +#define OPENCV_CORE_MATX_HPP #ifndef __cplusplus # error matx.hpp header must be compiled as C++ @@ -53,6 +53,10 @@ #include "opencv2/core/traits.hpp" #include "opencv2/core/saturate.hpp" +#ifdef CV_CXX11 +#include +#endif + namespace cv { @@ -77,21 +81,33 @@ If you need a more flexible type, use Mat . The elements of the matrix M are acc M(i,j) notation. Most of the common matrix operations (see also @ref MatrixExpressions ) are available. To do an operation on Matx that is not implemented, you can easily convert the matrix to Mat and backwards: -@code +@code{.cpp} Matx33f m(1, 2, 3, 4, 5, 6, 7, 8, 9); cout << sum(Mat(m*m.t())) << endl; - @endcode +@endcode +Except of the plain constructor which takes a list of elements, Matx can be initialized from a C-array: +@code{.cpp} + float values[] = { 1, 2, 3}; + Matx31f m(values); +@endcode +In case if C++11 features are avaliable, std::initializer_list can be also used to initizlize Matx: +@code{.cpp} + Matx31f m = { 1, 2, 3}; +@endcode */ template class Matx { public: - enum { depth = DataType<_Tp>::depth, + enum { rows = m, cols = n, channels = rows*cols, +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + depth = traits::Type<_Tp>::value, type = CV_MAKETYPE(depth, channels), +#endif shortdim = (m < n ? m : n) }; @@ -125,6 +141,10 @@ public: _Tp v12, _Tp v13, _Tp v14, _Tp v15); //!< 1x16, 4x4 or 16x1 matrix explicit Matx(const _Tp* vals); //!< initialize from a plain array +#ifdef CV_CXX11 + Matx(std::initializer_list<_Tp>); //!< initialize from an initializer list +#endif + static Matx all(_Tp alpha); static Matx zeros(); static Matx ones(); @@ -242,13 +262,23 @@ public: typedef value_type vec_type; enum { generic_type = 0, - depth = DataType::depth, channels = m * n, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; }; +namespace traits { +template +struct Depth< Matx<_Tp, m, n> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Matx<_Tp, m, n> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, n*m) }; }; +} // namespace + + /** @brief Comma-separated Matrix Initializer */ template class MatxCommaInitializer @@ -306,9 +336,13 @@ template class Vec : public Matx<_Tp, cn, 1> { public: typedef _Tp value_type; - enum { depth = Matx<_Tp, cn, 1>::depth, + enum { channels = cn, - type = CV_MAKETYPE(depth, channels) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + depth = Matx<_Tp, cn, 1>::depth, + type = CV_MAKETYPE(depth, channels), +#endif + _dummy_enum_finalizer = 0 }; //! default constructor @@ -327,6 +361,10 @@ public: Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13); //!< 14-element vector constructor explicit Vec(const _Tp* values); +#ifdef CV_CXX11 + Vec(std::initializer_list<_Tp>); +#endif + Vec(const Vec<_Tp, cn>& v); static Vec all(_Tp alpha); @@ -401,13 +439,24 @@ public: typedef value_type vec_type; enum { generic_type = 0, - depth = DataType::depth, channels = cn, fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + depth = DataType::depth, + type = CV_MAKETYPE(depth, channels), +#endif + _dummy_enum_finalizer = 0 }; }; +namespace traits { +template +struct Depth< Vec<_Tp, cn> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Vec<_Tp, cn> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, cn) }; }; +} // namespace + + /** @brief Comma-separated Vec Initializer */ template class VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1> @@ -438,7 +487,7 @@ template struct Matx_DetOp return p; for( int i = 0; i < m; i++ ) p *= temp(i, i); - return 1./p; + return p; } }; @@ -590,11 +639,12 @@ Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp template inline Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13) { - CV_StaticAssert(channels == 14, "Matx should have at least 14 elements."); + CV_StaticAssert(channels >= 14, "Matx should have at least 14 elements."); val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11; val[12] = v12; val[13] = v13; + for (int i = 14; i < channels; i++) val[i] = _Tp(0); } @@ -615,6 +665,19 @@ Matx<_Tp, m, n>::Matx(const _Tp* values) for( int i = 0; i < channels; i++ ) val[i] = values[i]; } +#ifdef CV_CXX11 +template inline +Matx<_Tp, m, n>::Matx(std::initializer_list<_Tp> list) +{ + CV_DbgAssert(list.size() == channels); + int i = 0; + for(const auto& elem : list) + { + val[i++] = elem; + } +} +#endif + template inline Matx<_Tp, m, n> Matx<_Tp, m, n>::all(_Tp alpha) { @@ -956,6 +1019,12 @@ template inline Vec<_Tp, cn>::Vec(const _Tp* values) : Matx<_Tp, cn, 1>(values) {} +#ifdef CV_CXX11 +template inline +Vec<_Tp, cn>::Vec(std::initializer_list<_Tp> list) + : Matx<_Tp, cn, 1>(list) {} +#endif + template inline Vec<_Tp, cn>::Vec(const Vec<_Tp, cn>& m) : Matx<_Tp, cn, 1>(m.val) {} @@ -1022,17 +1091,17 @@ Vec<_Tp, cn> Vec<_Tp, cn>::cross(const Vec<_Tp, cn>&) const template<> inline Vec Vec::cross(const Vec& v) const { - return Vec(val[1]*v.val[2] - val[2]*v.val[1], - val[2]*v.val[0] - val[0]*v.val[2], - val[0]*v.val[1] - val[1]*v.val[0]); + return Vec(this->val[1]*v.val[2] - this->val[2]*v.val[1], + this->val[2]*v.val[0] - this->val[0]*v.val[2], + this->val[0]*v.val[1] - this->val[1]*v.val[0]); } template<> inline Vec Vec::cross(const Vec& v) const { - return Vec(val[1]*v.val[2] - val[2]*v.val[1], - val[2]*v.val[0] - val[0]*v.val[2], - val[0]*v.val[1] - val[1]*v.val[0]); + return Vec(this->val[1]*v.val[2] - this->val[2]*v.val[1], + this->val[2]*v.val[0] - this->val[0]*v.val[2], + this->val[0]*v.val[1] - this->val[1]*v.val[0]); } template template inline @@ -1080,7 +1149,7 @@ Vec<_Tp, cn> normalize(const Vec<_Tp, cn>& v) -//////////////////////////////// matx comma initializer ////////////////////////////////// +//////////////////////////////// vec comma initializer ////////////////////////////////// template static inline @@ -1404,4 +1473,4 @@ template inline Vec<_Tp, 4>& operator *= (Vec<_Tp, 4>& v1, const V } // cv -#endif // __OPENCV_CORE_MATX_HPP__ +#endif // OPENCV_CORE_MATX_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/neon_utils.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/neon_utils.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/neon_utils.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/neon_utils.hpp index adb750fd..573ba99e 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/neon_utils.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/neon_utils.hpp @@ -39,8 +39,8 @@ // //M*/ -#ifndef __OPENCV_HAL_NEON_UTILS_HPP__ -#define __OPENCV_HAL_NEON_UTILS_HPP__ +#ifndef OPENCV_HAL_NEON_UTILS_HPP +#define OPENCV_HAL_NEON_UTILS_HPP #include "opencv2/core/cvdef.h" @@ -125,4 +125,4 @@ inline float32x2_t cv_vsqrt_f32(float32x2_t val) //! @} -#endif // __OPENCV_HAL_NEON_UTILS_HPP__ +#endif // OPENCV_HAL_NEON_UTILS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/ocl.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/ocl.hpp similarity index 74% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/ocl.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/ocl.hpp index bc989a32..888477e1 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/ocl.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/ocl.hpp @@ -39,8 +39,8 @@ // //M*/ -#ifndef __OPENCV_OPENCL_HPP__ -#define __OPENCV_OPENCL_HPP__ +#ifndef OPENCV_OPENCL_HPP +#define OPENCV_OPENCL_HPP #include "opencv2/core.hpp" @@ -91,6 +91,7 @@ public: String name() const; String extensions() const; + bool isExtensionSupported(const String& extensionName) const; String version() const; String vendorName() const; String OpenCL_C_Version() const; @@ -160,6 +161,9 @@ public: uint imagePitchAlignment() const; uint imageBaseAddressAlignment() const; + /// deprecated, use isExtensionSupported() method (probably with "cl_khr_subgroups" value) + bool intelSubgroupsSupport() const; + size_t image2DMaxWidth() const; size_t image2DMaxHeight() const; @@ -246,6 +250,7 @@ public: const Device& device(size_t idx) const; Program getProg(const ProgramSource& prog, const String& buildopt, String& errmsg); + void unloadProg(Program& prog); static Context& getDefault(bool initialize = true); void* ptr() const; @@ -256,6 +261,8 @@ public: void setUseSVM(bool enabled); struct Impl; + inline Impl* getImpl() const { return (Impl*)p; } +//protected: Impl* p; }; @@ -276,55 +283,38 @@ protected: Impl* p; }; -/* -//! @brief Attaches OpenCL context to OpenCV -// -//! @note Note: -// OpenCV will check if available OpenCL platform has platformName name, -// then assign context to OpenCV and call clRetainContext function. -// The deviceID device will be used as target device and new command queue -// will be created. -// -// Params: -//! @param platformName - name of OpenCL platform to attach, -//! this string is used to check if platform is available -//! to OpenCV at runtime -//! @param platfromID - ID of platform attached context was created for -//! @param context - OpenCL context to be attached to OpenCV -//! @param deviceID - ID of device, must be created from attached context +/** @brief Attaches OpenCL context to OpenCV +@note + OpenCV will check if available OpenCL platform has platformName name, then assign context to + OpenCV and call `clRetainContext` function. The deviceID device will be used as target device and + new command queue will be created. +@param platformName name of OpenCL platform to attach, this string is used to check if platform is available to OpenCV at runtime +@param platformID ID of platform attached context was created for +@param context OpenCL context to be attached to OpenCV +@param deviceID ID of device, must be created from attached context */ CV_EXPORTS void attachContext(const String& platformName, void* platformID, void* context, void* deviceID); -/* -//! @brief Convert OpenCL buffer to UMat -// -//! @note Note: -// OpenCL buffer (cl_mem_buffer) should contain 2D image data, compatible with OpenCV. -// Memory content is not copied from clBuffer to UMat. Instead, buffer handle assigned -// to UMat and clRetainMemObject is called. -// -// Params: -//! @param cl_mem_buffer - source clBuffer handle -//! @param step - num of bytes in single row -//! @param rows - number of rows -//! @param cols - number of cols -//! @param type - OpenCV type of image -//! @param dst - destination UMat +/** @brief Convert OpenCL buffer to UMat +@note + OpenCL buffer (cl_mem_buffer) should contain 2D image data, compatible with OpenCV. Memory + content is not copied from `clBuffer` to UMat. Instead, buffer handle assigned to UMat and + `clRetainMemObject` is called. +@param cl_mem_buffer source clBuffer handle +@param step num of bytes in single row +@param rows number of rows +@param cols number of cols +@param type OpenCV type of image +@param dst destination UMat */ CV_EXPORTS void convertFromBuffer(void* cl_mem_buffer, size_t step, int rows, int cols, int type, UMat& dst); -/* -//! @brief Convert OpenCL image2d_t to UMat -// -//! @note Note: -// OpenCL image2d_t (cl_mem_image), should be compatible with OpenCV -// UMat formats. -// Memory content is copied from image to UMat with -// clEnqueueCopyImageToBuffer function. -// -// Params: -//! @param cl_mem_image - source image2d_t handle -//! @param dst - destination UMat +/** @brief Convert OpenCL image2d_t to UMat +@note + OpenCL `image2d_t` (cl_mem_image), should be compatible with OpenCV UMat formats. Memory content + is copied from image to UMat with `clEnqueueCopyImageToBuffer` function. +@param cl_mem_image source image2d_t handle +@param dst destination UMat */ CV_EXPORTS void convertFromImage(void* cl_mem_image, UMat& dst); @@ -345,8 +335,12 @@ public: void* ptr() const; static Queue& getDefault(); + /// @brief Returns OpenCL command queue with enable profiling mode support + const Queue& getProfilingQueue() const; + + struct Impl; friend struct Impl; + inline Impl* getImpl() const { return p; } protected: - struct Impl; Impl* p; }; @@ -567,11 +561,26 @@ public: i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11); i = set(i, a12); i = set(i, a13); i = set(i, a14); set(i, a15); return *this; } - + /** @brief Run the OpenCL kernel. + @param dims the work problem dimensions. It is the length of globalsize and localsize. It can be either 1, 2 or 3. + @param globalsize work items for each dimension. It is not the final globalsize passed to + OpenCL. Each dimension will be adjusted to the nearest integer divisible by the corresponding + value in localsize. If localsize is NULL, it will still be adjusted depending on dims. The + adjusted values are greater than or equal to the original values. + @param localsize work-group size for each dimension. + @param sync specify whether to wait for OpenCL computation to finish before return. + @param q command queue + */ bool run(int dims, size_t globalsize[], size_t localsize[], bool sync, const Queue& q=Queue()); bool runTask(bool sync, const Queue& q=Queue()); + /** @brief Similar to synchronized run() call with returning of kernel execution time + * Separate OpenCL command queue may be used (with CL_QUEUE_PROFILING_ENABLE) + * @return Execution time in nanoseconds or negative number on error + */ + int64 runProfiling(int dims, size_t globalsize[], size_t localsize[], const Queue& q=Queue()); + size_t workGroupSize() const; size_t preferedWorkGroupSizeMultiple() const; bool compileWorkGroupSize(size_t wsz[]) const; @@ -590,7 +599,6 @@ public: Program(); Program(const ProgramSource& src, const String& buildflags, String& errmsg); - explicit Program(const String& buf); Program(const Program& prog); Program& operator = (const Program& prog); @@ -598,38 +606,104 @@ public: bool create(const ProgramSource& src, const String& buildflags, String& errmsg); - bool read(const String& buf, const String& buildflags); - bool write(String& buf) const; - const ProgramSource& source() const; void* ptr() const; - String getPrefix() const; - static String getPrefix(const String& buildflags); + /** + * @brief Query device-specific program binary. + * + * Returns RAW OpenCL executable binary without additional attachments. + * + * @sa ProgramSource::fromBinary + * + * @param[out] binary output buffer + */ + void getBinary(std::vector& binary) const; + struct Impl; friend struct Impl; + inline Impl* getImpl() const { return (Impl*)p; } protected: - struct Impl; Impl* p; +public: +#ifndef OPENCV_REMOVE_DEPRECATED_API + // TODO Remove this + CV_DEPRECATED bool read(const String& buf, const String& buildflags); // removed, use ProgramSource instead + CV_DEPRECATED bool write(String& buf) const; // removed, use getBinary() method instead (RAW OpenCL binary) + CV_DEPRECATED const ProgramSource& source() const; // implementation removed + CV_DEPRECATED String getPrefix() const; // deprecated, implementation replaced + CV_DEPRECATED static String getPrefix(const String& buildflags); // deprecated, implementation replaced +#endif }; class CV_EXPORTS ProgramSource { public: - typedef uint64 hash_t; + typedef uint64 hash_t; // deprecated ProgramSource(); - explicit ProgramSource(const String& prog); - explicit ProgramSource(const char* prog); + explicit ProgramSource(const String& module, const String& name, const String& codeStr, const String& codeHash); + explicit ProgramSource(const String& prog); // deprecated + explicit ProgramSource(const char* prog); // deprecated ~ProgramSource(); ProgramSource(const ProgramSource& prog); ProgramSource& operator = (const ProgramSource& prog); - const String& source() const; - hash_t hash() const; + const String& source() const; // deprecated + hash_t hash() const; // deprecated + + /** @brief Describe OpenCL program binary. + * Do not call clCreateProgramWithBinary() and/or clBuildProgram(). + * + * Caller should guarantee binary buffer lifetime greater than ProgramSource object (and any of its copies). + * + * This kind of binary is not portable between platforms in general - it is specific to OpenCL vendor / device / driver version. + * + * @param module name of program owner module + * @param name unique name of program (module+name is used as key for OpenCL program caching) + * @param binary buffer address. See buffer lifetime requirement in description. + * @param size buffer size + * @param buildOptions additional program-related build options passed to clBuildProgram() + * @return created ProgramSource object + */ + static ProgramSource fromBinary(const String& module, const String& name, + const unsigned char* binary, const size_t size, + const cv::String& buildOptions = cv::String()); + + /** @brief Describe OpenCL program in SPIR format. + * Do not call clCreateProgramWithBinary() and/or clBuildProgram(). + * + * Supports SPIR 1.2 by default (pass '-spir-std=X.Y' in buildOptions to override this behavior) + * + * Caller should guarantee binary buffer lifetime greater than ProgramSource object (and any of its copies). + * + * Programs in this format are portable between OpenCL implementations with 'khr_spir' extension: + * https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/cl_khr_spir.html + * (but they are not portable between different platforms: 32-bit / 64-bit) + * + * Note: these programs can't support vendor specific extensions, like 'cl_intel_subgroups'. + * + * @param module name of program owner module + * @param name unique name of program (module+name is used as key for OpenCL program caching) + * @param binary buffer address. See buffer lifetime requirement in description. + * @param size buffer size + * @param buildOptions additional program-related build options passed to clBuildProgram() + * (these options are added automatically: '-x spir' and '-spir-std=1.2') + * @return created ProgramSource object. + */ + static ProgramSource fromSPIR(const String& module, const String& name, + const unsigned char* binary, const size_t size, + const cv::String& buildOptions = cv::String()); + + //OpenCL 2.1+ only + //static Program fromSPIRV(const String& module, const String& name, + // const unsigned char* binary, const size_t size, + // const cv::String& buildOptions = cv::String()); + + struct Impl; friend struct Impl; + inline Impl* getImpl() const { return (Impl*)p; } protected: - struct Impl; Impl* p; }; @@ -658,6 +732,7 @@ CV_EXPORTS const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf) CV_EXPORTS const char* typeToStr(int t); CV_EXPORTS const char* memopTypeToStr(int t); CV_EXPORTS const char* vecopTypeToStr(int t); +CV_EXPORTS const char* getOpenCLErrorString(int errorCode); CV_EXPORTS String kernelToStr(InputArray _kernel, int ddepth = -1, const char * name = NULL); CV_EXPORTS void getPlatfomsInfo(std::vector& platform_info); @@ -697,22 +772,25 @@ class CV_EXPORTS Image2D public: Image2D(); - // src: The UMat from which to get image properties and data - // norm: Flag to enable the use of normalized channel data types - // alias: Flag indicating that the image should alias the src UMat. - // If true, changes to the image or src will be reflected in - // both objects. + /** + @param src UMat object from which to get image properties and data + @param norm flag to enable the use of normalized channel data types + @param alias flag indicating that the image should alias the src UMat. If true, changes to the + image or src will be reflected in both objects. + */ explicit Image2D(const UMat &src, bool norm = false, bool alias = false); Image2D(const Image2D & i); ~Image2D(); Image2D & operator = (const Image2D & i); - // Indicates if creating an aliased image should succeed. Depends on the - // underlying platform and the dimensions of the UMat. + /** Indicates if creating an aliased image should succeed. + Depends on the underlying platform and the dimensions of the UMat. + */ static bool canCreateAlias(const UMat &u); - // Indicates if the image format is supported. + /** Indicates if the image format is supported. + */ static bool isFormatSupported(int depth, int cn, bool norm); void* ptr() const; @@ -721,6 +799,24 @@ protected: Impl* p; }; +class CV_EXPORTS Timer +{ +public: + Timer(const Queue& q); + ~Timer(); + void start(); + void stop(); + + uint64 durationNS() const; //< duration in nanoseconds + +protected: + struct Impl; + Impl* const p; + +private: + Timer(const Timer&); // disabled + Timer& operator=(const Timer&); // disabled +}; CV_EXPORTS MatAllocator* getOpenCLAllocator(); @@ -728,6 +824,9 @@ CV_EXPORTS MatAllocator* getOpenCLAllocator(); #ifdef __OPENCV_BUILD namespace internal { +CV_EXPORTS bool isOpenCLForced(); +#define OCL_FORCE_CHECK(condition) (cv::ocl::internal::isOpenCLForced() || (condition)) + CV_EXPORTS bool isPerformanceCheckBypassed(); #define OCL_PERFORMANCE_CHECK(condition) (cv::ocl::internal::isPerformanceCheckBypassed() || (condition)) diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/ocl_genbase.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/ocl_genbase.hpp similarity index 87% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/ocl_genbase.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/ocl_genbase.hpp index d53bc1ab..5334cf1f 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/ocl_genbase.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/ocl_genbase.hpp @@ -39,26 +39,31 @@ // //M*/ -#ifndef __OPENCV_OPENCL_GENBASE_HPP__ -#define __OPENCV_OPENCL_GENBASE_HPP__ - -namespace cv -{ -namespace ocl -{ +#ifndef OPENCV_OPENCL_GENBASE_HPP +#define OPENCV_OPENCL_GENBASE_HPP //! @cond IGNORED -struct ProgramEntry +namespace cv { +namespace ocl { + +class ProgramSource; + +namespace internal { + +struct CV_EXPORTS ProgramEntry { + const char* module; const char* name; - const char* programStr; + const char* programCode; const char* programHash; + ProgramSource* pProgramSource; + + operator ProgramSource& () const; }; +} } } // namespace + //! @endcond -} -} - #endif diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/opengl.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/opengl.hpp similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/opengl.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/opengl.hpp index fd47c520..8b63d6c9 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/opengl.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/opengl.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_CORE_OPENGL_HPP__ -#define __OPENCV_CORE_OPENGL_HPP__ +#ifndef OPENCV_CORE_OPENGL_HPP +#define OPENCV_CORE_OPENGL_HPP #ifndef __cplusplus # error opengl.hpp header must be compiled as C++ @@ -726,4 +726,4 @@ bool cv::ogl::Arrays::empty() const //! @endcond -#endif /* __OPENCV_CORE_OPENGL_HPP__ */ +#endif /* OPENCV_CORE_OPENGL_HPP */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/operations.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/operations.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/operations.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/operations.hpp index bced1a75..9858d067 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/operations.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/operations.hpp @@ -42,8 +42,8 @@ // //M*/ -#ifndef __OPENCV_CORE_OPERATIONS_HPP__ -#define __OPENCV_CORE_OPERATIONS_HPP__ +#ifndef OPENCV_CORE_OPERATIONS_HPP +#define OPENCV_CORE_OPERATIONS_HPP #ifndef __cplusplus # error operations.hpp header must be compiled as C++ @@ -82,7 +82,7 @@ template struct Matx_FastInvOp<_Tp, 2> { bool operator()(const Matx<_Tp, 2, 2>& a, Matx<_Tp, 2, 2>& b, int) const { - _Tp d = determinant(a); + _Tp d = (_Tp)determinant(a); if( d == 0 ) return false; d = 1/d; @@ -137,7 +137,7 @@ template struct Matx_FastSolveOp<_Tp, 2, 1> bool operator()(const Matx<_Tp, 2, 2>& a, const Matx<_Tp, 2, 1>& b, Matx<_Tp, 2, 1>& x, int) const { - _Tp d = determinant(a); + _Tp d = (_Tp)determinant(a); if( d == 0 ) return false; d = 1/d; @@ -349,6 +349,8 @@ inline int RNG::uniform(int a, int b) { return a == b ? a : (int)(next( inline float RNG::uniform(float a, float b) { return ((float)*this)*(b - a) + a; } inline double RNG::uniform(double a, double b) { return ((double)*this)*(b - a) + a; } +inline bool RNG::operator ==(const RNG& other) const { return state == other.state; } + inline unsigned RNG::next() { state = (uint64)(unsigned)state* /*CV_RNG_COEFF*/ 4164903690U + (unsigned)(state >> 32); diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/optim.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/optim.hpp similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/optim.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/optim.hpp index 23e21558..190d5431 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/optim.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/optim.hpp @@ -39,8 +39,8 @@ // //M*/ -#ifndef __OPENCV_OPTIM_HPP__ -#define __OPENCV_OPTIM_HPP__ +#ifndef OPENCV_OPTIM_HPP +#define OPENCV_OPTIM_HPP #include "opencv2/core.hpp" @@ -73,7 +73,7 @@ public: /** @brief Getter for the optimized function. The optimized function is represented by Function interface, which requires derivatives to - implement the sole method calc(double*) to evaluate the function. + implement the calc(double*) and getDim() methods to evaluate the function. @return Smart-pointer to an object that implements Function interface - it represents the function that is being optimized. It can be empty, if no function was given so far. diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/core/ovx.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/ovx.hpp new file mode 100644 index 00000000..8bb7d549 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/ovx.hpp @@ -0,0 +1,28 @@ +// 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. + +// Copyright (C) 2016, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. + +// OpenVX related definitions and declarations + +#pragma once +#ifndef OPENCV_OVX_HPP +#define OPENCV_OVX_HPP + +#include "cvdef.h" + +namespace cv +{ +/// Check if use of OpenVX is possible +CV_EXPORTS_W bool haveOpenVX(); + +/// Check if use of OpenVX is enabled +CV_EXPORTS_W bool useOpenVX(); + +/// Enable/disable use of OpenVX +CV_EXPORTS_W void setUseOpenVX(bool flag); +} // namespace cv + +#endif // OPENCV_OVX_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/persistence.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/persistence.hpp similarity index 81% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/persistence.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/persistence.hpp index 17686dd0..6d8ad20c 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/persistence.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/persistence.hpp @@ -41,8 +41,13 @@ // //M*/ -#ifndef __OPENCV_CORE_PERSISTENCE_HPP__ -#define __OPENCV_CORE_PERSISTENCE_HPP__ +#ifndef OPENCV_CORE_PERSISTENCE_HPP +#define OPENCV_CORE_PERSISTENCE_HPP + +#ifndef CV_DOXYGEN +/// Define to support persistence legacy formats +#define CV__LEGACY_PERSISTENCE +#endif #ifndef __cplusplus # error persistence.hpp header must be compiled as C++ @@ -57,8 +62,9 @@ Several functions that are described below take CvFileStorage\* as inputs and al save or to load hierarchical collections that consist of scalar values, standard CXCore objects (such as matrices, sequences, graphs), and user-defined objects. -OpenCV can read and write data in XML () or YAML () -formats. Below is an example of 3x3 floating-point identity matrix A, stored in XML and YAML files +OpenCV can read and write data in XML (), YAML () or +JSON () formats. Below is an example of 3x3 floating-point identity matrix A, +stored in XML and YAML files using CXCore functions: XML: @code{.xml} @@ -85,10 +91,13 @@ As it can be seen from the examples, XML uses nested tags to represent hierarchy indentation for that purpose (similar to the Python programming language). The same functions can read and write data in both formats; the particular format is determined by -the extension of the opened file, ".xml" for XML files and ".yml" or ".yaml" for YAML. +the extension of the opened file, ".xml" for XML files, ".yml" or ".yaml" for YAML and ".json" for +JSON. */ typedef struct CvFileStorage CvFileStorage; typedef struct CvFileNode CvFileNode; +typedef struct CvMat CvMat; +typedef struct CvMatND CvMatND; //! @} core_c @@ -99,20 +108,20 @@ namespace cv { /** @addtogroup core_xml -XML/YAML file storages. {#xml_storage} +XML/YAML/JSON file storages. {#xml_storage} ======================= Writing to a file storage. -------------------------- -You can store and then restore various OpenCV data structures to/from XML () -or YAML () formats. Also, it is possible store and load arbitrarily complex -data structures, which include OpenCV data structures, as well as primitive data types (integer and -floating-point numbers and text strings) as their elements. +You can store and then restore various OpenCV data structures to/from XML (), +YAML () or JSON () formats. Also, it is possible to store +and load arbitrarily complex data structures, which include OpenCV data structures, as well as +primitive data types (integer and floating-point numbers and text strings) as their elements. -Use the following procedure to write something to XML or YAML: +Use the following procedure to write something to XML, YAML or JSON: -# Create new FileStorage and open it for writing. It can be done with a single call to FileStorage::FileStorage constructor that takes a filename, or you can use the default constructor -and then call FileStorage::open. Format of the file (XML or YAML) is determined from the filename -extension (".xml" and ".yml"/".yaml", respectively) +and then call FileStorage::open. Format of the file (XML, YAML or JSON) is determined from the filename +extension (".xml", ".yml"/".yaml" and ".json", respectively) -# Write all the data you want using the streaming operator `<<`, just like in the case of STL streams. -# Close the file using FileStorage::release. FileStorage destructor also closes the file. @@ -151,7 +160,7 @@ Here is an example: return 0; } @endcode -The sample above stores to XML and integer, text string (calibration date), 2 matrices, and a custom +The sample above stores to YML an integer, a text string (calibration date), 2 matrices, and a custom structure "feature", which includes feature coordinates and LBP (local binary pattern) value. Here is output of the sample: @code{.yaml} @@ -175,19 +184,19 @@ features: - { x:344, y:158, lbp:[ 1, 1, 0, 0, 0, 0, 1, 0 ] } @endcode -As an exercise, you can replace ".yml" with ".xml" in the sample above and see, how the +As an exercise, you can replace ".yml" with ".xml" or ".json" in the sample above and see, how the corresponding XML file will look like. Several things can be noted by looking at the sample code and the output: -- The produced YAML (and XML) consists of heterogeneous collections that can be nested. There are 2 - types of collections: named collections (mappings) and unnamed collections (sequences). In mappings +- The produced YAML (and XML/JSON) consists of heterogeneous collections that can be nested. There are + 2 types of collections: named collections (mappings) and unnamed collections (sequences). In mappings each element has a name and is accessed by name. This is similar to structures and std::map in C/C++ and dictionaries in Python. In sequences elements do not have names, they are accessed by indices. This is similar to arrays and std::vector in C/C++ and lists, tuples in Python. "Heterogeneous" means that elements of each single collection can have different types. - Top-level collection in YAML/XML is a mapping. Each matrix is stored as a mapping, and the matrix + Top-level collection in YAML/XML/JSON is a mapping. Each matrix is stored as a mapping, and the matrix elements are stored as a sequence. Then, there is a sequence of features, where each feature is represented a mapping, and lbp value in a nested sequence. @@ -203,7 +212,7 @@ Several things can be noted by looking at the sample code and the output: - To write a sequence, you first write the special string `[`, then write the elements, then write the closing `]`. -- In YAML (but not XML), mappings and sequences can be written in a compact Python-like inline +- In YAML/JSON (but not XML), mappings and sequences can be written in a compact Python-like inline form. In the sample above matrix elements, as well as each feature, including its lbp value, is stored in such inline form. To store a mapping/sequence in a compact form, put `:` after the opening character, e.g. use `{:` instead of `{` and `[:` instead of `[`. When the @@ -211,7 +220,7 @@ Several things can be noted by looking at the sample code and the output: Reading data from a file storage. --------------------------------- -To read the previously written XML or YAML file, do the following: +To read the previously written XML, YAML or JSON file, do the following: -# Open the file storage using FileStorage::FileStorage constructor or FileStorage::open method. In the current implementation the whole file is parsed and the whole representation of file storage is built in memory as a hierarchy of file nodes (see FileNode) @@ -292,8 +301,8 @@ A complete example using the FileStorage interface class CV_EXPORTS FileNode; class CV_EXPORTS FileNodeIterator; -/** @brief XML/YAML file storage class that encapsulates all the information necessary for writing or reading -data to/from a file. +/** @brief XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or +reading data to/from a file. */ class CV_EXPORTS_W FileStorage { @@ -309,7 +318,11 @@ public: FORMAT_MASK = (7<<3), //!< mask for format flags FORMAT_AUTO = 0, //!< flag, auto format FORMAT_XML = (1<<3), //!< flag, XML format - FORMAT_YAML = (2<<3) //!< flag, YAML format + FORMAT_YAML = (2<<3), //!< flag, YAML format + FORMAT_JSON = (3<<3), //!< flag, JSON format + + BASE64 = 64, //!< flag, write rawdata in Base64 by default. (consider using WRITE_BASE64) + WRITE_BASE64 = BASE64 | WRITE, //!< flag, enable both WRITE and BASE64 }; enum { @@ -327,16 +340,9 @@ public: CV_WRAP FileStorage(); /** @overload - @param source Name of the file to open or the text string to read the data from. Extension of the - file (.xml or .yml/.yaml) determines its format (XML or YAML respectively). Also you can append .gz - to work with compressed files, for example myHugeMatrix.xml.gz. If both FileStorage::WRITE and - FileStorage::MEMORY flags are specified, source is used just to specify the output file format (e.g. - mydata.xml, .yml etc.). - @param flags Mode of operation. See FileStorage::Mode - @param encoding Encoding of the file. Note that UTF-16 XML encoding is not supported currently and - you should use 8-bit encoding instead of it. + @copydoc open() */ - CV_WRAP FileStorage(const String& source, int flags, const String& encoding=String()); + CV_WRAP FileStorage(const String& filename, int flags, const String& encoding=String()); /** @overload */ FileStorage(CvFileStorage* fs, bool owning=true); @@ -349,10 +355,12 @@ public: See description of parameters in FileStorage::FileStorage. The method calls FileStorage::release before opening the file. @param filename Name of the file to open or the text string to read the data from. - Extension of the file (.xml or .yml/.yaml) determines its format (XML or YAML respectively). - Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both + Extension of the file (.xml, .yml/.yaml or .json) determines its format (XML, YAML or JSON + respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify - the output file format (e.g. mydata.xml, .yml etc.). + the output file format (e.g. mydata.xml, .yml etc.). A file name can also contain parameters. + You can use this format, "*?base64" (e.g. "file.json?base64" (case sensitive)), as an alternative to + FileStorage::BASE64 flag. @param flags Mode of operation. One of FileStorage::Mode @param encoding Encoding of the file. Note that UTF-16 XML encoding is not supported currently and you should use 8-bit encoding instead of it. @@ -398,7 +406,7 @@ public: FileNode operator[](const String& nodename) const; /** @overload */ - CV_WRAP FileNode operator[](const char* nodename) const; + CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const; /** @brief Returns the obsolete C FileStorage structure. @returns Pointer to the underlying C FileStorage structure @@ -425,12 +433,38 @@ public: */ void writeObj( const String& name, const void* obj ); + /** + * @brief Simplified writing API to use with bindings. + * @param name Name of the written object + * @param val Value of the written object + */ + CV_WRAP void write(const String& name, double val); + /// @overload + CV_WRAP void write(const String& name, const String& val); + /// @overload + CV_WRAP void write(const String& name, InputArray val); + + /** @brief Writes a comment. + + The function writes a comment into file storage. The comments are skipped when the storage is read. + @param comment The written comment, single-line or multi-line + @param append If true, the function tries to put the comment at the end of current line. + Else if the comment is multi-line, or if it does not fit at the end of the current + line, the comment starts a new line. + */ + CV_WRAP void writeComment(const String& comment, bool append = false); + /** @brief Returns the normalized object name for the specified name of a file. @param filename Name of a file @returns The normalized object name. */ static String getDefaultObjectName(const String& filename); + /** @brief Returns the current format. + * @returns The current format, see FileStorage::Mode + */ + CV_WRAP int getFormat() const; + Ptr fs; //!< the underlying C FileStorage structure String elname; //!< the currently written element std::vector structs; //!< the stack of written structures @@ -443,7 +477,7 @@ template<> CV_EXPORTS void DefaultDeleter::operator ()(CvFileStor The node is used to store each and every element of the file storage opened for reading. When XML/YAML file is read, it is first parsed and stored in the memory as a hierarchical collection of -nodes. Each node can be a “leaf” that is contain a single number or a string, or be a collection of +nodes. Each node can be a "leaf" that is contain a single number or a string, or be a collection of other nodes. There can be named collections (mappings) where each element has a name and it is accessed by a name, and ordered collections (sequences) where elements do not have names but rather accessed by index. Type of the file node can be determined using FileNode::type method. @@ -499,12 +533,12 @@ public: /** @overload @param nodename Name of an element in the mapping node. */ - CV_WRAP FileNode operator[](const char* nodename) const; + CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const; /** @overload @param i Index of an element in the sequence node. */ - CV_WRAP FileNode operator[](int i) const; + CV_WRAP_AS(at) FileNode operator[](int i) const; /** @brief Returns type of the node. @returns Type of the node. See FileNode::Type @@ -539,9 +573,7 @@ public: operator double() const; //! returns the node content as text string operator String() const; -#ifndef OPENCV_NOSTL operator std::string() const; -#endif //! returns pointer to the underlying file node CvFileNode* operator *(); @@ -566,6 +598,13 @@ public: //! reads the registered object and returns pointer to it void* readObj() const; + //! Simplified reading API to use with bindings. + CV_WRAP double real() const; + //! Simplified reading API to use with bindings. + CV_WRAP String string() const; + //! Simplified reading API to use with bindings. + CV_WRAP Mat mat() const; + // do not use wrapper pointer classes for better efficiency const CvFileStorage* fs; const CvFileNode* node; @@ -659,8 +698,10 @@ CV_EXPORTS void write( FileStorage& fs, const String& name, double value ); CV_EXPORTS void write( FileStorage& fs, const String& name, const String& value ); CV_EXPORTS void write( FileStorage& fs, const String& name, const Mat& value ); CV_EXPORTS void write( FileStorage& fs, const String& name, const SparseMat& value ); +#ifdef CV__LEGACY_PERSISTENCE CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector& value); CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector& value); +#endif CV_EXPORTS void writeScalar( FileStorage& fs, int value ); CV_EXPORTS void writeScalar( FileStorage& fs, float value ); @@ -676,10 +717,15 @@ CV_EXPORTS void read(const FileNode& node, int& value, int default_value); CV_EXPORTS void read(const FileNode& node, float& value, float default_value); CV_EXPORTS void read(const FileNode& node, double& value, double default_value); CV_EXPORTS void read(const FileNode& node, String& value, const String& default_value); +CV_EXPORTS void read(const FileNode& node, std::string& value, const std::string& default_value); CV_EXPORTS void read(const FileNode& node, Mat& mat, const Mat& default_mat = Mat() ); CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() ); +#ifdef CV__LEGACY_PERSISTENCE CV_EXPORTS void read(const FileNode& node, std::vector& keypoints); CV_EXPORTS void read(const FileNode& node, std::vector& matches); +#endif +CV_EXPORTS void read(const FileNode& node, KeyPoint& value, const KeyPoint& default_value); +CV_EXPORTS void read(const FileNode& node, DMatch& value, const DMatch& default_value); template static inline void read(const FileNode& node, Point_<_Tp>& value, const Point_<_Tp>& default_value) { @@ -773,7 +819,7 @@ namespace internal VecWriterProxy( FileStorage* _fs ) : fs(_fs) {} void operator()(const std::vector<_Tp>& vec) const { - int _fmt = DataType<_Tp>::fmt; + int _fmt = traits::SafeFmt<_Tp>::fmt; char fmt[] = { (char)((_fmt >> 8) + '1'), (char)_fmt, '\0' }; fs->writeRaw(fmt, !vec.empty() ? (uchar*)&vec[0] : 0, vec.size() * sizeof(_Tp)); } @@ -804,8 +850,10 @@ namespace internal { size_t remaining = it->remaining; size_t cn = DataType<_Tp>::channels; - int _fmt = DataType<_Tp>::fmt; + int _fmt = traits::SafeFmt<_Tp>::fmt; + CV_Assert((_fmt >> 8) < 9); char fmt[] = { (char)((_fmt >> 8)+'1'), (char)_fmt, '\0' }; + CV_Assert((remaining % cn) == 0); size_t remaining1 = remaining / cn; count = count < remaining1 ? count : remaining1; vec.resize(count); @@ -916,11 +964,10 @@ void write(FileStorage& fs, const Range& r ) template static inline void write( FileStorage& fs, const std::vector<_Tp>& vec ) { - cv::internal::VecWriterProxy<_Tp, DataType<_Tp>::fmt != 0> w(&fs); + cv::internal::VecWriterProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> w(&fs); w(vec); } - template static inline void write(FileStorage& fs, const String& name, const Point_<_Tp>& pt ) { @@ -977,13 +1024,65 @@ void write(FileStorage& fs, const String& name, const Range& r ) write(fs, r); } +static inline +void write(FileStorage& fs, const String& name, const KeyPoint& kpt) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, kpt.pt.x); + write(fs, kpt.pt.y); + write(fs, kpt.size); + write(fs, kpt.angle); + write(fs, kpt.response); + write(fs, kpt.octave); + write(fs, kpt.class_id); +} + +static inline +void write(FileStorage& fs, const String& name, const DMatch& m) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, m.queryIdx); + write(fs, m.trainIdx); + write(fs, m.imgIdx); + write(fs, m.distance); +} + template static inline void write( FileStorage& fs, const String& name, const std::vector<_Tp>& vec ) { - cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+(DataType<_Tp>::fmt != 0 ? FileNode::FLOW : 0)); + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+(traits::SafeFmt<_Tp>::fmt != 0 ? FileNode::FLOW : 0)); write(fs, vec); } +template static inline +void write( FileStorage& fs, const String& name, const std::vector< std::vector<_Tp> >& vec ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ); + for(size_t i = 0; i < vec.size(); i++) + { + cv::internal::WriteStructContext ws_(fs, name, FileNode::SEQ+(traits::SafeFmt<_Tp>::fmt != 0 ? FileNode::FLOW : 0)); + write(fs, vec[i]); + } +} + +#ifdef CV__LEGACY_PERSISTENCE +// This code is not needed anymore, but it is preserved here to keep source compatibility +// Implementation is similar to templates instantiations +static inline void write(FileStorage& fs, const KeyPoint& kpt) { write(fs, String(), kpt); } +static inline void write(FileStorage& fs, const DMatch& m) { write(fs, String(), m); } +static inline void write(FileStorage& fs, const std::vector& vec) +{ + cv::internal::VecWriterProxy w(&fs); + w(vec); +} +static inline void write(FileStorage& fs, const std::vector& vec) +{ + cv::internal::VecWriterProxy w(&fs); + w(vec); + +} +#endif + //! @} FileStorage //! @relates cv::FileNode @@ -1032,7 +1131,7 @@ void read(const FileNode& node, short& value, short default_value) template static inline void read( FileNodeIterator& it, std::vector<_Tp>& vec, size_t maxCount = (size_t)INT_MAX ) { - cv::internal::VecReaderProxy<_Tp, DataType<_Tp>::fmt != 0> r(&it); + cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> r(&it); r(vec, maxCount); } @@ -1048,6 +1147,24 @@ void read( const FileNode& node, std::vector<_Tp>& vec, const std::vector<_Tp>& } } +static inline +void read( const FileNode& node, std::vector& vec, const std::vector& default_value ) +{ + if(!node.node) + vec = default_value; + else + read(node, vec); +} + +static inline +void read( const FileNode& node, std::vector& vec, const std::vector& default_value ) +{ + if(!node.node) + vec = default_value; + else + read(node, vec); +} + //! @} FileNode //! @relates cv::FileStorage @@ -1103,7 +1220,7 @@ FileNodeIterator& operator >> (FileNodeIterator& it, _Tp& value) template static inline FileNodeIterator& operator >> (FileNodeIterator& it, std::vector<_Tp>& vec) { - cv::internal::VecReaderProxy<_Tp, DataType<_Tp>::fmt != 0> r(&it); + cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> r(&it); r(vec, (size_t)INT_MAX); return it; } @@ -1130,6 +1247,39 @@ void operator >> (const FileNode& n, std::vector<_Tp>& vec) it >> vec; } +/** @brief Reads KeyPoint from a file storage. +*/ +//It needs special handling because it contains two types of fields, int & float. +static inline +void operator >> (const FileNode& n, KeyPoint& kpt) +{ + FileNodeIterator it = n.begin(); + it >> kpt.pt.x >> kpt.pt.y >> kpt.size >> kpt.angle >> kpt.response >> kpt.octave >> kpt.class_id; +} + +#ifdef CV__LEGACY_PERSISTENCE +static inline +void operator >> (const FileNode& n, std::vector& vec) +{ + read(n, vec); +} +static inline +void operator >> (const FileNode& n, std::vector& vec) +{ + read(n, vec); +} +#endif + +/** @brief Reads DMatch from a file storage. +*/ +//It needs special handling because it contains two types of fields, int & float. +static inline +void operator >> (const FileNode& n, DMatch& m) +{ + FileNodeIterator it = n.begin(); + it >> m.queryIdx >> m.trainIdx >> m.imgIdx >> m.distance; +} + //! @} FileNode //! @relates cv::FileNodeIterator @@ -1181,6 +1331,9 @@ inline FileNode::operator int() const { int value; read(*this, value, 0); inline FileNode::operator float() const { float value; read(*this, value, 0.f); return value; } inline FileNode::operator double() const { double value; read(*this, value, 0.); return value; } inline FileNode::operator String() const { String value; read(*this, value, value); return value; } +inline double FileNode::real() const { return double(*this); } +inline String FileNode::string() const { return String(*this); } +inline Mat FileNode::mat() const { Mat value; read(*this, value, value); return value; } inline FileNodeIterator FileNode::begin() const { return FileNodeIterator(fs, node); } inline FileNodeIterator FileNode::end() const { return FileNodeIterator(fs, node, size()); } inline void FileNode::readRaw( const String& fmt, uchar* vec, size_t len ) const { begin().readRaw( fmt, vec, len ); } @@ -1190,6 +1343,17 @@ inline String::String(const FileNode& fn): cstr_(0), len_(0) { read(fn, *this, * //! @endcond + +CV_EXPORTS void cvStartWriteRawData_Base64(::CvFileStorage * fs, const char* name, int len, const char* dt); + +CV_EXPORTS void cvWriteRawData_Base64(::CvFileStorage * fs, const void* _data, int len); + +CV_EXPORTS void cvEndWriteRawData_Base64(::CvFileStorage * fs); + +CV_EXPORTS void cvWriteMat_Base64(::CvFileStorage* fs, const char* name, const ::CvMat* mat); + +CV_EXPORTS void cvWriteMatND_Base64(::CvFileStorage* fs, const char* name, const ::CvMatND* mat); + } // cv -#endif // __OPENCV_CORE_PERSISTENCE_HPP__ +#endif // OPENCV_CORE_PERSISTENCE_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/ptr.inl.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/ptr.inl.hpp similarity index 89% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/ptr.inl.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/ptr.inl.hpp index 3f6f214a..3c095a1f 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/ptr.inl.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/ptr.inl.hpp @@ -39,8 +39,8 @@ // //M*/ -#ifndef __OPENCV_CORE_PTR_INL_HPP__ -#define __OPENCV_CORE_PTR_INL_HPP__ +#ifndef OPENCV_CORE_PTR_INL_HPP +#define OPENCV_CORE_PTR_INL_HPP #include @@ -264,6 +264,9 @@ Ptr::Ptr(Ptr&& o) : owner(o.owner), stored(o.stored) template Ptr& Ptr::operator = (Ptr&& o) { + if (this == &o) + return *this; + release(); owner = o.owner; stored = o.stored; @@ -358,8 +361,19 @@ Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& return Ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)); } +template +Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10, const A11& a11) +{ + return Ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)); +} + +template +Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10, const A11& a11, const A12& a12) +{ + return Ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)); +} } // namespace cv //! @endcond -#endif // __OPENCV_CORE_PTR_INL_HPP__ +#endif // OPENCV_CORE_PTR_INL_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/saturate.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/saturate.hpp similarity index 83% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/saturate.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/saturate.hpp index 1442eab1..118599f8 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/saturate.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/saturate.hpp @@ -42,8 +42,8 @@ // //M*/ -#ifndef __OPENCV_CORE_SATURATE_HPP__ -#define __OPENCV_CORE_SATURATE_HPP__ +#ifndef OPENCV_CORE_SATURATE_HPP +#define OPENCV_CORE_SATURATE_HPP #include "opencv2/core/cvdef.h" #include "opencv2/core/fast_math.hpp" @@ -58,8 +58,8 @@ namespace cv /** @brief Template function for accurate conversion from one primitive type to another. - The functions saturate_cast resemble the standard C++ cast operations, such as static_cast\() - and others. They perform an efficient and accurate conversion from one primitive type to another + The function saturate_cast resembles the standard C++ cast operations, such as static_cast\() + and others. It perform an efficient and accurate conversion from one primitive type to another (see the introduction chapter). saturate in the name means that when the input value v is out of the range of the target type, the result is not formed just by taking low bits of the input, but instead the value is clipped. For example: @@ -136,15 +136,30 @@ template<> inline short saturate_cast(double v) { int iv = cvRound( template<> inline short saturate_cast(int64 v) { return (short)((uint64)((int64)v - SHRT_MIN) <= (uint64)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); } template<> inline short saturate_cast(uint64 v) { return (short)std::min(v, (uint64)SHRT_MAX); } +template<> inline int saturate_cast(unsigned v) { return (int)std::min(v, (unsigned)INT_MAX); } +template<> inline int saturate_cast(int64 v) { return (int)((uint64)(v - INT_MIN) <= (uint64)UINT_MAX ? v : v > 0 ? INT_MAX : INT_MIN); } +template<> inline int saturate_cast(uint64 v) { return (int)std::min(v, (uint64)INT_MAX); } template<> inline int saturate_cast(float v) { return cvRound(v); } template<> inline int saturate_cast(double v) { return cvRound(v); } +template<> inline unsigned saturate_cast(schar v) { return (unsigned)std::max(v, (schar)0); } +template<> inline unsigned saturate_cast(short v) { return (unsigned)std::max(v, (short)0); } +template<> inline unsigned saturate_cast(int v) { return (unsigned)std::max(v, (int)0); } +template<> inline unsigned saturate_cast(int64 v) { return (unsigned)((uint64)v <= (uint64)UINT_MAX ? v : v > 0 ? UINT_MAX : 0); } +template<> inline unsigned saturate_cast(uint64 v) { return (unsigned)std::min(v, (uint64)UINT_MAX); } // we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc. -template<> inline unsigned saturate_cast(float v) { return cvRound(v); } -template<> inline unsigned saturate_cast(double v) { return cvRound(v); } +template<> inline unsigned saturate_cast(float v) { return static_cast(cvRound(v)); } +template<> inline unsigned saturate_cast(double v) { return static_cast(cvRound(v)); } + +template<> inline uint64 saturate_cast(schar v) { return (uint64)std::max(v, (schar)0); } +template<> inline uint64 saturate_cast(short v) { return (uint64)std::max(v, (short)0); } +template<> inline uint64 saturate_cast(int v) { return (uint64)std::max(v, (int)0); } +template<> inline uint64 saturate_cast(int64 v) { return (uint64)std::max(v, (int64)0); } + +template<> inline int64 saturate_cast(uint64 v) { return (int64)std::min(v, (uint64)LLONG_MAX); } //! @} } // cv -#endif // __OPENCV_CORE_SATURATE_HPP__ +#endif // OPENCV_CORE_SATURATE_HPP diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/core/softfloat.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/softfloat.hpp new file mode 100644 index 00000000..b640111b --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/softfloat.hpp @@ -0,0 +1,526 @@ +// 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 + +// This file is based on files from package issued with the following license: + +/*============================================================================ + +This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3c, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the +University of California. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions, and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions, and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE +DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ + +#pragma once +#ifndef softfloat_h +#define softfloat_h 1 + +#include "cvdef.h" + +// int32_t / uint32_t +#if defined(_MSC_VER) && _MSC_VER < 1600 /* MSVS 2010 */ +namespace cv { +typedef signed int int32_t; +typedef unsigned int uint32_t; +} +#elif defined(_MSC_VER) || __cplusplus >= 201103L +#include +#else +#include +#endif + +namespace cv +{ + +/** @addtogroup core_utils_softfloat + + [SoftFloat](http://www.jhauser.us/arithmetic/SoftFloat.html) is a software implementation + of floating-point calculations according to IEEE 754 standard. + All calculations are done in integers, that's why they are machine-independent and bit-exact. + This library can be useful in accuracy-critical parts like look-up tables generation, tests, etc. + OpenCV contains a subset of SoftFloat partially rewritten to C++. + + ### Types + + There are two basic types: @ref softfloat and @ref softdouble. + These types are binary compatible with float and double types respectively + and support conversions to/from them. + Other types from original SoftFloat library like fp16 or fp128 were thrown away + as well as quiet/signaling NaN support, on-the-fly rounding mode switch + and exception flags (though exceptions can be implemented in the future). + + ### Operations + + Both types support the following: + - Construction from signed and unsigned 32-bit and 64 integers, + float/double or raw binary representation + - Conversions betweeen each other, to float or double and to int + using @ref cvRound, @ref cvTrunc, @ref cvFloor, @ref cvCeil or a bunch of + saturate_cast functions + - Add, subtract, multiply, divide, remainder, square root, FMA with absolute precision + - Comparison operations + - Explicit sign, exponent and significand manipulation through get/set methods, + number state indicators (isInf, isNan, isSubnormal) + - Type-specific constants like eps, minimum/maximum value, best pi approximation, etc. + - min(), max(), abs(), exp(), log() and pow() functions + +*/ +//! @{ + +struct softfloat; +struct softdouble; + +struct CV_EXPORTS softfloat +{ +public: + /** @brief Default constructor */ + softfloat() { v = 0; } + /** @brief Copy constructor */ + softfloat( const softfloat& c) { v = c.v; } + /** @brief Assign constructor */ + softfloat& operator=( const softfloat& c ) + { + if(&c != this) v = c.v; + return *this; + } + /** @brief Construct from raw + + Builds new value from raw binary representation + */ + static const softfloat fromRaw( const uint32_t a ) { softfloat x; x.v = a; return x; } + + /** @brief Construct from integer */ + explicit softfloat( const uint32_t ); + explicit softfloat( const uint64_t ); + explicit softfloat( const int32_t ); + explicit softfloat( const int64_t ); + +#ifdef CV_INT32_T_IS_LONG_INT + // for platforms with int32_t = long int + explicit softfloat( const int a ) { *this = softfloat(static_cast(a)); } +#endif + + /** @brief Construct from float */ + explicit softfloat( const float a ) { Cv32suf s; s.f = a; v = s.u; } + + /** @brief Type casts */ + operator softdouble() const; + operator float() const { Cv32suf s; s.u = v; return s.f; } + + /** @brief Basic arithmetics */ + softfloat operator + (const softfloat&) const; + softfloat operator - (const softfloat&) const; + softfloat operator * (const softfloat&) const; + softfloat operator / (const softfloat&) const; + softfloat operator - () const { softfloat x; x.v = v ^ (1U << 31); return x; } + + /** @brief Remainder operator + + A quote from original SoftFloat manual: + + > The IEEE Standard remainder operation computes the value + > a - n * b, where n is the integer closest to a / b. + > If a / b is exactly halfway between two integers, n is the even integer + > closest to a / b. The IEEE Standard’s remainder operation is always exact and so requires no rounding. + > Depending on the relative magnitudes of the operands, the remainder functions + > can take considerably longer to execute than the other SoftFloat functions. + > This is an inherent characteristic of the remainder operation itself and is not a flaw + > in the SoftFloat implementation. + */ + softfloat operator % (const softfloat&) const; + + softfloat& operator += (const softfloat& a) { *this = *this + a; return *this; } + softfloat& operator -= (const softfloat& a) { *this = *this - a; return *this; } + softfloat& operator *= (const softfloat& a) { *this = *this * a; return *this; } + softfloat& operator /= (const softfloat& a) { *this = *this / a; return *this; } + softfloat& operator %= (const softfloat& a) { *this = *this % a; return *this; } + + /** @brief Comparison operations + + - Any operation with NaN produces false + + The only exception is when x is NaN: x != y for any y. + - Positive and negative zeros are equal + */ + bool operator == ( const softfloat& ) const; + bool operator != ( const softfloat& ) const; + bool operator > ( const softfloat& ) const; + bool operator >= ( const softfloat& ) const; + bool operator < ( const softfloat& ) const; + bool operator <= ( const softfloat& ) const; + + /** @brief NaN state indicator */ + inline bool isNaN() const { return (v & 0x7fffffff) > 0x7f800000; } + /** @brief Inf state indicator */ + inline bool isInf() const { return (v & 0x7fffffff) == 0x7f800000; } + /** @brief Subnormal number indicator */ + inline bool isSubnormal() const { return ((v >> 23) & 0xFF) == 0; } + + /** @brief Get sign bit */ + inline bool getSign() const { return (v >> 31) != 0; } + /** @brief Construct a copy with new sign bit */ + inline softfloat setSign(bool sign) const { softfloat x; x.v = (v & ((1U << 31) - 1)) | ((uint32_t)sign << 31); return x; } + /** @brief Get 0-based exponent */ + inline int getExp() const { return ((v >> 23) & 0xFF) - 127; } + /** @brief Construct a copy with new 0-based exponent */ + inline softfloat setExp(int e) const { softfloat x; x.v = (v & 0x807fffff) | (((e + 127) & 0xFF) << 23 ); return x; } + + /** @brief Get a fraction part + + Returns a number 1 <= x < 2 with the same significand + */ + inline softfloat getFrac() const + { + uint_fast32_t vv = (v & 0x007fffff) | (127 << 23); + return softfloat::fromRaw(vv); + } + /** @brief Construct a copy with provided significand + + Constructs a copy of a number with significand taken from parameter + */ + inline softfloat setFrac(const softfloat& s) const + { + softfloat x; + x.v = (v & 0xff800000) | (s.v & 0x007fffff); + return x; + } + + /** @brief Zero constant */ + static softfloat zero() { return softfloat::fromRaw( 0 ); } + /** @brief Positive infinity constant */ + static softfloat inf() { return softfloat::fromRaw( 0xFF << 23 ); } + /** @brief Default NaN constant */ + static softfloat nan() { return softfloat::fromRaw( 0x7fffffff ); } + /** @brief One constant */ + static softfloat one() { return softfloat::fromRaw( 127 << 23 ); } + /** @brief Smallest normalized value */ + static softfloat min() { return softfloat::fromRaw( 0x01 << 23 ); } + /** @brief Difference between 1 and next representable value */ + static softfloat eps() { return softfloat::fromRaw( (127 - 23) << 23 ); } + /** @brief Biggest finite value */ + static softfloat max() { return softfloat::fromRaw( (0xFF << 23) - 1 ); } + /** @brief Correct pi approximation */ + static softfloat pi() { return softfloat::fromRaw( 0x40490fdb ); } + + uint32_t v; +}; + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ + +struct CV_EXPORTS softdouble +{ +public: + /** @brief Default constructor */ + softdouble() : v(0) { } + /** @brief Copy constructor */ + softdouble( const softdouble& c) { v = c.v; } + /** @brief Assign constructor */ + softdouble& operator=( const softdouble& c ) + { + if(&c != this) v = c.v; + return *this; + } + /** @brief Construct from raw + + Builds new value from raw binary representation + */ + static softdouble fromRaw( const uint64_t a ) { softdouble x; x.v = a; return x; } + + /** @brief Construct from integer */ + explicit softdouble( const uint32_t ); + explicit softdouble( const uint64_t ); + explicit softdouble( const int32_t ); + explicit softdouble( const int64_t ); + +#ifdef CV_INT32_T_IS_LONG_INT + // for platforms with int32_t = long int + explicit softdouble( const int a ) { *this = softdouble(static_cast(a)); } +#endif + + /** @brief Construct from double */ + explicit softdouble( const double a ) { Cv64suf s; s.f = a; v = s.u; } + + /** @brief Type casts */ + operator softfloat() const; + operator double() const { Cv64suf s; s.u = v; return s.f; } + + /** @brief Basic arithmetics */ + softdouble operator + (const softdouble&) const; + softdouble operator - (const softdouble&) const; + softdouble operator * (const softdouble&) const; + softdouble operator / (const softdouble&) const; + softdouble operator - () const { softdouble x; x.v = v ^ (1ULL << 63); return x; } + + /** @brief Remainder operator + + A quote from original SoftFloat manual: + + > The IEEE Standard remainder operation computes the value + > a - n * b, where n is the integer closest to a / b. + > If a / b is exactly halfway between two integers, n is the even integer + > closest to a / b. The IEEE Standard’s remainder operation is always exact and so requires no rounding. + > Depending on the relative magnitudes of the operands, the remainder functions + > can take considerably longer to execute than the other SoftFloat functions. + > This is an inherent characteristic of the remainder operation itself and is not a flaw + > in the SoftFloat implementation. + */ + softdouble operator % (const softdouble&) const; + + softdouble& operator += (const softdouble& a) { *this = *this + a; return *this; } + softdouble& operator -= (const softdouble& a) { *this = *this - a; return *this; } + softdouble& operator *= (const softdouble& a) { *this = *this * a; return *this; } + softdouble& operator /= (const softdouble& a) { *this = *this / a; return *this; } + softdouble& operator %= (const softdouble& a) { *this = *this % a; return *this; } + + /** @brief Comparison operations + + - Any operation with NaN produces false + + The only exception is when x is NaN: x != y for any y. + - Positive and negative zeros are equal + */ + bool operator == ( const softdouble& ) const; + bool operator != ( const softdouble& ) const; + bool operator > ( const softdouble& ) const; + bool operator >= ( const softdouble& ) const; + bool operator < ( const softdouble& ) const; + bool operator <= ( const softdouble& ) const; + + /** @brief NaN state indicator */ + inline bool isNaN() const { return (v & 0x7fffffffffffffff) > 0x7ff0000000000000; } + /** @brief Inf state indicator */ + inline bool isInf() const { return (v & 0x7fffffffffffffff) == 0x7ff0000000000000; } + /** @brief Subnormal number indicator */ + inline bool isSubnormal() const { return ((v >> 52) & 0x7FF) == 0; } + + /** @brief Get sign bit */ + inline bool getSign() const { return (v >> 63) != 0; } + /** @brief Construct a copy with new sign bit */ + softdouble setSign(bool sign) const { softdouble x; x.v = (v & ((1ULL << 63) - 1)) | ((uint_fast64_t)(sign) << 63); return x; } + /** @brief Get 0-based exponent */ + inline int getExp() const { return ((v >> 52) & 0x7FF) - 1023; } + /** @brief Construct a copy with new 0-based exponent */ + inline softdouble setExp(int e) const + { + softdouble x; + x.v = (v & 0x800FFFFFFFFFFFFF) | ((uint_fast64_t)((e + 1023) & 0x7FF) << 52); + return x; + } + + /** @brief Get a fraction part + + Returns a number 1 <= x < 2 with the same significand + */ + inline softdouble getFrac() const + { + uint_fast64_t vv = (v & 0x000FFFFFFFFFFFFF) | ((uint_fast64_t)(1023) << 52); + return softdouble::fromRaw(vv); + } + /** @brief Construct a copy with provided significand + + Constructs a copy of a number with significand taken from parameter + */ + inline softdouble setFrac(const softdouble& s) const + { + softdouble x; + x.v = (v & 0xFFF0000000000000) | (s.v & 0x000FFFFFFFFFFFFF); + return x; + } + + /** @brief Zero constant */ + static softdouble zero() { return softdouble::fromRaw( 0 ); } + /** @brief Positive infinity constant */ + static softdouble inf() { return softdouble::fromRaw( (uint_fast64_t)(0x7FF) << 52 ); } + /** @brief Default NaN constant */ + static softdouble nan() { return softdouble::fromRaw( CV_BIG_INT(0x7FFFFFFFFFFFFFFF) ); } + /** @brief One constant */ + static softdouble one() { return softdouble::fromRaw( (uint_fast64_t)( 1023) << 52 ); } + /** @brief Smallest normalized value */ + static softdouble min() { return softdouble::fromRaw( (uint_fast64_t)( 0x01) << 52 ); } + /** @brief Difference between 1 and next representable value */ + static softdouble eps() { return softdouble::fromRaw( (uint_fast64_t)( 1023 - 52 ) << 52 ); } + /** @brief Biggest finite value */ + static softdouble max() { return softdouble::fromRaw( ((uint_fast64_t)(0x7FF) << 52) - 1 ); } + /** @brief Correct pi approximation */ + static softdouble pi() { return softdouble::fromRaw( CV_BIG_INT(0x400921FB54442D18) ); } + + uint64_t v; +}; + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ + +/** @brief Fused Multiplication and Addition + +Computes (a*b)+c with single rounding +*/ +CV_EXPORTS softfloat mulAdd( const softfloat& a, const softfloat& b, const softfloat & c); +CV_EXPORTS softdouble mulAdd( const softdouble& a, const softdouble& b, const softdouble& c); + +/** @brief Square root */ +CV_EXPORTS softfloat sqrt( const softfloat& a ); +CV_EXPORTS softdouble sqrt( const softdouble& a ); +} + +/*---------------------------------------------------------------------------- +| Ported from OpenCV and added for usability +*----------------------------------------------------------------------------*/ + +/** @brief Truncates number to integer with minimum magnitude */ +CV_EXPORTS int cvTrunc(const cv::softfloat& a); +CV_EXPORTS int cvTrunc(const cv::softdouble& a); + +/** @brief Rounds a number to nearest even integer */ +CV_EXPORTS int cvRound(const cv::softfloat& a); +CV_EXPORTS int cvRound(const cv::softdouble& a); + +/** @brief Rounds a number to nearest even long long integer */ +CV_EXPORTS int64_t cvRound64(const cv::softdouble& a); + +/** @brief Rounds a number down to integer */ +CV_EXPORTS int cvFloor(const cv::softfloat& a); +CV_EXPORTS int cvFloor(const cv::softdouble& a); + +/** @brief Rounds number up to integer */ +CV_EXPORTS int cvCeil(const cv::softfloat& a); +CV_EXPORTS int cvCeil(const cv::softdouble& a); + +namespace cv +{ +/** @brief Saturate casts */ +template static inline _Tp saturate_cast(softfloat a) { return _Tp(a); } +template static inline _Tp saturate_cast(softdouble a) { return _Tp(a); } + +template<> inline uchar saturate_cast(softfloat a) { return (uchar)std::max(std::min(cvRound(a), (int)UCHAR_MAX), 0); } +template<> inline uchar saturate_cast(softdouble a) { return (uchar)std::max(std::min(cvRound(a), (int)UCHAR_MAX), 0); } + +template<> inline schar saturate_cast(softfloat a) { return (schar)std::min(std::max(cvRound(a), (int)SCHAR_MIN), (int)SCHAR_MAX); } +template<> inline schar saturate_cast(softdouble a) { return (schar)std::min(std::max(cvRound(a), (int)SCHAR_MIN), (int)SCHAR_MAX); } + +template<> inline ushort saturate_cast(softfloat a) { return (ushort)std::max(std::min(cvRound(a), (int)USHRT_MAX), 0); } +template<> inline ushort saturate_cast(softdouble a) { return (ushort)std::max(std::min(cvRound(a), (int)USHRT_MAX), 0); } + +template<> inline short saturate_cast(softfloat a) { return (short)std::min(std::max(cvRound(a), (int)SHRT_MIN), (int)SHRT_MAX); } +template<> inline short saturate_cast(softdouble a) { return (short)std::min(std::max(cvRound(a), (int)SHRT_MIN), (int)SHRT_MAX); } + +template<> inline int saturate_cast(softfloat a) { return cvRound(a); } +template<> inline int saturate_cast(softdouble a) { return cvRound(a); } + +template<> inline int64_t saturate_cast(softfloat a) { return cvRound(a); } +template<> inline int64_t saturate_cast(softdouble a) { return cvRound64(a); } + +/** @brief Saturate cast to unsigned integer and unsigned long long integer +We intentionally do not clip negative numbers, to make -1 become 0xffffffff etc. +*/ +template<> inline unsigned saturate_cast(softfloat a) { return cvRound(a); } +template<> inline unsigned saturate_cast(softdouble a) { return cvRound(a); } + +template<> inline uint64_t saturate_cast(softfloat a) { return cvRound(a); } +template<> inline uint64_t saturate_cast(softdouble a) { return cvRound64(a); } + +/** @brief Min and Max functions */ +inline softfloat min(const softfloat& a, const softfloat& b) { return (a > b) ? b : a; } +inline softdouble min(const softdouble& a, const softdouble& b) { return (a > b) ? b : a; } + +inline softfloat max(const softfloat& a, const softfloat& b) { return (a > b) ? a : b; } +inline softdouble max(const softdouble& a, const softdouble& b) { return (a > b) ? a : b; } + +/** @brief Absolute value */ +inline softfloat abs( softfloat a) { softfloat x; x.v = a.v & ((1U << 31) - 1); return x; } +inline softdouble abs( softdouble a) { softdouble x; x.v = a.v & ((1ULL << 63) - 1); return x; } + +/** @brief Exponent + +Special cases: +- exp(NaN) is NaN +- exp(-Inf) == 0 +- exp(+Inf) == +Inf +*/ +CV_EXPORTS softfloat exp( const softfloat& a); +CV_EXPORTS softdouble exp( const softdouble& a); + +/** @brief Natural logarithm + +Special cases: +- log(NaN), log(x < 0) are NaN +- log(0) == -Inf +*/ +CV_EXPORTS softfloat log( const softfloat& a ); +CV_EXPORTS softdouble log( const softdouble& a ); + +/** @brief Raising to the power + +Special cases: +- x**NaN is NaN for any x +- ( |x| == 1 )**Inf is NaN +- ( |x| > 1 )**+Inf or ( |x| < 1 )**-Inf is +Inf +- ( |x| > 1 )**-Inf or ( |x| < 1 )**+Inf is 0 +- x ** 0 == 1 for any x +- x ** 1 == 1 for any x +- NaN ** y is NaN for any other y +- Inf**(y < 0) == 0 +- Inf ** y is +Inf for any other y +- (x < 0)**y is NaN for any other y if x can't be correctly rounded to integer +- 0 ** 0 == 1 +- 0 ** (y < 0) is +Inf +- 0 ** (y > 0) is 0 +*/ +CV_EXPORTS softfloat pow( const softfloat& a, const softfloat& b); +CV_EXPORTS softdouble pow( const softdouble& a, const softdouble& b); + +/** @brief Cube root + +Special cases: +- cbrt(NaN) is NaN +- cbrt(+/-Inf) is +/-Inf +*/ +CV_EXPORTS softfloat cbrt( const softfloat& a ); + +/** @brief Sine + +Special cases: +- sin(Inf) or sin(NaN) is NaN +- sin(x) == x when sin(x) is close to zero +*/ +CV_EXPORTS softdouble sin( const softdouble& a ); + +/** @brief Cosine + * +Special cases: +- cos(Inf) or cos(NaN) is NaN +- cos(x) == +/- 1 when cos(x) is close to +/- 1 +*/ +CV_EXPORTS softdouble cos( const softdouble& a ); + +} + +//! @} + +#endif diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/sse_utils.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/sse_utils.hpp similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/sse_utils.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/sse_utils.hpp index c87b029a..69efffe4 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/sse_utils.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/sse_utils.hpp @@ -39,8 +39,8 @@ // //M*/ -#ifndef __OPENCV_CORE_SSE_UTILS_HPP__ -#define __OPENCV_CORE_SSE_UTILS_HPP__ +#ifndef OPENCV_CORE_SSE_UTILS_HPP +#define OPENCV_CORE_SSE_UTILS_HPP #ifndef __cplusplus # error sse_utils.hpp header must be compiled as C++ @@ -649,4 +649,4 @@ inline void _mm_interleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m12 //! @} -#endif //__OPENCV_CORE_SSE_UTILS_HPP__ +#endif //OPENCV_CORE_SSE_UTILS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/traits.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/traits.hpp similarity index 83% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/traits.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/traits.hpp index 49bc8440..6cb10f44 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/traits.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/traits.hpp @@ -41,19 +41,23 @@ // //M*/ -#ifndef __OPENCV_CORE_TRAITS_HPP__ -#define __OPENCV_CORE_TRAITS_HPP__ +#ifndef OPENCV_CORE_TRAITS_HPP +#define OPENCV_CORE_TRAITS_HPP #include "opencv2/core/cvdef.h" namespace cv { +//#define OPENCV_TRAITS_ENABLE_DEPRECATED + //! @addtogroup core_basic //! @{ /** @brief Template "trait" class for OpenCV primitive data types. +@note Deprecated. This is replaced by "single purpose" traits: traits::Type and traits::Depth + A primitive OpenCV data type is one of unsigned char, bool, signed char, unsigned short, signed short, int, float, double, or a tuple of values of one of these types, where all the values in the tuple have the same type. Any primitive type from the list can be defined by an identifier in the @@ -102,10 +106,13 @@ So, such traits are used to tell OpenCV which data type you are working with, ev not native to OpenCV. For example, the matrix B initialization above is compiled because OpenCV defines the proper specialized template class DataType\ \> . This mechanism is also useful (and used in OpenCV this way) for generic algorithms implementations. + +@note Default values were dropped to stop confusing developers about using of unsupported types (see #7599) */ template class DataType { public: +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED typedef _Tp value_type; typedef value_type work_type; typedef value_type channel_type; @@ -116,6 +123,7 @@ public: fmt = 0, type = CV_MAKETYPE(depth, channels) }; +#endif }; template<> class DataType @@ -270,11 +278,14 @@ public: }; +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED template class TypeDepth { +#ifdef OPENCV_TRAITS_ENABLE_LEGACY_DEFAULTS enum { depth = CV_USRTYPE1 }; typedef void value_type; +#endif }; template<> class TypeDepth @@ -319,8 +330,68 @@ template<> class TypeDepth typedef double value_type; }; +#endif + //! @} +namespace traits { + +namespace internal { +#define CV_CREATE_MEMBER_CHECK(X) \ +template class CheckMember_##X { \ + struct Fallback { int X; }; \ + struct Derived : T, Fallback { }; \ + template struct Check; \ + typedef char CV_NO[1]; \ + typedef char CV_YES[2]; \ + template static CV_NO & func(Check *); \ + template static CV_YES & func(...); \ +public: \ + typedef CheckMember_##X type; \ + enum { value = sizeof(func(0)) == sizeof(CV_YES) }; \ +}; + +CV_CREATE_MEMBER_CHECK(fmt) +CV_CREATE_MEMBER_CHECK(type) + +} // namespace internal + + +template +struct Depth +{ enum { value = DataType::depth }; }; + +template +struct Type +{ enum { value = DataType::type }; }; + +/** Similar to traits::Type but has value = -1 in case of unknown type (instead of compiler error) */ +template >::value > +struct SafeType {}; + +template +struct SafeType +{ enum { value = -1 }; }; + +template +struct SafeType +{ enum { value = Type::value }; }; + + +template >::value > +struct SafeFmt {}; + +template +struct SafeFmt +{ enum { fmt = 0 }; }; + +template +struct SafeFmt +{ enum { fmt = DataType::fmt }; }; + + +} // namespace + } // cv -#endif // __OPENCV_CORE_TRAITS_HPP__ +#endif // OPENCV_CORE_TRAITS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/types.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/types.hpp similarity index 90% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/types.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/types.hpp index e166556a..f3a7b518 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/types.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/types.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_CORE_TYPES_HPP__ -#define __OPENCV_CORE_TYPES_HPP__ +#ifndef OPENCV_CORE_TYPES_HPP +#define OPENCV_CORE_TYPES_HPP #ifndef __cplusplus # error types.hpp header must be compiled as C++ @@ -51,6 +51,7 @@ #include #include #include +#include #include "opencv2/core/cvdef.h" #include "opencv2/core/cvstd.hpp" @@ -97,14 +98,23 @@ public: typedef _Tp channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 2, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) }; + fmt = DataType::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; typedef Vec vec_type; }; +namespace traits { +template +struct Depth< Complex<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Complex<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; }; +} // namespace //////////////////////////////// Point_ //////////////////////////////// @@ -176,6 +186,7 @@ public: }; typedef Point_ Point2i; +typedef Point_ Point2l; typedef Point_ Point2f; typedef Point_ Point2d; typedef Point2i Point; @@ -188,15 +199,23 @@ public: typedef _Tp channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 2, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; +namespace traits { +template +struct Depth< Point_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Point_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; }; +} // namespace //////////////////////////////// Point3_ //////////////////////////////// @@ -231,7 +250,11 @@ public: //! conversion to another data type template operator Point3_<_Tp2>() const; //! conversion to cv::Vec<> +#if OPENCV_ABI_COMPATIBILITY > 300 + template operator Vec<_Tp2, 3>() const; +#else operator Vec<_Tp, 3>() const; +#endif //! dot product _Tp dot(const Point3_& pt) const; @@ -255,16 +278,23 @@ public: typedef _Tp channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 3, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; - +namespace traits { +template +struct Depth< Point3_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Point3_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 3) }; }; +} // namespace //////////////////////////////// Size_ //////////////////////////////// @@ -295,6 +325,8 @@ public: Size_& operator = (const Size_& sz); //! the area (width*height) _Tp area() const; + //! true if empty + bool empty() const; //! conversion of another data type. template operator Size_<_Tp2>() const; @@ -303,6 +335,7 @@ public: }; typedef Size_ Size2i; +typedef Size_ Size2l; typedef Size_ Size2f; typedef Size_ Size2d; typedef Size2i Size; @@ -315,16 +348,23 @@ public: typedef _Tp channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 2, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = DataType::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; - +namespace traits { +template +struct Depth< Size_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Size_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; }; +} // namespace //////////////////////////////// Rect_ //////////////////////////////// @@ -393,6 +433,8 @@ public: Size_<_Tp> size() const; //! area (width*height) of the rectangle _Tp area() const; + //! true if empty + bool empty() const; //! conversion to another data type template operator Rect_<_Tp2>() const; @@ -416,16 +458,23 @@ public: typedef _Tp channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 4, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; - +namespace traits { +template +struct Depth< Rect_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Rect_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 4) }; }; +} // namespace ///////////////////////////// RotatedRect ///////////////////////////// @@ -473,11 +522,13 @@ public: RotatedRect(const Point2f& point1, const Point2f& point2, const Point2f& point3); /** returns 4 vertices of the rectangle - @param pts The points array for storing rectangle vertices. + @param pts The points array for storing rectangle vertices. The order is bottomLeft, topLeft, topRight, bottomRight. */ void points(Point2f pts[]) const; - //! returns the minimal up-right rectangle containing the rotated rectangle + //! returns the minimal up-right integer rectangle containing the rotated rectangle Rect boundingRect() const; + //! returns the minimal (exact) floating point rectangle containing the rotated rectangle, not intended for use with images + Rect_ boundingRect2f() const; Point2f center; //< the rectangle mass center Size2f size; //< width and height of the rectangle @@ -492,15 +543,23 @@ public: typedef float channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = (int)sizeof(value_type)/sizeof(channel_type), // 5 - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; +namespace traits { +template<> +struct Depth< RotatedRect > { enum { value = Depth::value }; }; +template<> +struct Type< RotatedRect > { enum { value = CV_MAKETYPE(Depth::value, (int)sizeof(RotatedRect)/sizeof(float)) }; }; +} // namespace //////////////////////////////// Range ///////////////////////////////// @@ -548,22 +607,30 @@ public: typedef int channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 2, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; +namespace traits { +template<> +struct Depth< Range > { enum { value = Depth::value }; }; +template<> +struct Type< Range > { enum { value = CV_MAKETYPE(Depth::value, 2) }; }; +} // namespace //////////////////////////////// Scalar_ /////////////////////////////// /** @brief Template class for a 4-element vector derived from Vec. -Being derived from Vec\<_Tp, 4\> , Scalar_ and Scalar can be used just as typical 4-element +Being derived from Vec\<_Tp, 4\> , Scalar\_ and Scalar can be used just as typical 4-element vectors. In addition, they can be converted to/from CvScalar . The type Scalar is widely used in OpenCV to pass pixel values. */ @@ -604,15 +671,23 @@ public: typedef _Tp channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = 4, - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; +namespace traits { +template +struct Depth< Scalar_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Scalar_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 4) }; }; +} // namespace /////////////////////////////// KeyPoint //////////////////////////////// @@ -699,6 +774,7 @@ public: CV_PROP_RW int class_id; //!< object class (if the keypoints need to be clustered by an object they belong to) }; +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED template<> class DataType { public: @@ -715,7 +791,7 @@ public: typedef Vec vec_type; }; - +#endif //////////////////////////////// DMatch ///////////////////////////////// @@ -742,6 +818,7 @@ public: bool operator<(const DMatch &m) const; }; +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED template<> class DataType { public: @@ -758,7 +835,7 @@ public: typedef Vec vec_type; }; - +#endif ///////////////////////////// TermCriteria ////////////////////////////// @@ -872,15 +949,24 @@ public: typedef double channel_type; enum { generic_type = 0, - depth = DataType::depth, channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 24 - fmt = DataType::fmt + ((channels - 1) << 8), - type = CV_MAKETYPE(depth, channels) + fmt = DataType::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif }; typedef Vec vec_type; }; +namespace traits { +template<> +struct Depth< Moments > { enum { value = Depth::value }; }; +template<> +struct Type< Moments > { enum { value = CV_MAKETYPE(Depth::value, (int)(sizeof(Moments)/sizeof(double))) }; }; +} // namespace + //! @} imgproc_shape //! @cond IGNORED @@ -1031,7 +1117,8 @@ Complex<_Tp> operator / (const Complex<_Tp>& a, const Complex<_Tp>& b) template static inline Complex<_Tp>& operator /= (Complex<_Tp>& a, const Complex<_Tp>& b) { - return (a = a / b); + a = a / b; + return a; } template static inline @@ -1326,11 +1413,19 @@ Point3_<_Tp>::operator Point3_<_Tp2>() const return Point3_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(z)); } +#if OPENCV_ABI_COMPATIBILITY > 300 +template template inline +Point3_<_Tp>::operator Vec<_Tp2, 3>() const +{ + return Vec<_Tp2, 3>(x, y, z); +} +#else template inline Point3_<_Tp>::operator Vec<_Tp, 3>() const { return Vec<_Tp, 3>(x, y, z); } +#endif template inline Point3_<_Tp>& Point3_<_Tp>::operator = (const Point3_& pt) @@ -1575,9 +1670,19 @@ Size_<_Tp>& Size_<_Tp>::operator = (const Size_<_Tp>& sz) template inline _Tp Size_<_Tp>::area() const { - return width * height; + const _Tp result = width * height; + CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer + || width == 0 || result / width == height); // make sure the result fits in the return value + return result; } +template inline +bool Size_<_Tp>::empty() const +{ + return width <= 0 || height <= 0; +} + + template static inline Size_<_Tp>& operator *= (Size_<_Tp>& a, _Tp b) { @@ -1714,7 +1819,16 @@ Size_<_Tp> Rect_<_Tp>::size() const template inline _Tp Rect_<_Tp>::area() const { - return width * height; + const _Tp result = width * height; + CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer + || width == 0 || result / width == height); // make sure the result fits in the return value + return result; +} + +template inline +bool Rect_<_Tp>::empty() const +{ + return width <= 0 || height <= 0; } template template inline @@ -1779,12 +1893,17 @@ Rect_<_Tp>& operator &= ( Rect_<_Tp>& a, const Rect_<_Tp>& b ) template static inline Rect_<_Tp>& operator |= ( Rect_<_Tp>& a, const Rect_<_Tp>& b ) { - _Tp x1 = std::min(a.x, b.x); - _Tp y1 = std::min(a.y, b.y); - a.width = std::max(a.x + a.width, b.x + b.width) - x1; - a.height = std::max(a.y + a.height, b.y + b.height) - y1; - a.x = x1; - a.y = y1; + if (a.empty()) { + a = b; + } + else if (!b.empty()) { + _Tp x1 = std::min(a.x, b.x); + _Tp y1 = std::min(a.y, b.y); + a.width = std::max(a.x + a.width, b.x + b.width) - x1; + a.height = std::max(a.y + a.height, b.y + b.height) - y1; + a.x = x1; + a.y = y1; + } return a; } @@ -1832,7 +1951,26 @@ Rect_<_Tp> operator | (const Rect_<_Tp>& a, const Rect_<_Tp>& b) return c |= b; } +/** + * @brief measure dissimilarity between two sample sets + * + * computes the complement of the Jaccard Index as described in . + * For rectangles this reduces to computing the intersection over the union. + */ +template static inline +double jaccardDistance(const Rect_<_Tp>& a, const Rect_<_Tp>& b) { + _Tp Aa = a.area(); + _Tp Ab = b.area(); + if ((Aa + Ab) <= std::numeric_limits<_Tp>::epsilon()) { + // jaccard_index = 1 -> distance = 0 + return 0.0; + } + + double Aab = (a & b).area(); + // distance = 1 - jaccard_index + return 1.0 - Aab / (Aa + Ab - Aab); +} ////////////////////////////// RotatedRect ////////////////////////////// @@ -2225,4 +2363,4 @@ TermCriteria::TermCriteria(int _type, int _maxCount, double _epsilon) } // cv -#endif //__OPENCV_CORE_TYPES_HPP__ +#endif //OPENCV_CORE_TYPES_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/types_c.h b/lib/3rdParty/OpenCV3.4/include/opencv2/core/types_c.h similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/types_c.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/types_c.h index cb39587a..4f04d0c0 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/types_c.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/types_c.h @@ -41,12 +41,12 @@ // //M*/ -#ifndef __OPENCV_CORE_TYPES_H__ -#define __OPENCV_CORE_TYPES_H__ +#ifndef OPENCV_CORE_TYPES_H +#define OPENCV_CORE_TYPES_H #ifdef HAVE_IPL # ifndef __IPL_H__ -# if defined WIN32 || defined _WIN32 +# if defined _WIN32 # include # else # include @@ -65,7 +65,7 @@ #include #endif // SKIP_INCLUDES -#if defined WIN32 || defined _WIN32 +#if defined _WIN32 # define CV_CDECL __cdecl # define CV_STDCALL __stdcall #else @@ -130,24 +130,24 @@ enum { CV_BadImageSize= -10, /**< image size is invalid */ CV_BadOffset= -11, /**< offset is invalid */ CV_BadDataPtr= -12, /**/ - CV_BadStep= -13, /**/ + CV_BadStep= -13, /**< image step is wrong, this may happen for a non-continuous matrix */ CV_BadModelOrChSeq= -14, /**/ - CV_BadNumChannels= -15, /**/ + CV_BadNumChannels= -15, /**< bad number of channels, for example, some functions accept only single channel matrices */ CV_BadNumChannel1U= -16, /**/ - CV_BadDepth= -17, /**/ + CV_BadDepth= -17, /**< input image depth is not supported by the function */ CV_BadAlphaChannel= -18, /**/ - CV_BadOrder= -19, /**/ - CV_BadOrigin= -20, /**/ - CV_BadAlign= -21, /**/ + CV_BadOrder= -19, /**< number of dimensions is out of range */ + CV_BadOrigin= -20, /**< incorrect input origin */ + CV_BadAlign= -21, /**< incorrect input align */ CV_BadCallBack= -22, /**/ CV_BadTileSize= -23, /**/ - CV_BadCOI= -24, /**/ - CV_BadROISize= -25, /**/ + CV_BadCOI= -24, /**< input COI is not supported */ + CV_BadROISize= -25, /**< incorrect input roi */ CV_MaskIsTiled= -26, /**/ CV_StsNullPtr= -27, /**< null pointer */ CV_StsVecLengthErr= -28, /**< incorrect vector length */ - CV_StsFilterStructContentErr= -29, /**< incorr. filter structure content */ - CV_StsKernelStructContentErr= -30, /**< incorr. transform kernel content */ + CV_StsFilterStructContentErr= -29, /**< incorrect filter structure content */ + CV_StsKernelStructContentErr= -30, /**< incorrect transform kernel content */ CV_StsFilterOffsetErr= -31, /**< incorrect filter offset value */ CV_StsBadSize= -201, /**< the input/output structure size is incorrect */ CV_StsDivByZero= -202, /**< division by zero */ @@ -163,14 +163,14 @@ enum { CV_StsParseError= -212, /**< invalid syntax/structure of the parsed file */ CV_StsNotImplemented= -213, /**< the requested function/feature is not implemented */ CV_StsBadMemBlock= -214, /**< an allocated block has been corrupted */ - CV_StsAssert= -215, /**< assertion failed */ - CV_GpuNotSupported= -216, - CV_GpuApiCallError= -217, - CV_OpenGlNotSupported= -218, - CV_OpenGlApiCallError= -219, - CV_OpenCLApiCallError= -220, + CV_StsAssert= -215, /**< assertion failed */ + CV_GpuNotSupported= -216, /**< no CUDA support */ + CV_GpuApiCallError= -217, /**< GPU API call error */ + CV_OpenGlNotSupported= -218, /**< no OpenGL support */ + CV_OpenGlApiCallError= -219, /**< OpenGL API call error */ + CV_OpenCLApiCallError= -220, /**< OpenCL API call error */ CV_OpenCLDoubleNotSupported= -221, - CV_OpenCLInitError= -222, + CV_OpenCLInitError= -222, /**< OpenCL initialization error */ CV_OpenCLNoAMDBlasFft= -223 }; @@ -1669,6 +1669,9 @@ typedef struct CvFileStorage CvFileStorage; #define CV_STORAGE_FORMAT_AUTO 0 #define CV_STORAGE_FORMAT_XML 8 #define CV_STORAGE_FORMAT_YAML 16 +#define CV_STORAGE_FORMAT_JSON 24 +#define CV_STORAGE_BASE64 64 +#define CV_STORAGE_WRITE_BASE64 (CV_STORAGE_BASE64 | CV_STORAGE_WRITE) /** @brief List of attributes. : @@ -1829,6 +1832,6 @@ CvModuleInfo; /** @} */ -#endif /*__OPENCV_CORE_TYPES_H__*/ +#endif /*OPENCV_CORE_TYPES_H*/ /* End of file. */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/utility.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/utility.hpp similarity index 72% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/utility.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/utility.hpp index b66ade5c..69d114e1 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/utility.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/utility.hpp @@ -42,14 +42,23 @@ // //M*/ -#ifndef __OPENCV_CORE_UTILITY_H__ -#define __OPENCV_CORE_UTILITY_H__ +#ifndef OPENCV_CORE_UTILITY_H +#define OPENCV_CORE_UTILITY_H #ifndef __cplusplus # error utility.hpp header must be compiled as C++ #endif +#if defined(check) +# warning Detected Apple 'check' macro definition, it can cause build conflicts. Please, include this header before any Apple headers. +#endif + #include "opencv2/core.hpp" +#include + +#ifdef CV_CXX11 +#include +#endif namespace cv { @@ -57,8 +66,8 @@ namespace cv #ifdef CV_COLLECT_IMPL_DATA CV_EXPORTS void setImpl(int flags); // set implementation flags and reset storage arrays CV_EXPORTS void addImpl(int flag, const char* func = 0); // add implementation and function name to storage arrays -// Get stored implementation flags and fucntions names arrays -// Each implementation entry correspond to function name entry, so you can find which implementation was executed in which fucntion +// Get stored implementation flags and functions names arrays +// Each implementation entry correspond to function name entry, so you can find which implementation was executed in which function CV_EXPORTS int getImpl(std::vector &impl, std::vector &funName); CV_EXPORTS bool useCollection(); // return implementation collection state @@ -98,7 +107,7 @@ CV_EXPORTS void setUseCollection(bool flag); // set implementation collection st \code void my_func(const cv::Mat& m) { - cv::AutoBuffer buf; // create automatic buffer containing 1000 floats + cv::AutoBuffer buf(1000); // create automatic buffer containing 1000 floats buf.allocate(m.rows); // if m.rows <= 1000, the pre-allocated buffer is used, // otherwise the buffer of "m.rows" floats will be allocated @@ -133,9 +142,9 @@ public: void resize(size_t _size); //! returns the current buffer size size_t size() const; - //! returns pointer to the real buffer, stack-allocated or head-allocated + //! returns pointer to the real buffer, stack-allocated or heap-allocated operator _Tp* (); - //! returns read-only pointer to the real buffer, stack-allocated or head-allocated + //! returns read-only pointer to the real buffer, stack-allocated or heap-allocated operator const _Tp* () const; protected: @@ -143,7 +152,7 @@ protected: _Tp* ptr; //! size of the real buffer size_t sz; - //! pre-allocated buffer. At least 1 element to confirm C++ standard reqirements + //! pre-allocated buffer. At least 1 element to confirm C++ standard requirements _Tp buf[(fixed_size > 0) ? fixed_size : 1]; }; @@ -189,15 +198,15 @@ If threads == 0, OpenCV will disable threading optimizations and run all it's fu sequentially. Passing threads \< 0 will reset threads number to system default. This function must be called outside of parallel region. -OpenCV will try to run it's functions with specified threads number, but some behaviour differs from +OpenCV will try to run its functions with specified threads number, but some behaviour differs from framework: -- `TBB` – User-defined parallel constructions will run with the same threads number, if - another does not specified. If late on user creates own scheduler, OpenCV will be use it. -- `OpenMP` – No special defined behaviour. -- `Concurrency` – If threads == 1, OpenCV will disable threading optimizations and run it's +- `TBB` - User-defined parallel constructions will run with the same threads number, if + another is not specified. If later on user creates his own scheduler, OpenCV will use it. +- `OpenMP` - No special defined behaviour. +- `Concurrency` - If threads == 1, OpenCV will disable threading optimizations and run its functions sequentially. -- `GCD` – Supports only values \<= 0. -- `C=` – No special defined behaviour. +- `GCD` - Supports only values \<= 0. +- `C=` - No special defined behaviour. @param nthreads Number of threads used by OpenCV. @sa getNumThreads, getThreadNum */ @@ -208,13 +217,13 @@ CV_EXPORTS_W void setNumThreads(int nthreads); Always returns 1 if OpenCV is built without threading support. The exact meaning of return value depends on the threading framework used by OpenCV library: -- `TBB` – The number of threads, that OpenCV will try to use for parallel regions. If there is +- `TBB` - The number of threads, that OpenCV will try to use for parallel regions. If there is any tbb::thread_scheduler_init in user code conflicting with OpenCV, then function returns default number of threads used by TBB library. -- `OpenMP` – An upper bound on the number of threads that could be used to form a new team. -- `Concurrency` – The number of threads, that OpenCV will try to use for parallel regions. -- `GCD` – Unsupported; returns the GCD thread pool limit (512) for compatibility. -- `C=` – The number of threads, that OpenCV will try to use for parallel regions, if before +- `OpenMP` - An upper bound on the number of threads that could be used to form a new team. +- `Concurrency` - The number of threads, that OpenCV will try to use for parallel regions. +- `GCD` - Unsupported; returns the GCD thread pool limit (512) for compatibility. +- `C=` - The number of threads, that OpenCV will try to use for parallel regions, if before called setNumThreads with threads \> 0, otherwise returns the number of logical CPUs, available for the process. @sa setNumThreads, getThreadNum @@ -224,13 +233,13 @@ CV_EXPORTS_W int getNumThreads(); /** @brief Returns the index of the currently executed thread within the current parallel region. Always returns 0 if called outside of parallel region. -The exact meaning of return value depends on the threading framework used by OpenCV library: -- `TBB` – Unsupported with current 4.1 TBB release. May be will be supported in future. -- `OpenMP` – The thread number, within the current team, of the calling thread. -- `Concurrency` – An ID for the virtual processor that the current context is executing on (0 +The exact meaning of the return value depends on the threading framework used by OpenCV library: +- `TBB` - Unsupported with current 4.1 TBB release. Maybe will be supported in future. +- `OpenMP` - The thread number, within the current team, of the calling thread. +- `Concurrency` - An ID for the virtual processor that the current context is executing on (0 for master thread and unique number for others, but not necessary 1,2,3,...). -- `GCD` – System calling thread's ID. Never returns 0 inside parallel region. -- `C=` – The index of the current parallel task. +- `GCD` - System calling thread's ID. Never returns 0 inside parallel region. +- `C=` - The index of the current parallel task. @sa setNumThreads, getNumThreads */ CV_EXPORTS_W int getThreadNum(); @@ -247,7 +256,8 @@ CV_EXPORTS_W const String& getBuildInformation(); The function returns the number of ticks after the certain event (for example, when the machine was turned on). It can be used to initialize RNG or to measure a function execution time by reading the -tick count before and after the function call. See also the tick frequency. +tick count before and after the function call. +@sa getTickFrequency, TickMeter */ CV_EXPORTS_W int64 getTickCount(); @@ -260,9 +270,139 @@ execution time in seconds: // do something ... t = ((double)getTickCount() - t)/getTickFrequency(); @endcode +@sa getTickCount, TickMeter */ CV_EXPORTS_W double getTickFrequency(); +/** @brief a Class to measure passing time. + +The class computes passing time by counting the number of ticks per second. That is, the following code computes the +execution time in seconds: +@code +TickMeter tm; +tm.start(); +// do something ... +tm.stop(); +std::cout << tm.getTimeSec(); +@endcode + +It is also possible to compute the average time over multiple runs: +@code +TickMeter tm; +for (int i = 0; i < 100; i++) +{ + tm.start(); + // do something ... + tm.stop(); +} +double average_time = tm.getTimeSec() / tm.getCounter(); +std::cout << "Average time in second per iteration is: " << average_time << std::endl; +@endcode +@sa getTickCount, getTickFrequency +*/ + +class CV_EXPORTS_W TickMeter +{ +public: + //! the default constructor + CV_WRAP TickMeter() + { + reset(); + } + + /** + starts counting ticks. + */ + CV_WRAP void start() + { + startTime = cv::getTickCount(); + } + + /** + stops counting ticks. + */ + CV_WRAP void stop() + { + int64 time = cv::getTickCount(); + if (startTime == 0) + return; + ++counter; + sumTime += (time - startTime); + startTime = 0; + } + + /** + returns counted ticks. + */ + CV_WRAP int64 getTimeTicks() const + { + return sumTime; + } + + /** + returns passed time in microseconds. + */ + CV_WRAP double getTimeMicro() const + { + return getTimeMilli()*1e3; + } + + /** + returns passed time in milliseconds. + */ + CV_WRAP double getTimeMilli() const + { + return getTimeSec()*1e3; + } + + /** + returns passed time in seconds. + */ + CV_WRAP double getTimeSec() const + { + return (double)getTimeTicks() / getTickFrequency(); + } + + /** + returns internal counter value. + */ + CV_WRAP int64 getCounter() const + { + return counter; + } + + /** + resets internal values. + */ + CV_WRAP void reset() + { + startTime = 0; + sumTime = 0; + counter = 0; + } + +private: + int64 counter; + int64 sumTime; + int64 startTime; +}; + +/** @brief output operator +@code +TickMeter tm; +tm.start(); +// do something ... +tm.stop(); +std::cout << tm; +@endcode +*/ + +static inline +std::ostream& operator << (std::ostream& out, const TickMeter& tm) +{ + return out << tm.getTimeSec() << "sec"; +} + /** @brief Returns the number of CPU ticks. The function returns the current number of CPU ticks on some architectures (such as x86, x64, @@ -301,12 +441,13 @@ The function returns the aligned pointer of the same type as the input pointer: */ template static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp)) { + CV_DbgAssert((n & (n - 1)) == 0); // n is a power of 2 return (_Tp*)(((size_t)ptr + n-1) & -n); } /** @brief Aligns a buffer size to the specified number of bytes. -The function returns the minimum number that is greater or equal to sz and is divisible by n : +The function returns the minimum number that is greater than or equal to sz and is divisible by n : \f[\texttt{(sz + n-1) & -n}\f] @param sz Buffer size to align. @param n Alignment size that must be a power of two. @@ -317,6 +458,23 @@ static inline size_t alignSize(size_t sz, int n) return (sz + n-1) & -n; } +/** @brief Integer division with result round up. + +Use this function instead of `ceil((float)a / b)` expressions. + +@sa alignSize +*/ +static inline int divUp(int a, unsigned int b) +{ + CV_DbgAssert(a >= 0); + return (a + b - 1) / b; +} +/** @overload */ +static inline size_t divUp(size_t a, unsigned int b) +{ + return (a + b - 1) / b; +} + /** @brief Enables or disables the optimized code. The function can be used to dynamically turn on and off optimized code (code that uses SSE2, AVX, @@ -338,7 +496,7 @@ The function returns true if the optimized code is enabled. Otherwise, it return */ CV_EXPORTS_W bool useOptimized(); -static inline size_t getElemSize(int type) { return CV_ELEM_SIZE(type); } +static inline size_t getElemSize(int type) { return (size_t)CV_ELEM_SIZE(type); } /////////////////////////////// Parallel Primitives ////////////////////////////////// @@ -355,15 +513,37 @@ public: */ CV_EXPORTS void parallel_for_(const Range& range, const ParallelLoopBody& body, double nstripes=-1.); +#ifdef CV_CXX11 +class ParallelLoopBodyLambdaWrapper : public ParallelLoopBody +{ +private: + std::function m_functor; +public: + ParallelLoopBodyLambdaWrapper(std::function functor) : + m_functor(functor) + { } + + virtual void operator() (const cv::Range& range) const + { + m_functor(range); + } +}; + +inline void parallel_for_(const Range& range, std::function functor, double nstripes=-1.) +{ + parallel_for_(range, ParallelLoopBodyLambdaWrapper(functor), nstripes); +} +#endif + /////////////////////////////// forEach method of cv::Mat //////////////////////////// template inline void Mat::forEach_impl(const Functor& operation) { if (false) { - operation(*reinterpret_cast<_Tp*>(0), reinterpret_cast(NULL)); - // If your compiler fail in this line. + operation(*reinterpret_cast<_Tp*>(0), reinterpret_cast(0)); + // If your compiler fails in this line. // Please check that your functor signature is - // (_Tp&, const int*) <- multidimential - // or (_Tp&, void*) <- in case of you don't need current idx. + // (_Tp&, const int*) <- multi-dimensional + // or (_Tp&, void*) <- in case you don't need current idx. } CV_Assert(this->total() / this->size[this->dims - 1] <= INT_MAX); @@ -373,8 +553,8 @@ void Mat::forEach_impl(const Functor& operation) { { public: PixelOperationWrapper(Mat_<_Tp>* const frame, const Functor& _operation) - : mat(frame), op(_operation) {}; - virtual ~PixelOperationWrapper(){}; + : mat(frame), op(_operation) {} + virtual ~PixelOperationWrapper(){} // ! Overloaded virtual operator // convert range call to row call. virtual void operator()(const Range &range) const { @@ -385,7 +565,7 @@ void Mat::forEach_impl(const Functor& operation) { this->rowCall2(row, COLS); } } else { - std::vector idx(COLS); /// idx is modified in this->rowCall + std::vector idx(DIMS); /// idx is modified in this->rowCall idx[DIMS - 2] = range.start - 1; for (int line_num = range.start; line_num < range.end; ++line_num) { @@ -403,7 +583,7 @@ void Mat::forEach_impl(const Functor& operation) { this->rowCall(&idx[0], COLS, DIMS); } } - }; + } private: Mat_<_Tp>* const mat; const Functor op; @@ -440,12 +620,12 @@ void Mat::forEach_impl(const Functor& operation) { op(*pixel++, static_cast(idx)); idx[1]++; } - }; + } PixelOperationWrapper& operator=(const PixelOperationWrapper &) { CV_Assert(false); // We can not remove this implementation because Visual Studio warning C4822. return *this; - }; + } }; parallel_for_(cv::Range(0, LINES), PixelOperationWrapper(reinterpret_cast*>(this), operation)); @@ -505,6 +685,9 @@ public: virtual void deleteDataInstance(void* pData) const = 0; int key_; + +public: + void cleanup(); //! Release created TLS data container objects. It is similar to release() call, but it keeps TLS container valid. }; // Main TLS data class @@ -514,22 +697,25 @@ class TLSData : protected TLSDataContainer public: inline TLSData() {} inline ~TLSData() { release(); } // Release key and delete associated data - inline T* get() const { return (T*)getData(); } // Get data assosiated with key + inline T* get() const { return (T*)getData(); } // Get data associated with key + inline T& getRef() const { T* ptr = (T*)getData(); CV_Assert(ptr); return *ptr; } // Get data associated with key - // Get data from all threads + // Get data from all threads inline void gather(std::vector &data) const { std::vector &dataVoid = reinterpret_cast&>(data); gatherData(dataVoid); } + inline void cleanup() { TLSDataContainer::cleanup(); } + private: virtual void* createDataInstance() const {return new T;} // Wrapper to allocate data by template virtual void deleteDataInstance(void* pData) const {delete (T*)pData;} // Wrapper to release data by template // Disable TLS copy operations - TLSData(TLSData &) {}; - TLSData& operator =(const TLSData &) {return *this;}; + TLSData(TLSData &) {} + TLSData& operator =(const TLSData &) {return *this;} }; /** @brief Designed for command line parsing @@ -565,7 +751,7 @@ The sample below demonstrates how to use CommandLineParser: ### Keys syntax -The keys parameter is a string containing several blocks, each one is enclosed in curley braces and +The keys parameter is a string containing several blocks, each one is enclosed in curly braces and describes one argument. Each argument contains three parts separated by the `|` symbol: -# argument names is a space-separated list of option synonyms (to mark argument as positional, prefix it with the `@` symbol) @@ -636,7 +822,7 @@ public: This method returns the path to the executable from the command line (`argv[0]`). - For example, if the application has been started with such command: + For example, if the application has been started with such a command: @code{.sh} $ ./bin/my-executable @endcode @@ -723,7 +909,7 @@ public: /** @brief Check for parsing errors - Returns true if error occured while accessing the parameters (bad conversion, missing arguments, + Returns true if error occurred while accessing the parameters (bad conversion, missing arguments, etc.). Call @ref printErrors to print error messages list. */ bool check() const; @@ -742,7 +928,7 @@ public: */ void printMessage() const; - /** @brief Print list of errors occured + /** @brief Print list of errors occurred @sa check */ @@ -813,10 +999,10 @@ AutoBuffer<_Tp, fixed_size>::allocate(size_t _size) return; } deallocate(); + sz = _size; if(_size > fixed_size) { ptr = new _Tp[_size]; - sz = _size; } } @@ -867,7 +1053,6 @@ template inline AutoBuffer<_Tp, fixed_size>::operator const _Tp* () const { return ptr; } -#ifndef OPENCV_NOSTL template<> inline std::string CommandLineParser::get(int index, bool space_delete) const { return get(index, space_delete); @@ -876,14 +1061,179 @@ template<> inline std::string CommandLineParser::get(const String& { return get(name, space_delete); } -#endif // OPENCV_NOSTL //! @endcond + +// Basic Node class for tree building +template +class CV_EXPORTS Node +{ +public: + Node() + { + m_pParent = 0; + } + Node(OBJECT& payload) : m_payload(payload) + { + m_pParent = 0; + } + ~Node() + { + removeChilds(); + if (m_pParent) + { + int idx = m_pParent->findChild(this); + if (idx >= 0) + m_pParent->m_childs.erase(m_pParent->m_childs.begin() + idx); + } + } + + Node* findChild(OBJECT& payload) const + { + for(size_t i = 0; i < this->m_childs.size(); i++) + { + if(this->m_childs[i]->m_payload == payload) + return this->m_childs[i]; + } + return NULL; + } + + int findChild(Node *pNode) const + { + for (size_t i = 0; i < this->m_childs.size(); i++) + { + if(this->m_childs[i] == pNode) + return (int)i; + } + return -1; + } + + void addChild(Node *pNode) + { + if(!pNode) + return; + + CV_Assert(pNode->m_pParent == 0); + pNode->m_pParent = this; + this->m_childs.push_back(pNode); + } + + void removeChilds() + { + for(size_t i = 0; i < m_childs.size(); i++) + { + m_childs[i]->m_pParent = 0; // avoid excessive parent vector trimming + delete m_childs[i]; + } + m_childs.clear(); + } + + int getDepth() + { + int count = 0; + Node *pParent = m_pParent; + while(pParent) count++, pParent = pParent->m_pParent; + return count; + } + +public: + OBJECT m_payload; + Node* m_pParent; + std::vector*> m_childs; +}; + +// Instrumentation external interface +namespace instr +{ + +#if !defined OPENCV_ABI_CHECK + +enum TYPE +{ + TYPE_GENERAL = 0, // OpenCV API function, e.g. exported function + TYPE_MARKER, // Information marker + TYPE_WRAPPER, // Wrapper function for implementation + TYPE_FUN, // Simple function call +}; + +enum IMPL +{ + IMPL_PLAIN = 0, + IMPL_IPP, + IMPL_OPENCL, +}; + +struct NodeDataTls +{ + NodeDataTls() + { + m_ticksTotal = 0; + } + uint64 m_ticksTotal; +}; + +class CV_EXPORTS NodeData +{ +public: + NodeData(const char* funName = 0, const char* fileName = NULL, int lineNum = 0, void* retAddress = NULL, bool alwaysExpand = false, cv::instr::TYPE instrType = TYPE_GENERAL, cv::instr::IMPL implType = IMPL_PLAIN); + NodeData(NodeData &ref); + ~NodeData(); + NodeData& operator=(const NodeData&); + + cv::String m_funName; + cv::instr::TYPE m_instrType; + cv::instr::IMPL m_implType; + const char* m_fileName; + int m_lineNum; + void* m_retAddress; + bool m_alwaysExpand; + bool m_funError; + + volatile int m_counter; + volatile uint64 m_ticksTotal; + TLSData m_tls; + int m_threads; + + // No synchronization + double getTotalMs() const { return ((double)m_ticksTotal / cv::getTickFrequency()) * 1000; } + double getMeanMs() const { return (((double)m_ticksTotal/m_counter) / cv::getTickFrequency()) * 1000; } +}; +bool operator==(const NodeData& lhs, const NodeData& rhs); + +typedef Node InstrNode; + +CV_EXPORTS InstrNode* getTrace(); + +#endif // !defined OPENCV_ABI_CHECK + + +CV_EXPORTS bool useInstrumentation(); +CV_EXPORTS void setUseInstrumentation(bool flag); +CV_EXPORTS void resetTrace(); + +enum FLAGS +{ + FLAGS_NONE = 0, + FLAGS_MAPPING = 0x01, + FLAGS_EXPAND_SAME_NAMES = 0x02, +}; + +CV_EXPORTS void setFlags(FLAGS modeFlags); +static inline void setFlags(int modeFlags) { setFlags((FLAGS)modeFlags); } +CV_EXPORTS FLAGS getFlags(); +} + +namespace utils { + +CV_EXPORTS int getThreadID(); + +} // namespace + } //namespace cv #ifndef DISABLE_OPENCV_24_COMPATIBILITY #include "opencv2/core/core_c.h" #endif -#endif //__OPENCV_CORE_UTILITY_H__ +#endif //OPENCV_CORE_UTILITY_H diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/filesystem.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/filesystem.hpp new file mode 100644 index 00000000..12b10a76 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/filesystem.hpp @@ -0,0 +1,71 @@ +// 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. + +#ifndef OPENCV_UTILS_FILESYSTEM_HPP +#define OPENCV_UTILS_FILESYSTEM_HPP + +namespace cv { namespace utils { namespace fs { + + +CV_EXPORTS bool exists(const cv::String& path); +CV_EXPORTS bool isDirectory(const cv::String& path); + +CV_EXPORTS void remove_all(const cv::String& path); + + +CV_EXPORTS cv::String getcwd(); + +/** Join path components */ +CV_EXPORTS cv::String join(const cv::String& base, const cv::String& path); + +/** + * Generate a list of all files that match the globbing pattern. + * + * Result entries are prefixed by base directory path. + * + * @param directory base directory + * @param pattern filter pattern (based on '*'/'?' symbols). Use empty string to disable filtering and return all results + * @param[out] result result of globing. + * @param recursive scan nested directories too + * @param includeDirectories include directories into results list + */ +CV_EXPORTS void glob(const cv::String& directory, const cv::String& pattern, + CV_OUT std::vector& result, + bool recursive = false, bool includeDirectories = false); + +/** + * Generate a list of all files that match the globbing pattern. + * + * @param directory base directory + * @param pattern filter pattern (based on '*'/'?' symbols). Use empty string to disable filtering and return all results + * @param[out] result globbing result with relative paths from base directory + * @param recursive scan nested directories too + * @param includeDirectories include directories into results list + */ +CV_EXPORTS void glob_relative(const cv::String& directory, const cv::String& pattern, + CV_OUT std::vector& result, + bool recursive = false, bool includeDirectories = false); + + +CV_EXPORTS bool createDirectory(const cv::String& path); +CV_EXPORTS bool createDirectories(const cv::String& path); + +#ifdef __OPENCV_BUILD +// TODO +//CV_EXPORTS cv::String getTempDirectory(); + +/** + * @brief Returns directory to store OpenCV cache files + * Create sub-directory in common OpenCV cache directory if it doesn't exist. + * @param sub_directory_name name of sub-directory. NULL or "" value asks to return root cache directory. + * @param configuration_name optional name of configuration parameter name which overrides default behavior. + * @return Path to cache directory. Returns empty string if cache directories support is not available. Returns "disabled" if cache disabled by user. + */ +CV_EXPORTS cv::String getCacheDirectory(const char* sub_directory_name, const char* configuration_name = NULL); + +#endif + +}}} // namespace + +#endif // OPENCV_UTILS_FILESYSTEM_HPP diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/logger.defines.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/logger.defines.hpp new file mode 100644 index 00000000..b2dfc417 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/logger.defines.hpp @@ -0,0 +1,22 @@ +// 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. + +#ifndef OPENCV_LOGGER_DEFINES_HPP +#define OPENCV_LOGGER_DEFINES_HPP + +//! @addtogroup core_logging +//! @{ + +// Supported logging levels and their semantic +#define CV_LOG_LEVEL_SILENT 0 //!< for using in setLogLevel() call +#define CV_LOG_LEVEL_FATAL 1 //!< Fatal (critical) error (unrecoverable internal error) +#define CV_LOG_LEVEL_ERROR 2 //!< Error message +#define CV_LOG_LEVEL_WARN 3 //!< Warning message +#define CV_LOG_LEVEL_INFO 4 //!< Info message +#define CV_LOG_LEVEL_DEBUG 5 //!< Debug message. Disabled in the "Release" build. +#define CV_LOG_LEVEL_VERBOSE 6 //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build. + +//! @} + +#endif // OPENCV_LOGGER_DEFINES_HPP diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/logger.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/logger.hpp new file mode 100644 index 00000000..47094f99 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/logger.hpp @@ -0,0 +1,87 @@ +// 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. + +#ifndef OPENCV_LOGGER_HPP +#define OPENCV_LOGGER_HPP + +#include +#include +#include // INT_MAX + +#include "logger.defines.hpp" + +//! @addtogroup core_logging +// This section describes OpenCV logging utilities. +// +//! @{ + +namespace cv { +namespace utils { +namespace logging { + +//! Supported logging levels and their semantic +enum LogLevel { + LOG_LEVEL_SILENT = 0, //!< for using in setLogVevel() call + LOG_LEVEL_FATAL = 1, //!< Fatal (critical) error (unrecoverable internal error) + LOG_LEVEL_ERROR = 2, //!< Error message + LOG_LEVEL_WARNING = 3, //!< Warning message + LOG_LEVEL_INFO = 4, //!< Info message + LOG_LEVEL_DEBUG = 5, //!< Debug message. Disabled in the "Release" build. + LOG_LEVEL_VERBOSE = 6, //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build. +#ifndef CV_DOXYGEN + ENUM_LOG_LEVEL_FORCE_INT = INT_MAX +#endif +}; + +/** Set global logging level +@return previous logging level +*/ +CV_EXPORTS LogLevel setLogLevel(LogLevel logLevel); +/** Get global logging level */ +CV_EXPORTS LogLevel getLogLevel(); + +namespace internal { +/** Write log message */ +CV_EXPORTS void writeLogMessage(LogLevel logLevel, const char* message); +} // namespace + +/** + * \def CV_LOG_STRIP_LEVEL + * + * Define CV_LOG_STRIP_LEVEL=CV_LOG_LEVEL_[DEBUG|INFO|WARN|ERROR|FATAL|DISABLED] to compile out anything at that and before that logging level + */ +#ifndef CV_LOG_STRIP_LEVEL +# if defined NDEBUG +# define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_DEBUG +# else +# define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_VERBOSE +# endif +#endif + + +#define CV_LOG_FATAL(tag, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_FATAL) break; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_FATAL, ss.str().c_str()); break; } +#define CV_LOG_ERROR(tag, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_ERROR) break; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_ERROR, ss.str().c_str()); break; } +#define CV_LOG_WARNING(tag, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_WARNING) break; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_WARNING, ss.str().c_str()); break; } +#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO +#define CV_LOG_INFO(tag, ...) +#else +#define CV_LOG_INFO(tag, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_INFO) break; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_INFO, ss.str().c_str()); break; } +#endif +#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_DEBUG +#define CV_LOG_DEBUG(tag, ...) +#else +#define CV_LOG_DEBUG(tag, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_DEBUG) break; std::stringstream ss; ss << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_DEBUG, ss.str().c_str()); break; } +#endif +#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_VERBOSE +#define CV_LOG_VERBOSE(tag, v, ...) +#else +#define CV_LOG_VERBOSE(tag, v, ...) for(;;) { if (cv::utils::logging::getLogLevel() < cv::utils::logging::LOG_LEVEL_VERBOSE) break; std::stringstream ss; ss << "[VERB" << v << ":" << cv::utils::getThreadID() << "] " << __VA_ARGS__; cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LOG_LEVEL_VERBOSE, ss.str().c_str()); break; } +#endif + + +}}} // namespace + +//! @} + +#endif // OPENCV_LOGGER_HPP diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/trace.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/trace.hpp new file mode 100644 index 00000000..1539fb9a --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/utils/trace.hpp @@ -0,0 +1,250 @@ +// 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. + +#ifndef OPENCV_TRACE_HPP +#define OPENCV_TRACE_HPP + +#include + +//! @addtogroup core_logging +// This section describes OpenCV tracing utilities. +// +//! @{ + +namespace cv { +namespace utils { +namespace trace { + +//! Macro to trace function +#define CV_TRACE_FUNCTION() + +#define CV_TRACE_FUNCTION_SKIP_NESTED() + +//! Trace code scope. +//! @note Dynamic names are not supported in this macro (on stack or heap). Use string literals here only, like "initialize". +#define CV_TRACE_REGION(name_as_static_string_literal) +//! mark completed of the current opened region and create new one +//! @note Dynamic names are not supported in this macro (on stack or heap). Use string literals here only, like "step1". +#define CV_TRACE_REGION_NEXT(name_as_static_string_literal) + +//! Macro to trace argument value +#define CV_TRACE_ARG(arg_id) + +//! Macro to trace argument value (expanded version) +#define CV_TRACE_ARG_VALUE(arg_id, arg_name, value) + +//! @cond IGNORED +#define CV_TRACE_NS cv::utils::trace + +namespace details { + +#ifndef __OPENCV_TRACE +# if defined __OPENCV_BUILD && !defined __OPENCV_TESTS && !defined __OPENCV_APPS +# define __OPENCV_TRACE 1 +# else +# define __OPENCV_TRACE 0 +# endif +#endif + +#ifndef CV_TRACE_FILENAME +# define CV_TRACE_FILENAME __FILE__ +#endif + +#ifndef CV__TRACE_FUNCTION +# if defined _MSC_VER +# define CV__TRACE_FUNCTION __FUNCSIG__ +# elif defined __GNUC__ +# define CV__TRACE_FUNCTION __PRETTY_FUNCTION__ +# else +# define CV__TRACE_FUNCTION "" +# endif +#endif + +//! Thread-local instance (usually allocated on stack) +class CV_EXPORTS Region +{ +public: + struct LocationExtraData; + struct LocationStaticStorage + { + LocationExtraData** ppExtra; //< implementation specific data + const char* name; //< region name (function name or other custom name) + const char* filename; //< source code filename + int line; //< source code line + int flags; //< flags (implementation code path: Plain, IPP, OpenCL) + }; + + Region(const LocationStaticStorage& location); + inline ~Region() + { + if (implFlags != 0) + destroy(); + CV_DbgAssert(implFlags == 0); + CV_DbgAssert(pImpl == NULL); + } + + class Impl; + Impl* pImpl; // NULL if current region is not active + int implFlags; // see RegionFlag, 0 if region is ignored + + bool isActive() const { return pImpl != NULL; } + + void destroy(); +private: + Region(const Region&); // disabled + Region& operator= (const Region&); // disabled +}; + +//! Specify region flags +enum RegionLocationFlag { + REGION_FLAG_FUNCTION = (1 << 0), //< region is function (=1) / nested named region (=0) + REGION_FLAG_APP_CODE = (1 << 1), //< region is Application code (=1) / OpenCV library code (=0) + REGION_FLAG_SKIP_NESTED = (1 << 2), //< avoid processing of nested regions + + REGION_FLAG_IMPL_IPP = (1 << 16), //< region is part of IPP code path + REGION_FLAG_IMPL_OPENCL = (2 << 16), //< region is part of OpenCL code path + REGION_FLAG_IMPL_OPENVX = (3 << 16), //< region is part of OpenVX code path + + REGION_FLAG_IMPL_MASK = (15 << 16), + + REGION_FLAG_REGION_FORCE = (1 << 30), + REGION_FLAG_REGION_NEXT = (1 << 31), //< close previous region (see #CV_TRACE_REGION_NEXT macro) + + ENUM_REGION_FLAG_FORCE_INT = INT_MAX +}; + +struct CV_EXPORTS TraceArg { +public: + struct ExtraData; + ExtraData** ppExtra; + const char* name; + int flags; +}; +/** @brief Add meta information to current region (function) + * See CV_TRACE_ARG macro + * @param arg argument information structure (global static cache) + * @param value argument value (can by dynamic string literal in case of string, static allocation is not required) + */ +CV_EXPORTS void traceArg(const TraceArg& arg, const char* value); +//! @overload +CV_EXPORTS void traceArg(const TraceArg& arg, int value); +//! @overload +CV_EXPORTS void traceArg(const TraceArg& arg, int64 value); +//! @overload +CV_EXPORTS void traceArg(const TraceArg& arg, double value); + +#define CV__TRACE_LOCATION_VARNAME(loc_id) CVAUX_CONCAT(CVAUX_CONCAT(__cv_trace_location_, loc_id), __LINE__) +#define CV__TRACE_LOCATION_EXTRA_VARNAME(loc_id) CVAUX_CONCAT(CVAUX_CONCAT(__cv_trace_location_extra_, loc_id) , __LINE__) + +#define CV__TRACE_DEFINE_LOCATION_(loc_id, name, flags) \ + static CV_TRACE_NS::details::Region::LocationExtraData* CV__TRACE_LOCATION_EXTRA_VARNAME(loc_id) = 0; \ + static const CV_TRACE_NS::details::Region::LocationStaticStorage \ + CV__TRACE_LOCATION_VARNAME(loc_id) = { &(CV__TRACE_LOCATION_EXTRA_VARNAME(loc_id)), name, CV_TRACE_FILENAME, __LINE__, flags}; + +#define CV__TRACE_DEFINE_LOCATION_FN(name, flags) CV__TRACE_DEFINE_LOCATION_(fn, name, (flags | CV_TRACE_NS::details::REGION_FLAG_FUNCTION)) + + +#define CV__TRACE_OPENCV_FUNCTION() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, 0); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_OPENCV_FUNCTION_NAME(name) \ + CV__TRACE_DEFINE_LOCATION_FN(name, 0); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_APP_FUNCTION() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, CV_TRACE_NS::details::REGION_FLAG_APP_CODE); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_APP_FUNCTION_NAME(name) \ + CV__TRACE_DEFINE_LOCATION_FN(name, CV_TRACE_NS::details::REGION_FLAG_APP_CODE); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + + +#define CV__TRACE_OPENCV_FUNCTION_SKIP_NESTED() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, CV_TRACE_NS::details::REGION_FLAG_SKIP_NESTED); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_OPENCV_FUNCTION_NAME_SKIP_NESTED(name) \ + CV__TRACE_DEFINE_LOCATION_FN(name, CV_TRACE_NS::details::REGION_FLAG_SKIP_NESTED); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_APP_FUNCTION_SKIP_NESTED() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, CV_TRACE_NS::details::REGION_FLAG_SKIP_NESTED | CV_TRACE_NS::details::REGION_FLAG_APP_CODE); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + + +#define CV__TRACE_REGION_(name_as_static_string_literal, flags) \ + CV__TRACE_DEFINE_LOCATION_(region, name_as_static_string_literal, flags); \ + CV_TRACE_NS::details::Region CVAUX_CONCAT(__region_, __LINE__)(CV__TRACE_LOCATION_VARNAME(region)); + +#define CV__TRACE_REGION(name_as_static_string_literal) CV__TRACE_REGION_(name_as_static_string_literal, 0) +#define CV__TRACE_REGION_NEXT(name_as_static_string_literal) CV__TRACE_REGION_(name_as_static_string_literal, CV_TRACE_NS::details::REGION_FLAG_REGION_NEXT) + +#define CV__TRACE_ARG_VARNAME(arg_id) CVAUX_CONCAT(__cv_trace_arg_ ## arg_id, __LINE__) +#define CV__TRACE_ARG_EXTRA_VARNAME(arg_id) CVAUX_CONCAT(__cv_trace_arg_extra_ ## arg_id, __LINE__) + +#define CV__TRACE_DEFINE_ARG_(arg_id, name, flags) \ + static CV_TRACE_NS::details::TraceArg::ExtraData* CV__TRACE_ARG_EXTRA_VARNAME(arg_id) = 0; \ + static const CV_TRACE_NS::details::TraceArg \ + CV__TRACE_ARG_VARNAME(arg_id) = { &(CV__TRACE_ARG_EXTRA_VARNAME(arg_id)), name, flags }; + +#define CV__TRACE_ARG_VALUE(arg_id, arg_name, value) \ + CV__TRACE_DEFINE_ARG_(arg_id, arg_name, 0); \ + CV_TRACE_NS::details::traceArg((CV__TRACE_ARG_VARNAME(arg_id)), value); + +#define CV__TRACE_ARG(arg_id) CV_TRACE_ARG_VALUE(arg_id, #arg_id, (arg_id)) + +} // namespace + +#ifndef OPENCV_DISABLE_TRACE +#undef CV_TRACE_FUNCTION +#undef CV_TRACE_FUNCTION_SKIP_NESTED +#if __OPENCV_TRACE +#define CV_TRACE_FUNCTION CV__TRACE_OPENCV_FUNCTION +#define CV_TRACE_FUNCTION_SKIP_NESTED CV__TRACE_OPENCV_FUNCTION_SKIP_NESTED +#else +#define CV_TRACE_FUNCTION CV__TRACE_APP_FUNCTION +#define CV_TRACE_FUNCTION_SKIP_NESTED CV__TRACE_APP_FUNCTION_SKIP_NESTED +#endif + +#undef CV_TRACE_REGION +#define CV_TRACE_REGION CV__TRACE_REGION + +#undef CV_TRACE_REGION_NEXT +#define CV_TRACE_REGION_NEXT CV__TRACE_REGION_NEXT + +#undef CV_TRACE_ARG_VALUE +#define CV_TRACE_ARG_VALUE(arg_id, arg_name, value) \ + if (__region_fn.isActive()) \ + { \ + CV__TRACE_ARG_VALUE(arg_id, arg_name, value); \ + } + +#undef CV_TRACE_ARG +#define CV_TRACE_ARG CV__TRACE_ARG + +#endif // OPENCV_DISABLE_TRACE + +#ifdef OPENCV_TRACE_VERBOSE +#define CV_TRACE_FUNCTION_VERBOSE CV_TRACE_FUNCTION +#define CV_TRACE_REGION_VERBOSE CV_TRACE_REGION +#define CV_TRACE_REGION_NEXT_VERBOSE CV_TRACE_REGION_NEXT +#define CV_TRACE_ARG_VALUE_VERBOSE CV_TRACE_ARG_VALUE +#define CV_TRACE_ARG_VERBOSE CV_TRACE_ARG +#else +#define CV_TRACE_FUNCTION_VERBOSE(...) +#define CV_TRACE_REGION_VERBOSE(...) +#define CV_TRACE_REGION_NEXT_VERBOSE(...) +#define CV_TRACE_ARG_VALUE_VERBOSE(...) +#define CV_TRACE_ARG_VERBOSE(...) +#endif + +//! @endcond + +}}} // namespace + +//! @} + +#endif // OPENCV_TRACE_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/va_intel.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/va_intel.hpp similarity index 95% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/va_intel.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/va_intel.hpp index f4bb8a65..33258484 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/va_intel.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/va_intel.hpp @@ -5,8 +5,8 @@ // Copyright (C) 2015, Itseez, Inc., all rights reserved. // Third party copyrights are property of their respective owners. -#ifndef __OPENCV_CORE_VA_INTEL_HPP__ -#define __OPENCV_CORE_VA_INTEL_HPP__ +#ifndef OPENCV_CORE_VA_INTEL_HPP +#define OPENCV_CORE_VA_INTEL_HPP #ifndef __cplusplus # error va_intel.hpp header must be compiled as C++ @@ -74,4 +74,4 @@ CV_EXPORTS void convertFromVASurface(VADisplay display, VASurfaceID surface, Siz }} // namespace cv::va_intel -#endif /* __OPENCV_CORE_VA_INTEL_HPP__ */ +#endif /* OPENCV_CORE_VA_INTEL_HPP */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/version.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/version.hpp similarity index 95% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/version.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/version.hpp index cf1442b5..308389ce 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/version.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/version.hpp @@ -47,18 +47,18 @@ Usefull to test in user programs */ -#ifndef __OPENCV_VERSION_HPP__ -#define __OPENCV_VERSION_HPP__ +#ifndef OPENCV_VERSION_HPP +#define OPENCV_VERSION_HPP #define CV_VERSION_MAJOR 3 -#define CV_VERSION_MINOR 1 +#define CV_VERSION_MINOR 4 #define CV_VERSION_REVISION 0 #define CV_VERSION_STATUS "" #define CVAUX_STR_EXP(__A) #__A #define CVAUX_STR(__A) CVAUX_STR_EXP(__A) -#define CVAUX_STRW_EXP(__A) L#__A +#define CVAUX_STRW_EXP(__A) L ## #__A #define CVAUX_STRW(__A) CVAUX_STRW_EXP(__A) #define CV_VERSION CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION) CV_VERSION_STATUS diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/core/vsx_utils.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/vsx_utils.hpp new file mode 100644 index 00000000..3888cbfc --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/vsx_utils.hpp @@ -0,0 +1,1070 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_HAL_VSX_UTILS_HPP +#define OPENCV_HAL_VSX_UTILS_HPP + +#include "opencv2/core/cvdef.h" + +//! @addtogroup core_utils_vsx +//! @{ +#if CV_VSX + +#define __VSX_S16__(c, v) (c){v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v} +#define __VSX_S8__(c, v) (c){v, v, v, v, v, v, v, v} +#define __VSX_S4__(c, v) (c){v, v, v, v} +#define __VSX_S2__(c, v) (c){v, v} + +typedef __vector unsigned char vec_uchar16; +#define vec_uchar16_set(...) (vec_uchar16){__VA_ARGS__} +#define vec_uchar16_sp(c) (__VSX_S16__(vec_uchar16, c)) +#define vec_uchar16_c(v) ((vec_uchar16)(v)) +#define vec_uchar16_mx vec_uchar16_sp(0xFF) +#define vec_uchar16_mn vec_uchar16_sp(0) +#define vec_uchar16_z vec_uchar16_mn + +typedef __vector signed char vec_char16; +#define vec_char16_set(...) (vec_char16){__VA_ARGS__} +#define vec_char16_sp(c) (__VSX_S16__(vec_char16, c)) +#define vec_char16_c(v) ((vec_char16)(v)) +#define vec_char16_mx vec_char16_sp(0x7F) +#define vec_char16_mn vec_char16_sp(-0x7F-1) +#define vec_char16_z vec_char16_sp(0) + +typedef __vector unsigned short vec_ushort8; +#define vec_ushort8_set(...) (vec_ushort8){__VA_ARGS__} +#define vec_ushort8_sp(c) (__VSX_S8__(vec_ushort8, c)) +#define vec_ushort8_c(v) ((vec_ushort8)(v)) +#define vec_ushort8_mx vec_ushort8_sp(0xFFFF) +#define vec_ushort8_mn vec_ushort8_sp(0) +#define vec_ushort8_z vec_ushort8_mn + +typedef __vector signed short vec_short8; +#define vec_short8_set(...) (vec_short8){__VA_ARGS__} +#define vec_short8_sp(c) (__VSX_S8__(vec_short8, c)) +#define vec_short8_c(v) ((vec_short8)(v)) +#define vec_short8_mx vec_short8_sp(0x7FFF) +#define vec_short8_mn vec_short8_sp(-0x7FFF-1) +#define vec_short8_z vec_short8_sp(0) + +typedef __vector unsigned int vec_uint4; +#define vec_uint4_set(...) (vec_uint4){__VA_ARGS__} +#define vec_uint4_sp(c) (__VSX_S4__(vec_uint4, c)) +#define vec_uint4_c(v) ((vec_uint4)(v)) +#define vec_uint4_mx vec_uint4_sp(0xFFFFFFFFU) +#define vec_uint4_mn vec_uint4_sp(0) +#define vec_uint4_z vec_uint4_mn + +typedef __vector signed int vec_int4; +#define vec_int4_set(...) (vec_int4){__VA_ARGS__} +#define vec_int4_sp(c) (__VSX_S4__(vec_int4, c)) +#define vec_int4_c(v) ((vec_int4)(v)) +#define vec_int4_mx vec_int4_sp(0x7FFFFFFF) +#define vec_int4_mn vec_int4_sp(-0x7FFFFFFF-1) +#define vec_int4_z vec_int4_sp(0) + +typedef __vector float vec_float4; +#define vec_float4_set(...) (vec_float4){__VA_ARGS__} +#define vec_float4_sp(c) (__VSX_S4__(vec_float4, c)) +#define vec_float4_c(v) ((vec_float4)(v)) +#define vec_float4_mx vec_float4_sp(3.40282347E+38F) +#define vec_float4_mn vec_float4_sp(1.17549435E-38F) +#define vec_float4_z vec_float4_sp(0) + +typedef __vector unsigned long long vec_udword2; +#define vec_udword2_set(...) (vec_udword2){__VA_ARGS__} +#define vec_udword2_sp(c) (__VSX_S2__(vec_udword2, c)) +#define vec_udword2_c(v) ((vec_udword2)(v)) +#define vec_udword2_mx vec_udword2_sp(18446744073709551615ULL) +#define vec_udword2_mn vec_udword2_sp(0) +#define vec_udword2_z vec_udword2_mn + +typedef __vector signed long long vec_dword2; +#define vec_dword2_set(...) (vec_dword2){__VA_ARGS__} +#define vec_dword2_sp(c) (__VSX_S2__(vec_dword2, c)) +#define vec_dword2_c(v) ((vec_dword2)(v)) +#define vec_dword2_mx vec_dword2_sp(9223372036854775807LL) +#define vec_dword2_mn vec_dword2_sp(-9223372036854775807LL-1) +#define vec_dword2_z vec_dword2_sp(0) + +typedef __vector double vec_double2; +#define vec_double2_set(...) (vec_double2){__VA_ARGS__} +#define vec_double2_c(v) ((vec_double2)(v)) +#define vec_double2_sp(c) (__VSX_S2__(vec_double2, c)) +#define vec_double2_mx vec_double2_sp(1.7976931348623157E+308) +#define vec_double2_mn vec_double2_sp(2.2250738585072014E-308) +#define vec_double2_z vec_double2_sp(0) + +#define vec_bchar16 __vector __bool char +#define vec_bchar16_set(...) (vec_bchar16){__VA_ARGS__} +#define vec_bchar16_c(v) ((vec_bchar16)(v)) +#define vec_bchar16_f (__VSX_S16__(vec_bchar16, 0)) +#define vec_bchar16_t (__VSX_S16__(vec_bchar16, 1)) + +#define vec_bshort8 __vector __bool short +#define vec_bshort8_set(...) (vec_bshort8){__VA_ARGS__} +#define vec_bshort8_c(v) ((vec_bshort8)(v)) +#define vec_bshort8_f (__VSX_S8__(vec_bshort8, 0)) +#define vec_bshort8_t (__VSX_S8__(vec_bshort8, 1)) + +#define vec_bint4 __vector __bool int +#define vec_bint4_set(...) (vec_bint4){__VA_ARGS__} +#define vec_bint4_c(v) ((vec_bint4)(v)) +#define vec_bint4_f (__VSX_S4__(vec_bint4, 0)) +#define vec_bint4_t (__VSX_S4__(vec_bint4, 1)) + +#define vec_bdword2 __vector __bool long long +#define vec_bdword2_set(...) (vec_bdword2){__VA_ARGS__} +#define vec_bdword2_c(v) ((vec_bdword2)(v)) +#define vec_bdword2_f (__VSX_S2__(vec_bdword2, 0)) +#define vec_bdword2_t (__VSX_S2__(vec_bdword2, 1)) + + +#define VSX_FINLINE(tp) extern inline tp __attribute__((always_inline)) + +#define VSX_REDIRECT_1RG(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) { return fn2(a); } + +#define VSX_REDIRECT_2RG(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a, const rg& b) { return fn2(a, b); } + +/* + * GCC VSX compatibility +**/ +#if defined(__GNUG__) && !defined(__clang__) + +// inline asm helper +#define VSX_IMPL_1RG(rt, rto, rg, rgo, opc, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ rt rs; __asm__ __volatile__(#opc" %x0,%x1" : "="#rto (rs) : #rgo (a)); return rs; } + +#define VSX_IMPL_1VRG(rt, rg, opc, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ rt rs; __asm__ __volatile__(#opc" %0,%1" : "=v" (rs) : "v" (a)); return rs; } + +#define VSX_IMPL_2VRG_F(rt, rg, fopc, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a, const rg& b) \ +{ rt rs; __asm__ __volatile__(fopc : "=v" (rs) : "v" (a), "v" (b)); return rs; } + +#define VSX_IMPL_2VRG(rt, rg, opc, fnm) VSX_IMPL_2VRG_F(rt, rg, #opc" %0,%1,%2", fnm) + +#if __GNUG__ < 7 +// up to GCC 6 vec_mul only supports precisions and llong +# ifdef vec_mul +# undef vec_mul +# endif +/* + * there's no a direct instruction for supporting 16-bit multiplication in ISA 2.07, + * XLC Implement it by using instruction "multiply even", "multiply odd" and "permute" + * todo: Do I need to support 8-bit ? +**/ +# define VSX_IMPL_MULH(Tvec, Tcast) \ + VSX_FINLINE(Tvec) vec_mul(const Tvec& a, const Tvec& b) \ + { \ + static const vec_uchar16 even_perm = {0, 1, 16, 17, 4, 5, 20, 21, \ + 8, 9, 24, 25, 12, 13, 28, 29}; \ + return vec_perm(Tcast(vec_mule(a, b)), Tcast(vec_mulo(a, b)), even_perm); \ + } + VSX_IMPL_MULH(vec_short8, vec_short8_c) + VSX_IMPL_MULH(vec_ushort8, vec_ushort8_c) + // vmuluwm can be used for unsigned or signed integers, that's what they said + VSX_IMPL_2VRG(vec_int4, vec_int4, vmuluwm, vec_mul) + VSX_IMPL_2VRG(vec_uint4, vec_uint4, vmuluwm, vec_mul) + // redirect to GCC builtin vec_mul, since it already supports precisions and llong + VSX_REDIRECT_2RG(vec_float4, vec_float4, vec_mul, __builtin_vec_mul) + VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mul, __builtin_vec_mul) + VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mul, __builtin_vec_mul) + VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mul, __builtin_vec_mul) +#endif // __GNUG__ < 7 + +#if __GNUG__ < 6 +/* + * Instruction "compare greater than or equal" in ISA 2.07 only supports single + * and double precision. + * In XLC and new versions of GCC implement integers by using instruction "greater than" and NOR. +**/ +# ifdef vec_cmpge +# undef vec_cmpge +# endif +# ifdef vec_cmple +# undef vec_cmple +# endif +# define vec_cmple(a, b) vec_cmpge(b, a) +# define VSX_IMPL_CMPGE(rt, rg, opc, fnm) \ + VSX_IMPL_2VRG_F(rt, rg, #opc" %0,%2,%1\n\t xxlnor %x0,%x0,%x0", fnm) + + VSX_IMPL_CMPGE(vec_bchar16, vec_char16, vcmpgtsb, vec_cmpge) + VSX_IMPL_CMPGE(vec_bchar16, vec_uchar16, vcmpgtub, vec_cmpge) + VSX_IMPL_CMPGE(vec_bshort8, vec_short8, vcmpgtsh, vec_cmpge) + VSX_IMPL_CMPGE(vec_bshort8, vec_ushort8, vcmpgtuh, vec_cmpge) + VSX_IMPL_CMPGE(vec_bint4, vec_int4, vcmpgtsw, vec_cmpge) + VSX_IMPL_CMPGE(vec_bint4, vec_uint4, vcmpgtuw, vec_cmpge) + VSX_IMPL_CMPGE(vec_bdword2, vec_dword2, vcmpgtsd, vec_cmpge) + VSX_IMPL_CMPGE(vec_bdword2, vec_udword2, vcmpgtud, vec_cmpge) + +// redirect to GCC builtin cmpge, since it already supports precisions + VSX_REDIRECT_2RG(vec_bint4, vec_float4, vec_cmpge, __builtin_vec_cmpge) + VSX_REDIRECT_2RG(vec_bdword2, vec_double2, vec_cmpge, __builtin_vec_cmpge) + +// up to gcc5 vec_nor doesn't support bool long long +# undef vec_nor + template + VSX_REDIRECT_2RG(T, T, vec_nor, __builtin_vec_nor) + + VSX_FINLINE(vec_bdword2) vec_nor(const vec_bdword2& a, const vec_bdword2& b) + { return vec_bdword2_c(__builtin_vec_nor(vec_dword2_c(a), vec_dword2_c(b))); } + +// vec_packs doesn't support double words in gcc4 and old versions of gcc5 +# undef vec_packs + VSX_REDIRECT_2RG(vec_char16, vec_short8, vec_packs, __builtin_vec_packs) + VSX_REDIRECT_2RG(vec_uchar16, vec_ushort8, vec_packs, __builtin_vec_packs) + VSX_REDIRECT_2RG(vec_short8, vec_int4, vec_packs, __builtin_vec_packs) + VSX_REDIRECT_2RG(vec_ushort8, vec_uint4, vec_packs, __builtin_vec_packs) + + VSX_IMPL_2VRG_F(vec_int4, vec_dword2, "vpksdss %0,%2,%1", vec_packs) + VSX_IMPL_2VRG_F(vec_uint4, vec_udword2, "vpkudus %0,%2,%1", vec_packs) +#endif // __GNUG__ < 6 + +#if __GNUG__ < 5 +// vec_xxpermdi in gcc4 missing little-endian supports just like clang +# define vec_permi(a, b, c) vec_xxpermdi(b, a, (3 ^ ((c & 1) << 1 | c >> 1))) +#else +# define vec_permi vec_xxpermdi +#endif // __GNUG__ < 5 + +// shift left double by word immediate +#ifndef vec_sldw +# define vec_sldw __builtin_vsx_xxsldwi +#endif + +// vector population count +VSX_IMPL_1VRG(vec_uchar16, vec_uchar16, vpopcntb, vec_popcntu) +VSX_IMPL_1VRG(vec_uchar16, vec_char16, vpopcntb, vec_popcntu) +VSX_IMPL_1VRG(vec_ushort8, vec_ushort8, vpopcnth, vec_popcntu) +VSX_IMPL_1VRG(vec_ushort8, vec_short8, vpopcnth, vec_popcntu) +VSX_IMPL_1VRG(vec_uint4, vec_uint4, vpopcntw, vec_popcntu) +VSX_IMPL_1VRG(vec_uint4, vec_int4, vpopcntw, vec_popcntu) +VSX_IMPL_1VRG(vec_udword2, vec_udword2, vpopcntd, vec_popcntu) +VSX_IMPL_1VRG(vec_udword2, vec_dword2, vpopcntd, vec_popcntu) + +// converts between single and double-precision +VSX_REDIRECT_1RG(vec_float4, vec_double2, vec_cvfo, __builtin_vsx_xvcvdpsp) +VSX_REDIRECT_1RG(vec_double2, vec_float4, vec_cvfo, __builtin_vsx_xvcvspdp) + +// converts word and doubleword to double-precision +#ifdef vec_ctd +# undef vec_ctd +#endif +VSX_IMPL_1RG(vec_double2, wd, vec_int4, wa, xvcvsxwdp, vec_ctdo) +VSX_IMPL_1RG(vec_double2, wd, vec_uint4, wa, xvcvuxwdp, vec_ctdo) +VSX_IMPL_1RG(vec_double2, wd, vec_dword2, wi, xvcvsxddp, vec_ctd) +VSX_IMPL_1RG(vec_double2, wd, vec_udword2, wi, xvcvuxddp, vec_ctd) + +// converts word and doubleword to single-precision +#undef vec_ctf +VSX_IMPL_1RG(vec_float4, wf, vec_int4, wa, xvcvsxwsp, vec_ctf) +VSX_IMPL_1RG(vec_float4, wf, vec_uint4, wa, xvcvuxwsp, vec_ctf) +VSX_IMPL_1RG(vec_float4, wf, vec_dword2, wi, xvcvsxdsp, vec_ctfo) +VSX_IMPL_1RG(vec_float4, wf, vec_udword2, wi, xvcvuxdsp, vec_ctfo) + +// converts single and double precision to signed word +#undef vec_cts +VSX_IMPL_1RG(vec_int4, wa, vec_double2, wd, xvcvdpsxws, vec_ctso) +VSX_IMPL_1RG(vec_int4, wa, vec_float4, wf, xvcvspsxws, vec_cts) + +// converts single and double precision to unsigned word +#undef vec_ctu +VSX_IMPL_1RG(vec_uint4, wa, vec_double2, wd, xvcvdpuxws, vec_ctuo) +VSX_IMPL_1RG(vec_uint4, wa, vec_float4, wf, xvcvspuxws, vec_ctu) + +// converts single and double precision to signed doubleword +#ifdef vec_ctsl +# undef vec_ctsl +#endif +VSX_IMPL_1RG(vec_dword2, wi, vec_double2, wd, xvcvdpsxds, vec_ctsl) +VSX_IMPL_1RG(vec_dword2, wi, vec_float4, wf, xvcvspsxds, vec_ctslo) + +// converts single and double precision to unsigned doubleword +#ifdef vec_ctul +# undef vec_ctul +#endif +VSX_IMPL_1RG(vec_udword2, wi, vec_double2, wd, xvcvdpuxds, vec_ctul) +VSX_IMPL_1RG(vec_udword2, wi, vec_float4, wf, xvcvspuxds, vec_ctulo) + +// just in case if GCC doesn't define it +#ifndef vec_xl +# define vec_xl vec_vsx_ld +# define vec_xst vec_vsx_st +#endif + +#endif // GCC VSX compatibility + +/* + * CLANG VSX compatibility +**/ +#if defined(__clang__) && !defined(__IBMCPP__) + +/* + * CLANG doesn't support %x in the inline asm template which fixes register number + * when using any of the register constraints wa, wd, wf + * + * For more explanation checkout PowerPC and IBM RS6000 in https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html + * Also there's already an open bug https://bugs.llvm.org/show_bug.cgi?id=31837 + * + * So we're not able to use inline asm and only use built-in functions that CLANG supports + * and use __builtin_convertvector if clang missng any of vector conversions built-in functions +*/ + +// convert vector helper +#define VSX_IMPL_CONVERT(rt, rg, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) { return __builtin_convertvector(a, rt); } + +#if __clang_major__ < 5 +// implement vec_permi in a dirty way +# define VSX_IMPL_CLANG_4_PERMI(Tvec) \ + VSX_FINLINE(Tvec) vec_permi(const Tvec& a, const Tvec& b, unsigned const char c) \ + { \ + switch (c) \ + { \ + case 0: \ + return vec_mergeh(a, b); \ + case 1: \ + return vec_mergel(vec_mergeh(a, a), b); \ + case 2: \ + return vec_mergeh(vec_mergel(a, a), b); \ + default: \ + return vec_mergel(a, b); \ + } \ + } + VSX_IMPL_CLANG_4_PERMI(vec_udword2) + VSX_IMPL_CLANG_4_PERMI(vec_dword2) + VSX_IMPL_CLANG_4_PERMI(vec_double2) + +// vec_xxsldwi is missing in clang 4 +# define vec_xxsldwi(a, b, c) vec_sld(a, b, (c) * 4) +#else +// vec_xxpermdi is missing little-endian supports in clang 4 just like gcc4 +# define vec_permi(a, b, c) vec_xxpermdi(b, a, (3 ^ ((c & 1) << 1 | c >> 1))) +#endif // __clang_major__ < 5 + +// shift left double by word immediate +#ifndef vec_sldw +# define vec_sldw vec_xxsldwi +#endif + +// Implement vec_rsqrt since clang only supports vec_rsqrte +#ifndef vec_rsqrt + VSX_FINLINE(vec_float4) vec_rsqrt(const vec_float4& a) + { return vec_div(vec_float4_sp(1), vec_sqrt(a)); } + + VSX_FINLINE(vec_double2) vec_rsqrt(const vec_double2& a) + { return vec_div(vec_double2_sp(1), vec_sqrt(a)); } +#endif + +// vec_promote missing support for doubleword +VSX_FINLINE(vec_dword2) vec_promote(long long a, int b) +{ + vec_dword2 ret = vec_dword2_z; + ret[b & 1] = a; + return ret; +} + +VSX_FINLINE(vec_udword2) vec_promote(unsigned long long a, int b) +{ + vec_udword2 ret = vec_udword2_z; + ret[b & 1] = a; + return ret; +} + +// vec_popcnt should return unsigned but clang has different thought just like gcc in vec_vpopcnt +#define VSX_IMPL_POPCNTU(Tvec, Tvec2, ucast) \ +VSX_FINLINE(Tvec) vec_popcntu(const Tvec2& a) \ +{ return ucast(vec_popcnt(a)); } +VSX_IMPL_POPCNTU(vec_uchar16, vec_char16, vec_uchar16_c); +VSX_IMPL_POPCNTU(vec_ushort8, vec_short8, vec_ushort8_c); +VSX_IMPL_POPCNTU(vec_uint4, vec_int4, vec_uint4_c); +// redirect unsigned types +VSX_REDIRECT_1RG(vec_uchar16, vec_uchar16, vec_popcntu, vec_popcnt) +VSX_REDIRECT_1RG(vec_ushort8, vec_ushort8, vec_popcntu, vec_popcnt) +VSX_REDIRECT_1RG(vec_uint4, vec_uint4, vec_popcntu, vec_popcnt) + +// converts between single and double precision +VSX_REDIRECT_1RG(vec_float4, vec_double2, vec_cvfo, __builtin_vsx_xvcvdpsp) +VSX_REDIRECT_1RG(vec_double2, vec_float4, vec_cvfo, __builtin_vsx_xvcvspdp) + +// converts word and doubleword to double-precision +#ifdef vec_ctd +# undef vec_ctd +#endif +VSX_REDIRECT_1RG(vec_double2, vec_int4, vec_ctdo, __builtin_vsx_xvcvsxwdp) +VSX_REDIRECT_1RG(vec_double2, vec_uint4, vec_ctdo, __builtin_vsx_xvcvuxwdp) + +VSX_IMPL_CONVERT(vec_double2, vec_dword2, vec_ctd) +VSX_IMPL_CONVERT(vec_double2, vec_udword2, vec_ctd) + +// converts word and doubleword to single-precision +#if __clang_major__ > 4 +# undef vec_ctf +#endif +VSX_IMPL_CONVERT(vec_float4, vec_int4, vec_ctf) +VSX_IMPL_CONVERT(vec_float4, vec_uint4, vec_ctf) +VSX_REDIRECT_1RG(vec_float4, vec_dword2, vec_ctfo, __builtin_vsx_xvcvsxdsp) +VSX_REDIRECT_1RG(vec_float4, vec_udword2, vec_ctfo, __builtin_vsx_xvcvuxdsp) + +// converts single and double precision to signed word +#if __clang_major__ > 4 +# undef vec_cts +#endif +VSX_REDIRECT_1RG(vec_int4, vec_double2, vec_ctso, __builtin_vsx_xvcvdpsxws) +VSX_IMPL_CONVERT(vec_int4, vec_float4, vec_cts) + +// converts single and double precision to unsigned word +#if __clang_major__ > 4 +# undef vec_ctu +#endif +VSX_REDIRECT_1RG(vec_uint4, vec_double2, vec_ctuo, __builtin_vsx_xvcvdpuxws) +VSX_IMPL_CONVERT(vec_uint4, vec_float4, vec_ctu) + +// converts single and double precision to signed doubleword +#ifdef vec_ctsl +# undef vec_ctsl +#endif +VSX_IMPL_CONVERT(vec_dword2, vec_double2, vec_ctsl) +// __builtin_convertvector unable to convert, xvcvspsxds is missing on it +VSX_FINLINE(vec_dword2) vec_ctslo(const vec_float4& a) +{ return vec_ctsl(vec_cvfo(a)); } + +// converts single and double precision to unsigned doubleword +#ifdef vec_ctul +# undef vec_ctul +#endif +VSX_IMPL_CONVERT(vec_udword2, vec_double2, vec_ctul) +// __builtin_convertvector unable to convert, xvcvspuxds is missing on it +VSX_FINLINE(vec_udword2) vec_ctulo(const vec_float4& a) +{ return vec_ctul(vec_cvfo(a)); } + +#endif // CLANG VSX compatibility + +/* + * Common GCC, CLANG compatibility +**/ +#if defined(__GNUG__) && !defined(__IBMCPP__) + +#ifdef vec_cvf +# undef vec_cvf +#endif + +#define VSX_IMPL_CONV_EVEN_4_2(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ return fn2(vec_sldw(a, a, 1)); } + +VSX_IMPL_CONV_EVEN_4_2(vec_double2, vec_float4, vec_cvf, vec_cvfo) +VSX_IMPL_CONV_EVEN_4_2(vec_double2, vec_int4, vec_ctd, vec_ctdo) +VSX_IMPL_CONV_EVEN_4_2(vec_double2, vec_uint4, vec_ctd, vec_ctdo) + +VSX_IMPL_CONV_EVEN_4_2(vec_dword2, vec_float4, vec_ctsl, vec_ctslo) +VSX_IMPL_CONV_EVEN_4_2(vec_udword2, vec_float4, vec_ctul, vec_ctulo) + +#define VSX_IMPL_CONV_EVEN_2_4(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ \ + rt v4 = fn2(a); \ + return vec_sldw(v4, v4, 3); \ +} + +VSX_IMPL_CONV_EVEN_2_4(vec_float4, vec_double2, vec_cvf, vec_cvfo) +VSX_IMPL_CONV_EVEN_2_4(vec_float4, vec_dword2, vec_ctf, vec_ctfo) +VSX_IMPL_CONV_EVEN_2_4(vec_float4, vec_udword2, vec_ctf, vec_ctfo) + +VSX_IMPL_CONV_EVEN_2_4(vec_int4, vec_double2, vec_cts, vec_ctso) +VSX_IMPL_CONV_EVEN_2_4(vec_uint4, vec_double2, vec_ctu, vec_ctuo) + +#endif // Common GCC, CLANG compatibility + +/* + * XLC VSX compatibility +**/ +#if defined(__IBMCPP__) + +// vector population count +#define vec_popcntu vec_popcnt + +// overload and redirect wih setting second arg to zero +// since we only support conversions without the second arg +#define VSX_IMPL_OVERLOAD_Z2(rt, rg, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) { return fnm(a, 0); } + +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_int4, vec_ctd) +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_uint4, vec_ctd) +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_dword2, vec_ctd) +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_udword2, vec_ctd) + +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_int4, vec_ctf) +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_uint4, vec_ctf) +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_dword2, vec_ctf) +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_udword2, vec_ctf) + +VSX_IMPL_OVERLOAD_Z2(vec_int4, vec_double2, vec_cts) +VSX_IMPL_OVERLOAD_Z2(vec_int4, vec_float4, vec_cts) + +VSX_IMPL_OVERLOAD_Z2(vec_uint4, vec_double2, vec_ctu) +VSX_IMPL_OVERLOAD_Z2(vec_uint4, vec_float4, vec_ctu) + +VSX_IMPL_OVERLOAD_Z2(vec_dword2, vec_double2, vec_ctsl) +VSX_IMPL_OVERLOAD_Z2(vec_dword2, vec_float4, vec_ctsl) + +VSX_IMPL_OVERLOAD_Z2(vec_udword2, vec_double2, vec_ctul) +VSX_IMPL_OVERLOAD_Z2(vec_udword2, vec_float4, vec_ctul) + +// fixme: implement conversions of odd-numbered elements in a dirty way +// since xlc doesn't support VSX registers operand in inline asm. +#define VSX_IMPL_CONV_ODD_4_2(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) { return fn2(vec_sldw(a, a, 3)); } + +VSX_IMPL_CONV_ODD_4_2(vec_double2, vec_float4, vec_cvfo, vec_cvf) +VSX_IMPL_CONV_ODD_4_2(vec_double2, vec_int4, vec_ctdo, vec_ctd) +VSX_IMPL_CONV_ODD_4_2(vec_double2, vec_uint4, vec_ctdo, vec_ctd) + +VSX_IMPL_CONV_ODD_4_2(vec_dword2, vec_float4, vec_ctslo, vec_ctsl) +VSX_IMPL_CONV_ODD_4_2(vec_udword2, vec_float4, vec_ctulo, vec_ctul) + +#define VSX_IMPL_CONV_ODD_2_4(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ \ + rt v4 = fn2(a); \ + return vec_sldw(v4, v4, 1); \ +} + +VSX_IMPL_CONV_ODD_2_4(vec_float4, vec_double2, vec_cvfo, vec_cvf) +VSX_IMPL_CONV_ODD_2_4(vec_float4, vec_dword2, vec_ctfo, vec_ctf) +VSX_IMPL_CONV_ODD_2_4(vec_float4, vec_udword2, vec_ctfo, vec_ctf) + +VSX_IMPL_CONV_ODD_2_4(vec_int4, vec_double2, vec_ctso, vec_cts) +VSX_IMPL_CONV_ODD_2_4(vec_uint4, vec_double2, vec_ctuo, vec_ctu) + +#endif // XLC VSX compatibility + +// ignore GCC warning that casued by -Wunused-but-set-variable in rare cases +#if defined(__GNUG__) && !defined(__clang__) +# define VSX_UNUSED(Tvec) Tvec __attribute__((__unused__)) +#else // CLANG, XLC +# define VSX_UNUSED(Tvec) Tvec +#endif + +// gcc can find his way in casting log int and XLC, CLANG ambiguous +#if defined(__clang__) || defined(__IBMCPP__) + VSX_FINLINE(vec_udword2) vec_splats(uint64 v) + { return vec_splats((unsigned long long) v); } + + VSX_FINLINE(vec_dword2) vec_splats(int64 v) + { return vec_splats((long long) v); } + + VSX_FINLINE(vec_udword2) vec_promote(uint64 a, int b) + { return vec_promote((unsigned long long) a, b); } + + VSX_FINLINE(vec_dword2) vec_promote(int64 a, int b) + { return vec_promote((long long) a, b); } +#endif + +/* + * implement vsx_ld(offset, pointer), vsx_st(vector, offset, pointer) + * load and set using offset depend on the pointer type + * + * implement vsx_ldf(offset, pointer), vsx_stf(vector, offset, pointer) + * load and set using offset depend on fixed bytes size + * + * Note: In clang vec_xl and vec_xst fails to load unaligned addresses + * so we are using vec_vsx_ld, vec_vsx_st instead +*/ + +#if defined(__clang__) && !defined(__IBMCPP__) +# define vsx_ldf vec_vsx_ld +# define vsx_stf vec_vsx_st +#else // GCC , XLC +# define vsx_ldf vec_xl +# define vsx_stf vec_xst +#endif + +#define VSX_OFFSET(o, p) ((o) * sizeof(*(p))) +#define vsx_ld(o, p) vsx_ldf(VSX_OFFSET(o, p), p) +#define vsx_st(v, o, p) vsx_stf(v, VSX_OFFSET(o, p), p) + +/* + * implement vsx_ld2(offset, pointer), vsx_st2(vector, offset, pointer) to load and store double words + * In GCC vec_xl and vec_xst it maps to vec_vsx_ld, vec_vsx_st which doesn't support long long + * and in CLANG we are using vec_vsx_ld, vec_vsx_st because vec_xl, vec_xst fails to load unaligned addresses + * + * In XLC vec_xl and vec_xst fail to cast int64(long int) to long long +*/ +#if (defined(__GNUG__) || defined(__clang__)) && !defined(__IBMCPP__) + VSX_FINLINE(vec_udword2) vsx_ld2(long o, const uint64* p) + { return vec_udword2_c(vsx_ldf(VSX_OFFSET(o, p), (unsigned int*)p)); } + + VSX_FINLINE(vec_dword2) vsx_ld2(long o, const int64* p) + { return vec_dword2_c(vsx_ldf(VSX_OFFSET(o, p), (int*)p)); } + + VSX_FINLINE(void) vsx_st2(const vec_udword2& vec, long o, uint64* p) + { vsx_stf(vec_uint4_c(vec), VSX_OFFSET(o, p), (unsigned int*)p); } + + VSX_FINLINE(void) vsx_st2(const vec_dword2& vec, long o, int64* p) + { vsx_stf(vec_int4_c(vec), VSX_OFFSET(o, p), (int*)p); } +#else // XLC + VSX_FINLINE(vec_udword2) vsx_ld2(long o, const uint64* p) + { return vsx_ldf(VSX_OFFSET(o, p), (unsigned long long*)p); } + + VSX_FINLINE(vec_dword2) vsx_ld2(long o, const int64* p) + { return vsx_ldf(VSX_OFFSET(o, p), (long long*)p); } + + VSX_FINLINE(void) vsx_st2(const vec_udword2& vec, long o, uint64* p) + { vsx_stf(vec, VSX_OFFSET(o, p), (unsigned long long*)p); } + + VSX_FINLINE(void) vsx_st2(const vec_dword2& vec, long o, int64* p) + { vsx_stf(vec, VSX_OFFSET(o, p), (long long*)p); } +#endif + +// load 4 unsigned bytes into uint4 vector +#define vec_ld_buw(p) vec_uint4_set((p)[0], (p)[1], (p)[2], (p)[3]) + +// load 4 signed bytes into int4 vector +#define vec_ld_bsw(p) vec_int4_set((p)[0], (p)[1], (p)[2], (p)[3]) + +// load 4 unsigned bytes into float vector +#define vec_ld_bps(p) vec_ctf(vec_ld_buw(p), 0) + +// Store lower 8 byte +#define vec_st_l8(v, p) *((uint64*)(p)) = vec_extract(vec_udword2_c(v), 0) + +// Store higher 8 byte +#define vec_st_h8(v, p) *((uint64*)(p)) = vec_extract(vec_udword2_c(v), 1) + +/* + * vec_ld_l8(ptr) -> Load 64-bits of integer data to lower part + * vec_ldz_l8(ptr) -> Load 64-bits of integer data to lower part and zero upper part +**/ +#define VSX_IMPL_LOAD_L8(Tvec, Tp) \ +VSX_FINLINE(Tvec) vec_ld_l8(const Tp *p) \ +{ return ((Tvec)vec_promote(*((uint64*)p), 0)); } \ +VSX_FINLINE(Tvec) vec_ldz_l8(const Tp *p) \ +{ \ + /* TODO: try (Tvec)(vec_udword2{*((uint64*)p), 0}) */ \ + static const vec_bdword2 mask = {0xFFFFFFFFFFFFFFFF, 0x0000000000000000}; \ + return vec_and(vec_ld_l8(p), (Tvec)mask); \ +} +VSX_IMPL_LOAD_L8(vec_uchar16, uchar) +VSX_IMPL_LOAD_L8(vec_char16, schar) +VSX_IMPL_LOAD_L8(vec_ushort8, ushort) +VSX_IMPL_LOAD_L8(vec_short8, short) +VSX_IMPL_LOAD_L8(vec_uint4, uint) +VSX_IMPL_LOAD_L8(vec_int4, int) +VSX_IMPL_LOAD_L8(vec_float4, float) +VSX_IMPL_LOAD_L8(vec_udword2, uint64) +VSX_IMPL_LOAD_L8(vec_dword2, int64) +VSX_IMPL_LOAD_L8(vec_double2, double) + +// logical not +#define vec_not(a) vec_nor(a, a) + +// power9 yaya +// not equal +#ifndef vec_cmpne +# define vec_cmpne(a, b) vec_not(vec_cmpeq(a, b)) +#endif + +// absoulte difference +#ifndef vec_absd +# define vec_absd(a, b) vec_sub(vec_max(a, b), vec_min(a, b)) +#endif + +/* + * Implement vec_unpacklu and vec_unpackhu + * since vec_unpackl, vec_unpackh only support signed integers +**/ +#define VSX_IMPL_UNPACKU(rt, rg, zero) \ +VSX_FINLINE(rt) vec_unpacklu(const rg& a) \ +{ return reinterpret_cast(vec_mergel(a, zero)); } \ +VSX_FINLINE(rt) vec_unpackhu(const rg& a) \ +{ return reinterpret_cast(vec_mergeh(a, zero)); } + +VSX_IMPL_UNPACKU(vec_ushort8, vec_uchar16, vec_uchar16_z) +VSX_IMPL_UNPACKU(vec_uint4, vec_ushort8, vec_ushort8_z) +VSX_IMPL_UNPACKU(vec_udword2, vec_uint4, vec_uint4_z) + +/* + * Implement vec_mergesqe and vec_mergesqo + * Merges the sequence values of even and odd elements of two vectors +*/ +#define VSX_IMPL_PERM(rt, fnm, ...) \ +VSX_FINLINE(rt) fnm(const rt& a, const rt& b) \ +{ static const vec_uchar16 perm = {__VA_ARGS__}; return vec_perm(a, b, perm); } + +// 16 +#define perm16_mergesqe 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 +#define perm16_mergesqo 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31 +VSX_IMPL_PERM(vec_uchar16, vec_mergesqe, perm16_mergesqe) +VSX_IMPL_PERM(vec_uchar16, vec_mergesqo, perm16_mergesqo) +VSX_IMPL_PERM(vec_char16, vec_mergesqe, perm16_mergesqe) +VSX_IMPL_PERM(vec_char16, vec_mergesqo, perm16_mergesqo) +// 8 +#define perm8_mergesqe 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 +#define perm8_mergesqo 2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31 +VSX_IMPL_PERM(vec_ushort8, vec_mergesqe, perm8_mergesqe) +VSX_IMPL_PERM(vec_ushort8, vec_mergesqo, perm8_mergesqo) +VSX_IMPL_PERM(vec_short8, vec_mergesqe, perm8_mergesqe) +VSX_IMPL_PERM(vec_short8, vec_mergesqo, perm8_mergesqo) +// 4 +#define perm4_mergesqe 0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19, 24, 25, 26, 27 +#define perm4_mergesqo 4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31 +VSX_IMPL_PERM(vec_uint4, vec_mergesqe, perm4_mergesqe) +VSX_IMPL_PERM(vec_uint4, vec_mergesqo, perm4_mergesqo) +VSX_IMPL_PERM(vec_int4, vec_mergesqe, perm4_mergesqe) +VSX_IMPL_PERM(vec_int4, vec_mergesqo, perm4_mergesqo) +VSX_IMPL_PERM(vec_float4, vec_mergesqe, perm4_mergesqe) +VSX_IMPL_PERM(vec_float4, vec_mergesqo, perm4_mergesqo) +// 2 +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesqe, vec_mergeh) +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesqo, vec_mergel) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesqe, vec_mergeh) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesqo, vec_mergel) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesqe, vec_mergeh) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesqo, vec_mergel) + +/* + * Implement vec_mergesqh and vec_mergesql + * Merges the sequence most and least significant halves of two vectors +*/ +#define VSX_IMPL_MERGESQHL(Tvec) \ +VSX_FINLINE(Tvec) vec_mergesqh(const Tvec& a, const Tvec& b) \ +{ return (Tvec)vec_mergeh(vec_udword2_c(a), vec_udword2_c(b)); } \ +VSX_FINLINE(Tvec) vec_mergesql(const Tvec& a, const Tvec& b) \ +{ return (Tvec)vec_mergel(vec_udword2_c(a), vec_udword2_c(b)); } +VSX_IMPL_MERGESQHL(vec_uchar16) +VSX_IMPL_MERGESQHL(vec_char16) +VSX_IMPL_MERGESQHL(vec_ushort8) +VSX_IMPL_MERGESQHL(vec_short8) +VSX_IMPL_MERGESQHL(vec_uint4) +VSX_IMPL_MERGESQHL(vec_int4) +VSX_IMPL_MERGESQHL(vec_float4) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesqh, vec_mergeh) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesql, vec_mergel) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesqh, vec_mergeh) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesql, vec_mergel) +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesqh, vec_mergeh) +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesql, vec_mergel) + + +// 2 and 4 channels interleave for all types except 2 lanes +#define VSX_IMPL_ST_INTERLEAVE(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, Tp* ptr) \ +{ \ + vsx_stf(vec_mergeh(a, b), 0, ptr); \ + vsx_stf(vec_mergel(a, b), 16, ptr); \ +} \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, const Tvec& d, Tp* ptr) \ +{ \ + Tvec ac = vec_mergeh(a, c); \ + Tvec bd = vec_mergeh(b, d); \ + vsx_stf(vec_mergeh(ac, bd), 0, ptr); \ + vsx_stf(vec_mergel(ac, bd), 16, ptr); \ + ac = vec_mergel(a, c); \ + bd = vec_mergel(b, d); \ + vsx_stf(vec_mergeh(ac, bd), 32, ptr); \ + vsx_stf(vec_mergel(ac, bd), 48, ptr); \ +} +VSX_IMPL_ST_INTERLEAVE(uchar, vec_uchar16) +VSX_IMPL_ST_INTERLEAVE(schar, vec_char16) +VSX_IMPL_ST_INTERLEAVE(ushort, vec_ushort8) +VSX_IMPL_ST_INTERLEAVE(short, vec_short8) +VSX_IMPL_ST_INTERLEAVE(uint, vec_uint4) +VSX_IMPL_ST_INTERLEAVE(int, vec_int4) +VSX_IMPL_ST_INTERLEAVE(float, vec_float4) + +// 2 and 4 channels deinterleave for 16 lanes +#define VSX_IMPL_ST_DINTERLEAVE_8(Tp, Tvec) \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(16, ptr); \ + a = vec_mergesqe(v0, v1); \ + b = vec_mergesqo(v0, v1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(16, ptr); \ + Tvec v2 = vsx_ld(32, ptr); \ + Tvec v3 = vsx_ld(48, ptr); \ + Tvec m0 = vec_mergesqe(v0, v1); \ + Tvec m1 = vec_mergesqe(v2, v3); \ + a = vec_mergesqe(m0, m1); \ + c = vec_mergesqo(m0, m1); \ + m0 = vec_mergesqo(v0, v1); \ + m1 = vec_mergesqo(v2, v3); \ + b = vec_mergesqe(m0, m1); \ + d = vec_mergesqo(m0, m1); \ +} +VSX_IMPL_ST_DINTERLEAVE_8(uchar, vec_uchar16) +VSX_IMPL_ST_DINTERLEAVE_8(schar, vec_char16) + +// 2 and 4 channels deinterleave for 8 lanes +#define VSX_IMPL_ST_DINTERLEAVE_16(Tp, Tvec) \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(8, ptr); \ + a = vec_mergesqe(v0, v1); \ + b = vec_mergesqo(v0, v1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(8, ptr); \ + Tvec m0 = vec_mergeh(v0, v1); \ + Tvec m1 = vec_mergel(v0, v1); \ + Tvec ab0 = vec_mergeh(m0, m1); \ + Tvec cd0 = vec_mergel(m0, m1); \ + v0 = vsx_ld(16, ptr); \ + v1 = vsx_ld(24, ptr); \ + m0 = vec_mergeh(v0, v1); \ + m1 = vec_mergel(v0, v1); \ + Tvec ab1 = vec_mergeh(m0, m1); \ + Tvec cd1 = vec_mergel(m0, m1); \ + a = vec_mergesqh(ab0, ab1); \ + b = vec_mergesql(ab0, ab1); \ + c = vec_mergesqh(cd0, cd1); \ + d = vec_mergesql(cd0, cd1); \ +} +VSX_IMPL_ST_DINTERLEAVE_16(ushort, vec_ushort8) +VSX_IMPL_ST_DINTERLEAVE_16(short, vec_short8) + +// 2 and 4 channels deinterleave for 4 lanes +#define VSX_IMPL_ST_DINTERLEAVE_32(Tp, Tvec) \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + a = vsx_ld(0, ptr); \ + b = vsx_ld(4, ptr); \ + Tvec m0 = vec_mergeh(a, b); \ + Tvec m1 = vec_mergel(a, b); \ + a = vec_mergeh(m0, m1); \ + b = vec_mergel(m0, m1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(4, ptr); \ + Tvec v2 = vsx_ld(8, ptr); \ + Tvec v3 = vsx_ld(12, ptr); \ + Tvec m0 = vec_mergeh(v0, v2); \ + Tvec m1 = vec_mergeh(v1, v3); \ + a = vec_mergeh(m0, m1); \ + b = vec_mergel(m0, m1); \ + m0 = vec_mergel(v0, v2); \ + m1 = vec_mergel(v1, v3); \ + c = vec_mergeh(m0, m1); \ + d = vec_mergel(m0, m1); \ +} +VSX_IMPL_ST_DINTERLEAVE_32(uint, vec_uint4) +VSX_IMPL_ST_DINTERLEAVE_32(int, vec_int4) +VSX_IMPL_ST_DINTERLEAVE_32(float, vec_float4) + +// 2 and 4 channels interleave and deinterleave for 2 lanes +#define VSX_IMPL_ST_D_INTERLEAVE_64(Tp, Tvec, ld_func, st_func) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, Tp* ptr) \ +{ \ + st_func(vec_mergeh(a, b), 0, ptr); \ + st_func(vec_mergel(a, b), 2, ptr); \ +} \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, const Tvec& d, Tp* ptr) \ +{ \ + st_func(vec_mergeh(a, b), 0, ptr); \ + st_func(vec_mergeh(c, d), 2, ptr); \ + st_func(vec_mergel(a, b), 4, ptr); \ + st_func(vec_mergel(c, d), 6, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + Tvec m0 = ld_func(0, ptr); \ + Tvec m1 = ld_func(2, ptr); \ + a = vec_mergeh(m0, m1); \ + b = vec_mergel(m0, m1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = ld_func(0, ptr); \ + Tvec v1 = ld_func(2, ptr); \ + Tvec v2 = ld_func(4, ptr); \ + Tvec v3 = ld_func(6, ptr); \ + a = vec_mergeh(v0, v2); \ + b = vec_mergel(v0, v2); \ + c = vec_mergeh(v1, v3); \ + d = vec_mergel(v1, v3); \ +} +VSX_IMPL_ST_D_INTERLEAVE_64(int64, vec_dword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_D_INTERLEAVE_64(uint64, vec_udword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_D_INTERLEAVE_64(double, vec_double2, vsx_ld, vsx_st) + +/* 3 channels */ +#define VSX_IMPL_ST_INTERLEAVE_3CH_16(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + static const vec_uchar16 a12 = {0, 16, 0, 1, 17, 0, 2, 18, 0, 3, 19, 0, 4, 20, 0, 5}; \ + static const vec_uchar16 a123 = {0, 1, 16, 3, 4, 17, 6, 7, 18, 9, 10, 19, 12, 13, 20, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, a12), c, a123), 0, ptr); \ + static const vec_uchar16 b12 = {21, 0, 6, 22, 0, 7, 23, 0, 8, 24, 0, 9, 25, 0, 10, 26}; \ + static const vec_uchar16 b123 = {0, 21, 2, 3, 22, 5, 6, 23, 8, 9, 24, 11, 12, 25, 14, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, b12), c, b123), 16, ptr); \ + static const vec_uchar16 c12 = {0, 11, 27, 0, 12, 28, 0, 13, 29, 0, 14, 30, 0, 15, 31, 0}; \ + static const vec_uchar16 c123 = {26, 1, 2, 27, 4, 5, 28, 7, 8, 29, 10, 11, 30, 13, 14, 31}; \ + vsx_st(vec_perm(vec_perm(a, b, c12), c, c123), 32, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = vsx_ld(0, ptr); \ + Tvec v2 = vsx_ld(16, ptr); \ + Tvec v3 = vsx_ld(32, ptr); \ + static const vec_uchar16 a12_perm = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 a123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 17, 20, 23, 26, 29}; \ + a = vec_perm(vec_perm(v1, v2, a12_perm), v3, a123_perm); \ + static const vec_uchar16 b12_perm = {1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 b123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 18, 21, 24, 27, 30}; \ + b = vec_perm(vec_perm(v1, v2, b12_perm), v3, b123_perm); \ + static const vec_uchar16 c12_perm = {2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 0, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 c123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 19, 22, 25, 28, 31}; \ + c = vec_perm(vec_perm(v1, v2, c12_perm), v3, c123_perm); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_16(uchar, vec_uchar16) +VSX_IMPL_ST_INTERLEAVE_3CH_16(schar, vec_char16) + +#define VSX_IMPL_ST_INTERLEAVE_3CH_8(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + static const vec_uchar16 a12 = {0, 1, 16, 17, 0, 0, 2, 3, 18, 19, 0, 0, 4, 5, 20, 21}; \ + static const vec_uchar16 a123 = {0, 1, 2, 3, 16, 17, 6, 7, 8, 9, 18, 19, 12, 13, 14, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, a12), c, a123), 0, ptr); \ + static const vec_uchar16 b12 = {0, 0, 6, 7, 22, 23, 0, 0, 8, 9, 24, 25, 0, 0, 10, 11}; \ + static const vec_uchar16 b123 = {20, 21, 2, 3, 4, 5, 22, 23, 8, 9, 10, 11, 24, 25, 14, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, b12), c, b123), 8, ptr); \ + static const vec_uchar16 c12 = {26, 27, 0, 0, 12, 13, 28, 29, 0, 0, 14, 15, 30, 31, 0, 0}; \ + static const vec_uchar16 c123 = {0, 1, 26, 27, 4, 5, 6, 7, 28, 29, 10, 11, 12, 13, 30, 31}; \ + vsx_st(vec_perm(vec_perm(a, b, c12), c, c123), 16, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = vsx_ld(0, ptr); \ + Tvec v2 = vsx_ld(8, ptr); \ + Tvec v3 = vsx_ld(16, ptr); \ + static const vec_uchar16 a12_perm = {0, 1, 6, 7, 12, 13, 18, 19, 24, 25, 30, 31, 0, 0, 0, 0}; \ + static const vec_uchar16 a123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 20, 21, 26, 27}; \ + a = vec_perm(vec_perm(v1, v2, a12_perm), v3, a123_perm); \ + static const vec_uchar16 b12_perm = {2, 3, 8, 9, 14, 15, 20, 21, 26, 27, 0, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 b123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 17, 22, 23, 28, 29}; \ + b = vec_perm(vec_perm(v1, v2, b12_perm), v3, b123_perm); \ + static const vec_uchar16 c12_perm = {4, 5, 10, 11, 16, 17, 22, 23, 28, 29, 0, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 c123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 18, 19, 24, 25, 30, 31}; \ + c = vec_perm(vec_perm(v1, v2, c12_perm), v3, c123_perm); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_8(ushort, vec_ushort8) +VSX_IMPL_ST_INTERLEAVE_3CH_8(short, vec_short8) + +#define VSX_IMPL_ST_INTERLEAVE_3CH_4(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + Tvec hbc = vec_mergeh(b, c); \ + static const vec_uchar16 ahbc = {0, 1, 2, 3, 16, 17, 18, 19, 20, 21, 22, 23, 4, 5, 6, 7}; \ + vsx_st(vec_perm(a, hbc, ahbc), 0, ptr); \ + Tvec lab = vec_mergel(a, b); \ + vsx_st(vec_sld(lab, hbc, 8), 4, ptr); \ + static const vec_uchar16 clab = {8, 9, 10, 11, 24, 25, 26, 27, 28, 29, 30, 31, 12, 13, 14, 15};\ + vsx_st(vec_perm(c, lab, clab), 8, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = vsx_ld(0, ptr); \ + Tvec v2 = vsx_ld(4, ptr); \ + Tvec v3 = vsx_ld(8, ptr); \ + static const vec_uchar16 flp = {0, 1, 2, 3, 12, 13, 14, 15, 16, 17, 18, 19, 28, 29, 30, 31}; \ + a = vec_perm(v1, vec_sld(v3, v2, 8), flp); \ + static const vec_uchar16 flp2 = {28, 29, 30, 31, 0, 1, 2, 3, 12, 13, 14, 15, 16, 17, 18, 19}; \ + b = vec_perm(v2, vec_sld(v1, v3, 8), flp2); \ + c = vec_perm(vec_sld(v2, v1, 8), v3, flp); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_4(uint, vec_uint4) +VSX_IMPL_ST_INTERLEAVE_3CH_4(int, vec_int4) +VSX_IMPL_ST_INTERLEAVE_3CH_4(float, vec_float4) + +#define VSX_IMPL_ST_INTERLEAVE_3CH_2(Tp, Tvec, ld_func, st_func) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + st_func(vec_mergeh(a, b), 0, ptr); \ + st_func(vec_permi(c, a, 1), 2, ptr); \ + st_func(vec_mergel(b, c), 4, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, \ + Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = ld_func(0, ptr); \ + Tvec v2 = ld_func(2, ptr); \ + Tvec v3 = ld_func(4, ptr); \ + a = vec_permi(v1, v2, 1); \ + b = vec_permi(v1, v3, 2); \ + c = vec_permi(v2, v3, 1); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_2(int64, vec_dword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_INTERLEAVE_3CH_2(uint64, vec_udword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_INTERLEAVE_3CH_2(double, vec_double2, vsx_ld, vsx_st) + +#endif // CV_VSX + +//! @} + +#endif // OPENCV_HAL_VSX_UTILS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/core/wimage.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/core/wimage.hpp similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/core/wimage.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/core/wimage.hpp index ef9d3983..b246c89d 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/core/wimage.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/core/wimage.hpp @@ -39,8 +39,8 @@ ///////////////////////////////////////////////////////////////////////////////// //M*/ -#ifndef __OPENCV_CORE_WIMAGE_HPP__ -#define __OPENCV_CORE_WIMAGE_HPP__ +#ifndef OPENCV_CORE_WIMAGE_HPP +#define OPENCV_CORE_WIMAGE_HPP #include "opencv2/core/core_c.h" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/cvconfig.h b/lib/3rdParty/OpenCV3.4/include/opencv2/cvconfig.h similarity index 72% rename from lib/3rdParty/OpenCV3.1/include/opencv2/cvconfig.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/cvconfig.h index da75317d..cdf2cdbc 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/cvconfig.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/cvconfig.h @@ -1,6 +1,15 @@ +#ifndef OPENCV_CVCONFIG_H_INCLUDED +#define OPENCV_CVCONFIG_H_INCLUDED + /* OpenCV compiled as static or dynamic libs */ #define BUILD_SHARED_LIBS +/* OpenCV intrinsics optimized code */ +#define CV_ENABLE_INTRINSICS + +/* OpenCV additional optimized code */ +/* #undef CV_DISABLE_OPTIMIZATION */ + /* Compile for 'real' NVIDIA GPU architectures */ #define CUDA_ARCH_BIN "" @@ -26,10 +35,10 @@ /* #undef HAVE_CARBON */ /* AMD's Basic Linear Algebra Subprograms Library*/ -#define HAVE_CLAMDBLAS +/* #undef HAVE_CLAMDBLAS */ /* AMD's OpenCL Fast Fourier Transform Library*/ -#define HAVE_CLAMDFFT +/* #undef HAVE_CLAMDFFT */ /* Clp support */ /* #undef HAVE_CLP */ @@ -71,12 +80,6 @@ /* FFMpeg video library */ #define HAVE_FFMPEG -/* ffmpeg's libswscale */ -#define HAVE_FFMPEG_SWSCALE - -/* ffmpeg in Gentoo */ -#define HAVE_GENTOO_FFMPEG - /* Geospatial Data Abstraction Library */ /* #undef HAVE_GDAL */ @@ -89,15 +92,19 @@ /* GTK+ 2.x toolkit */ /* #undef HAVE_GTK */ +/* Halide support */ +/* #undef HAVE_HALIDE */ + /* Define to 1 if you have the header file. */ -/* #undef HAVE_INTTYPES_H */ +#define HAVE_INTTYPES_H 1 /* Intel Perceptual Computing SDK library */ /* #undef HAVE_INTELPERC */ /* Intel Integrated Performance Primitives */ #define HAVE_IPP -#define HAVE_IPP_ICV_ONLY +#define HAVE_IPP_ICV +#define HAVE_IPP_IW /* Intel IPP Async */ /* #undef HAVE_IPP_A */ @@ -111,6 +118,9 @@ /* libpng/png.h needs to be included */ /* #undef HAVE_LIBPNG_PNG_H */ +/* GDCM DICOM codec */ +/* #undef HAVE_GDCM */ + /* V4L/V4L2 capturing support via libv4l */ /* #undef HAVE_LIBV4L */ @@ -120,6 +130,9 @@ /* NVidia Video Decoding API*/ /* #undef HAVE_NVCUVID */ +/* NVidia Video Encoding API*/ +/* #undef HAVE_NVCUVENC */ + /* OpenCL Support */ #define HAVE_OPENCL /* #undef HAVE_OPENCL_STATIC */ @@ -141,7 +154,7 @@ #define HAVE_PNG /* Posix threads (pthreads) */ -/* #undef HAVE_PTHREADS */ +/* #undef HAVE_PTHREAD */ /* parallel_for with pthreads */ /* #undef HAVE_PTHREADS_PF */ @@ -194,3 +207,42 @@ /* Intel VA-API/OpenCL */ /* #undef HAVE_VA_INTEL */ + +/* Intel Media SDK */ +/* #undef HAVE_MFX */ + +/* Lapack */ +/* #undef HAVE_LAPACK */ + +/* Library was compiled with functions instrumentation */ +/* #undef ENABLE_INSTRUMENTATION */ + +/* OpenVX */ +/* #undef HAVE_OPENVX */ + +#if defined(HAVE_XINE) || \ + defined(HAVE_GSTREAMER) || \ + defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ + defined(HAVE_AVFOUNDATION) || \ + /*defined(HAVE_OPENNI) || too specialized */ \ + defined(HAVE_FFMPEG) || \ + defined(HAVE_MSMF) +#define HAVE_VIDEO_INPUT +#endif + +#if /*defined(HAVE_XINE) || */\ + defined(HAVE_GSTREAMER) || \ + defined(HAVE_QUICKTIME) || \ + defined(HAVE_QTKIT) || \ + defined(HAVE_AVFOUNDATION) || \ + defined(HAVE_FFMPEG) || \ + defined(HAVE_MSMF) +#define HAVE_VIDEO_OUTPUT +#endif + +/* OpenCV trace utilities */ +#define OPENCV_TRACE + + +#endif // OPENCV_CVCONFIG_H_INCLUDED diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/opencv.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn.hpp similarity index 69% rename from lib/3rdParty/OpenCV3.1/include/opencv2/opencv.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/dnn.hpp index fd9ca589..690a82ab 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/opencv.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn.hpp @@ -10,8 +10,7 @@ // License Agreement // For Open Source Computer Vision Library // -// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009-2010, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, @@ -40,19 +39,26 @@ // //M*/ -#ifndef __OPENCV_ALL_HPP__ -#define __OPENCV_ALL_HPP__ +#ifndef OPENCV_DNN_HPP +#define OPENCV_DNN_HPP -#include "opencv2/core.hpp" -#include "opencv2/imgproc.hpp" -#include "opencv2/photo.hpp" -#include "opencv2/video.hpp" -#include "opencv2/features2d.hpp" -#include "opencv2/objdetect.hpp" -#include "opencv2/calib3d.hpp" -#include "opencv2/imgcodecs.hpp" -#include "opencv2/videoio.hpp" -#include "opencv2/highgui.hpp" -#include "opencv2/ml.hpp" +// This is an umbrealla header to include into you project. +// We are free to change headers layout in dnn subfolder, so please include +// this header for future compatibility -#endif + +/** @defgroup dnn Deep Neural Network module + @{ + This module contains: + - API for new layers creation, layers are building bricks of neural networks; + - set of built-in most-useful Layers; + - API to constuct and modify comprehensive neural networks from layers; + - functionality for loading serialized networks models from differnet frameworks. + + Functionality of this module is designed only for forward pass computations (i. e. network testing). + A network training is in principle not supported. + @} +*/ +#include + +#endif /* OPENCV_DNN_HPP */ diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/all_layers.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/all_layers.hpp new file mode 100644 index 00000000..da0e34af --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/all_layers.hpp @@ -0,0 +1,583 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_ALL_LAYERS_HPP +#define OPENCV_DNN_DNN_ALL_LAYERS_HPP +#include + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN +//! @addtogroup dnn +//! @{ + +/** @defgroup dnnLayerList Partial List of Implemented Layers + @{ + This subsection of dnn module contains information about bult-in layers and their descriptions. + + Classes listed here, in fact, provides C++ API for creating intances of bult-in layers. + In addition to this way of layers instantiation, there is a more common factory API (see @ref dnnLayerFactory), it allows to create layers dynamically (by name) and register new ones. + You can use both API, but factory API is less convinient for native C++ programming and basically designed for use inside importers (see @ref readNetFromCaffe(), @ref readNetFromTorch(), @ref readNetFromTensorflow()). + + Bult-in layers partially reproduce functionality of corresponding Caffe and Torch7 layers. + In partuclar, the following layers and Caffe importer were tested to reproduce Caffe functionality: + - Convolution + - Deconvolution + - Pooling + - InnerProduct + - TanH, ReLU, Sigmoid, BNLL, Power, AbsVal + - Softmax + - Reshape, Flatten, Slice, Split + - LRN + - MVN + - Dropout (since it does nothing on forward pass -)) +*/ + + class CV_EXPORTS BlankLayer : public Layer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + //! LSTM recurrent layer + class CV_EXPORTS LSTMLayer : public Layer + { + public: + /** Creates instance of LSTM layer */ + static Ptr create(const LayerParams& params); + + /** @deprecated Use LayerParams::blobs instead. + @brief Set trained weights for LSTM layer. + + LSTM behavior on each step is defined by current input, previous output, previous cell state and learned weights. + + Let @f$x_t@f$ be current input, @f$h_t@f$ be current output, @f$c_t@f$ be current state. + Than current output and current cell state is computed as follows: + @f{eqnarray*}{ + h_t &= o_t \odot tanh(c_t), \\ + c_t &= f_t \odot c_{t-1} + i_t \odot g_t, \\ + @f} + where @f$\odot@f$ is per-element multiply operation and @f$i_t, f_t, o_t, g_t@f$ is internal gates that are computed using learned wights. + + Gates are computed as follows: + @f{eqnarray*}{ + i_t &= sigmoid&(W_{xi} x_t + W_{hi} h_{t-1} + b_i), \\ + f_t &= sigmoid&(W_{xf} x_t + W_{hf} h_{t-1} + b_f), \\ + o_t &= sigmoid&(W_{xo} x_t + W_{ho} h_{t-1} + b_o), \\ + g_t &= tanh &(W_{xg} x_t + W_{hg} h_{t-1} + b_g), \\ + @f} + where @f$W_{x?}@f$, @f$W_{h?}@f$ and @f$b_{?}@f$ are learned weights represented as matrices: + @f$W_{x?} \in R^{N_h \times N_x}@f$, @f$W_{h?} \in R^{N_h \times N_h}@f$, @f$b_? \in R^{N_h}@f$. + + For simplicity and performance purposes we use @f$ W_x = [W_{xi}; W_{xf}; W_{xo}, W_{xg}] @f$ + (i.e. @f$W_x@f$ is vertical contacentaion of @f$ W_{x?} @f$), @f$ W_x \in R^{4N_h \times N_x} @f$. + The same for @f$ W_h = [W_{hi}; W_{hf}; W_{ho}, W_{hg}], W_h \in R^{4N_h \times N_h} @f$ + and for @f$ b = [b_i; b_f, b_o, b_g]@f$, @f$b \in R^{4N_h} @f$. + + @param Wh is matrix defining how previous output is transformed to internal gates (i.e. according to abovemtioned notation is @f$ W_h @f$) + @param Wx is matrix defining how current input is transformed to internal gates (i.e. according to abovemtioned notation is @f$ W_x @f$) + @param b is bias vector (i.e. according to abovemtioned notation is @f$ b @f$) + */ + CV_DEPRECATED virtual void setWeights(const Mat &Wh, const Mat &Wx, const Mat &b) = 0; + + /** @brief Specifies shape of output blob which will be [[`T`], `N`] + @p outTailShape. + * @details If this parameter is empty or unset then @p outTailShape = [`Wh`.size(0)] will be used, + * where `Wh` is parameter from setWeights(). + */ + virtual void setOutShape(const MatShape &outTailShape = MatShape()) = 0; + + /** @deprecated Use flag `produce_cell_output` in LayerParams. + * @brief Specifies either interpet first dimension of input blob as timestamp dimenion either as sample. + * + * If flag is set to true then shape of input blob will be interpeted as [`T`, `N`, `[data dims]`] where `T` specifies number of timpestamps, `N` is number of independent streams. + * In this case each forward() call will iterate through `T` timestamps and update layer's state `T` times. + * + * If flag is set to false then shape of input blob will be interpeted as [`N`, `[data dims]`]. + * In this case each forward() call will make one iteration and produce one timestamp with shape [`N`, `[out dims]`]. + */ + CV_DEPRECATED virtual void setUseTimstampsDim(bool use = true) = 0; + + /** @deprecated Use flag `use_timestamp_dim` in LayerParams. + * @brief If this flag is set to true then layer will produce @f$ c_t @f$ as second output. + * @details Shape of the second output is the same as first output. + */ + CV_DEPRECATED virtual void setProduceCellOutput(bool produce = false) = 0; + + /* In common case it use single input with @f$x_t@f$ values to compute output(s) @f$h_t@f$ (and @f$c_t@f$). + * @param input should contain packed values @f$x_t@f$ + * @param output contains computed outputs: @f$h_t@f$ (and @f$c_t@f$ if setProduceCellOutput() flag was set to true). + * + * If setUseTimstampsDim() is set to true then @p input[0] should has at least two dimensions with the following shape: [`T`, `N`, `[data dims]`], + * where `T` specifies number of timpestamps, `N` is number of independent streams (i.e. @f$ x_{t_0 + t}^{stream} @f$ is stored inside @p input[0][t, stream, ...]). + * + * If setUseTimstampsDim() is set to fase then @p input[0] should contain single timestamp, its shape should has form [`N`, `[data dims]`] with at least one dimension. + * (i.e. @f$ x_{t}^{stream} @f$ is stored inside @p input[0][stream, ...]). + */ + + int inputNameToIndex(String inputName); + int outputNameToIndex(String outputName); + }; + + /** @brief Classical recurrent layer + + Accepts two inputs @f$x_t@f$ and @f$h_{t-1}@f$ and compute two outputs @f$o_t@f$ and @f$h_t@f$. + + - input: should contain packed input @f$x_t@f$. + - output: should contain output @f$o_t@f$ (and @f$h_t@f$ if setProduceHiddenOutput() is set to true). + + input[0] should have shape [`T`, `N`, `data_dims`] where `T` and `N` is number of timestamps and number of independent samples of @f$x_t@f$ respectively. + + output[0] will have shape [`T`, `N`, @f$N_o@f$], where @f$N_o@f$ is number of rows in @f$ W_{xo} @f$ matrix. + + If setProduceHiddenOutput() is set to true then @p output[1] will contain a Mat with shape [`T`, `N`, @f$N_h@f$], where @f$N_h@f$ is number of rows in @f$ W_{hh} @f$ matrix. + */ + class CV_EXPORTS RNNLayer : public Layer + { + public: + /** Creates instance of RNNLayer */ + static Ptr create(const LayerParams& params); + + /** Setups learned weights. + + Recurrent-layer behavior on each step is defined by current input @f$ x_t @f$, previous state @f$ h_t @f$ and learned weights as follows: + @f{eqnarray*}{ + h_t &= tanh&(W_{hh} h_{t-1} + W_{xh} x_t + b_h), \\ + o_t &= tanh&(W_{ho} h_t + b_o), + @f} + + @param Wxh is @f$ W_{xh} @f$ matrix + @param bh is @f$ b_{h} @f$ vector + @param Whh is @f$ W_{hh} @f$ matrix + @param Who is @f$ W_{xo} @f$ matrix + @param bo is @f$ b_{o} @f$ vector + */ + virtual void setWeights(const Mat &Wxh, const Mat &bh, const Mat &Whh, const Mat &Who, const Mat &bo) = 0; + + /** @brief If this flag is set to true then layer will produce @f$ h_t @f$ as second output. + * @details Shape of the second output is the same as first output. + */ + virtual void setProduceHiddenOutput(bool produce = false) = 0; + + }; + + class CV_EXPORTS BaseConvolutionLayer : public Layer + { + public: + Size kernel, stride, pad, dilation, adjustPad; + String padMode; + int numOutput; + }; + + class CV_EXPORTS ConvolutionLayer : public BaseConvolutionLayer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS DeconvolutionLayer : public BaseConvolutionLayer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS LRNLayer : public Layer + { + public: + int type; + + int size; + float alpha, beta, bias; + bool normBySize; + + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS PoolingLayer : public Layer + { + public: + int type; + Size kernel, stride, pad; + bool globalPooling; + bool computeMaxIdx; + String padMode; + bool ceilMode; + // ROIPooling parameters. + Size pooledSize; + float spatialScale; + // PSROIPooling parameters. + int psRoiOutChannels; + + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS SoftmaxLayer : public Layer + { + public: + bool logSoftMax; + + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS InnerProductLayer : public Layer + { + public: + int axis; + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS MVNLayer : public Layer + { + public: + float eps; + bool normVariance, acrossChannels; + + static Ptr create(const LayerParams& params); + }; + + /* Reshaping */ + + class CV_EXPORTS ReshapeLayer : public Layer + { + public: + MatShape newShapeDesc; + Range newShapeRange; + + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS FlattenLayer : public Layer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ConcatLayer : public Layer + { + public: + int axis; + /** + * @brief Add zero padding in case of concatenation of blobs with different + * spatial sizes. + * + * Details: https://github.com/torch/nn/blob/master/doc/containers.md#depthconcat + */ + bool padding; + + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS SplitLayer : public Layer + { + public: + int outputsCount; //!< Number of copies that will be produced (is ignored when negative). + + static Ptr create(const LayerParams ¶ms); + }; + + /** + * Slice layer has several modes: + * 1. Caffe mode + * @param[in] axis Axis of split operation + * @param[in] slice_point Array of split points + * + * Number of output blobs equals to number of split points plus one. The + * first blob is a slice on input from 0 to @p slice_point[0] - 1 by @p axis, + * the second output blob is a slice of input from @p slice_point[0] to + * @p slice_point[1] - 1 by @p axis and the last output blob is a slice of + * input from @p slice_point[-1] up to the end of @p axis size. + * + * 2. TensorFlow mode + * @param begin Vector of start indices + * @param size Vector of sizes + * + * More convinient numpy-like slice. One and only output blob + * is a slice `input[begin[0]:begin[0]+size[0], begin[1]:begin[1]+size[1], ...]` + * + * 3. Torch mode + * @param axis Axis of split operation + * + * Split input blob on the equal parts by @p axis. + */ + class CV_EXPORTS SliceLayer : public Layer + { + public: + /** + * @brief Vector of slice ranges. + * + * The first dimension equals number of output blobs. + * Inner vector has slice ranges for the first number of input dimensions. + */ + std::vector > sliceRanges; + int axis; + + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS PermuteLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + /** + * @brief Adds extra values for specific axes. + * @param paddings Vector of paddings in format + * @code + * [ pad_before, pad_after, // [0]th dimension + * pad_before, pad_after, // [1]st dimension + * ... + * pad_before, pad_after ] // [n]th dimension + * @endcode + * that represents number of padded values at every dimension + * starting from the first one. The rest of dimensions won't + * be padded. + * @param value Value to be padded. Defaults to zero. + * @param type Padding type: 'constant', 'reflect' + * @param input_dims Torch's parameter. If @p input_dims is not equal to the + * actual input dimensionality then the `[0]th` dimension + * is considered as a batch dimension and @p paddings are shifted + * to a one dimension. Defaults to `-1` that means padding + * corresponding to @p paddings. + */ + class CV_EXPORTS PaddingLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + /* Activations */ + class CV_EXPORTS ActivationLayer : public Layer + { + public: + virtual void forwardSlice(const float* src, float* dst, int len, + size_t outPlaneSize, int cn0, int cn1) const = 0; + }; + + class CV_EXPORTS ReLULayer : public ActivationLayer + { + public: + float negativeSlope; + + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ReLU6Layer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ChannelsPReLULayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS ELULayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS TanHLayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS SigmoidLayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS BNLLLayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS AbsLayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS PowerLayer : public ActivationLayer + { + public: + float power, scale, shift; + + static Ptr create(const LayerParams ¶ms); + }; + + /* Layers used in semantic segmentation */ + + class CV_EXPORTS CropLayer : public Layer + { + public: + int startAxis; + std::vector offset; + + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS EltwiseLayer : public Layer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS BatchNormLayer : public Layer + { + public: + bool hasWeights, hasBias; + float epsilon; + + virtual void getScaleShift(Mat& scale, Mat& shift) const = 0; + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS MaxUnpoolLayer : public Layer + { + public: + Size poolKernel; + Size poolPad; + Size poolStride; + + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ScaleLayer : public Layer + { + public: + bool hasBias; + + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS ShiftLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS PriorBoxLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS ReorgLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS RegionLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS DetectionOutputLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + /** + * @brief \f$ L_p \f$ - normalization layer. + * @param p Normalization factor. The most common `p = 1` for \f$ L_1 \f$ - + * normalization or `p = 2` for \f$ L_2 \f$ - normalization or a custom one. + * @param eps Parameter \f$ \epsilon \f$ to prevent a division by zero. + * @param across_spatial If true, normalize an input across all non-batch dimensions. + * Otherwise normalize an every channel separately. + * + * Across spatial: + * @f[ + * norm = \sqrt[p]{\epsilon + \sum_{x, y, c} |src(x, y, c)|^p } \\ + * dst(x, y, c) = \frac{ src(x, y, c) }{norm} + * @f] + * + * Channel wise normalization: + * @f[ + * norm(c) = \sqrt[p]{\epsilon + \sum_{x, y} |src(x, y, c)|^p } \\ + * dst(x, y, c) = \frac{ src(x, y, c) }{norm(c)} + * @f] + * + * Where `x, y` - spatial cooridnates, `c` - channel. + * + * An every sample in the batch is normalized separately. Optionally, + * output is scaled by the trained parameters. + */ + class NormalizeBBoxLayer : public Layer + { + public: + float pnorm, epsilon; + bool acrossSpatial; + + static Ptr create(const LayerParams& params); + }; + + /** + * @brief Resize input 4-dimensional blob by nearest neghbor strategy. + * + * Layer is used to support TensorFlow's resize_nearest_neighbor op. + */ + class CV_EXPORTS ResizeNearestNeighborLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS ProposalLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + +//! @} +//! @} +CV__DNN_EXPERIMENTAL_NS_END +} +} +#endif diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/dict.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/dict.hpp new file mode 100644 index 00000000..43cb58a6 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/dict.hpp @@ -0,0 +1,152 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include +#include +#include + +#include + +#ifndef OPENCV_DNN_DNN_DICT_HPP +#define OPENCV_DNN_DNN_DICT_HPP + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN +//! @addtogroup dnn +//! @{ + +/** @brief This struct stores the scalar value (or array) of one of the following type: double, cv::String or int64. + * @todo Maybe int64 is useless because double type exactly stores at least 2^52 integers. + */ +struct CV_EXPORTS_W DictValue +{ + DictValue(const DictValue &r); + DictValue(int64 i = 0) : type(Param::INT), pi(new AutoBuffer) { (*pi)[0] = i; } //!< Constructs integer scalar + CV_WRAP DictValue(int i) : type(Param::INT), pi(new AutoBuffer) { (*pi)[0] = i; } //!< Constructs integer scalar + DictValue(unsigned p) : type(Param::INT), pi(new AutoBuffer) { (*pi)[0] = p; } //!< Constructs integer scalar + CV_WRAP DictValue(double p) : type(Param::REAL), pd(new AutoBuffer) { (*pd)[0] = p; } //!< Constructs floating point scalar + CV_WRAP DictValue(const String &s) : type(Param::STRING), ps(new AutoBuffer) { (*ps)[0] = s; } //!< Constructs string scalar + DictValue(const char *s) : type(Param::STRING), ps(new AutoBuffer) { (*ps)[0] = s; } //!< @overload + + template + static DictValue arrayInt(TypeIter begin, int size); //!< Constructs integer array + template + static DictValue arrayReal(TypeIter begin, int size); //!< Constructs floating point array + template + static DictValue arrayString(TypeIter begin, int size); //!< Constructs array of strings + + template + T get(int idx = -1) const; //!< Tries to convert array element with specified index to requested type and returns its. + + int size() const; + + CV_WRAP bool isInt() const; + CV_WRAP bool isString() const; + CV_WRAP bool isReal() const; + + CV_WRAP int getIntValue(int idx = -1) const; + CV_WRAP double getRealValue(int idx = -1) const; + CV_WRAP String getStringValue(int idx = -1) const; + + DictValue &operator=(const DictValue &r); + + friend std::ostream &operator<<(std::ostream &stream, const DictValue &dictv); + + ~DictValue(); + +private: + + int type; + + union + { + AutoBuffer *pi; + AutoBuffer *pd; + AutoBuffer *ps; + void *pv; + }; + + DictValue(int _type, void *_p) : type(_type), pv(_p) {} + void release(); +}; + +/** @brief This class implements name-value dictionary, values are instances of DictValue. */ +class CV_EXPORTS Dict +{ + typedef std::map _Dict; + _Dict dict; + +public: + + //! Checks a presence of the @p key in the dictionary. + bool has(const String &key) const; + + //! If the @p key in the dictionary then returns pointer to its value, else returns NULL. + DictValue *ptr(const String &key); + + /** @overload */ + const DictValue *ptr(const String &key) const; + + //! If the @p key in the dictionary then returns its value, else an error will be generated. + const DictValue &get(const String &key) const; + + /** @overload */ + template + T get(const String &key) const; + + //! If the @p key in the dictionary then returns its value, else returns @p defaultValue. + template + T get(const String &key, const T &defaultValue) const; + + //! Sets new @p value for the @p key, or adds new key-value pair into the dictionary. + template + const T &set(const String &key, const T &value); + + friend std::ostream &operator<<(std::ostream &stream, const Dict &dict); +}; + +//! @} +CV__DNN_EXPERIMENTAL_NS_END +} +} + +#endif diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/dnn.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/dnn.hpp new file mode 100644 index 00000000..74883514 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/dnn.hpp @@ -0,0 +1,757 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_HPP +#define OPENCV_DNN_DNN_HPP + +#include +#include + +#if !defined CV_DOXYGEN && !defined CV_DNN_DONT_ADD_EXPERIMENTAL_NS +#define CV__DNN_EXPERIMENTAL_NS_BEGIN namespace experimental_dnn_v3 { +#define CV__DNN_EXPERIMENTAL_NS_END } +namespace cv { namespace dnn { namespace experimental_dnn_v3 { } using namespace experimental_dnn_v3; }} +#else +#define CV__DNN_EXPERIMENTAL_NS_BEGIN +#define CV__DNN_EXPERIMENTAL_NS_END +#endif + +#include + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN +//! @addtogroup dnn +//! @{ + + typedef std::vector MatShape; + + /** + * @brief Enum of computation backends supported by layers. + */ + enum Backend + { + DNN_BACKEND_DEFAULT, + DNN_BACKEND_HALIDE + }; + + /** + * @brief Enum of target devices for computations. + */ + enum Target + { + DNN_TARGET_CPU, + DNN_TARGET_OPENCL + }; + + /** @brief This class provides all data needed to initialize layer. + * + * It includes dictionary with scalar params (which can be readed by using Dict interface), + * blob params #blobs and optional meta information: #name and #type of layer instance. + */ + class CV_EXPORTS LayerParams : public Dict + { + public: + //TODO: Add ability to name blob params + std::vector blobs; //!< List of learned parameters stored as blobs. + + String name; //!< Name of the layer instance (optional, can be used internal purposes). + String type; //!< Type name which was used for creating layer by layer factory (optional). + }; + + /** + * @brief Derivatives of this class encapsulates functions of certain backends. + */ + class BackendNode + { + public: + BackendNode(int backendId); + + virtual ~BackendNode(); //!< Virtual destructor to make polymorphism. + + int backendId; //!< Backend identifier. + }; + + /** + * @brief Derivatives of this class wraps cv::Mat for different backends and targets. + */ + class BackendWrapper + { + public: + BackendWrapper(int backendId, int targetId); + + /** + * @brief Wrap cv::Mat for specific backend and target. + * @param[in] targetId Target identifier. + * @param[in] m cv::Mat for wrapping. + * + * Make CPU->GPU data transfer if it's require for the target. + */ + BackendWrapper(int targetId, const cv::Mat& m); + + /** + * @brief Make wrapper for reused cv::Mat. + * @param[in] base Wrapper of cv::Mat that will be reused. + * @param[in] shape Specific shape. + * + * Initialize wrapper from another one. It'll wrap the same host CPU + * memory and mustn't allocate memory on device(i.e. GPU). It might + * has different shape. Use in case of CPU memory reusing for reuse + * associented memory on device too. + */ + BackendWrapper(const Ptr& base, const MatShape& shape); + + virtual ~BackendWrapper(); //!< Virtual destructor to make polymorphism. + + /** + * @brief Transfer data to CPU host memory. + */ + virtual void copyToHost() = 0; + + /** + * @brief Indicate that an actual data is on CPU. + */ + virtual void setHostDirty() = 0; + + int backendId; //!< Backend identifier. + int targetId; //!< Target identifier. + }; + + class CV_EXPORTS ActivationLayer; + class CV_EXPORTS BatchNormLayer; + class CV_EXPORTS ScaleLayer; + + /** @brief This interface class allows to build new Layers - are building blocks of networks. + * + * Each class, derived from Layer, must implement allocate() methods to declare own outputs and forward() to compute outputs. + * Also before using the new layer into networks you must register your layer by using one of @ref dnnLayerFactory "LayerFactory" macros. + */ + class CV_EXPORTS_W Layer : public Algorithm + { + public: + + //! List of learned parameters must be stored here to allow read them by using Net::getParam(). + CV_PROP_RW std::vector blobs; + + /** @brief Computes and sets internal parameters according to inputs, outputs and blobs. + * @param[in] input vector of already allocated input blobs + * @param[out] output vector of already allocated output blobs + * + * If this method is called after network has allocated all memory for input and output blobs + * and before inferencing. + */ + virtual void finalize(const std::vector &input, std::vector &output); + + /** @brief Given the @p input blobs, computes the output @p blobs. + * @param[in] input the input blobs. + * @param[out] output allocated output blobs, which will store results of the computation. + * @param[out] internals allocated internal blobs + */ + virtual void forward(std::vector &input, std::vector &output, std::vector &internals) = 0; + + /** @brief Given the @p input blobs, computes the output @p blobs. + * @param[in] inputs the input blobs. + * @param[out] outputs allocated output blobs, which will store results of the computation. + * @param[out] internals allocated internal blobs + */ + virtual void forward(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals) = 0; + + /** @brief Given the @p input blobs, computes the output @p blobs. + * @param[in] inputs the input blobs. + * @param[out] outputs allocated output blobs, which will store results of the computation. + * @param[out] internals allocated internal blobs + */ + void forward_fallback(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals); + + /** @brief @overload */ + CV_WRAP void finalize(const std::vector &inputs, CV_OUT std::vector &outputs); + + /** @brief @overload */ + CV_WRAP std::vector finalize(const std::vector &inputs); + + /** @brief Allocates layer and computes output. */ + CV_WRAP void run(const std::vector &inputs, CV_OUT std::vector &outputs, + CV_IN_OUT std::vector &internals); + + /** @brief Returns index of input blob into the input array. + * @param inputName label of input blob + * + * Each layer input and output can be labeled to easily identify them using "%[.output_name]" notation. + * This method maps label of input blob to its index into input vector. + */ + virtual int inputNameToIndex(String inputName); + /** @brief Returns index of output blob in output array. + * @see inputNameToIndex() + */ + virtual int outputNameToIndex(String outputName); + + /** + * @brief Ask layer if it support specific backend for doing computations. + * @param[in] backendId computation backend identifier. + * @see Backend + */ + virtual bool supportBackend(int backendId); + + /** + * @brief Returns Halide backend node. + * @param[in] inputs Input Halide buffers. + * @see BackendNode, BackendWrapper + * + * Input buffers should be exactly the same that will be used in forward invocations. + * Despite we can use Halide::ImageParam based on input shape only, + * it helps prevent some memory management issues (if something wrong, + * Halide tests will be failed). + */ + virtual Ptr initHalide(const std::vector > &inputs); + + /** + * @brief Automatic Halide scheduling based on layer hyper-parameters. + * @param[in] node Backend node with Halide functions. + * @param[in] inputs Blobs that will be used in forward invocations. + * @param[in] outputs Blobs that will be used in forward invocations. + * @param[in] targetId Target identifier + * @see BackendNode, Target + * + * Layer don't use own Halide::Func members because we can have applied + * layers fusing. In this way the fused function should be scheduled. + */ + virtual void applyHalideScheduler(Ptr& node, + const std::vector &inputs, + const std::vector &outputs, + int targetId) const; + + /** + * @brief Implement layers fusing. + * @param[in] node Backend node of bottom layer. + * @see BackendNode + * + * Actual for graph-based backends. If layer attached successfully, + * returns non-empty cv::Ptr to node of the same backend. + * Fuse only over the last function. + */ + virtual Ptr tryAttach(const Ptr& node); + + /** + * @brief Tries to attach to the layer the subsequent activation layer, i.e. do the layer fusion in a partial case. + * @param[in] layer The subsequent activation layer. + * + * Returns true if the activation layer has been attached successfully. + */ + virtual bool setActivation(const Ptr& layer); + + /** + * @brief Tries to attach to the layer the subsequent batch normalization layer, i.e. do the layer fusion in a partial case. + * @param[in] layer The subsequent batch normalization layer. + * + * Returns true if the batch normalization layer has been attached successfully. + */ + virtual bool setBatchNorm(const Ptr& layer); + + /** + * @brief Tries to attach to the layer the subsequent scaling layer, i.e. do the layer fusion in a partial case. + * @param[in] layer The subsequent scaling layer. + * + * Returns true if the scaling layer has been attached successfully. + */ + virtual bool setScale(const Ptr& layer); + + /** + * @brief "Deattaches" all the layers, attached to particular layer. + */ + virtual void unsetAttached(); + + virtual bool getMemoryShapes(const std::vector &inputs, + const int requiredOutputs, + std::vector &outputs, + std::vector &internals) const; + virtual int64 getFLOPS(const std::vector &inputs, + const std::vector &outputs) const {(void)inputs; (void)outputs; return 0;} + + CV_PROP String name; //!< Name of the layer instance, can be used for logging or other internal purposes. + CV_PROP String type; //!< Type name which was used for creating layer by layer factory. + CV_PROP int preferableTarget; //!< prefer target for layer forwarding + + Layer(); + explicit Layer(const LayerParams ¶ms); //!< Initializes only #name, #type and #blobs fields. + void setParamsFrom(const LayerParams ¶ms); //!< Initializes only #name, #type and #blobs fields. + virtual ~Layer(); + }; + + /** @brief This class allows to create and manipulate comprehensive artificial neural networks. + * + * Neural network is presented as directed acyclic graph (DAG), where vertices are Layer instances, + * and edges specify relationships between layers inputs and outputs. + * + * Each network layer has unique integer id and unique string name inside its network. + * LayerId can store either layer name or layer id. + * + * This class supports reference counting of its instances, i. e. copies point to the same instance. + */ + class CV_EXPORTS_W_SIMPLE Net + { + public: + + CV_WRAP Net(); //!< Default constructor. + CV_WRAP ~Net(); //!< Destructor frees the net only if there aren't references to the net anymore. + + /** Returns true if there are no layers in the network. */ + CV_WRAP bool empty() const; + + /** @brief Adds new layer to the net. + * @param name unique name of the adding layer. + * @param type typename of the adding layer (type must be registered in LayerRegister). + * @param params parameters which will be used to initialize the creating layer. + * @returns unique identifier of created layer, or -1 if a failure will happen. + */ + int addLayer(const String &name, const String &type, LayerParams ¶ms); + /** @brief Adds new layer and connects its first input to the first output of previously added layer. + * @see addLayer() + */ + int addLayerToPrev(const String &name, const String &type, LayerParams ¶ms); + + /** @brief Converts string name of the layer to the integer identifier. + * @returns id of the layer, or -1 if the layer wasn't found. + */ + CV_WRAP int getLayerId(const String &layer); + + CV_WRAP std::vector getLayerNames() const; + + /** @brief Container for strings and integers. */ + typedef DictValue LayerId; + + /** @brief Returns pointer to layer with specified id or name which the network use. */ + CV_WRAP Ptr getLayer(LayerId layerId); + + /** @brief Returns pointers to input layers of specific layer. */ + std::vector > getLayerInputs(LayerId layerId); // FIXIT: CV_WRAP + + /** @brief Delete layer for the network (not implemented yet) */ + CV_WRAP void deleteLayer(LayerId layer); + + /** @brief Connects output of the first layer to input of the second layer. + * @param outPin descriptor of the first layer output. + * @param inpPin descriptor of the second layer input. + * + * Descriptors have the following template <layer_name>[.input_number]: + * - the first part of the template layer_name is sting name of the added layer. + * If this part is empty then the network input pseudo layer will be used; + * - the second optional part of the template input_number + * is either number of the layer input, either label one. + * If this part is omitted then the first layer input will be used. + * + * @see setNetInputs(), Layer::inputNameToIndex(), Layer::outputNameToIndex() + */ + CV_WRAP void connect(String outPin, String inpPin); + + /** @brief Connects #@p outNum output of the first layer to #@p inNum input of the second layer. + * @param outLayerId identifier of the first layer + * @param inpLayerId identifier of the second layer + * @param outNum number of the first layer output + * @param inpNum number of the second layer input + */ + void connect(int outLayerId, int outNum, int inpLayerId, int inpNum); + + /** @brief Sets outputs names of the network input pseudo layer. + * + * Each net always has special own the network input pseudo layer with id=0. + * This layer stores the user blobs only and don't make any computations. + * In fact, this layer provides the only way to pass user data into the network. + * As any other layer, this layer can label its outputs and this function provides an easy way to do this. + */ + CV_WRAP void setInputsNames(const std::vector &inputBlobNames); + + /** @brief Runs forward pass to compute output of layer with name @p outputName. + * @param outputName name for layer which output is needed to get + * @return blob for first output of specified layer. + * @details By default runs forward pass for the whole network. + */ + CV_WRAP Mat forward(const String& outputName = String()); + + /** @brief Runs forward pass to compute output of layer with name @p outputName. + * @param outputBlobs contains all output blobs for specified layer. + * @param outputName name for layer which output is needed to get + * @details If @p outputName is empty, runs forward pass for the whole network. + */ + CV_WRAP void forward(OutputArrayOfArrays outputBlobs, const String& outputName = String()); + + /** @brief Runs forward pass to compute outputs of layers listed in @p outBlobNames. + * @param outputBlobs contains blobs for first outputs of specified layers. + * @param outBlobNames names for layers which outputs are needed to get + */ + CV_WRAP void forward(OutputArrayOfArrays outputBlobs, + const std::vector& outBlobNames); + + /** @brief Runs forward pass to compute outputs of layers listed in @p outBlobNames. + * @param outputBlobs contains all output blobs for each layer specified in @p outBlobNames. + * @param outBlobNames names for layers which outputs are needed to get + */ + CV_WRAP_AS(forwardAndRetrieve) void forward(CV_OUT std::vector >& outputBlobs, + const std::vector& outBlobNames); + + /** + * @brief Compile Halide layers. + * @param[in] scheduler Path to YAML file with scheduling directives. + * @see setPreferableBackend + * + * Schedule layers that support Halide backend. Then compile them for + * specific target. For layers that not represented in scheduling file + * or if no manual scheduling used at all, automatic scheduling will be applied. + */ + CV_WRAP void setHalideScheduler(const String& scheduler); + + /** + * @brief Ask network to use specific computation backend where it supported. + * @param[in] backendId backend identifier. + * @see Backend + */ + CV_WRAP void setPreferableBackend(int backendId); + + /** + * @brief Ask network to make computations on specific target device. + * @param[in] targetId target identifier. + * @see Target + */ + CV_WRAP void setPreferableTarget(int targetId); + + /** @brief Sets the new value for the layer output blob + * @param name descriptor of the updating layer output blob. + * @param blob new blob. + * @see connect(String, String) to know format of the descriptor. + * @note If updating blob is not empty then @p blob must have the same shape, + * because network reshaping is not implemented yet. + */ + CV_WRAP void setInput(InputArray blob, const String& name = ""); + + /** @brief Sets the new value for the learned param of the layer. + * @param layer name or id of the layer. + * @param numParam index of the layer parameter in the Layer::blobs array. + * @param blob the new value. + * @see Layer::blobs + * @note If shape of the new blob differs from the previous shape, + * then the following forward pass may fail. + */ + CV_WRAP void setParam(LayerId layer, int numParam, const Mat &blob); + + /** @brief Returns parameter blob of the layer. + * @param layer name or id of the layer. + * @param numParam index of the layer parameter in the Layer::blobs array. + * @see Layer::blobs + */ + CV_WRAP Mat getParam(LayerId layer, int numParam = 0); + + /** @brief Returns indexes of layers with unconnected outputs. + */ + CV_WRAP std::vector getUnconnectedOutLayers() const; + /** @brief Returns input and output shapes for all layers in loaded model; + * preliminary inferencing isn't necessary. + * @param netInputShapes shapes for all input blobs in net input layer. + * @param layersIds output parameter for layer IDs. + * @param inLayersShapes output parameter for input layers shapes; + * order is the same as in layersIds + * @param outLayersShapes output parameter for output layers shapes; + * order is the same as in layersIds + */ + CV_WRAP void getLayersShapes(const std::vector& netInputShapes, + CV_OUT std::vector& layersIds, + CV_OUT std::vector >& inLayersShapes, + CV_OUT std::vector >& outLayersShapes) const; + + /** @overload */ + CV_WRAP void getLayersShapes(const MatShape& netInputShape, + CV_OUT std::vector& layersIds, + CV_OUT std::vector >& inLayersShapes, + CV_OUT std::vector >& outLayersShapes) const; + + /** @brief Returns input and output shapes for layer with specified + * id in loaded model; preliminary inferencing isn't necessary. + * @param netInputShape shape input blob in net input layer. + * @param layerId id for layer. + * @param inLayerShapes output parameter for input layers shapes; + * order is the same as in layersIds + * @param outLayerShapes output parameter for output layers shapes; + * order is the same as in layersIds + */ + void getLayerShapes(const MatShape& netInputShape, + const int layerId, + CV_OUT std::vector& inLayerShapes, + CV_OUT std::vector& outLayerShapes) const; // FIXIT: CV_WRAP + + /** @overload */ + void getLayerShapes(const std::vector& netInputShapes, + const int layerId, + CV_OUT std::vector& inLayerShapes, + CV_OUT std::vector& outLayerShapes) const; // FIXIT: CV_WRAP + + /** @brief Computes FLOP for whole loaded model with specified input shapes. + * @param netInputShapes vector of shapes for all net inputs. + * @returns computed FLOP. + */ + CV_WRAP int64 getFLOPS(const std::vector& netInputShapes) const; + /** @overload */ + CV_WRAP int64 getFLOPS(const MatShape& netInputShape) const; + /** @overload */ + CV_WRAP int64 getFLOPS(const int layerId, + const std::vector& netInputShapes) const; + /** @overload */ + CV_WRAP int64 getFLOPS(const int layerId, + const MatShape& netInputShape) const; + + /** @brief Returns list of types for layer used in model. + * @param layersTypes output parameter for returning types. + */ + CV_WRAP void getLayerTypes(CV_OUT std::vector& layersTypes) const; + + /** @brief Returns count of layers of specified type. + * @param layerType type. + * @returns count of layers + */ + CV_WRAP int getLayersCount(const String& layerType) const; + + /** @brief Computes bytes number which are requered to store + * all weights and intermediate blobs for model. + * @param netInputShapes vector of shapes for all net inputs. + * @param weights output parameter to store resulting bytes for weights. + * @param blobs output parameter to store resulting bytes for intermediate blobs. + */ + void getMemoryConsumption(const std::vector& netInputShapes, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; // FIXIT: CV_WRAP + /** @overload */ + CV_WRAP void getMemoryConsumption(const MatShape& netInputShape, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; + /** @overload */ + CV_WRAP void getMemoryConsumption(const int layerId, + const std::vector& netInputShapes, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; + /** @overload */ + CV_WRAP void getMemoryConsumption(const int layerId, + const MatShape& netInputShape, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; + + /** @brief Computes bytes number which are requered to store + * all weights and intermediate blobs for each layer. + * @param netInputShapes vector of shapes for all net inputs. + * @param layerIds output vector to save layer IDs. + * @param weights output parameter to store resulting bytes for weights. + * @param blobs output parameter to store resulting bytes for intermediate blobs. + */ + void getMemoryConsumption(const std::vector& netInputShapes, + CV_OUT std::vector& layerIds, + CV_OUT std::vector& weights, + CV_OUT std::vector& blobs) const; // FIXIT: CV_WRAP + /** @overload */ + void getMemoryConsumption(const MatShape& netInputShape, + CV_OUT std::vector& layerIds, + CV_OUT std::vector& weights, + CV_OUT std::vector& blobs) const; // FIXIT: CV_WRAP + + /** @brief Enables or disables layer fusion in the network. + * @param fusion true to enable the fusion, false to disable. The fusion is enabled by default. + */ + CV_WRAP void enableFusion(bool fusion); + + /** @brief Returns overall time for inference and timings (in ticks) for layers. + * Indexes in returned vector correspond to layers ids. Some layers can be fused with others, + * in this case zero ticks count will be return for that skipped layers. + * @param timings vector for tick timings for all layers. + * @return overall ticks for model inference. + */ + CV_WRAP int64 getPerfProfile(CV_OUT std::vector& timings); + + private: + struct Impl; + Ptr impl; + }; + + /** @brief Reads a network model stored in Darknet model files. + * @param cfgFile path to the .cfg file with text description of the network architecture. + * @param darknetModel path to the .weights file with learned network. + * @returns Network object that ready to do forward, throw an exception in failure cases. + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromDarknet(const String &cfgFile, const String &darknetModel = String()); + + /** @brief Reads a network model stored in Caffe framework's format. + * @param prototxt path to the .prototxt file with text description of the network architecture. + * @param caffeModel path to the .caffemodel file with learned network. + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromCaffe(const String &prototxt, const String &caffeModel = String()); + + /** @brief Reads a network model stored in Caffe model in memory. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + * @param bufferProto buffer containing the content of the .prototxt file + * @param lenProto length of bufferProto + * @param bufferModel buffer containing the content of the .caffemodel file + * @param lenModel length of bufferModel + * @returns Net object. + */ + CV_EXPORTS Net readNetFromCaffe(const char *bufferProto, size_t lenProto, + const char *bufferModel = NULL, size_t lenModel = 0); + + /** @brief Reads a network model stored in TensorFlow framework's format. + * @param model path to the .pb file with binary protobuf description of the network architecture + * @param config path to the .pbtxt file that contains text graph definition in protobuf format. + * Resulting Net object is built by text graph using weights from a binary one that + * let us make it more flexible. + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromTensorflow(const String &model, const String &config = String()); + + /** @brief Reads a network model stored in TensorFlow framework's format. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + * @param bufferModel buffer containing the content of the pb file + * @param lenModel length of bufferModel + * @param bufferConfig buffer containing the content of the pbtxt file + * @param lenConfig length of bufferConfig + */ + CV_EXPORTS Net readNetFromTensorflow(const char *bufferModel, size_t lenModel, + const char *bufferConfig = NULL, size_t lenConfig = 0); + + /** + * @brief Reads a network model stored in Torch7 framework's format. + * @param model path to the file, dumped from Torch by using torch.save() function. + * @param isBinary specifies whether the network was serialized in ascii mode or binary. + * @returns Net object. + * + * @note Ascii mode of Torch serializer is more preferable, because binary mode extensively use `long` type of C language, + * which has various bit-length on different systems. + * + * The loading file must contain serialized nn.Module object + * with importing network. Try to eliminate a custom objects from serialazing data to avoid importing errors. + * + * List of supported layers (i.e. object instances derived from Torch nn.Module class): + * - nn.Sequential + * - nn.Parallel + * - nn.Concat + * - nn.Linear + * - nn.SpatialConvolution + * - nn.SpatialMaxPooling, nn.SpatialAveragePooling + * - nn.ReLU, nn.TanH, nn.Sigmoid + * - nn.Reshape + * - nn.SoftMax, nn.LogSoftMax + * + * Also some equivalents of these classes from cunn, cudnn, and fbcunn may be successfully imported. + */ + CV_EXPORTS_W Net readNetFromTorch(const String &model, bool isBinary = true); + + /** @brief Loads blob which was serialized as torch.Tensor object of Torch7 framework. + * @warning This function has the same limitations as readNetFromTorch(). + */ + CV_EXPORTS_W Mat readTorchBlob(const String &filename, bool isBinary = true); + /** @brief Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center, + * subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels. + * @param image input image (with 1-, 3- or 4-channels). + * @param size spatial size for output image + * @param mean scalar with mean values which are subtracted from channels. Values are intended + * to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true. + * @param scalefactor multiplier for @p image values. + * @param swapRB flag which indicates that swap first and last channels + * in 3-channel image is necessary. + * @param crop flag which indicates whether image will be cropped after resize or not + * @details if @p crop is true, input image is resized so one side after resize is equal to corresponing + * dimension in @p size and another one is equal or larger. Then, crop from the center is performed. + * If @p crop is false, direct resize without cropping and preserving aspect ratio is performed. + * @returns 4-dimansional Mat with NCHW dimensions order. + */ + CV_EXPORTS_W Mat blobFromImage(InputArray image, double scalefactor=1.0, const Size& size = Size(), + const Scalar& mean = Scalar(), bool swapRB=true, bool crop=true); + /** @brief Creates 4-dimensional blob from series of images. Optionally resizes and + * crops @p images from center, subtract @p mean values, scales values by @p scalefactor, + * swap Blue and Red channels. + * @param images input images (all with 1-, 3- or 4-channels). + * @param size spatial size for output image + * @param mean scalar with mean values which are subtracted from channels. Values are intended + * to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true. + * @param scalefactor multiplier for @p images values. + * @param swapRB flag which indicates that swap first and last channels + * in 3-channel image is necessary. + * @param crop flag which indicates whether image will be cropped after resize or not + * @details if @p crop is true, input image is resized so one side after resize is equal to corresponing + * dimension in @p size and another one is equal or larger. Then, crop from the center is performed. + * If @p crop is false, direct resize without cropping and preserving aspect ratio is performed. + * @returns 4-dimansional Mat with NCHW dimensions order. + */ + CV_EXPORTS_W Mat blobFromImages(const std::vector& images, double scalefactor=1.0, + Size size = Size(), const Scalar& mean = Scalar(), bool swapRB=true, bool crop=true); + + /** @brief Convert all weights of Caffe network to half precision floating point. + * @param src Path to origin model from Caffe framework contains single + * precision floating point weights (usually has `.caffemodel` extension). + * @param dst Path to destination model with updated weights. + * @param layersTypes Set of layers types which parameters will be converted. + * By default, converts only Convolutional and Fully-Connected layers' + * weights. + * + * @note Shrinked model has no origin float32 weights so it can't be used + * in origin Caffe framework anymore. However the structure of data + * is taken from NVidia's Caffe fork: https://github.com/NVIDIA/caffe. + * So the resulting model may be used there. + */ + CV_EXPORTS_W void shrinkCaffeModel(const String& src, const String& dst, + const std::vector& layersTypes = std::vector()); + + /** @brief Performs non maximum suppression given boxes and corresponding scores. + + * @param bboxes a set of bounding boxes to apply NMS. + * @param scores a set of corresponding confidences. + * @param score_threshold a threshold used to filter boxes by score. + * @param nms_threshold a threshold used in non maximum suppression. + * @param indices the kept indices of bboxes after NMS. + * @param eta a coefficient in adaptive threshold formula: \f$nms\_threshold_{i+1}=eta\cdot nms\_threshold_i\f$. + * @param top_k if `>0`, keep at most @p top_k picked indices. + */ + CV_EXPORTS_W void NMSBoxes(const std::vector& bboxes, const std::vector& scores, + const float score_threshold, const float nms_threshold, + CV_OUT std::vector& indices, + const float eta = 1.f, const int top_k = 0); + + +//! @} +CV__DNN_EXPERIMENTAL_NS_END +} +} + +#include +#include + +#endif /* OPENCV_DNN_DNN_HPP */ diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/dnn.inl.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/dnn.inl.hpp new file mode 100644 index 00000000..c30185b2 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/dnn.inl.hpp @@ -0,0 +1,373 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_INL_HPP +#define OPENCV_DNN_DNN_INL_HPP + +#include + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN + +template +DictValue DictValue::arrayInt(TypeIter begin, int size) +{ + DictValue res(Param::INT, new AutoBuffer(size)); + for (int j = 0; j < size; begin++, j++) + (*res.pi)[j] = *begin; + return res; +} + +template +DictValue DictValue::arrayReal(TypeIter begin, int size) +{ + DictValue res(Param::REAL, new AutoBuffer(size)); + for (int j = 0; j < size; begin++, j++) + (*res.pd)[j] = *begin; + return res; +} + +template +DictValue DictValue::arrayString(TypeIter begin, int size) +{ + DictValue res(Param::STRING, new AutoBuffer(size)); + for (int j = 0; j < size; begin++, j++) + (*res.ps)[j] = *begin; + return res; +} + +template<> +inline DictValue DictValue::get(int idx) const +{ + CV_Assert(idx == -1); + return *this; +} + +template<> +inline int64 DictValue::get(int idx) const +{ + CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size())); + idx = (idx == -1) ? 0 : idx; + + if (type == Param::INT) + { + return (*pi)[idx]; + } + else if (type == Param::REAL) + { + double doubleValue = (*pd)[idx]; + + double fracpart, intpart; + fracpart = std::modf(doubleValue, &intpart); + CV_Assert(fracpart == 0.0); + + return (int64)doubleValue; + } + else + { + CV_Assert(isInt() || isReal()); + return 0; + } +} + +template<> +inline int DictValue::get(int idx) const +{ + return (int)get(idx); +} + +inline int DictValue::getIntValue(int idx) const +{ + return (int)get(idx); +} + +template<> +inline unsigned DictValue::get(int idx) const +{ + return (unsigned)get(idx); +} + +template<> +inline bool DictValue::get(int idx) const +{ + return (get(idx) != 0); +} + +template<> +inline double DictValue::get(int idx) const +{ + CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size())); + idx = (idx == -1) ? 0 : idx; + + if (type == Param::REAL) + { + return (*pd)[idx]; + } + else if (type == Param::INT) + { + return (double)(*pi)[idx]; + } + else + { + CV_Assert(isReal() || isInt()); + return 0; + } +} + +inline double DictValue::getRealValue(int idx) const +{ + return get(idx); +} + +template<> +inline float DictValue::get(int idx) const +{ + return (float)get(idx); +} + +template<> +inline String DictValue::get(int idx) const +{ + CV_Assert(isString()); + CV_Assert((idx == -1 && ps->size() == 1) || (idx >= 0 && idx < (int)ps->size())); + return (*ps)[(idx == -1) ? 0 : idx]; +} + + +inline String DictValue::getStringValue(int idx) const +{ + return get(idx); +} + +inline void DictValue::release() +{ + switch (type) + { + case Param::INT: + delete pi; + break; + case Param::STRING: + delete ps; + break; + case Param::REAL: + delete pd; + break; + } +} + +inline DictValue::~DictValue() +{ + release(); +} + +inline DictValue & DictValue::operator=(const DictValue &r) +{ + if (&r == this) + return *this; + + if (r.type == Param::INT) + { + AutoBuffer *tmp = new AutoBuffer(*r.pi); + release(); + pi = tmp; + } + else if (r.type == Param::STRING) + { + AutoBuffer *tmp = new AutoBuffer(*r.ps); + release(); + ps = tmp; + } + else if (r.type == Param::REAL) + { + AutoBuffer *tmp = new AutoBuffer(*r.pd); + release(); + pd = tmp; + } + + type = r.type; + + return *this; +} + +inline DictValue::DictValue(const DictValue &r) +{ + type = r.type; + + if (r.type == Param::INT) + pi = new AutoBuffer(*r.pi); + else if (r.type == Param::STRING) + ps = new AutoBuffer(*r.ps); + else if (r.type == Param::REAL) + pd = new AutoBuffer(*r.pd); +} + +inline bool DictValue::isString() const +{ + return (type == Param::STRING); +} + +inline bool DictValue::isInt() const +{ + return (type == Param::INT); +} + +inline bool DictValue::isReal() const +{ + return (type == Param::REAL || type == Param::INT); +} + +inline int DictValue::size() const +{ + switch (type) + { + case Param::INT: + return (int)pi->size(); + break; + case Param::STRING: + return (int)ps->size(); + break; + case Param::REAL: + return (int)pd->size(); + break; + default: + CV_Error(Error::StsInternal, ""); + return -1; + } +} + +inline std::ostream &operator<<(std::ostream &stream, const DictValue &dictv) +{ + int i; + + if (dictv.isInt()) + { + for (i = 0; i < dictv.size() - 1; i++) + stream << dictv.get(i) << ", "; + stream << dictv.get(i); + } + else if (dictv.isReal()) + { + for (i = 0; i < dictv.size() - 1; i++) + stream << dictv.get(i) << ", "; + stream << dictv.get(i); + } + else if (dictv.isString()) + { + for (i = 0; i < dictv.size() - 1; i++) + stream << "\"" << dictv.get(i) << "\", "; + stream << dictv.get(i); + } + + return stream; +} + +///////////////////////////////////////////////////////////////// + +inline bool Dict::has(const String &key) const +{ + return dict.count(key) != 0; +} + +inline DictValue *Dict::ptr(const String &key) +{ + _Dict::iterator i = dict.find(key); + return (i == dict.end()) ? NULL : &i->second; +} + +inline const DictValue *Dict::ptr(const String &key) const +{ + _Dict::const_iterator i = dict.find(key); + return (i == dict.end()) ? NULL : &i->second; +} + +inline const DictValue &Dict::get(const String &key) const +{ + _Dict::const_iterator i = dict.find(key); + if (i == dict.end()) + CV_Error(Error::StsObjectNotFound, "Required argument \"" + key + "\" not found into dictionary"); + return i->second; +} + +template +inline T Dict::get(const String &key) const +{ + return this->get(key).get(); +} + +template +inline T Dict::get(const String &key, const T &defaultValue) const +{ + _Dict::const_iterator i = dict.find(key); + + if (i != dict.end()) + return i->second.get(); + else + return defaultValue; +} + +template +inline const T &Dict::set(const String &key, const T &value) +{ + _Dict::iterator i = dict.find(key); + + if (i != dict.end()) + i->second = DictValue(value); + else + dict.insert(std::make_pair(key, DictValue(value))); + + return value; +} + +inline std::ostream &operator<<(std::ostream &stream, const Dict &dict) +{ + Dict::_Dict::const_iterator it; + for (it = dict.dict.begin(); it != dict.dict.end(); it++) + stream << it->first << " : " << it->second << "\n"; + + return stream; +} + +CV__DNN_EXPERIMENTAL_NS_END +} +} + +#endif diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/layer.details.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/layer.details.hpp new file mode 100644 index 00000000..82bd3b11 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/layer.details.hpp @@ -0,0 +1,78 @@ +// 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. +// +#ifndef OPENCV_DNN_LAYER_DETAILS_HPP +#define OPENCV_DNN_LAYER_DETAILS_HPP + +#include + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN + +/** @brief Registers layer constructor in runtime. +* @param type string, containing type name of the layer. +* @param constuctorFunc pointer to the function of type LayerRegister::Constuctor, which creates the layer. +* @details This macros must be placed inside the function code. +*/ +#define CV_DNN_REGISTER_LAYER_FUNC(type, constuctorFunc) \ + cv::dnn::LayerFactory::registerLayer(#type, constuctorFunc); + +/** @brief Registers layer class in runtime. + * @param type string, containing type name of the layer. + * @param class C++ class, derived from Layer. + * @details This macros must be placed inside the function code. + */ +#define CV_DNN_REGISTER_LAYER_CLASS(type, class) \ + cv::dnn::LayerFactory::registerLayer(#type, cv::dnn::details::_layerDynamicRegisterer); + +/** @brief Registers layer constructor on module load time. +* @param type string, containing type name of the layer. +* @param constuctorFunc pointer to the function of type LayerRegister::Constuctor, which creates the layer. +* @details This macros must be placed outside the function code. +*/ +#define CV_DNN_REGISTER_LAYER_FUNC_STATIC(type, constuctorFunc) \ +static cv::dnn::details::_LayerStaticRegisterer __LayerStaticRegisterer_##type(#type, constuctorFunc); + +/** @brief Registers layer class on module load time. + * @param type string, containing type name of the layer. + * @param class C++ class, derived from Layer. + * @details This macros must be placed outside the function code. + */ +#define CV_DNN_REGISTER_LAYER_CLASS_STATIC(type, class) \ +Ptr __LayerStaticRegisterer_func_##type(LayerParams ¶ms) \ + { return Ptr(new class(params)); } \ +static cv::dnn::details::_LayerStaticRegisterer __LayerStaticRegisterer_##type(#type, __LayerStaticRegisterer_func_##type); + +namespace details { + +template +Ptr _layerDynamicRegisterer(LayerParams ¶ms) +{ + return Ptr(LayerClass::create(params)); +} + +//allows automatically register created layer on module load time +class _LayerStaticRegisterer +{ + String type; +public: + + _LayerStaticRegisterer(const String &layerType, LayerFactory::Constuctor layerConstuctor) + { + this->type = layerType; + LayerFactory::registerLayer(layerType, layerConstuctor); + } + + ~_LayerStaticRegisterer() + { + LayerFactory::unregisterLayer(type); + } +}; + +} // namespace +CV__DNN_EXPERIMENTAL_NS_END +}} // namespace + +#endif diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/layer.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/layer.hpp new file mode 100644 index 00000000..3fb81f32 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/layer.hpp @@ -0,0 +1,85 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DNN_LAYER_HPP +#define OPENCV_DNN_LAYER_HPP +#include + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN +//! @addtogroup dnn +//! @{ +//! +//! @defgroup dnnLayerFactory Utilities for New Layers Registration +//! @{ + +/** @brief %Layer factory allows to create instances of registered layers. */ +class CV_EXPORTS LayerFactory +{ +public: + + //! Each Layer class must provide this function to the factory + typedef Ptr(*Constuctor)(LayerParams ¶ms); + + //! Registers the layer class with typename @p type and specified @p constructor. Thread-safe. + static void registerLayer(const String &type, Constuctor constructor); + + //! Unregisters registered layer with specified type name. Thread-safe. + static void unregisterLayer(const String &type); + + /** @brief Creates instance of registered layer. + * @param type type name of creating layer. + * @param params parameters which will be used for layer initialization. + * @note Thread-safe. + */ + static Ptr createLayerInstance(const String &type, LayerParams& params); + +private: + LayerFactory(); +}; + +//! @} +//! @} +CV__DNN_EXPERIMENTAL_NS_END +} +} +#endif diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/shape_utils.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/shape_utils.hpp new file mode 100644 index 00000000..fa4b497a --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/dnn/shape_utils.hpp @@ -0,0 +1,206 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_SHAPE_UTILS_HPP +#define OPENCV_DNN_DNN_SHAPE_UTILS_HPP + +#include +#include +#include + +namespace cv { +namespace dnn { +CV__DNN_EXPERIMENTAL_NS_BEGIN + +//Useful shortcut +inline std::ostream &operator<< (std::ostream &s, cv::Range &r) +{ + return s << "[" << r.start << ", " << r.end << ")"; +} + +//Slicing + +struct _Range : public cv::Range +{ + _Range(const Range &r) : cv::Range(r) {} + _Range(int start_, int size_ = 1) : cv::Range(start_, start_ + size_) {} +}; + +static inline Mat slice(const Mat &m, const _Range &r0) +{ + Range ranges[CV_MAX_DIM]; + for (int i = 1; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + return m(&ranges[0]); +} + +static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1) +{ + CV_Assert(m.dims >= 2); + Range ranges[CV_MAX_DIM]; + for (int i = 2; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + ranges[1] = r1; + return m(&ranges[0]); +} + +static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1, const _Range &r2) +{ + CV_Assert(m.dims >= 3); + Range ranges[CV_MAX_DIM]; + for (int i = 3; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + ranges[1] = r1; + ranges[2] = r2; + return m(&ranges[0]); +} + +static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1, const _Range &r2, const _Range &r3) +{ + CV_Assert(m.dims >= 4); + Range ranges[CV_MAX_DIM]; + for (int i = 4; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + ranges[1] = r1; + ranges[2] = r2; + ranges[3] = r3; + return m(&ranges[0]); +} + +static inline Mat getPlane(const Mat &m, int n, int cn) +{ + CV_Assert(m.dims > 2); + int sz[CV_MAX_DIM]; + for(int i = 2; i < m.dims; i++) + { + sz[i-2] = m.size.p[i]; + } + return Mat(m.dims - 2, sz, m.type(), (void*)m.ptr(n, cn)); +} + +static inline MatShape shape(const int* dims, const int n = 4) +{ + MatShape shape; + shape.assign(dims, dims + n); + return shape; +} + +static inline MatShape shape(const Mat& mat) +{ + return shape(mat.size.p, mat.dims); +} + +static inline MatShape shape(const UMat& mat) +{ + return shape(mat.size.p, mat.dims); +} + +namespace {inline bool is_neg(int i) { return i < 0; }} + +static inline MatShape shape(int a0, int a1=-1, int a2=-1, int a3=-1) +{ + int dims[] = {a0, a1, a2, a3}; + MatShape s = shape(dims); + s.erase(std::remove_if(s.begin(), s.end(), is_neg), s.end()); + return s; +} + +static inline int total(const MatShape& shape, int start = -1, int end = -1) +{ + if (start == -1) start = 0; + if (end == -1) end = (int)shape.size(); + + if (shape.empty()) + return 0; + + int elems = 1; + CV_Assert(start <= (int)shape.size() && end <= (int)shape.size() && + start <= end); + for(int i = start; i < end; i++) + { + elems *= shape[i]; + } + return elems; +} + +static inline MatShape concat(const MatShape& a, const MatShape& b) +{ + MatShape c = a; + c.insert(c.end(), b.begin(), b.end()); + + return c; +} + +inline void print(const MatShape& shape, const String& name = "") +{ + printf("%s: [", name.c_str()); + size_t i, n = shape.size(); + for( i = 0; i < n; i++ ) + printf(" %d", shape[i]); + printf(" ]\n"); +} + +inline int clamp(int ax, int dims) +{ + return ax < 0 ? ax + dims : ax; +} + +inline int clamp(int ax, const MatShape& shape) +{ + return clamp(ax, (int)shape.size()); +} + +inline Range clamp(const Range& r, int axisSize) +{ + Range clamped(std::max(r.start, 0), + r.end > 0 ? std::min(r.end, axisSize) : axisSize + r.end + 1); + CV_Assert(clamped.start < clamped.end, clamped.end <= axisSize); + return clamped; +} + +CV__DNN_EXPERIMENTAL_NS_END +} +} +#endif diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/features2d.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/features2d.hpp similarity index 91% rename from lib/3rdParty/OpenCV3.1/include/opencv2/features2d.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/features2d.hpp index 692d3d9f..82d76c40 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/features2d.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/features2d.hpp @@ -40,11 +40,15 @@ // //M*/ -#ifndef __OPENCV_FEATURES_2D_HPP__ -#define __OPENCV_FEATURES_2D_HPP__ +#ifndef OPENCV_FEATURES_2D_HPP +#define OPENCV_FEATURES_2D_HPP +#include "opencv2/opencv_modules.hpp" #include "opencv2/core.hpp" + +#ifdef HAVE_OPENCV_FLANN #include "opencv2/flann/miniflann.hpp" +#endif /** @defgroup features2d 2D Features Framework @@ -117,6 +121,10 @@ public: * Remove duplicated keypoints. */ static void removeDuplicated( std::vector& keypoints ); + /* + * Remove duplicated keypoints and sort the remaining keypoints + */ + static void removeDuplicatedSorted( std::vector& keypoints ); /* * Retain the specified number of the best keypoints (according to the response) @@ -153,8 +161,8 @@ public: @param masks Masks for each input image specifying where to look for keypoints (optional). masks[i] is a mask for images[i]. */ - virtual void detect( InputArrayOfArrays images, - std::vector >& keypoints, + CV_WRAP virtual void detect( InputArrayOfArrays images, + CV_OUT std::vector >& keypoints, InputArrayOfArrays masks=noArray() ); /** @brief Computes the descriptors for a set of keypoints detected in an image (first variant) or image set @@ -182,8 +190,8 @@ public: descriptors computed for a keypoints[i]. Row j is the keypoints (or keypoints[i]) is the descriptor for keypoint j-th keypoint. */ - virtual void compute( InputArrayOfArrays images, - std::vector >& keypoints, + CV_WRAP virtual void compute( InputArrayOfArrays images, + CV_OUT CV_IN_OUT std::vector >& keypoints, OutputArrayOfArrays descriptors ); /** Detects keypoints and computes the descriptors */ @@ -196,8 +204,21 @@ public: CV_WRAP virtual int descriptorType() const; CV_WRAP virtual int defaultNorm() const; + CV_WRAP void write( const String& fileName ) const; + + CV_WRAP void read( const String& fileName ); + + virtual void write( FileStorage&) const; + + // see corresponding cv::Algorithm method + CV_WRAP virtual void read( const FileNode&); + //! Return true if detector object is empty CV_WRAP virtual bool empty() const; + CV_WRAP virtual String getDefaultName() const; + + // see corresponding cv::Algorithm method + CV_WRAP inline void write(const Ptr& fs, const String& name = String()) const { Algorithm::write(fs, name); } }; /** Feature detectors in OpenCV have wrappers with a common interface that enables you to easily switch @@ -242,6 +263,24 @@ public: @param indexChange index remapping of the bits. */ CV_WRAP static Ptr create(const std::vector &radiusList, const std::vector &numberList, float dMax=5.85f, float dMin=8.2f, const std::vector& indexChange=std::vector()); + + /** @brief The BRISK constructor for a custom pattern, detection threshold and octaves + + @param thresh AGAST detection threshold score. + @param octaves detection octaves. Use 0 to do single scale. + @param radiusList defines the radii (in pixels) where the samples around a keypoint are taken (for + keypoint scale 1). + @param numberList defines the number of sampling points on the sampling circle. Must be the same + size as radiusList.. + @param dMax threshold for the short pairings used for descriptor formation (in pixels for keypoint + scale 1). + @param dMin threshold for the long pairings used for orientation determination (in pixels for + keypoint scale 1). + @param indexChange index remapping of the bits. */ + CV_WRAP static Ptr create(int thresh, int octaves, const std::vector &radiusList, + const std::vector &numberList, float dMax=5.85f, float dMin=8.2f, + const std::vector& indexChange=std::vector()); + CV_WRAP virtual String getDefaultName() const; }; /** @brief Class implementing the ORB (*oriented BRIEF*) keypoint detector and descriptor extractor @@ -315,6 +354,7 @@ public: CV_WRAP virtual void setFastThreshold(int fastThreshold) = 0; CV_WRAP virtual int getFastThreshold() const = 0; + CV_WRAP virtual String getDefaultName() const; }; /** @brief Maximally stable extremal region extractor @@ -355,13 +395,13 @@ public: /** @brief Detect %MSER regions - @param image input image (8UC1, 8UC3 or 8UC4) + @param image input image (8UC1, 8UC3 or 8UC4, must be greater or equal than 3x3) @param msers resulting list of point sets @param bboxes resulting bounding boxes */ CV_WRAP virtual void detectRegions( InputArray image, CV_OUT std::vector >& msers, - std::vector& bboxes ) = 0; + CV_OUT std::vector& bboxes ) = 0; CV_WRAP virtual void setDelta(int delta) = 0; CV_WRAP virtual int getDelta() const = 0; @@ -374,6 +414,7 @@ public: CV_WRAP virtual void setPass2Only(bool f) = 0; CV_WRAP virtual bool getPass2Only() const = 0; + CV_WRAP virtual String getDefaultName() const; }; /** @overload */ @@ -429,6 +470,7 @@ public: CV_WRAP virtual void setType(int type) = 0; CV_WRAP virtual int getType() const = 0; + CV_WRAP virtual String getDefaultName() const; }; /** @overload */ @@ -483,6 +525,7 @@ public: CV_WRAP virtual void setType(int type) = 0; CV_WRAP virtual int getType() const = 0; + CV_WRAP virtual String getDefaultName() const; }; /** @brief Wrapping class for feature detection using the goodFeaturesToTrack function. : @@ -492,6 +535,8 @@ class CV_EXPORTS_W GFTTDetector : public Feature2D public: CV_WRAP static Ptr create( int maxCorners=1000, double qualityLevel=0.01, double minDistance=1, int blockSize=3, bool useHarrisDetector=false, double k=0.04 ); + CV_WRAP static Ptr create( int maxCorners, double qualityLevel, double minDistance, + int blockSize, int gradiantSize, bool useHarrisDetector=false, double k=0.04 ); CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0; CV_WRAP virtual int getMaxFeatures() const = 0; @@ -509,6 +554,7 @@ public: CV_WRAP virtual void setK(double k) = 0; CV_WRAP virtual double getK() const = 0; + CV_WRAP virtual String getDefaultName() const; }; /** @brief Class for extracting blobs from an image. : @@ -575,6 +621,7 @@ public: CV_WRAP static Ptr create(const SimpleBlobDetector::Params ¶meters = SimpleBlobDetector::Params()); + CV_WRAP virtual String getDefaultName() const; }; //! @} features2d_main @@ -631,15 +678,25 @@ public: CV_WRAP virtual void setDiffusivity(int diff) = 0; CV_WRAP virtual int getDiffusivity() const = 0; + CV_WRAP virtual String getDefaultName() const; }; -/** @brief Class implementing the AKAZE keypoint detector and descriptor extractor, described in @cite ANB13 . : +/** @brief Class implementing the AKAZE keypoint detector and descriptor extractor, described in @cite ANB13. -@note AKAZE descriptors can only be used with KAZE or AKAZE keypoints. Try to avoid using *extract* -and *detect* instead of *operator()* due to performance reasons. .. [ANB13] Fast Explicit Diffusion -for Accelerated Features in Nonlinear Scale Spaces. Pablo F. Alcantarilla, Jesús Nuevo and Adrien -Bartoli. In British Machine Vision Conference (BMVC), Bristol, UK, September 2013. - */ +@details AKAZE descriptors can only be used with KAZE or AKAZE keypoints. This class is thread-safe. + +@note When you need descriptors use Feature2D::detectAndCompute, which +provides better performance. When using Feature2D::detect followed by +Feature2D::compute scale space pyramid is computed twice. + +@note AKAZE implements T-API. When image is passed as UMat some parts of the algorithm +will use OpenCL. + +@note [ANB13] Fast Explicit Diffusion for Accelerated Features in Nonlinear +Scale Spaces. Pablo F. Alcantarilla, Jesús Nuevo and Adrien Bartoli. In +British Machine Vision Conference (BMVC), Bristol, UK, September 2013. + +*/ class CV_EXPORTS_W AKAZE : public Feature2D { public: @@ -689,6 +746,7 @@ public: CV_WRAP virtual void setDiffusivity(int diff) = 0; CV_WRAP virtual int getDiffusivity() const = 0; + CV_WRAP virtual String getDefaultName() const; }; //! @} features2d_main @@ -728,7 +786,7 @@ struct CV_EXPORTS SL2 * Euclidean distance functor */ template -struct CV_EXPORTS L2 +struct L2 { enum { normType = NORM_L2 }; typedef T ValueType; @@ -744,7 +802,7 @@ struct CV_EXPORTS L2 * Manhattan distance (city block distance) functor */ template -struct CV_EXPORTS L1 +struct L1 { enum { normType = NORM_L1 }; typedef T ValueType; @@ -771,6 +829,15 @@ an image set. class CV_EXPORTS_W DescriptorMatcher : public Algorithm { public: + enum + { + FLANNBASED = 1, + BRUTEFORCE = 2, + BRUTEFORCE_L1 = 3, + BRUTEFORCE_HAMMING = 4, + BRUTEFORCE_HAMMINGLUT = 5, + BRUTEFORCE_SL2 = 6 + }; virtual ~DescriptorMatcher(); /** @brief Adds descriptors to train a CPU(trainDescCollectionis) or GPU(utrainDescCollectionis) descriptor @@ -868,8 +935,8 @@ public: query descriptor and the training descriptor is equal or smaller than maxDistance. Found matches are returned in the distance increasing order. */ - void radiusMatch( InputArray queryDescriptors, InputArray trainDescriptors, - std::vector >& matches, float maxDistance, + CV_WRAP void radiusMatch( InputArray queryDescriptors, InputArray trainDescriptors, + CV_OUT std::vector >& matches, float maxDistance, InputArray mask=noArray(), bool compactResult=false ) const; /** @overload @@ -906,11 +973,24 @@ public: false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, the matches vector does not contain matches for fully masked-out query descriptors. */ - void radiusMatch( InputArray queryDescriptors, std::vector >& matches, float maxDistance, + CV_WRAP void radiusMatch( InputArray queryDescriptors, CV_OUT std::vector >& matches, float maxDistance, InputArrayOfArrays masks=noArray(), bool compactResult=false ); + + CV_WRAP void write( const String& fileName ) const + { + FileStorage fs(fileName, FileStorage::WRITE); + write(fs); + } + + CV_WRAP void read( const String& fileName ) + { + FileStorage fs(fileName, FileStorage::READ); + read(fs.root()); + } // Reads matcher object from a file node - virtual void read( const FileNode& ); + // see corresponding cv::Algorithm method + CV_WRAP virtual void read( const FileNode& ); // Writes matcher object to a file storage virtual void write( FileStorage& ) const; @@ -920,7 +1000,7 @@ public: that is, copies both parameters and train data. If emptyTrainData is true, the method creates an object copy with the current parameters but with empty train data. */ - virtual Ptr clone( bool emptyTrainData=false ) const = 0; + CV_WRAP virtual Ptr clone( bool emptyTrainData=false ) const = 0; /** @brief Creates a descriptor matcher of a given type with the default parameters (using default constructor). @@ -934,6 +1014,13 @@ public: - `FlannBased` */ CV_WRAP static Ptr create( const String& descriptorMatcherType ); + + CV_WRAP static Ptr create( int matcherType ); + + + // see corresponding cv::Algorithm method + CV_WRAP inline void write(const Ptr& fs, const String& name = String()) const { Algorithm::write(fs, name); } + protected: /** * Class to work with descriptors from several images as with one merged matrix. @@ -990,8 +1077,17 @@ sets. class CV_EXPORTS_W BFMatcher : public DescriptorMatcher { public: - /** @brief Brute-force matcher constructor. + /** @brief Brute-force matcher constructor (obsolete). Please use BFMatcher.create() + * + * + */ + CV_WRAP BFMatcher( int normType=NORM_L2, bool crossCheck=false ); + virtual ~BFMatcher() {} + + virtual bool isMaskSupported() const { return true; } + + /** @brief Brute-force matcher create method. @param normType One of NORM_L1, NORM_L2, NORM_HAMMING, NORM_HAMMING2. L1 and L2 norms are preferable choices for SIFT and SURF descriptors, NORM_HAMMING should be used with ORB, BRISK and BRIEF, NORM_HAMMING2 should be used with ORB when WTA_K==3 or 4 (see ORB::ORB constructor @@ -1003,10 +1099,7 @@ public: pairs. Such technique usually produces best results with minimal number of outliers when there are enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper. */ - CV_WRAP BFMatcher( int normType=NORM_L2, bool crossCheck=false ); - virtual ~BFMatcher() {} - - virtual bool isMaskSupported() const { return true; } + CV_WRAP static Ptr create( int normType=NORM_L2, bool crossCheck=false ) ; virtual Ptr clone( bool emptyTrainData=false ) const; protected: @@ -1019,10 +1112,11 @@ protected: bool crossCheck; }; +#if defined(HAVE_OPENCV_FLANN) || defined(CV_DOXYGEN) /** @brief Flann-based descriptor matcher. -This matcher trains flann::Index_ on a train descriptor collection and calls its nearest search +This matcher trains cv::flann::Index on a train descriptor collection and calls its nearest search methods to find the best matches. So, this matcher may be faster when matching a large train collection than the brute force matcher. FlannBasedMatcher does not support masking permissible matches of descriptor sets because flann::Index does not support this. : @@ -1044,6 +1138,8 @@ public: virtual void train(); virtual bool isMaskSupported() const; + CV_WRAP static Ptr create(); + virtual Ptr clone( bool emptyTrainData=false ) const; protected: static void convertToDMatches( const DescriptorCollection& descriptors, @@ -1063,6 +1159,8 @@ protected: int addedDescCount; }; +#endif + //! @} features2d_match /****************************************************************************************\ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/features2d/features2d.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/features2d/features2d.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/features2d/features2d.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/features2d/features2d.hpp diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/flann.hpp similarity index 71% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann.hpp index 4f92d57e..22c6ffcf 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef _OPENCV_FLANN_HPP_ -#define _OPENCV_FLANN_HPP_ +#ifndef OPENCV_FLANN_HPP +#define OPENCV_FLANN_HPP #include "opencv2/core.hpp" #include "opencv2/flann/miniflann.hpp" @@ -59,7 +59,7 @@ can be found in @cite Muja2009 . namespace cvflann { CV_EXPORTS flann_distance_t flann_distance_type(); - FLANN_DEPRECATED CV_EXPORTS void set_distance_type(flann_distance_t distance_type, int order); + CV_DEPRECATED CV_EXPORTS void set_distance_type(flann_distance_t distance_type, int order); } @@ -230,7 +230,7 @@ public: ::cvflann::IndexParams getParameters() { return nnIndex->getParameters(); } - FLANN_DEPRECATED const ::cvflann::IndexParams* getIndexParameters() { return nnIndex->getIndexParameters(); } + CV_DEPRECATED const ::cvflann::IndexParams* getIndexParameters() { return nnIndex->getIndexParameters(); } private: ::cvflann::Index* nnIndex; @@ -338,164 +338,134 @@ int GenericIndex::radiusSearch(const Mat& query, Mat& indices, Mat& di * @deprecated Use GenericIndex class instead */ template -class -#ifndef _MSC_VER - FLANN_DEPRECATED -#endif - Index_ { +class Index_ +{ public: - typedef typename L2::ElementType ElementType; - typedef typename L2::ResultType DistanceType; + typedef typename L2::ElementType ElementType; + typedef typename L2::ResultType DistanceType; - Index_(const Mat& features, const ::cvflann::IndexParams& params); - - ~Index_(); - - void knnSearch(const std::vector& query, std::vector& indices, std::vector& dists, int knn, const ::cvflann::SearchParams& params); - void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& params); - - int radiusSearch(const std::vector& query, std::vector& indices, std::vector& dists, DistanceType radius, const ::cvflann::SearchParams& params); - int radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& params); - - void save(String filename) - { - if (nnIndex_L1) nnIndex_L1->save(filename); - if (nnIndex_L2) nnIndex_L2->save(filename); - } - - int veclen() const + CV_DEPRECATED Index_(const Mat& dataset, const ::cvflann::IndexParams& params) { - if (nnIndex_L1) return nnIndex_L1->veclen(); - if (nnIndex_L2) return nnIndex_L2->veclen(); - } + printf("[WARNING] The cv::flann::Index_ class is deperecated, use cv::flann::GenericIndex instead\n"); - int size() const + CV_Assert(dataset.type() == CvType::type()); + CV_Assert(dataset.isContinuous()); + ::cvflann::Matrix m_dataset((ElementType*)dataset.ptr(0), dataset.rows, dataset.cols); + + if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) { + nnIndex_L1 = NULL; + nnIndex_L2 = new ::cvflann::Index< L2 >(m_dataset, params); + } + else if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L1 ) { + nnIndex_L1 = new ::cvflann::Index< L1 >(m_dataset, params); + nnIndex_L2 = NULL; + } + else { + printf("[ERROR] cv::flann::Index_ only provides backwards compatibility for the L1 and L2 distances. " + "For other distance types you must use cv::flann::GenericIndex\n"); + CV_Assert(0); + } + if (nnIndex_L1) nnIndex_L1->buildIndex(); + if (nnIndex_L2) nnIndex_L2->buildIndex(); + } + CV_DEPRECATED ~Index_() { - if (nnIndex_L1) return nnIndex_L1->size(); - if (nnIndex_L2) return nnIndex_L2->size(); - } + if (nnIndex_L1) delete nnIndex_L1; + if (nnIndex_L2) delete nnIndex_L2; + } - ::cvflann::IndexParams getParameters() - { - if (nnIndex_L1) return nnIndex_L1->getParameters(); - if (nnIndex_L2) return nnIndex_L2->getParameters(); + CV_DEPRECATED void knnSearch(const std::vector& query, std::vector& indices, std::vector& dists, int knn, const ::cvflann::SearchParams& searchParams) + { + ::cvflann::Matrix m_query((ElementType*)&query[0], 1, query.size()); + ::cvflann::Matrix m_indices(&indices[0], 1, indices.size()); + ::cvflann::Matrix m_dists(&dists[0], 1, dists.size()); - } + if (nnIndex_L1) nnIndex_L1->knnSearch(m_query,m_indices,m_dists,knn,searchParams); + if (nnIndex_L2) nnIndex_L2->knnSearch(m_query,m_indices,m_dists,knn,searchParams); + } + CV_DEPRECATED void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& searchParams) + { + CV_Assert(queries.type() == CvType::type()); + CV_Assert(queries.isContinuous()); + ::cvflann::Matrix m_queries((ElementType*)queries.ptr(0), queries.rows, queries.cols); - FLANN_DEPRECATED const ::cvflann::IndexParams* getIndexParameters() - { - if (nnIndex_L1) return nnIndex_L1->getIndexParameters(); - if (nnIndex_L2) return nnIndex_L2->getIndexParameters(); - } + CV_Assert(indices.type() == CV_32S); + CV_Assert(indices.isContinuous()); + ::cvflann::Matrix m_indices((int*)indices.ptr(0), indices.rows, indices.cols); + + CV_Assert(dists.type() == CvType::type()); + CV_Assert(dists.isContinuous()); + ::cvflann::Matrix m_dists((DistanceType*)dists.ptr(0), dists.rows, dists.cols); + + if (nnIndex_L1) nnIndex_L1->knnSearch(m_queries,m_indices,m_dists,knn, searchParams); + if (nnIndex_L2) nnIndex_L2->knnSearch(m_queries,m_indices,m_dists,knn, searchParams); + } + + CV_DEPRECATED int radiusSearch(const std::vector& query, std::vector& indices, std::vector& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) + { + ::cvflann::Matrix m_query((ElementType*)&query[0], 1, query.size()); + ::cvflann::Matrix m_indices(&indices[0], 1, indices.size()); + ::cvflann::Matrix m_dists(&dists[0], 1, dists.size()); + + if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + } + + CV_DEPRECATED int radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) + { + CV_Assert(query.type() == CvType::type()); + CV_Assert(query.isContinuous()); + ::cvflann::Matrix m_query((ElementType*)query.ptr(0), query.rows, query.cols); + + CV_Assert(indices.type() == CV_32S); + CV_Assert(indices.isContinuous()); + ::cvflann::Matrix m_indices((int*)indices.ptr(0), indices.rows, indices.cols); + + CV_Assert(dists.type() == CvType::type()); + CV_Assert(dists.isContinuous()); + ::cvflann::Matrix m_dists((DistanceType*)dists.ptr(0), dists.rows, dists.cols); + + if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + } + + CV_DEPRECATED void save(String filename) + { + if (nnIndex_L1) nnIndex_L1->save(filename); + if (nnIndex_L2) nnIndex_L2->save(filename); + } + + CV_DEPRECATED int veclen() const + { + if (nnIndex_L1) return nnIndex_L1->veclen(); + if (nnIndex_L2) return nnIndex_L2->veclen(); + } + + CV_DEPRECATED int size() const + { + if (nnIndex_L1) return nnIndex_L1->size(); + if (nnIndex_L2) return nnIndex_L2->size(); + } + + CV_DEPRECATED ::cvflann::IndexParams getParameters() + { + if (nnIndex_L1) return nnIndex_L1->getParameters(); + if (nnIndex_L2) return nnIndex_L2->getParameters(); + + } + + CV_DEPRECATED const ::cvflann::IndexParams* getIndexParameters() + { + if (nnIndex_L1) return nnIndex_L1->getIndexParameters(); + if (nnIndex_L2) return nnIndex_L2->getIndexParameters(); + } private: - // providing backwards compatibility for L2 and L1 distances (most common) - ::cvflann::Index< L2 >* nnIndex_L2; - ::cvflann::Index< L1 >* nnIndex_L1; + // providing backwards compatibility for L2 and L1 distances (most common) + ::cvflann::Index< L2 >* nnIndex_L2; + ::cvflann::Index< L1 >* nnIndex_L1; }; -#ifdef _MSC_VER -template -class FLANN_DEPRECATED Index_; -#endif - -//! @cond IGNORED - -template -Index_::Index_(const Mat& dataset, const ::cvflann::IndexParams& params) -{ - printf("[WARNING] The cv::flann::Index_ class is deperecated, use cv::flann::GenericIndex instead\n"); - - CV_Assert(dataset.type() == CvType::type()); - CV_Assert(dataset.isContinuous()); - ::cvflann::Matrix m_dataset((ElementType*)dataset.ptr(0), dataset.rows, dataset.cols); - - if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) { - nnIndex_L1 = NULL; - nnIndex_L2 = new ::cvflann::Index< L2 >(m_dataset, params); - } - else if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L1 ) { - nnIndex_L1 = new ::cvflann::Index< L1 >(m_dataset, params); - nnIndex_L2 = NULL; - } - else { - printf("[ERROR] cv::flann::Index_ only provides backwards compatibility for the L1 and L2 distances. " - "For other distance types you must use cv::flann::GenericIndex\n"); - CV_Assert(0); - } - if (nnIndex_L1) nnIndex_L1->buildIndex(); - if (nnIndex_L2) nnIndex_L2->buildIndex(); -} - -template -Index_::~Index_() -{ - if (nnIndex_L1) delete nnIndex_L1; - if (nnIndex_L2) delete nnIndex_L2; -} - -template -void Index_::knnSearch(const std::vector& query, std::vector& indices, std::vector& dists, int knn, const ::cvflann::SearchParams& searchParams) -{ - ::cvflann::Matrix m_query((ElementType*)&query[0], 1, query.size()); - ::cvflann::Matrix m_indices(&indices[0], 1, indices.size()); - ::cvflann::Matrix m_dists(&dists[0], 1, dists.size()); - - if (nnIndex_L1) nnIndex_L1->knnSearch(m_query,m_indices,m_dists,knn,searchParams); - if (nnIndex_L2) nnIndex_L2->knnSearch(m_query,m_indices,m_dists,knn,searchParams); -} - - -template -void Index_::knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& searchParams) -{ - CV_Assert(queries.type() == CvType::type()); - CV_Assert(queries.isContinuous()); - ::cvflann::Matrix m_queries((ElementType*)queries.ptr(0), queries.rows, queries.cols); - - CV_Assert(indices.type() == CV_32S); - CV_Assert(indices.isContinuous()); - ::cvflann::Matrix m_indices((int*)indices.ptr(0), indices.rows, indices.cols); - - CV_Assert(dists.type() == CvType::type()); - CV_Assert(dists.isContinuous()); - ::cvflann::Matrix m_dists((DistanceType*)dists.ptr(0), dists.rows, dists.cols); - - if (nnIndex_L1) nnIndex_L1->knnSearch(m_queries,m_indices,m_dists,knn, searchParams); - if (nnIndex_L2) nnIndex_L2->knnSearch(m_queries,m_indices,m_dists,knn, searchParams); -} - -template -int Index_::radiusSearch(const std::vector& query, std::vector& indices, std::vector& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) -{ - ::cvflann::Matrix m_query((ElementType*)&query[0], 1, query.size()); - ::cvflann::Matrix m_indices(&indices[0], 1, indices.size()); - ::cvflann::Matrix m_dists(&dists[0], 1, dists.size()); - - if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); - if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); -} - -template -int Index_::radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) -{ - CV_Assert(query.type() == CvType::type()); - CV_Assert(query.isContinuous()); - ::cvflann::Matrix m_query((ElementType*)query.ptr(0), query.rows, query.cols); - - CV_Assert(indices.type() == CV_32S); - CV_Assert(indices.isContinuous()); - ::cvflann::Matrix m_indices((int*)indices.ptr(0), indices.rows, indices.cols); - - CV_Assert(dists.type() == CvType::type()); - CV_Assert(dists.isContinuous()); - ::cvflann::Matrix m_dists((DistanceType*)dists.ptr(0), dists.rows, dists.cols); - - if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); - if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); -} - -//! @endcond /** @brief Clusters features using hierarchical k-means algorithm. @@ -535,7 +505,7 @@ int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::K /** @deprecated */ template -FLANN_DEPRECATED int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::KMeansIndexParams& params) +CV_DEPRECATED int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::KMeansIndexParams& params) { printf("[WARNING] cv::flann::hierarchicalClustering is deprecated, use " "cv::flann::hierarchicalClustering instead\n"); diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/all_indices.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/all_indices.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/all_indices.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/all_indices.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/allocator.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/allocator.h similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/allocator.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/allocator.h index 26091d0c..f347f88e 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/allocator.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/allocator.h @@ -97,6 +97,7 @@ public: blocksize = blockSize; remaining = 0; base = NULL; + loc = NULL; usedMemory = 0; wastedMemory = 0; @@ -181,6 +182,9 @@ public: return mem; } +private: + PooledAllocator(const PooledAllocator &); // copy disabled + PooledAllocator& operator=(const PooledAllocator &); // assign disabled }; } diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/any.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/any.h similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/any.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/any.h index 8c2edaa7..e829162b 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/any.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/any.h @@ -79,7 +79,8 @@ struct big_any_policy : typed_base_any_policy { virtual void static_delete(void** x) { - if (* x) delete (* reinterpret_cast(x)); *x = NULL; + if (* x) delete (* reinterpret_cast(x)); + *x = NULL; } virtual void copy_from_value(void const* src, void** dest) { @@ -245,6 +246,12 @@ public: return assign(x); } + /// Assignment operator. Template-based version above doesn't work as expected. We need regular assignment operator here. + any& operator=(const any& x) + { + return assign(x); + } + /// Assignment operator, specialed for literal strings. /// They have types like const char [6] which don't work as expected. any& operator=(const char* x) diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/autotuned_index.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/autotuned_index.h similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/autotuned_index.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/autotuned_index.h index 6ffb9297..e9abbf72 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/autotuned_index.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/autotuned_index.h @@ -30,6 +30,8 @@ #ifndef OPENCV_FLANN_AUTOTUNED_INDEX_H_ #define OPENCV_FLANN_AUTOTUNED_INDEX_H_ +#include + #include "general.h" #include "nn_index.h" #include "ground_truth.h" @@ -81,6 +83,7 @@ public: memory_weight_ = get_param(params, "memory_weight", 0.0f); sample_fraction_ = get_param(params,"sample_fraction", 0.1f); bestIndex_ = NULL; + speedup_ = 0; } AutotunedIndex(const AutotunedIndex&); diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/composite_index.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/composite_index.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/composite_index.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/composite_index.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/config.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/config.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/config.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/config.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/defines.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/defines.h similarity index 92% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/defines.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/defines.h index f0264f74..6fd53c2f 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/defines.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/defines.h @@ -35,7 +35,7 @@ #ifdef FLANN_EXPORT #undef FLANN_EXPORT #endif -#ifdef WIN32 +#ifdef _WIN32 /* win32 dll export/import directives */ #ifdef FLANN_EXPORTS #define FLANN_EXPORT __declspec(dllexport) @@ -50,19 +50,6 @@ #endif -#ifdef FLANN_DEPRECATED -#undef FLANN_DEPRECATED -#endif -#ifdef __GNUC__ -#define FLANN_DEPRECATED __attribute__ ((deprecated)) -#elif defined(_MSC_VER) -#define FLANN_DEPRECATED __declspec(deprecated) -#else -#pragma message("WARNING: You need to implement FLANN_DEPRECATED for this compiler") -#define FLANN_DEPRECATED -#endif - - #undef FLANN_PLATFORM_32_BIT #undef FLANN_PLATFORM_64_BIT #if defined __amd64__ || defined __x86_64__ || defined _WIN64 || defined _M_X64 diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/dist.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/dist.h similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/dist.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/dist.h index 9dbe5278..9e2c5129 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/dist.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/dist.h @@ -43,7 +43,7 @@ typedef unsigned __int64 uint64_t; #include "defines.h" -#if (defined WIN32 || defined _WIN32) && defined(_M_ARM) +#if defined _WIN32 && defined(_M_ARM) # include #endif @@ -698,7 +698,7 @@ struct KL_Divergence typedef typename Accumulator::Type ResultType; /** - * Compute the Kullback–Leibler divergence + * Compute the Kullback-Leibler divergence */ template ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/flann/dummy.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/dummy.h new file mode 100644 index 00000000..d6837e53 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/dummy.h @@ -0,0 +1,13 @@ + +#ifndef OPENCV_FLANN_DUMMY_H_ +#define OPENCV_FLANN_DUMMY_H_ + +namespace cvflann +{ + +CV_DEPRECATED inline void dummyfunc() {} + +} + + +#endif /* OPENCV_FLANN_DUMMY_H_ */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/dynamic_bitset.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/dynamic_bitset.h similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/dynamic_bitset.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/dynamic_bitset.h index d795b5d6..923b6583 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/dynamic_bitset.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/dynamic_bitset.h @@ -59,7 +59,7 @@ class DynamicBitset public: /** default constructor */ - DynamicBitset() + DynamicBitset() : size_(0) { } diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/flann.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/flann.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/flann.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/flann.hpp diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/flann_base.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/flann_base.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/flann_base.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/flann_base.hpp index 98c33cf6..f3fd4fb2 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/flann_base.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/flann_base.hpp @@ -80,9 +80,11 @@ NNIndex* load_saved_index(const Matrix } IndexHeader header = load_header(fin); if (header.data_type != Datatype::type()) { + fclose(fin); throw FLANNException("Datatype of saved index is different than of the one to be created."); } if ((size_t(header.rows) != dataset.rows)||(size_t(header.cols) != dataset.cols)) { + fclose(fin); throw FLANNException("The index saved belongs to a different dataset"); } @@ -241,7 +243,7 @@ public: /** * \brief Returns actual index */ - FLANN_DEPRECATED NNIndex* getIndex() + CV_DEPRECATED NNIndex* getIndex() { return nnIndex_; } @@ -250,7 +252,7 @@ public: * \brief Returns index parameters. * \deprecated use getParameters() instead. */ - FLANN_DEPRECATED const IndexParams* getIndexParameters() + CV_DEPRECATED const IndexParams* getIndexParameters() { return &index_params_; } @@ -262,6 +264,9 @@ private: bool loaded_; /** Parameters passed to the index */ IndexParams index_params_; + + Index(const Index &); // copy disabled + Index& operator=(const Index &); // assign disabled }; /** diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/general.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/general.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/general.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/general.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/ground_truth.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/ground_truth.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/ground_truth.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/ground_truth.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/hdf5.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/hdf5.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/hdf5.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/hdf5.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/heap.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/heap.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/heap.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/heap.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/hierarchical_clustering_index.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/hierarchical_clustering_index.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/hierarchical_clustering_index.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/hierarchical_clustering_index.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/index_testing.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/index_testing.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/index_testing.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/index_testing.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/kdtree_index.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/kdtree_index.h similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/kdtree_index.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/kdtree_index.h index dc0971c9..3f6ee017 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/kdtree_index.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/kdtree_index.h @@ -125,7 +125,12 @@ public: /* Construct the randomized trees. */ for (int i = 0; i < trees_; i++) { /* Randomize the order of vectors to allow for unbiased sampling. */ +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::randShuffle(vind_); +#else std::random_shuffle(vind_.begin(), vind_.end()); +#endif + tree_roots_[i] = divideTree(&vind_[0], int(size_) ); } } diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/kdtree_single_index.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/kdtree_single_index.h similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/kdtree_single_index.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/kdtree_single_index.h index 30488ad5..ef153920 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/kdtree_single_index.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/kdtree_single_index.h @@ -87,6 +87,7 @@ public: { size_ = dataset_.rows; dim_ = dataset_.cols; + root_node_ = 0; int dim_param = get_param(params,"dim",-1); if (dim_param>0) dim_ = dim_param; leaf_max_size_ = get_param(params,"leaf_max_size",10); diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/kmeans_index.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/kmeans_index.h similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/kmeans_index.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/kmeans_index.h index 226fc71f..98ad0c86 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/kmeans_index.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/kmeans_index.h @@ -874,6 +874,8 @@ private: computeClustering(node->childs[c],indices+start, end-start, branching, level+1); start=end; } + + delete[] centers; } diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/linear_index.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/linear_index.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/linear_index.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/linear_index.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/logger.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/logger.h similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/logger.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/logger.h index 24f3fb69..32618dbb 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/logger.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/logger.h @@ -63,7 +63,12 @@ class Logger stream = stdout; } else { +#ifdef _MSC_VER + if (fopen_s(&stream, name, "w") != 0) + stream = NULL; +#else stream = fopen(name,"w"); +#endif if (stream == NULL) { stream = stdout; } diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/lsh_index.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/lsh_index.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/lsh_index.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/lsh_index.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/lsh_table.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/lsh_table.h similarity index 93% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/lsh_table.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/lsh_table.h index 582dcdb2..1db9960f 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/lsh_table.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/lsh_table.h @@ -146,6 +146,9 @@ public: */ LshTable() { + key_size_ = 0; + feature_size_ = 0; + speed_level_ = kArray; } /** Default constructor @@ -155,7 +158,7 @@ public: */ LshTable(unsigned int feature_size, unsigned int key_size) { - (void)feature_size; + feature_size_ = feature_size; (void)key_size; std::cerr << "LSH is not implemented for that type" << std::endl; assert(0); @@ -265,7 +268,7 @@ private: { const size_t key_size_lower_bound = 1; //a value (size_t(1) << key_size) must fit the size_t type so key_size has to be strictly less than size of size_t - const size_t key_size_upper_bound = std::min(sizeof(BucketKey) * CHAR_BIT + 1, sizeof(size_t) * CHAR_BIT); + const size_t key_size_upper_bound = (std::min)(sizeof(BucketKey) * CHAR_BIT + 1, sizeof(size_t) * CHAR_BIT); if (key_size < key_size_lower_bound || key_size >= key_size_upper_bound) { CV_Error(cv::Error::StsBadArg, cv::format("Invalid key_size (=%d). Valid values for your system are %d <= key_size < %d.", (int)key_size, (int)key_size_lower_bound, (int)key_size_upper_bound)); @@ -330,6 +333,8 @@ private: */ unsigned int key_size_; + unsigned int feature_size_; + // Members only used for the unsigned char specialization /** The mask to apply to a feature to get the hash key * Only used in the unsigned char case @@ -343,14 +348,19 @@ private: template<> inline LshTable::LshTable(unsigned int feature_size, unsigned int subsignature_size) { + feature_size_ = feature_size; initialize(subsignature_size); // Allocate the mask - mask_ = std::vector((size_t)ceil((float)(feature_size * sizeof(char)) / (float)sizeof(size_t)), 0); + mask_ = std::vector((feature_size * sizeof(char) + sizeof(size_t) - 1) / sizeof(size_t), 0); // A bit brutal but fast to code - std::vector indices(feature_size * CHAR_BIT); - for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) indices[i] = i; + std::vector indices(feature_size * CHAR_BIT); + for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) indices[i] = (int)i; +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::randShuffle(indices); +#else std::random_shuffle(indices.begin(), indices.end()); +#endif // Generate a random set of order of subsignature_size_ bits for (unsigned int i = 0; i < key_size_; ++i) { @@ -386,6 +396,7 @@ inline size_t LshTable::getKey(const unsigned char* feature) cons { // no need to check if T is dividable by sizeof(size_t) like in the Hamming // distance computation as we have a mask + // FIXIT: This is bad assumption, because we reading tail bytes after of the allocated features buffer const size_t* feature_block_ptr = reinterpret_cast ((const void*)feature); // Figure out the subsignature of the feature @@ -394,10 +405,20 @@ inline size_t LshTable::getKey(const unsigned char* feature) cons size_t subsignature = 0; size_t bit_index = 1; - for (std::vector::const_iterator pmask_block = mask_.begin(); pmask_block != mask_.end(); ++pmask_block) { + for (unsigned i = 0; i < feature_size_; i += sizeof(size_t)) { // get the mask and signature blocks - size_t feature_block = *feature_block_ptr; - size_t mask_block = *pmask_block; + size_t feature_block; + if (i <= feature_size_ - sizeof(size_t)) + { + feature_block = *feature_block_ptr; + } + else + { + size_t tmp = 0; + memcpy(&tmp, feature_block_ptr, feature_size_ - i); // preserve bytes order + feature_block = tmp; + } + size_t mask_block = mask_[i / sizeof(size_t)]; while (mask_block) { // Get the lowest set bit in the mask block size_t lowest_bit = mask_block & (-(ptrdiff_t)mask_block); diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/matrix.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/matrix.h similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/matrix.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/matrix.h index 51b6c635..f6092d13 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/matrix.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/matrix.h @@ -66,7 +66,7 @@ public: /** * Convenience function for deallocating the storage data. */ - FLANN_DEPRECATED void free() + CV_DEPRECATED void free() { fprintf(stderr, "The cvflann::Matrix::free() method is deprecated " "and it does not do any memory deallocation any more. You are" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/miniflann.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/miniflann.hpp similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/miniflann.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/miniflann.hpp index 02fa236d..bda2ed49 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/miniflann.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/miniflann.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef _OPENCV_MINIFLANN_HPP_ -#define _OPENCV_MINIFLANN_HPP_ +#ifndef OPENCV_MINIFLANN_HPP +#define OPENCV_MINIFLANN_HPP #include "opencv2/core.hpp" #include "opencv2/flann/defines.h" @@ -74,6 +74,10 @@ struct CV_EXPORTS IndexParams std::vector& numValues) const; void* params; + +private: + IndexParams(const IndexParams &); // copy disabled + IndexParams& operator=(const IndexParams &); // assign disabled }; struct CV_EXPORTS KDTreeIndexParams : public IndexParams diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/nn_index.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/nn_index.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/nn_index.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/nn_index.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/object_factory.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/object_factory.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/object_factory.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/object_factory.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/params.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/params.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/params.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/params.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/random.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/random.h similarity index 85% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/random.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/random.h index a3cf5ec5..d6784747 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/random.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/random.h @@ -40,13 +40,31 @@ namespace cvflann { +inline int rand() +{ +#ifndef OPENCV_FLANN_USE_STD_RAND +# if INT_MAX == RAND_MAX + int v = cv::theRNG().next() & INT_MAX; +# else + int v = cv::theRNG().uniform(0, RAND_MAX + 1); +# endif +#else + int v = std::rand(); +#endif // OPENCV_FLANN_USE_STD_RAND + return v; +} + /** * Seeds the random number generator * @param seed Random seed */ inline void seed_random(unsigned int seed) { - srand(seed); +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::theRNG() = cv::RNG(seed); +#else + std::srand(seed); +#endif } /* @@ -60,7 +78,7 @@ inline void seed_random(unsigned int seed) */ inline double rand_double(double high = 1.0, double low = 0) { - return low + ((high-low) * (std::rand() / (RAND_MAX + 1.0))); + return low + ((high-low) * (rand() / (RAND_MAX + 1.0))); } /** @@ -71,7 +89,7 @@ inline double rand_double(double high = 1.0, double low = 0) */ inline int rand_int(int high = RAND_MAX, int low = 0) { - return low + (int) ( double(high-low) * (std::rand() / (RAND_MAX + 1.0))); + return low + (int) ( double(high-low) * (rand() / (RAND_MAX + 1.0))); } /** @@ -107,7 +125,11 @@ public: for (int i = 0; i < size_; ++i) vals_[i] = i; // shuffle the elements in the array +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::randShuffle(vals_); +#else std::random_shuffle(vals_.begin(), vals_.end()); +#endif counter_ = 0; } diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/result_set.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/result_set.h similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/result_set.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/result_set.h index 97500195..7c090939 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/result_set.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/result_set.h @@ -303,7 +303,7 @@ public: /** Default cosntructor */ UniqueResultSet() : - worst_distance_(std::numeric_limits::max()) + is_full_(false), worst_distance_(std::numeric_limits::max()) { } diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/sampling.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/sampling.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/sampling.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/sampling.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/saving.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/saving.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/saving.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/saving.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/simplex_downhill.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/simplex_downhill.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/simplex_downhill.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/simplex_downhill.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/flann/timer.h b/lib/3rdParty/OpenCV3.4/include/opencv2/flann/timer.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/flann/timer.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/flann/timer.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/highgui.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/highgui.hpp similarity index 85% rename from lib/3rdParty/OpenCV3.1/include/opencv2/highgui.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/highgui.hpp index 41bd8aff..e8aff6d0 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/highgui.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/highgui.hpp @@ -40,12 +40,16 @@ // //M*/ -#ifndef __OPENCV_HIGHGUI_HPP__ -#define __OPENCV_HIGHGUI_HPP__ +#ifndef OPENCV_HIGHGUI_HPP +#define OPENCV_HIGHGUI_HPP #include "opencv2/core.hpp" +#ifdef HAVE_OPENCV_IMGCODECS #include "opencv2/imgcodecs.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEOIO #include "opencv2/videoio.hpp" +#endif /** @defgroup highgui High-level GUI @@ -182,15 +186,18 @@ enum WindowFlags { WINDOW_FULLSCREEN = 1, //!< change the window to fullscreen. WINDOW_FREERATIO = 0x00000100, //!< the image expends as much as it can (no ratio constraint). - WINDOW_KEEPRATIO = 0x00000000 //!< the ratio of the image is respected. - }; + WINDOW_KEEPRATIO = 0x00000000, //!< the ratio of the image is respected. + WINDOW_GUI_EXPANDED=0x00000000, //!< status bar and tool bar + WINDOW_GUI_NORMAL = 0x00000010, //!< old fashious way + }; //! Flags for cv::setWindowProperty / cv::getWindowProperty enum WindowPropertyFlags { WND_PROP_FULLSCREEN = 0, //!< fullscreen property (can be WINDOW_NORMAL or WINDOW_FULLSCREEN). WND_PROP_AUTOSIZE = 1, //!< autosize property (can be WINDOW_NORMAL or WINDOW_AUTOSIZE). WND_PROP_ASPECT_RATIO = 2, //!< window's aspect ration (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO). - WND_PROP_OPENGL = 3 //!< opengl support. + WND_PROP_OPENGL = 3, //!< opengl support. + WND_PROP_VISIBLE = 4 //!< checks whether the window exists and is visible }; //! Mouse Events see cv::MouseCallback @@ -237,9 +244,10 @@ enum QtFontStyles { //! Qt "button" type enum QtButtonTypes { - QT_PUSH_BUTTON = 0, //!< Push button. - QT_CHECKBOX = 1, //!< Checkbox button. - QT_RADIOBOX = 2 //!< Radiobox button. + QT_PUSH_BUTTON = 0, //!< Push button. + QT_CHECKBOX = 1, //!< Checkbox button. + QT_RADIOBOX = 2, //!< Radiobox button. + QT_NEW_BUTTONBAR = 1024 //!< Button should create a new buttonbar }; /** @brief Callback function for mouse events. see cv::setMouseCallback @@ -287,9 +295,9 @@ Qt backend supports additional flags: displayed image (see imshow ), and you cannot change the window size manually. - **WINDOW_FREERATIO or WINDOW_KEEPRATIO:** WINDOW_FREERATIO adjusts the image with no respect to its ratio, whereas WINDOW_KEEPRATIO keeps the image ratio. - - **CV_GUI_NORMAL or CV_GUI_EXPANDED:** CV_GUI_NORMAL is the old way to draw the window - without statusbar and toolbar, whereas CV_GUI_EXPANDED is a new enhanced GUI. -By default, flags == WINDOW_AUTOSIZE | WINDOW_KEEPRATIO | CV_GUI_EXPANDED + - **WINDOW_GUI_NORMAL or WINDOW_GUI_EXPANDED:** WINDOW_GUI_NORMAL is the old way to draw the window + without statusbar and toolbar, whereas WINDOW_GUI_EXPANDED is a new enhanced GUI. +By default, flags == WINDOW_AUTOSIZE | WINDOW_KEEPRATIO | WINDOW_GUI_EXPANDED @param winname Name of the window in the window caption that may be used as a window identifier. @param flags Flags of the window. The supported flags are: (cv::WindowFlags) @@ -312,6 +320,15 @@ CV_EXPORTS_W void destroyAllWindows(); CV_EXPORTS_W int startWindowThread(); +/** @brief Similar to #waitKey, but returns full key code. + +@note + +Key code is implementation specific and depends on used backend: QT/GTK/Win32/etc + +*/ +CV_EXPORTS_W int waitKeyEx(int delay = 0); + /** @brief Waits for a pressed key. The function waitKey waits for a key event infinitely (when \f$\texttt{delay}\leq 0\f$ ) or for delay @@ -344,7 +361,7 @@ Otherwise, the image is scaled to fit the window. The function may scale the ima - If the image is 8-bit unsigned, it is displayed as is. - If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the value range [0,255\*256] is mapped to [0,255]. -- If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the +- If the image is 32-bit or 64-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255]. If window was created with OpenGL support, cv::imshow also support ogl::Buffer , ogl::Texture2D and @@ -384,6 +401,12 @@ CV_EXPORTS_W void imshow(const String& winname, InputArray mat); */ CV_EXPORTS_W void resizeWindow(const String& winname, int width, int height); +/** @overload +@param winname Window name. +@param size The new window size. +*/ +CV_EXPORTS_W void resizeWindow(const String& winname, const cv::Size& size); + /** @brief Moves window to the specified position @param winname Name of the window. @@ -423,7 +446,7 @@ CV_EXPORTS_W double getWindowProperty(const String& winname, int prop_id); @param winname Name of the window. @param onMouse Mouse callback. See OpenCV samples, such as -, on how to specify and +, on how to specify and use the callback. @param userdata The optional parameter passed to the callback. */ @@ -451,6 +474,44 @@ Mouse-wheel events are currently supported only on Windows. */ CV_EXPORTS int getMouseWheelDelta(int flags); +/** @brief Selects ROI on the given image. +Function creates a window and allows user to select a ROI using mouse. +Controls: use `space` or `enter` to finish selection, use key `c` to cancel selection (function will return the zero cv::Rect). + +@param windowName name of the window where selection process will be shown. +@param img image to select a ROI. +@param showCrosshair if true crosshair of selection rectangle will be shown. +@param fromCenter if true center of selection will match initial mouse position. In opposite case a corner of +selection rectangle will correspont to the initial mouse position. +@return selected ROI or empty rect if selection canceled. + +@note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...). +After finish of work an empty callback will be set for the used window. + */ +CV_EXPORTS_W Rect selectROI(const String& windowName, InputArray img, bool showCrosshair = true, bool fromCenter = false); + +/** @overload + */ +CV_EXPORTS_W Rect selectROI(InputArray img, bool showCrosshair = true, bool fromCenter = false); + +/** @brief Selects ROIs on the given image. +Function creates a window and allows user to select a ROIs using mouse. +Controls: use `space` or `enter` to finish current selection and start a new one, +use `esc` to terminate multiple ROI selection process. + +@param windowName name of the window where selection process will be shown. +@param img image to select a ROI. +@param boundingBoxes selected ROIs. +@param showCrosshair if true crosshair of selection rectangle will be shown. +@param fromCenter if true center of selection will match initial mouse position. In opposite case a corner of +selection rectangle will correspont to the initial mouse position. + +@note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...). +After finish of work an empty callback will be set for the used window. + */ +CV_EXPORTS_W void selectROIs(const String& windowName, InputArray img, + CV_OUT std::vector& boundingBoxes, bool showCrosshair = true, bool fromCenter = false); + /** @brief Creates a trackbar and attaches it to the specified window. The function createTrackbar creates a trackbar (a slider or range control) with the specified name @@ -537,7 +598,7 @@ panel. @param trackbarname Name of the trackbar. @param winname Name of the window that is the parent of trackbar. -@param minval New maximum position. +@param minval New minimum position. */ CV_EXPORTS_W void setTrackbarMin(const String& trackbarname, const String& winname, int minval); @@ -663,6 +724,23 @@ The function addText draws *text* on the image *img* using a specific font *font */ CV_EXPORTS void addText( const Mat& img, const String& text, Point org, const QtFont& font); +/** @brief Draws a text on the image. + +@param img 8-bit 3-channel image where the text should be drawn. +@param text Text to write on an image. +@param org Point(x,y) where the text should start on an image. +@param nameFont Name of the font. The name should match the name of a system font (such as +*Times*). If the font is not found, a default one is used. +@param pointSize Size of the font. If not specified, equal zero or negative, the point size of the +font is set to a system-dependent default value. Generally, this is 12 points. +@param color Color of the font in BGRA where A = 255 is fully transparent. +@param weight Font weight. Available operation flags are : cv::QtFontWeights You can also specify a positive integer for better control. +@param style Font style. Available operation flags are : cv::QtFontStyles +@param spacing Spacing between characters. It can be negative or positive. + */ +CV_EXPORTS_W void addText(const Mat& img, const String& text, Point org, const String& nameFont, int pointSize = -1, Scalar color = Scalar::all(0), + int weight = QT_FONT_NORMAL, int style = QT_STYLE_NORMAL, int spacing = 0); + /** @brief Displays a text on a window image as an overlay for a specified duration. The function displayOverlay displays useful information/tips on top of the window for a certain @@ -675,7 +753,7 @@ after the specified delay the original content of the window is restored. function is called before the previous overlay text timed out, the timer is restarted and the text is updated. If this value is zero, the text never disappears. */ -CV_EXPORTS void displayOverlay(const String& winname, const String& text, int delayms = 0); +CV_EXPORTS_W void displayOverlay(const String& winname, const String& text, int delayms = 0); /** @brief Displays a text on the window statusbar during the specified period of time. @@ -689,7 +767,7 @@ created with the CV_GUI_EXPANDED flags). the previous text timed out, the timer is restarted and the text is updated. If this value is zero, the text never disappears. */ -CV_EXPORTS void displayStatusBar(const String& winname, const String& text, int delayms = 0); +CV_EXPORTS_W void displayStatusBar(const String& winname, const String& text, int delayms = 0); /** @brief Saves parameters of the specified window. @@ -717,7 +795,8 @@ CV_EXPORTS void stopLoop(); The function createButton attaches a button to the control panel. Each button is added to a buttonbar to the right of the last button. A new buttonbar is created if nothing was attached to the -control panel before, or if the last element attached to the control panel was a trackbar. +control panel before, or if the last element attached to the control panel was a trackbar or if the +QT_NEW_BUTTONBAR flag is added to the type. See below various examples of the cv::createButton function call: : @code @@ -726,6 +805,7 @@ See below various examples of the cv::createButton function call: : createButton("button3",callbackButton,&value); createButton("button5",callbackButton1,NULL,QT_RADIOBOX); createButton("button6",callbackButton2,NULL,QT_PUSH_BUTTON,1); + createButton("button6",callbackButton2,NULL,QT_PUSH_BUTTON|QT_NEW_BUTTONBAR);// create a push button in a new row @endcode @param bar_name Name of the button. diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/highgui/highgui.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/highgui/highgui.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/highgui/highgui.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/highgui/highgui.hpp diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/highgui/highgui_c.h b/lib/3rdParty/OpenCV3.4/include/opencv2/highgui/highgui_c.h similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/highgui/highgui_c.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/highgui/highgui_c.h index 47fdb84a..d8323d0d 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/highgui/highgui_c.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/highgui/highgui_c.h @@ -39,13 +39,17 @@ // //M*/ -#ifndef __OPENCV_HIGHGUI_H__ -#define __OPENCV_HIGHGUI_H__ +#ifndef OPENCV_HIGHGUI_H +#define OPENCV_HIGHGUI_H #include "opencv2/core/core_c.h" #include "opencv2/imgproc/imgproc_c.h" +#ifdef HAVE_OPENCV_IMGCODECS #include "opencv2/imgcodecs/imgcodecs_c.h" +#endif +#ifdef HAVE_OPENCV_VIDEOIO #include "opencv2/videoio/videoio_c.h" +#endif #ifdef __cplusplus extern "C" { @@ -107,6 +111,7 @@ enum CV_WND_PROP_AUTOSIZE = 1, //to change/get window's autosize property CV_WND_PROP_ASPECTRATIO= 2, //to change/get window's aspectratio property CV_WND_PROP_OPENGL = 3, //to change/get window's opengl support + CV_WND_PROP_VISIBLE = 4, //These 2 flags are used by cvNamedWindow and cvSet/GetWindowProperty CV_WINDOW_NORMAL = 0x00000000, //the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size @@ -234,7 +239,7 @@ CVAPI(void) cvUpdateWindow(const char* window_name); #define set_preprocess_func cvSetPreprocessFuncWin32 #define set_postprocess_func cvSetPostprocessFuncWin32 -#if defined WIN32 || defined _WIN32 +#if defined _WIN32 CVAPI(void) cvSetPreprocessFuncWin32_(const void* callback); CVAPI(void) cvSetPostprocessFuncWin32_(const void* callback); diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/imgcodecs.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/imgcodecs.hpp similarity index 89% rename from lib/3rdParty/OpenCV3.1/include/opencv2/imgcodecs.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/imgcodecs.hpp index ac0fd24e..567344dc 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/imgcodecs.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/imgcodecs.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_IMGCODECS_HPP__ -#define __OPENCV_IMGCODECS_HPP__ +#ifndef OPENCV_IMGCODECS_HPP +#define OPENCV_IMGCODECS_HPP #include "opencv2/core.hpp" @@ -73,7 +73,8 @@ enum ImreadModes { IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4. IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4. IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8. - IMREAD_REDUCED_COLOR_8 = 65 //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8. + IMREAD_REDUCED_COLOR_8 = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8. + IMREAD_IGNORE_ORIENTATION = 128 //!< If set, do not rotate the image according to EXIF's orientation flag. }; //! Imwrite flags @@ -84,11 +85,19 @@ enum ImwriteFlags { IMWRITE_JPEG_RST_INTERVAL = 4, //!< JPEG restart interval, 0 - 65535, default is 0 - no restart. IMWRITE_JPEG_LUMA_QUALITY = 5, //!< Separate luma quality level, 0 - 100, default is 0 - don't use. IMWRITE_JPEG_CHROMA_QUALITY = 6, //!< Separate chroma quality level, 0 - 100, default is 0 - don't use. - IMWRITE_PNG_COMPRESSION = 16, //!< For PNG, it can be the compression level from 0 to 9. A higher value means a smaller size and longer compression time. Default value is 3. - IMWRITE_PNG_STRATEGY = 17, //!< One of cv::ImwritePNGFlags, default is IMWRITE_PNG_STRATEGY_DEFAULT. + IMWRITE_PNG_COMPRESSION = 16, //!< For PNG, it can be the compression level from 0 to 9. A higher value means a smaller size and longer compression time. If specified, strategy is changed to IMWRITE_PNG_STRATEGY_DEFAULT (Z_DEFAULT_STRATEGY). Default value is 1 (best speed setting). + IMWRITE_PNG_STRATEGY = 17, //!< One of cv::ImwritePNGFlags, default is IMWRITE_PNG_STRATEGY_RLE. IMWRITE_PNG_BILEVEL = 18, //!< Binary level PNG, 0 or 1, default is 0. IMWRITE_PXM_BINARY = 32, //!< For PPM, PGM, or PBM, it can be a binary format flag, 0 or 1. Default value is 1. - 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_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 + }; + +enum ImwriteEXRTypeFlags { + /*IMWRITE_EXR_TYPE_UNIT = 0, //!< not supported */ + IMWRITE_EXR_TYPE_HALF = 1, //!< store as HALF (FP16) + IMWRITE_EXR_TYPE_FLOAT = 2 //!< store as FP32 (default) }; //! Imwrite PNG specific flags used to tune the compression algorithm. @@ -107,6 +116,16 @@ enum ImwritePNGFlags { IMWRITE_PNG_STRATEGY_FIXED = 4 //!< Using this value prevents the use of dynamic Huffman codes, allowing for a simpler decoder for special applications. }; +//! Imwrite PAM specific tupletype flags used to define the 'TUPETYPE' field of a PAM file. +enum ImwritePAMFlags { + IMWRITE_PAM_FORMAT_NULL = 0, + IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1, + IMWRITE_PAM_FORMAT_GRAYSCALE = 2, + IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3, + IMWRITE_PAM_FORMAT_RGB = 4, + IMWRITE_PAM_FORMAT_RGB_ALPHA = 5, + }; + /** @brief Loads an image from a file. @anchor imread @@ -146,6 +165,8 @@ Currently, the following file formats are supported: then [GDAL](http://www.gdal.org) driver will be used in order to decode the image by supporting the following formats: [Raster](http://www.gdal.org/formats_list.html), [Vector](http://www.gdal.org/ogr_formats.html). +- If EXIF information are embedded in the image file, the EXIF orientation will be taken into account + and thus the image will be rotated accordingly except if the flag @ref IMREAD_IGNORE_ORIENTATION is passed. @param filename Name of file to be loaded. @param flags Flag that can take values of cv::ImreadModes */ @@ -159,7 +180,7 @@ The function imreadmulti loads a multi-page image from the specified file into a @param mats A vector of Mat objects holding each page, if more than one. @sa cv::imread */ -CV_EXPORTS_W bool imreadmulti(const String& filename, std::vector& mats, int flags = IMREAD_ANYCOLOR); +CV_EXPORTS_W bool imreadmulti(const String& filename, CV_OUT std::vector& mats, int flags = IMREAD_ANYCOLOR); /** @brief Saves an image to a specified file. @@ -264,4 +285,4 @@ CV_EXPORTS_W bool imencode( const String& ext, InputArray img, } // cv -#endif //__OPENCV_IMGCODECS_HPP__ +#endif //OPENCV_IMGCODECS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/imgcodecs/imgcodecs.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/imgcodecs/imgcodecs.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/imgcodecs/imgcodecs.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/imgcodecs/imgcodecs.hpp diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/imgcodecs/imgcodecs_c.h b/lib/3rdParty/OpenCV3.4/include/opencv2/imgcodecs/imgcodecs_c.h similarity index 90% rename from lib/3rdParty/OpenCV3.1/include/opencv2/imgcodecs/imgcodecs_c.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/imgcodecs/imgcodecs_c.h index ad793cc9..c36dac33 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/imgcodecs/imgcodecs_c.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/imgcodecs/imgcodecs_c.h @@ -39,8 +39,8 @@ // //M*/ -#ifndef __OPENCV_IMGCODECS_H__ -#define __OPENCV_IMGCODECS_H__ +#ifndef OPENCV_IMGCODECS_H +#define OPENCV_IMGCODECS_H #include "opencv2/core/core_c.h" @@ -63,7 +63,9 @@ enum /* any depth, ? */ CV_LOAD_IMAGE_ANYDEPTH =2, /* ?, any color */ - CV_LOAD_IMAGE_ANYCOLOR =4 + CV_LOAD_IMAGE_ANYCOLOR =4, +/* ?, no rotate */ + CV_LOAD_IMAGE_IGNORE_ORIENTATION =128 }; /* load image from file @@ -92,9 +94,19 @@ enum CV_IMWRITE_PNG_STRATEGY_RLE =3, CV_IMWRITE_PNG_STRATEGY_FIXED =4, CV_IMWRITE_PXM_BINARY =32, - CV_IMWRITE_WEBP_QUALITY =64 + CV_IMWRITE_EXR_TYPE = 48, + CV_IMWRITE_WEBP_QUALITY =64, + CV_IMWRITE_PAM_TUPLETYPE = 128, + CV_IMWRITE_PAM_FORMAT_NULL = 0, + CV_IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1, + CV_IMWRITE_PAM_FORMAT_GRAYSCALE = 2, + CV_IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3, + CV_IMWRITE_PAM_FORMAT_RGB = 4, + CV_IMWRITE_PAM_FORMAT_RGB_ALPHA = 5, }; + + /* save image to file */ CVAPI(int) cvSaveImage( const char* filename, const CvArr* image, const int* params CV_DEFAULT(0) ); @@ -134,4 +146,4 @@ CVAPI(int) cvHaveImageWriter(const char* filename); } #endif -#endif // __OPENCV_IMGCODECS_H__ +#endif // OPENCV_IMGCODECS_H diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/imgcodecs/ios.h b/lib/3rdParty/OpenCV3.4/include/opencv2/imgcodecs/ios.h similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/imgcodecs/ios.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/imgcodecs/ios.h diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/imgproc.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc.hpp similarity index 86% rename from lib/3rdParty/OpenCV3.1/include/opencv2/imgproc.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/imgproc.hpp index 717dcf57..109b547f 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/imgproc.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_IMGPROC_HPP__ -#define __OPENCV_IMGPROC_HPP__ +#ifndef OPENCV_IMGPROC_HPP +#define OPENCV_IMGPROC_HPP #include "opencv2/core.hpp" @@ -117,6 +117,8 @@ f_y(x,y))\f$, and then the value of the polynomial at \f$(f_x(x,y), f_y(x,y))\f$ interpolated pixel value. In OpenCV, you can choose between several interpolation methods. See resize for details. +@note The geometrical transformations do not work with `CV_8S` or `CV_32S` images. + @defgroup imgproc_misc Miscellaneous Image Transformations @defgroup imgproc_draw Drawing Functions @@ -194,12 +196,30 @@ int main(int argc, const char *argv[]) @see cv::ColormapTypes + @defgroup imgproc_subdiv2d Planar Subdivision + +The Subdiv2D class described in this section is used to perform various planar subdivision on +a set of 2D points (represented as vector of Point2f). OpenCV subdivides a plane into triangles +using the Delaunay's algorithm, which corresponds to the dual graph of the Voronoi diagram. +In the figure below, the Delaunay's triangulation is marked with black lines and the Voronoi +diagram with red lines. + +![Delaunay triangulation (black) and Voronoi (red)](pics/delaunay_voronoi.png) + +The subdivisions can be used for the 3D piece-wise transformation of a plane, morphing, fast +location of points on the plane, building special graphs (such as NNG,RNG), and so forth. + @defgroup imgproc_hist Histograms @defgroup imgproc_shape Structural Analysis and Shape Descriptors @defgroup imgproc_motion Motion Analysis and Object Tracking @defgroup imgproc_feature Feature Detection @defgroup imgproc_object Object Detection @defgroup imgproc_c C API + @defgroup imgproc_hal Hardware Acceleration Layer + @{ + @defgroup imgproc_hal_functions Functions + @defgroup imgproc_hal_interface Interface + @} @} */ @@ -227,8 +247,8 @@ enum MorphTypes{ //!< \f[\texttt{dst} = \mathrm{tophat} ( \texttt{src} , \texttt{element} )= \texttt{src} - \mathrm{open} ( \texttt{src} , \texttt{element} )\f] MORPH_BLACKHAT = 6, //!< "black hat" //!< \f[\texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}\f] - MORPH_HITMISS = 7 //!< "hit and miss" - //!< .- Only supported for CV_8UC1 binary images. Tutorial can be found in [this page](http://opencv-code.com/tutorials/hit-or-miss-transform-in-opencv/) + MORPH_HITMISS = 7 //!< "hit or miss" + //!< .- Only supported for CV_8UC1 binary images. A tutorial can be found in the documentation }; //! shape of the structuring element @@ -259,6 +279,8 @@ enum InterpolationFlags{ INTER_AREA = 3, /** Lanczos interpolation over 8x8 neighborhood */ INTER_LANCZOS4 = 4, + /** Bit exact bilinear interpolation */ + INTER_LINEAR_EXACT = 5, /** mask for interpolation codes */ INTER_MAX = 7, /** flag, fills all of the destination image pixels. If some of them correspond to outliers in the @@ -266,9 +288,9 @@ enum InterpolationFlags{ WARP_FILL_OUTLIERS = 8, /** flag, inverse transformation - For example, polar transforms: - - flag is __not__ set: \f$dst( \phi , \rho ) = src(x,y)\f$ - - flag is set: \f$dst(x,y) = src( \phi , \rho )\f$ + For example, @ref cv::linearPolar or @ref cv::logPolar transforms: + - flag is __not__ set: \f$dst( \rho , \phi ) = src(x,y)\f$ + - flag is set: \f$dst(x,y) = src( \rho , \phi )\f$ */ WARP_INVERSE_MAP = 16 }; @@ -395,6 +417,13 @@ enum ConnectedComponentsTypes { CC_STAT_MAX = 5 }; +//! connected components algorithm +enum ConnectedComponentsAlgorithmsTypes { + CCL_WU = 0, //!< SAUF algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity + CCL_DEFAULT = -1, //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity + CCL_GRANA = 1 //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity +}; + //! mode of the contour retrieval algorithm enum RetrievalModes { /** retrieves only the extreme outer contours. It sets `hierarchy[i][2]=hierarchy[i][3]=-1` for @@ -427,6 +456,20 @@ enum ContourApproximationModes { CHAIN_APPROX_TC89_KCOS = 4 }; +/** @brief Shape matching methods + +\f$A\f$ denotes object1,\f$B\f$ denotes object2 + +\f$\begin{array}{l} m^A_i = \mathrm{sign} (h^A_i) \cdot \log{h^A_i} \\ m^B_i = \mathrm{sign} (h^B_i) \cdot \log{h^B_i} \end{array}\f$ + +and \f$h^A_i, h^B_i\f$ are the Hu moments of \f$A\f$ and \f$B\f$ , respectively. +*/ +enum ShapeMatchModes { + CONTOURS_MATCH_I1 =1, //!< \f[I_1(A,B) = \sum _{i=1...7} \left | \frac{1}{m^A_i} - \frac{1}{m^B_i} \right |\f] + CONTOURS_MATCH_I2 =2, //!< \f[I_2(A,B) = \sum _{i=1...7} \left | m^A_i - m^B_i \right |\f] + CONTOURS_MATCH_I3 =3 //!< \f[I_3(A,B) = \max _{i=1...7} \frac{ \left| m^A_i - m^B_i \right| }{ \left| m^A_i \right| }\f] +}; + //! @} imgproc_shape //! Variants of a Hough transform @@ -744,8 +787,18 @@ enum ColorConversionCodes { COLOR_BayerRG2RGB_EA = COLOR_BayerBG2BGR_EA, COLOR_BayerGR2RGB_EA = COLOR_BayerGB2BGR_EA, + //! Demosaicing with alpha channel + COLOR_BayerBG2BGRA = 139, + COLOR_BayerGB2BGRA = 140, + COLOR_BayerRG2BGRA = 141, + COLOR_BayerGR2BGRA = 142, - COLOR_COLORCVT_MAX = 139 + COLOR_BayerBG2RGBA = COLOR_BayerRG2BGRA, + COLOR_BayerGB2RGBA = COLOR_BayerGR2BGRA, + COLOR_BayerRG2RGBA = COLOR_BayerBG2BGRA, + COLOR_BayerGR2RGBA = COLOR_BayerGB2BGRA, + + COLOR_COLORCVT_MAX = 143 }; /** types of intersection between rectangles @@ -791,7 +844,7 @@ public: }; //! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122. -//! Detects position only without traslation and rotation +//! Detects position only without translation and rotation class CV_EXPORTS GeneralizedHoughBallard : public GeneralizedHough { public: @@ -805,7 +858,7 @@ public: }; //! Guil, N., González-Linares, J.M. and Zapata, E.L. (1999). Bidimensional shape detection using an invariant approach. Pattern Recognition 32 (6): 1025-1038. -//! Detects position, traslation and rotation +//! Detects position, translation and rotation class CV_EXPORTS GeneralizedHoughGuil : public GeneralizedHough { public: @@ -874,16 +927,21 @@ public: }; +//! @addtogroup imgproc_subdiv2d +//! @{ + class CV_EXPORTS_W Subdiv2D { public: - enum { PTLOC_ERROR = -2, - PTLOC_OUTSIDE_RECT = -1, - PTLOC_INSIDE = 0, - PTLOC_VERTEX = 1, - PTLOC_ON_EDGE = 2 + /** Subdiv2D point location cases */ + enum { PTLOC_ERROR = -2, //!< Point location error + PTLOC_OUTSIDE_RECT = -1, //!< Point outside the subdivision bounding rect + PTLOC_INSIDE = 0, //!< Point inside some facet + PTLOC_VERTEX = 1, //!< Point coincides with one of the subdivision vertices + PTLOC_ON_EDGE = 2 //!< Point on some edge }; + /** Subdiv2D edge type navigation (see: getEdge()) */ enum { NEXT_AROUND_ORG = 0x00, NEXT_AROUND_DST = 0x22, PREV_AROUND_ORG = 0x11, @@ -894,27 +952,190 @@ public: PREV_AROUND_RIGHT = 0x02 }; + /** creates an empty Subdiv2D object. + To create a new empty Delaunay subdivision you need to use the initDelaunay() function. + */ CV_WRAP Subdiv2D(); + + /** @overload + + @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision. + + The function creates an empty Delaunay subdivision where 2D points can be added using the function + insert() . All of the points to be added must be within the specified rectangle, otherwise a runtime + error is raised. + */ CV_WRAP Subdiv2D(Rect rect); + + /** @brief Creates a new empty Delaunay subdivision + + @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision. + + */ CV_WRAP void initDelaunay(Rect rect); + /** @brief Insert a single point into a Delaunay triangulation. + + @param pt Point to insert. + + The function inserts a single point into a subdivision and modifies the subdivision topology + appropriately. If a point with the same coordinates exists already, no new point is added. + @returns the ID of the point. + + @note If the point is outside of the triangulation specified rect a runtime error is raised. + */ CV_WRAP int insert(Point2f pt); + + /** @brief Insert multiple points into a Delaunay triangulation. + + @param ptvec Points to insert. + + The function inserts a vector of points into a subdivision and modifies the subdivision topology + appropriately. + */ CV_WRAP void insert(const std::vector& ptvec); + + /** @brief Returns the location of a point within a Delaunay triangulation. + + @param pt Point to locate. + @param edge Output edge that the point belongs to or is located to the right of it. + @param vertex Optional output vertex the input point coincides with. + + The function locates the input point within the subdivision and gives one of the triangle edges + or vertices. + + @returns an integer which specify one of the following five cases for point location: + - The point falls into some facet. The function returns PTLOC_INSIDE and edge will contain one of + edges of the facet. + - The point falls onto the edge. The function returns PTLOC_ON_EDGE and edge will contain this edge. + - The point coincides with one of the subdivision vertices. The function returns PTLOC_VERTEX and + vertex will contain a pointer to the vertex. + - The point is outside the subdivision reference rectangle. The function returns PTLOC_OUTSIDE_RECT + and no pointers are filled. + - One of input arguments is invalid. A runtime error is raised or, if silent or "parent" error + processing mode is selected, CV_PTLOC_ERROR is returned. + */ CV_WRAP int locate(Point2f pt, CV_OUT int& edge, CV_OUT int& vertex); + /** @brief Finds the subdivision vertex closest to the given point. + + @param pt Input point. + @param nearestPt Output subdivision vertex point. + + The function is another function that locates the input point within the subdivision. It finds the + subdivision vertex that is the closest to the input point. It is not necessarily one of vertices + of the facet containing the input point, though the facet (located using locate() ) is used as a + starting point. + + @returns vertex ID. + */ CV_WRAP int findNearest(Point2f pt, CV_OUT Point2f* nearestPt = 0); + + /** @brief Returns a list of all edges. + + @param edgeList Output vector. + + The function gives each edge as a 4 numbers vector, where each two are one of the edge + vertices. i.e. org_x = v[0], org_y = v[1], dst_x = v[2], dst_y = v[3]. + */ CV_WRAP void getEdgeList(CV_OUT std::vector& edgeList) const; + + /** @brief Returns a list of the leading edge ID connected to each triangle. + + @param leadingEdgeList Output vector. + + The function gives one edge ID for each triangle. + */ + CV_WRAP void getLeadingEdgeList(CV_OUT std::vector& leadingEdgeList) const; + + /** @brief Returns a list of all triangles. + + @param triangleList Output vector. + + The function gives each triangle as a 6 numbers vector, where each two are one of the triangle + vertices. i.e. p1_x = v[0], p1_y = v[1], p2_x = v[2], p2_y = v[3], p3_x = v[4], p3_y = v[5]. + */ CV_WRAP void getTriangleList(CV_OUT std::vector& triangleList) const; + + /** @brief Returns a list of all Voroni facets. + + @param idx Vector of vertices IDs to consider. For all vertices you can pass empty vector. + @param facetList Output vector of the Voroni facets. + @param facetCenters Output vector of the Voroni facets center points. + + */ CV_WRAP void getVoronoiFacetList(const std::vector& idx, CV_OUT std::vector >& facetList, CV_OUT std::vector& facetCenters); + /** @brief Returns vertex location from vertex ID. + + @param vertex vertex ID. + @param firstEdge Optional. The first edge ID which is connected to the vertex. + @returns vertex (x,y) + + */ CV_WRAP Point2f getVertex(int vertex, CV_OUT int* firstEdge = 0) const; + /** @brief Returns one of the edges related to the given edge. + + @param edge Subdivision edge ID. + @param nextEdgeType Parameter specifying which of the related edges to return. + The following values are possible: + - NEXT_AROUND_ORG next around the edge origin ( eOnext on the picture below if e is the input edge) + - NEXT_AROUND_DST next around the edge vertex ( eDnext ) + - PREV_AROUND_ORG previous around the edge origin (reversed eRnext ) + - PREV_AROUND_DST previous around the edge destination (reversed eLnext ) + - NEXT_AROUND_LEFT next around the left facet ( eLnext ) + - NEXT_AROUND_RIGHT next around the right facet ( eRnext ) + - PREV_AROUND_LEFT previous around the left facet (reversed eOnext ) + - PREV_AROUND_RIGHT previous around the right facet (reversed eDnext ) + + ![sample output](pics/quadedge.png) + + @returns edge ID related to the input edge. + */ CV_WRAP int getEdge( int edge, int nextEdgeType ) const; + + /** @brief Returns next edge around the edge origin. + + @param edge Subdivision edge ID. + + @returns an integer which is next edge ID around the edge origin: eOnext on the + picture above if e is the input edge). + */ CV_WRAP int nextEdge(int edge) const; + + /** @brief Returns another edge of the same quad-edge. + + @param edge Subdivision edge ID. + @param rotate Parameter specifying which of the edges of the same quad-edge as the input + one to return. The following values are possible: + - 0 - the input edge ( e on the picture below if e is the input edge) + - 1 - the rotated edge ( eRot ) + - 2 - the reversed edge (reversed e (in green)) + - 3 - the reversed rotated edge (reversed eRot (in green)) + + @returns one of the edges ID of the same quad-edge as the input edge. + */ CV_WRAP int rotateEdge(int edge, int rotate) const; CV_WRAP int symEdge(int edge) const; + + /** @brief Returns the edge origin. + + @param edge Subdivision edge ID. + @param orgpt Output vertex location. + + @returns vertex ID. + */ CV_WRAP int edgeOrg(int edge, CV_OUT Point2f* orgpt = 0) const; + + /** @brief Returns the edge destination. + + @param edge Subdivision edge ID. + @param dstpt Output vertex location. + + @returns vertex ID. + */ CV_WRAP int edgeDst(int edge, CV_OUT Point2f* dstpt = 0) const; protected: @@ -953,22 +1174,29 @@ protected: int pt[4]; }; + //! All of the vertices std::vector vtx; + //! All of the edges std::vector qedges; int freeQEdge; int freePoint; bool validGeometry; int recentEdge; + //! Top left corner of the bounding rect Point2f topLeft; + //! Bottom right corner of the bounding rect Point2f bottomRight; }; +//! @} imgproc_subdiv2d + //! @addtogroup imgproc_feature //! @{ /** @example lsd_lines.cpp An example using the LineSegmentDetector +\image html building_lsd.png "Sample output image" width=434 height=300 */ /** @brief Line segment detector class @@ -1004,7 +1232,7 @@ public: OutputArray nfa = noArray()) = 0; /** @brief Draws the line segments on a given image. - @param _image The image, where the liens will be drawn. Should be bigger or equal to the image, + @param _image The image, where the lines will be drawn. Should be bigger or equal to the image, where the lines were found. @param lines A vector of the lines that needed to be drawn. */ @@ -1033,7 +1261,7 @@ to edit those, as to tailor it for their own application. @param _sigma_scale Sigma for Gaussian filter. It is computed as sigma = _sigma_scale/_scale. @param _quant Bound to the quantization error on the gradient norm. @param _ang_th Gradient angle tolerance in degrees. -@param _log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advancent refinement +@param _log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement is chosen. @param _density_th Minimal density of aligned region points in the enclosing rectangle. @param _n_bins Number of bins in pseudo-ordering of gradient modulus. @@ -1062,7 +1290,7 @@ smoothing kernels (a symmetrical kernel with sum of weights equal to 1) and hand You may also use the higher-level GaussianBlur. @param ksize Aperture size. It should be odd ( \f$\texttt{ksize} \mod 2 = 1\f$ ) and positive. @param sigma Gaussian standard deviation. If it is non-positive, it is computed from ksize as -`sigma = 0.3\*((ksize-1)\*0.5 - 1) + 0.8`. +`sigma = 0.3*((ksize-1)*0.5 - 1) + 0.8`. @param ktype Type of filter coefficients. It can be CV_32F or CV_64F . @sa sepFilter2D, getDerivKernels, getStructuringElement, GaussianBlur */ @@ -1124,12 +1352,19 @@ operation is shifted. */ CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1)); +/** @example Smoothing.cpp +Sample code for simple filters +![Sample screenshot](Smoothing_Tutorial_Result_Median_Filter.jpg) +Check @ref tutorial_gausian_median_blur_bilateral_filter "the corresponding tutorial" for more details + */ /** @brief Blurs an image using the median filter. The function smoothes an image using the median filter with the \f$\texttt{ksize} \times \texttt{ksize}\f$ aperture. Each channel of a multi-channel image is processed independently. In-place operation is supported. +@note The median filter uses BORDER_REPLICATE internally to cope with border pixels, see cv::BorderTypes + @param src input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U. @param dst destination array of the same size and type as src. @@ -1196,7 +1431,7 @@ CV_EXPORTS_W void bilateralFilter( InputArray src, OutputArray dst, int d, /** @brief Blurs an image using the box filter. -The function smoothes an image using the kernel: +The function smooths an image using the kernel: \f[\texttt{K} = \alpha \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \end{bmatrix}\f] @@ -1248,7 +1483,7 @@ CV_EXPORTS_W void sqrBoxFilter( InputArray _src, OutputArray _dst, int ddepth, /** @brief Blurs an image using the normalized box filter. -The function smoothes an image using the kernel: +The function smooths an image using the kernel: \f[\texttt{K} = \frac{1}{\texttt{ksize.width*ksize.height}} \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \end{bmatrix}\f] @@ -1324,6 +1559,11 @@ CV_EXPORTS_W void sepFilter2D( InputArray src, OutputArray dst, int ddepth, Point anchor = Point(-1,-1), double delta = 0, int borderType = BORDER_DEFAULT ); +/** @example Sobel_Demo.cpp +Sample code using Sobel and/or Scharr OpenCV functions to make a simple Edge Detector +![Sample screenshot](Sobel_Derivatives_Tutorial_Result.jpg) +Check @ref tutorial_sobel_derivatives "the corresponding tutorial" for more details + */ /** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator. In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to @@ -1456,12 +1696,14 @@ CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth, //! @{ /** @example edge.cpp - An example on using the canny edge detector + This program demonstrates usage of the Canny edge detector + + Check @ref tutorial_canny_detector "the corresponding tutorial" for more details */ /** @brief Finds edges in an image using the Canny algorithm @cite Canny86 . -The function finds edges in the input image image and marks them in the output map edges using the +The function finds edges in the input image and marks them in the output map edges using the Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The largest value is used to find initial segments of strong edges. See @@ -1480,6 +1722,19 @@ CV_EXPORTS_W void Canny( InputArray image, OutputArray edges, double threshold1, double threshold2, int apertureSize = 3, bool L2gradient = false ); +/** \overload + +Finds edges in an image using the Canny algorithm with custom image gradient. + +@param dx 16-bit x derivative of input image (CV_16SC1 or CV_16SC3). +@param dy 16-bit y derivative of input image (same type as dx). +@param edges,threshold1,threshold2,L2gradient See cv::Canny + */ +CV_EXPORTS_W void Canny( InputArray dx, InputArray dy, + OutputArray edges, + double threshold1, double threshold2, + bool L2gradient = false ); + /** @brief Calculates the minimal eigenvalue of gradient matrices for corner detection. The function is similar to cornerEigenValsAndVecs but it calculates and stores only the minimal @@ -1644,7 +1899,8 @@ with qualityLevel=B . @param image Input 8-bit or floating-point 32-bit, single-channel image. @param corners Output vector of detected corners. @param maxCorners Maximum number of corners to return. If there are more corners than are found, -the strongest of them is returned. +the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set +and all detected corners are returned. @param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue (see cornerMinEigenVal ) or the Harris function response (see cornerHarris ). The corners with the @@ -1662,13 +1918,20 @@ or cornerMinEigenVal. @sa cornerMinEigenVal, cornerHarris, calcOpticalFlowPyrLK, estimateRigidTransform, */ + CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners, int maxCorners, double qualityLevel, double minDistance, InputArray mask = noArray(), int blockSize = 3, bool useHarrisDetector = false, double k = 0.04 ); +CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners, + int maxCorners, double qualityLevel, double minDistance, + InputArray mask, int blockSize, + int gradientSize, bool useHarrisDetector = false, + double k = 0.04 ); /** @example houghlines.cpp An example using the Hough line detector +![Sample input image](Hough_Lines_Tutorial_Original_Image.jpg) ![Output image](Hough_Lines_Tutorial_Result.jpg) */ /** @brief Finds lines in a binary image using the standard Hough transform. @@ -1831,7 +2094,7 @@ Example: : @note Usually the function detects the centers of circles well. However, it may fail to find correct radii. You can assist to the function by specifying the radius range ( minRadius and maxRadius ) if -you know it. Or, you may ignore the returned radius, use only the center, and find the correct +you know it. Or, you may set maxRadius to 0 to return centers only without radius search, and find the correct radius using an additional procedure. @param image 8-bit, single-channel, grayscale input image. @@ -1866,7 +2129,9 @@ CV_EXPORTS_W void HoughCircles( InputArray image, OutputArray circles, //! @{ /** @example morphology2.cpp - An example using the morphological operations +Advanced morphology Transformations sample code +![Sample screenshot](Morphology_2_Tutorial_Result.jpg) +Check @ref tutorial_opening_closing_hats "the corresponding tutorial" for more details */ /** @brief Erodes an image by using a specific structuring element. @@ -1896,6 +2161,11 @@ CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel, int borderType = BORDER_CONSTANT, const Scalar& borderValue = morphologyDefaultBorderValue() ); +/** @example Morphology_1.cpp +Erosion and Dilation sample code +![Sample Screenshot-Erosion](Morphology_1_Tutorial_Erosion_Result.jpg)![Sample Screenshot-Dilation](Morphology_1_Tutorial_Dilation_Result.jpg) +Check @ref tutorial_erosion_dilatation "the corresponding tutorial" for more details + */ /** @brief Dilates an image by using a specific structuring element. The function dilates the source image using the specified structuring element that determines the @@ -1942,6 +2212,9 @@ kernel center. @param borderValue Border value in case of a constant border. The default value has a special meaning. @sa dilate, erode, getStructuringElement +@note The number of iterations is the number of times erosion or dilatation operation will be applied. +For instance, an opening operation (#MORPH_OPEN) with two iterations is equivalent to apply +successively: erode -> erode -> dilate -> dilate (and not erode -> dilate -> erode -> dilate). */ CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst, int op, InputArray kernel, @@ -2022,6 +2295,9 @@ CV_EXPORTS_W void warpAffine( InputArray src, OutputArray dst, int borderMode = BORDER_CONSTANT, const Scalar& borderValue = Scalar()); +/** @example warpPerspective_demo.cpp +An example program shows using cv::findHomography and cv::warpPerspective for image warping + */ /** @brief Applies a perspective transformation to an image. The function warpPerspective transforms the source image using the specified matrix: @@ -2079,6 +2355,8 @@ not supported by this function. borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that corresponds to the "outliers" in the source image are not modified by the function. @param borderValue Value used in case of a constant border. By default, it is 0. +@note +Due to current implementation limitations the size of an input and output images should be less than 32767x32767. */ CV_EXPORTS_W void remap( InputArray src, OutputArray dst, InputArray map1, InputArray map2, @@ -2091,13 +2369,13 @@ The function converts a pair of maps for remap from one representation to anothe options ( (map1.type(), map2.type()) \f$\rightarrow\f$ (dstmap1.type(), dstmap2.type()) ) are supported: -- \f$\texttt{(CV\_32FC1, CV\_32FC1)} \rightarrow \texttt{(CV\_16SC2, CV\_16UC1)}\f$. This is the +- \f$\texttt{(CV_32FC1, CV_32FC1)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. This is the most frequently used conversion operation, in which the original floating-point maps (see remap ) are converted to a more compact and much faster fixed-point representation. The first output array contains the rounded coordinates and the second array (created only when nninterpolation=false ) contains indices in the interpolation tables. -- \f$\texttt{(CV\_32FC2)} \rightarrow \texttt{(CV\_16SC2, CV\_16UC1)}\f$. The same as above but +- \f$\texttt{(CV_32FC2)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. The same as above but the original maps are stored in one 2-channel matrix. - Reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same @@ -2147,7 +2425,7 @@ CV_EXPORTS Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] The function calculates the \f$2 \times 3\f$ matrix of an affine transform so that: -\f[\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map\_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f] +\f[\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f] where @@ -2177,7 +2455,7 @@ CV_EXPORTS_W void invertAffineTransform( InputArray M, OutputArray iM ); The function calculates the \f$3 \times 3\f$ matrix of a perspective transform so that: -\f[\begin{bmatrix} t_i x'_i \\ t_i y'_i \\ t_i \end{bmatrix} = \texttt{map\_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f] +\f[\begin{bmatrix} t_i x'_i \\ t_i y'_i \\ t_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f] where @@ -2196,13 +2474,12 @@ CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst ); The function getRectSubPix extracts pixels from src: -\f[dst(x, y) = src(x + \texttt{center.x} - ( \texttt{dst.cols} -1)*0.5, y + \texttt{center.y} - ( \texttt{dst.rows} -1)*0.5)\f] +\f[patch(x, y) = src(x + \texttt{center.x} - ( \texttt{dst.cols} -1)*0.5, y + \texttt{center.y} - ( \texttt{dst.rows} -1)*0.5)\f] where the values of the pixels at non-integer coordinates are retrieved using bilinear -interpolation. Every channel of multi-channel images is processed independently. While the center of -the rectangle must be inside the image, parts of the rectangle may be outside. In this case, the -replication border mode (see cv::BorderTypes) is used to extrapolate the pixel values outside of -the image. +interpolation. Every channel of multi-channel images is processed independently. Also +the image should be a single channel or three channel image. While the center of the +rectangle must be inside the image, parts of the rectangle may be outside. @param image Source image. @param patchSize Size of the extracted patch. @@ -2220,41 +2497,78 @@ CV_EXPORTS_W void getRectSubPix( InputArray image, Size patchSize, An example using the cv::linearPolar and cv::logPolar operations */ -/** @brief Remaps an image to log-polar space. +/** @brief Remaps an image to semilog-polar coordinates space. + +Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image"): +\f[\begin{array}{l} + dst( \rho , \phi ) = src(x,y) \\ + dst.size() \leftarrow src.size() +\end{array}\f] -transforms the source image using the following transformation: -\f[dst( \phi , \rho ) = src(x,y)\f] where -\f[\rho = M \cdot \log{\sqrt{x^2 + y^2}} , \phi =atan(y/x)\f] +\f[\begin{array}{l} + I = (dx,dy) = (x - center.x,y - center.y) \\ + \rho = M \cdot log_e(\texttt{magnitude} (I)) ,\\ + \phi = Ky \cdot \texttt{angle} (I)_{0..360 deg} \\ +\end{array}\f] + +and +\f[\begin{array}{l} + M = src.cols / log_e(maxRadius) \\ + Ky = src.rows / 360 \\ +\end{array}\f] The function emulates the human "foveal" vision and can be used for fast scale and -rotation-invariant template matching, for object tracking and so forth. The function can not operate -in-place. - +rotation-invariant template matching, for object tracking and so forth. @param src Source image -@param dst Destination image +@param dst Destination image. It will have same size and type as src. @param center The transformation center; where the output precision is maximal -@param M Magnitude scale parameter. +@param M Magnitude scale parameter. It determines the radius of the bounding circle to transform too. @param flags A combination of interpolation methods, see cv::InterpolationFlags - */ + +@note +- The function can not operate in-place. +- To calculate magnitude and angle in degrees @ref cv::cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees. +*/ CV_EXPORTS_W void logPolar( InputArray src, OutputArray dst, Point2f center, double M, int flags ); -/** @brief Remaps an image to polar space. +/** @brief Remaps an image to polar coordinates space. + +@anchor polar_remaps_reference_image +![Polar remaps reference](pics/polar_remap_doc.png) + +Transform the source image using the following transformation: +\f[\begin{array}{l} + dst( \rho , \phi ) = src(x,y) \\ + dst.size() \leftarrow src.size() +\end{array}\f] -transforms the source image using the following transformation: -\f[dst( \phi , \rho ) = src(x,y)\f] where -\f[\rho = (src.width/maxRadius) \cdot \sqrt{x^2 + y^2} , \phi =atan(y/x)\f] +\f[\begin{array}{l} + I = (dx,dy) = (x - center.x,y - center.y) \\ + \rho = Kx \cdot \texttt{magnitude} (I) ,\\ + \phi = Ky \cdot \texttt{angle} (I)_{0..360 deg} +\end{array}\f] + +and +\f[\begin{array}{l} + Kx = src.cols / maxRadius \\ + Ky = src.rows / 360 +\end{array}\f] -The function can not operate in-place. @param src Source image -@param dst Destination image +@param dst Destination image. It will have same size and type as src. @param center The transformation center; -@param maxRadius Inverse magnitude scale parameter +@param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too. @param flags A combination of interpolation methods, see cv::InterpolationFlags - */ + +@note +- The function can not operate in-place. +- To calculate magnitude and angle in degrees @ref cv::cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees. + +*/ CV_EXPORTS_W void linearPolar( InputArray src, OutputArray dst, Point2f center, double maxRadius, int flags ); @@ -2272,7 +2586,7 @@ CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum, /** @brief Calculates the integral of an image. -The functions calculate one or more integral images for the source image as follows: +The function calculates one or more integral images for the source image as follows: \f[\texttt{sum} (X,Y) = \sum _{x 1) @param type Created array type */ CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type); @@ -2455,7 +2768,7 @@ CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type); /** @brief Applies a fixed-level threshold to each array element. -The function applies fixed-level thresholding to a single-channel array. The function is typically +The function applies fixed-level thresholding to a multiple-channel array. The function is typically used to get a bi-level (binary) image out of a grayscale image ( cv::compare could be also used for this purpose) or for removing a noise, that is, filtering out pixels with too small or too large values. There are several types of thresholding supported by the function. They are determined by @@ -2467,8 +2780,10 @@ or Triangle algorithm and uses it instead of the specified thresh . The function computed threshold value. Currently, the Otsu's and Triangle methods are implemented only for 8-bit images. -@param src input array (single-channel, 8-bit or 32-bit floating point). -@param dst output array of the same size and type as src. +@note Input image should be single channel only in case of CV_THRESH_OTSU or CV_THRESH_TRIANGLE flags + +@param src input array (multiple-channel, 8-bit or 32-bit floating point). +@param dst output array of the same size and type and the same number of channels as src. @param thresh threshold value. @param maxval maximum value to use with the THRESH_BINARY and THRESH_BINARY_INV thresholding types. @@ -2494,7 +2809,8 @@ The function can process the image in-place. @param src Source 8-bit single-channel image. @param dst Destination image of the same size and the same type as src. @param maxValue Non-zero value assigned to the pixels for which the condition is satisfied -@param adaptiveMethod Adaptive thresholding algorithm to use, see cv::AdaptiveThresholdTypes +@param adaptiveMethod Adaptive thresholding algorithm to use, see cv::AdaptiveThresholdTypes. +The BORDER_REPLICATE | BORDER_ISOLATED is used to process boundaries. @param thresholdType Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV, see cv::ThresholdTypes. @param blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the @@ -2513,6 +2829,9 @@ CV_EXPORTS_W void adaptiveThreshold( InputArray src, OutputArray dst, //! @addtogroup imgproc_filter //! @{ +/** @example Pyramids.cpp +An example using pyrDown and pyrUp functions + */ /** @brief Blurs an image and downsamples it. By default, size of the output image is computed as `Size((src.cols+1)/2, (src.rows+1)/2)`, but in @@ -2666,7 +2985,7 @@ computed by stereoRectify can be passed here. If the matrix is empty, the identi is assumed. In cvInitUndistortMap R assumed to be an identity matrix. @param newCameraMatrix New camera matrix \f$A'=\vecthreethree{f_x'}{0}{c_x'}{0}{f_y'}{c_y'}{0}{0}{1}\f$. @param size Undistorted image size. -@param m1type Type of the first output map that can be CV_32FC1 or CV_16SC2, see cv::convertMaps +@param m1type Type of the first output map that can be CV_32FC1, CV_32FC2 or CV_16SC2, see cv::convertMaps @param map1 The first output map. @param map2 The second output map. */ @@ -2711,20 +3030,23 @@ The function is similar to cv::undistort and cv::initUndistortRectifyMap but it sparse set of points instead of a raster image. Also the function performs a reverse transformation to projectPoints. In case of a 3D object, it does not reconstruct its 3D coordinates, but for a planar object, it does, up to a translation vector, if the proper R is specified. -@code - // (u,v) is the input point, (u', v') is the output point - // camera_matrix=[fx 0 cx; 0 fy cy; 0 0 1] - // P=[fx' 0 cx' tx; 0 fy' cy' ty; 0 0 1 tz] - x" = (u - cx)/fx - y" = (v - cy)/fy - (x',y') = undistort(x",y",dist_coeffs) - [X,Y,W]T = R*[x' y' 1]T - x = X/W, y = Y/W - // only performed if P=[fx' 0 cx' [tx]; 0 fy' cy' [ty]; 0 0 1 [tz]] is specified - u' = x*fx' + cx' - v' = y*fy' + cy', -@endcode -where cv::undistort is an approximate iterative algorithm that estimates the normalized original + +For each observed point coordinate \f$(u, v)\f$ the function computes: +\f[ +\begin{array}{l} +x^{"} \leftarrow (u - c_x)/f_x \\ +y^{"} \leftarrow (v - c_y)/f_y \\ +(x',y') = undistort(x^{"},y^{"}, \texttt{distCoeffs}) \\ +{[X\,Y\,W]} ^T \leftarrow R*[x' \, y' \, 1]^T \\ +x \leftarrow X/W \\ +y \leftarrow Y/W \\ +\text{only performed if P is specified:} \\ +u' \leftarrow x {f'}_x + {c'}_x \\ +v' \leftarrow y {f'}_y + {c'}_y +\end{array} +\f] + +where *undistort* is an approximate iterative algorithm that estimates the normalized original point coordinates out of the normalized distorted point coordinates ("normalized" means that the coordinates do not depend on the camera matrix). @@ -2739,12 +3061,19 @@ transformation. If matrix P is identity or omitted, dst will contain normalized of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. @param R Rectification transformation in the object space (3x3 matrix). R1 or R2 computed by cv::stereoRectify can be passed here. If the matrix is empty, the identity transformation is used. -@param P New camera matrix (3x3) or new projection matrix (3x4). P1 or P2 computed by +@param P New camera matrix (3x3) or new projection matrix (3x4) \f$\begin{bmatrix} {f'}_x & 0 & {c'}_x & t_x \\ 0 & {f'}_y & {c'}_y & t_y \\ 0 & 0 & 1 & t_z \end{bmatrix}\f$. P1 or P2 computed by cv::stereoRectify can be passed here. If the matrix is empty, the identity new camera matrix is used. */ CV_EXPORTS_W void undistortPoints( InputArray src, OutputArray dst, InputArray cameraMatrix, InputArray distCoeffs, InputArray R = noArray(), InputArray P = noArray()); +/** @overload + @note Default version of cv::undistortPoints does 5 iterations to compute undistorted points. + + */ +CV_EXPORTS_AS(undistortPointsIter) void undistortPoints( InputArray src, OutputArray dst, + InputArray cameraMatrix, InputArray distCoeffs, + InputArray R, InputArray P, TermCriteria criteria); //! @} imgproc_transform @@ -2757,7 +3086,7 @@ An example for creating histograms of an image /** @brief Calculates a histogram of a set of arrays. -The functions calcHist calculate the histogram of one or more arrays. The elements of a tuple used +The function cv::calcHist calculates the histogram of one or more arrays. The elements of a tuple used to increment a histogram bin are taken from the corresponding input arrays at the same location. The sample below shows how to compute a 2D Hue-Saturation histogram for a color image. : @code @@ -2818,7 +3147,7 @@ sample below shows how to compute a 2D Hue-Saturation histogram for a color imag } @endcode -@param images Source arrays. They all should have the same depth, CV_8U or CV_32F , and the same +@param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same size. Each of them can have an arbitrary number of channels. @param nimages Number of source images. @param channels List of the dims channels used to compute the histogram. The first array channels @@ -2869,7 +3198,7 @@ CV_EXPORTS_W void calcHist( InputArrayOfArrays images, /** @brief Calculates the back projection of a histogram. -The functions calcBackProject calculate the back project of the histogram. That is, similarly to +The function cv::calcBackProject calculates the back project of the histogram. That is, similarly to cv::calcHist , at each location (x, y) the function collects the values from the selected channels in the input images and finds the corresponding histogram bin. But instead of incrementing it, the function reads the bin value, scales it by scale , and stores in backProject(x,y) . In terms of @@ -2890,7 +3219,7 @@ component. This is an approximate algorithm of the CamShift color object tracker. -@param images Source arrays. They all should have the same depth, CV_8U or CV_32F , and the same +@param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same size. Each of them can have an arbitrary number of channels. @param nimages Number of source images. @param channels The list of channels used to compute the back projection. The number of channels @@ -2900,7 +3229,7 @@ images[0].channels() + images[1].channels()-1, and so on. @param hist Input histogram that can be dense or sparse. @param backProject Destination back projection array that is a single-channel array of the same size and depth as images[0] . -@param ranges Array of arrays of the histogram bin boundaries in each dimension. See calcHist . +@param ranges Array of arrays of the histogram bin boundaries in each dimension. See cv::calcHist . @param scale Optional scale factor for the output back projection. @param uniform Flag indicating whether the histogram is uniform or not (see above). @@ -2925,7 +3254,7 @@ CV_EXPORTS_W void calcBackProject( InputArrayOfArrays images, const std::vector< /** @brief Compares two histograms. -The function compare two dense or two sparse histograms using the specified method. +The function cv::compareHist compares two dense or two sparse histograms using the specified method. The function returns \f$d(H_1, H_2)\f$ . @@ -2973,10 +3302,12 @@ same object. @param signature1 First signature, a \f$\texttt{size1}\times \texttt{dims}+1\f$ floating-point matrix. Each row stores the point weight followed by the point coordinates. The matrix is allowed to have -a single column (weights only) if the user-defined cost matrix is used. +a single column (weights only) if the user-defined cost matrix is used. The weights must be +non-negative and have at least one non-zero value. @param signature2 Second signature of the same format as signature1 , though the number of rows may be different. The total weights may be different. In this case an extra "dummy" point is added -to either signature1 or signature2 . +to either signature1 or signature2. The weights must be non-negative and have at least one non-zero +value. @param distType Used metric. See cv::DistanceTypes. @param cost User-defined \f$\texttt{size1}\times \texttt{size2}\f$ cost matrix. Also, if a cost matrix is used, lower boundary lowerBound cannot be calculated because it needs a metric function. @@ -2996,6 +3327,10 @@ CV_EXPORTS float EMD( InputArray signature1, InputArray signature2, int distType, InputArray cost=noArray(), float* lowerBound = 0, OutputArray flow = noArray() ); +CV_EXPORTS_AS(EMD) float wrapperEMD( InputArray signature1, InputArray signature2, + int distType, InputArray cost=noArray(), + CV_IN_OUT Ptr lowerBound = Ptr(), OutputArray flow = noArray() ); + //! @} imgproc_hist /** @example watershed.cpp @@ -3080,6 +3415,7 @@ CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst, /** @example grabcut.cpp An example using the GrabCut algorithm +![Sample Screenshot](grabcut_output1.jpg) */ /** @brief Runs the GrabCut algorithm. @@ -3111,7 +3447,7 @@ An example on using the distance transform\ /** @brief Calculates the distance to the closest zero pixel for each pixel of the source image. -The functions distanceTransform calculate the approximate or precise distance from every binary +The function cv::distanceTransform calculates the approximate or precise distance from every binary image pixel to the nearest zero pixel. For zero image pixels, the distance will obviously be zero. When maskSize == DIST_MASK_PRECISE and distanceType == DIST_L2 , the function runs the @@ -3195,7 +3531,7 @@ CV_EXPORTS int floodFill( InputOutputArray image, /** @brief Fills a connected component with the given color. -The functions floodFill fill a connected component starting from the seed point with the specified +The function cv::floodFill fills a connected component starting from the seed point with the specified color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The pixel at \f$(x,y)\f$ is considered to belong to the repainted domain if: @@ -3239,7 +3575,8 @@ taller than image. Since this is both an input and output parameter, you must ta of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example, an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the mask corresponding to filled pixels in the image are set to 1 or to the a value specified in flags -as described below. It is therefore possible to use the same mask in multiple calls to the function +as described below. Additionally, the function fills the border of the mask with ones to simplify +internal processing. It is therefore possible to use the same mask in multiple calls to the function to make sure the filled areas do not overlap. @param seedPoint Starting point. @param newVal New value of the repainted domain pixels. @@ -3313,7 +3650,7 @@ CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn //! @} imgproc_misc -// main function for all demosaicing procceses +// main function for all demosaicing processes CV_EXPORTS_W void demosaicing(InputArray _src, OutputArray _dst, int code, int dcn = 0); //! @addtogroup imgproc_shape @@ -3330,6 +3667,9 @@ results are returned in the structure cv::Moments. used for images only. @returns moments. +@note Only applicable to contour moments calculations from Python bindings: Note that the numpy +type for the input array should be either np.int32 or np.float32. + @sa contourArea, arcLength */ CV_EXPORTS_W Moments moments( InputArray array, bool binaryImage = false ); @@ -3375,6 +3715,9 @@ enum TemplateMatchModes { TM_CCOEFF_NORMED = 5 //!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{ \sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2} }\f] }; +/** @example MatchTemplate_Demo.cpp +An example using Template Matching algorithm + */ /** @brief Compares a template against overlapped image regions. The function slides through image , compares the overlapped patches of size \f$w \times h\f$ against @@ -3396,7 +3739,7 @@ data type. is \f$W \times H\f$ and templ is \f$w \times h\f$ , then result is \f$(W-w+1) \times (H-h+1)\f$ . @param method Parameter specifying the comparison method, see cv::TemplateMatchModes @param mask Mask of searched template. It must have the same datatype and size with templ. It is -not set by default. +not set by default. Currently, only the TM_SQDIFF and TM_CCORR_NORMED methods are supported. */ CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ, OutputArray result, int method, InputArray mask = noArray() ); @@ -3411,16 +3754,59 @@ CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ, image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0 represents the background label. ltype specifies the output label image type, an important consideration based on the total number of labels or alternatively the total number of pixels in -the source image. +the source image. ccltype specifies the connected components labeling algorithm to use, currently +Grana (BBDT) and Wu's (SAUF) algorithms are supported, see the cv::ConnectedComponentsAlgorithmsTypes +for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not. +This function uses parallel version of both Grana and Wu's algorithms if at least one allowed +parallel framework is enabled and if the rows of the image are at least twice the number returned by getNumberOfCPUs. @param image the 8-bit single-channel image to be labeled @param labels destination labeled image @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively @param ltype output image label type. Currently CV_32S and CV_16U are supported. - */ +@param ccltype connected components algorithm type (see the cv::ConnectedComponentsAlgorithmsTypes). +*/ +CV_EXPORTS_AS(connectedComponentsWithAlgorithm) int connectedComponents(InputArray image, OutputArray labels, + int connectivity, int ltype, int ccltype); + + +/** @overload + +@param image the 8-bit single-channel image to be labeled +@param labels destination labeled image +@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively +@param ltype output image label type. Currently CV_32S and CV_16U are supported. +*/ CV_EXPORTS_W int connectedComponents(InputArray image, OutputArray labels, int connectivity = 8, int ltype = CV_32S); + +/** @brief computes the connected components labeled image of boolean image and also produces a statistics output for each label + +image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0 +represents the background label. ltype specifies the output label image type, an important +consideration based on the total number of labels or alternatively the total number of pixels in +the source image. ccltype specifies the connected components labeling algorithm to use, currently +Grana's (BBDT) and Wu's (SAUF) algorithms are supported, see the cv::ConnectedComponentsAlgorithmsTypes +for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not. +This function uses parallel version of both Grana and Wu's algorithms (statistics included) if at least one allowed +parallel framework is enabled and if the rows of the image are at least twice the number returned by getNumberOfCPUs. + +@param image the 8-bit single-channel image to be labeled +@param labels destination labeled image +@param stats statistics output for each label, including the background label, see below for +available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of +cv::ConnectedComponentsTypes. The data type is CV_32S. +@param centroids centroid output for each label, including the background label. Centroids are +accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F. +@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively +@param ltype output image label type. Currently CV_32S and CV_16U are supported. +@param ccltype connected components algorithm type (see the cv::ConnectedComponentsAlgorithmsTypes). +*/ +CV_EXPORTS_AS(connectedComponentsWithStatsWithAlgorithm) int connectedComponentsWithStats(InputArray image, OutputArray labels, + OutputArray stats, OutputArray centroids, + int connectivity, int ltype, int ccltype); + /** @overload @param image the 8-bit single-channel image to be labeled @param labels destination labeled image @@ -3440,22 +3826,19 @@ CV_EXPORTS_W int connectedComponentsWithStats(InputArray image, OutputArray labe /** @brief Finds contours in a binary image. The function retrieves contours from the binary image using the algorithm @cite Suzuki85 . The contours -are a useful tool for shape analysis and object detection and recognition. See squares.c in the +are a useful tool for shape analysis and object detection and recognition. See squares.cpp in the OpenCV sample directory. - -@note Source image is modified by this function. Also, the function does not take into account -1-pixel border of the image (it's filled with 0's and used for neighbor analysis in the algorithm), -therefore the contours touching the image border will be clipped. +@note Since opencv 3.2 source image is not modified by this function. @param image Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero -pixels remain 0's, so the image is treated as binary . You can use compare , inRange , threshold , -adaptiveThreshold , Canny , and others to create a binary image out of a grayscale or color one. -The function modifies the image while extracting the contours. If mode equals to RETR_CCOMP -or RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1). -@param contours Detected contours. Each contour is stored as a vector of points. -@param hierarchy Optional output vector, containing information about the image topology. It has -as many elements as the number of contours. For each i-th contour contours[i] , the elements -hierarchy[i][0] , hiearchy[i][1] , hiearchy[i][2] , and hiearchy[i][3] are set to 0-based indices +pixels remain 0's, so the image is treated as binary . You can use cv::compare, cv::inRange, cv::threshold , +cv::adaptiveThreshold, cv::Canny, and others to create a binary image out of a grayscale or color one. +If mode equals to cv::RETR_CCOMP or cv::RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1). +@param contours Detected contours. Each contour is stored as a vector of points (e.g. +std::vector >). +@param hierarchy Optional output vector (e.g. std::vector), containing information about the image topology. It has +as many elements as the number of contours. For each i-th contour contours[i], the elements +hierarchy[i][0] , hierarchy[i][1] , hierarchy[i][2] , and hierarchy[i][3] are set to 0-based indices in contours of the next and previous contours at the same hierarchical level, the first child contour and the parent contour, respectively. If for the contour i there are no next, previous, parent, or nested contours, the corresponding elements of hierarchy[i] will be negative. @@ -3475,7 +3858,7 @@ CV_EXPORTS void findContours( InputOutputArray image, OutputArrayOfArrays contou /** @brief Approximates a polygonal curve(s) with the specified precision. -The functions approxPolyDP approximate a curve or a polygon with another curve/polygon with less +The function cv::approxPolyDP approximates a curve or a polygon with another curve/polygon with less vertices so that the distance between them is less or equal to the specified precision. It uses the Douglas-Peucker algorithm @@ -3542,9 +3925,8 @@ CV_EXPORTS_W double contourArea( InputArray contour, bool oriented = false ); /** @brief Finds a rotated rectangle of the minimum area enclosing the input 2D point set. The function calculates and returns the minimum-area bounding rectangle (possibly rotated) for a -specified point set. See the OpenCV sample minarea.cpp . Developer should keep in mind that the -returned rotatedRect can contain negative indices when data is close to the containing Mat element -boundary. +specified point set. Developer should keep in mind that the returned RotatedRect can contain negative +indices when data is close to the containing Mat element boundary. @param points Input vector of 2D points, stored in std::vector\<\> or Mat */ @@ -3565,8 +3947,7 @@ CV_EXPORTS_W void boxPoints(RotatedRect box, OutputArray points); /** @brief Finds a circle of the minimum area enclosing a 2D point set. -The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm. See -the OpenCV sample minarea.cpp . +The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm. @param points Input vector of 2D points, stored in std::vector\<\> or Mat @param center Output center of the circle. @@ -3605,7 +3986,7 @@ The function compares two shapes. All three implemented methods use the Hu invar @param contour1 First contour or grayscale image. @param contour2 Second contour or grayscale image. -@param method Comparison method, see ::ShapeMatchModes +@param method Comparison method, see cv::ShapeMatchModes @param parameter Method-specific parameter (not supported now). */ CV_EXPORTS_W double matchShapes( InputArray contour1, InputArray contour2, @@ -3617,7 +3998,7 @@ An example using the convexHull functionality /** @brief Finds the convex hull of a point set. -The functions find the convex hull of a 2D point set using the Sklansky's algorithm @cite Sklansky82 +The function cv::convexHull finds the convex hull of a 2D point set using the Sklansky's algorithm @cite Sklansky82 that has *O(N logN)* complexity in the current implementation. See the OpenCV sample convexhull.cpp that demonstrates the usage of different function variants. @@ -3632,8 +4013,10 @@ to the right, and its Y axis pointing upwards. @param returnPoints Operation flag. In case of a matrix, when the flag is true, the function returns convex hull points. Otherwise, it returns indices of the convex hull points. When the output array is std::vector, the flag is ignored, and the output depends on the type of the -vector: std::vector\ implies returnPoints=true, std::vector\ implies -returnPoints=false. +vector: std::vector\ implies returnPoints=false, std::vector\ implies +returnPoints=true. + +@note `points` and `hull` should be different arrays, inplace processing isn't supported. */ CV_EXPORTS_W void convexHull( InputArray points, OutputArray hull, bool clockwise = false, bool returnPoints = true ); @@ -3686,6 +4069,88 @@ border of the containing Mat element. */ CV_EXPORTS_W RotatedRect fitEllipse( InputArray points ); +/** @brief Fits an ellipse around a set of 2D points. + + The function calculates the ellipse that fits a set of 2D points. + It returns the rotated rectangle in which the ellipse is inscribed. + The Approximate Mean Square (AMS) proposed by @cite Taubin1991 is used. + + For an ellipse, this basis set is \f$ \chi= \left(x^2, x y, y^2, x, y, 1\right) \f$, + which is a set of six free coefficients \f$ A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \f$. + However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \f$ (a,b) \f$, + the position \f$ (x_0,y_0) \f$, and the orientation \f$ \theta \f$. This is because the basis set includes lines, + quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits. + If the fit is found to be a parabolic or hyperbolic function then the standard fitEllipse method is used. + The AMS method restricts the fit to parabolic, hyperbolic and elliptical curves + by imposing the condition that \f$ A^T ( D_x^T D_x + D_y^T D_y) A = 1 \f$ where + the matrices \f$ Dx \f$ and \f$ Dy \f$ are the partial derivatives of the design matrix \f$ D \f$ with + respect to x and y. The matrices are formed row by row applying the following to + each of the points in the set: + \f{align*}{ + D(i,:)&=\left\{x_i^2, x_i y_i, y_i^2, x_i, y_i, 1\right\} & + D_x(i,:)&=\left\{2 x_i,y_i,0,1,0,0\right\} & + D_y(i,:)&=\left\{0,x_i,2 y_i,0,1,0\right\} + \f} + The AMS method minimizes the cost function + \f{equation*}{ + \epsilon ^2=\frac{ A^T D^T D A }{ A^T (D_x^T D_x + D_y^T D_y) A^T } + \f} + + The minimum cost is found by solving the generalized eigenvalue problem. + + \f{equation*}{ + D^T D A = \lambda \left( D_x^T D_x + D_y^T D_y\right) A + \f} + + @param points Input 2D point set, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W RotatedRect fitEllipseAMS( InputArray points ); + + +/** @brief Fits an ellipse around a set of 2D points. + + The function calculates the ellipse that fits a set of 2D points. + It returns the rotated rectangle in which the ellipse is inscribed. + The Direct least square (Direct) method by @cite Fitzgibbon1999 is used. + + For an ellipse, this basis set is \f$ \chi= \left(x^2, x y, y^2, x, y, 1\right) \f$, + which is a set of six free coefficients \f$ A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \f$. + However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \f$ (a,b) \f$, + the position \f$ (x_0,y_0) \f$, and the orientation \f$ \theta \f$. This is because the basis set includes lines, + quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits. + The Direct method confines the fit to ellipses by ensuring that \f$ 4 A_{xx} A_{yy}- A_{xy}^2 > 0 \f$. + The condition imposed is that \f$ 4 A_{xx} A_{yy}- A_{xy}^2=1 \f$ which satisfies the inequality + and as the coefficients can be arbitrarily scaled is not overly restrictive. + + \f{equation*}{ + \epsilon ^2= A^T D^T D A \quad \text{with} \quad A^T C A =1 \quad \text{and} \quad C=\left(\begin{matrix} + 0 & 0 & 2 & 0 & 0 & 0 \\ + 0 & -1 & 0 & 0 & 0 & 0 \\ + 2 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 0 + \end{matrix} \right) + \f} + + The minimum cost is found by solving the generalized eigenvalue problem. + + \f{equation*}{ + D^T D A = \lambda \left( C\right) A + \f} + + The system produces only one positive eigenvalue \f$ \lambda\f$ which is chosen as the solution + with its eigenvector \f$\mathbf{u}\f$. These are used to find the coefficients + + \f{equation*}{ + A = \sqrt{\frac{1}{\mathbf{u}^T C \mathbf{u}}} \mathbf{u} + \f} + The scaling factor guarantees that \f$A^T C A =1\f$. + + @param points Input 2D point set, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W RotatedRect fitEllipseDirect( InputArray points ); + /** @brief Fits a line to a 2D or 3D point set. The function fitLine fits a line to a 2D or 3D point set by minimizing \f$\sum_i \rho(r_i)\f$ where @@ -3743,7 +4208,7 @@ CV_EXPORTS_W double pointPolygonTest( InputArray contour, Point2f pt, bool measu /** @brief Finds out if there is any intersection between two rotated rectangles. -If there is then the vertices of the interesecting region are returned as well. +If there is then the vertices of the intersecting region are returned as well. Below are some examples of intersection configurations. The hatched pattern indicates the intersecting region and the red vertices are returned by the function. @@ -3752,7 +4217,7 @@ intersecting region and the red vertices are returned by the function. @param rect1 First rectangle @param rect2 Second rectangle -@param intersectingRegion The output array of the verticies of the intersecting region. It returns +@param intersectingRegion The output array of the vertices of the intersecting region. It returns at most 8 vertices. Stored as std::vector\ or cv::Mat as Mx1 of type CV_32FC2. @returns One of cv::RectanglesIntersectTypes */ @@ -3763,14 +4228,20 @@ CV_EXPORTS_W int rotatedRectangleIntersection( const RotatedRect& rect1, const R CV_EXPORTS_W Ptr createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8)); //! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122. -//! Detects position only without traslation and rotation +//! Detects position only without translation and rotation CV_EXPORTS Ptr createGeneralizedHoughBallard(); //! Guil, N., González-Linares, J.M. and Zapata, E.L. (1999). Bidimensional shape detection using an invariant approach. Pattern Recognition 32 (6): 1025-1038. -//! Detects position, traslation and rotation +//! Detects position, translation and rotation CV_EXPORTS Ptr createGeneralizedHoughGuil(); -//! Performs linear blending of two images +//! Performs linear blending of two images: +//! \f[ \texttt{dst}(i,j) = \texttt{weights1}(i,j)*\texttt{src1}(i,j) + \texttt{weights2}(i,j)*\texttt{src2}(i,j) \f] +//! @param src1 It has a type of CV_8UC(n) or CV_32FC(n), where n is a positive integer. +//! @param src2 It has the same type and size as src1. +//! @param weights1 It has a type of CV_32FC1 and the same size with src1. +//! @param weights2 It has a type of CV_32FC1 and the same size with src1. +//! @param dst It is created if it does not have the same size and type with src1. CV_EXPORTS void blendLinear(InputArray src1, InputArray src2, InputArray weights1, InputArray weights2, OutputArray dst); //! @addtogroup imgproc_colormap @@ -3794,14 +4265,25 @@ enum ColormapTypes COLORMAP_PARULA = 12 //!< ![parula](pics/colormaps/colorscale_parula.jpg) }; +/** @example falsecolor.cpp +An example using applyColorMap function +*/ /** @brief Applies a GNU Octave/MATLAB equivalent colormap on a given image. -@param src The source image, grayscale or colored does not matter. +@param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3. @param dst The result is the colormapped source image. Note: Mat::create is called on dst. @param colormap The colormap to apply, see cv::ColormapTypes - */ +*/ CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap); +/** @brief Applies a user colormap on a given image. + +@param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3. +@param dst The result is the colormapped source image. Note: Mat::create is called on dst. +@param userColor The colormap to apply of type CV_8UC1 or CV_8UC3 and size 256 +*/ +CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, InputArray userColor); + //! @} imgproc_colormap //! @addtogroup imgproc_draw @@ -3868,6 +4350,9 @@ CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec, const Scalar& color, int thickness = 1, int lineType = LINE_8, int shift = 0); +/** @example Drawing_2.cpp +An example using drawing functions + */ /** @brief Draws a circle. The function circle draws a simple or filled circle with a given center and radius. @@ -3886,14 +4371,16 @@ CV_EXPORTS_W void circle(InputOutputArray img, Point center, int radius, /** @brief Draws a simple or thick elliptic arc or fills an ellipse sector. -The functions ellipse with less parameters draw an ellipse outline, a filled ellipse, an elliptic -arc, or a filled ellipse sector. A piecewise-linear curve is used to approximate the elliptic arc +The function cv::ellipse with more parameters draws an ellipse outline, a filled ellipse, an elliptic +arc, or a filled ellipse sector. The drawing code uses general parametric form. +A piecewise-linear curve is used to approximate the elliptic arc boundary. If you need more control of the ellipse rendering, you can retrieve the curve using -ellipse2Poly and then render it with polylines or fill it with fillPoly . If you use the first -variant of the function and want to draw the whole ellipse, not an arc, pass startAngle=0 and -endAngle=360 . The figure below explains the meaning of the parameters. +cv::ellipse2Poly and then render it with polylines or fill it with cv::fillPoly. If you use the first +variant of the function and want to draw the whole ellipse, not an arc, pass `startAngle=0` and +`endAngle=360`. If `startAngle` is greater than `endAngle`, they are swapped. The figure below explains +the meaning of the parameters to draw the blue arc. -![Parameters of Elliptic Arc](pics/ellipse.png) +![Parameters of Elliptic Arc](pics/ellipse.svg) @param img Image. @param center Center of the ellipse. @@ -3947,8 +4434,8 @@ marker types are supported, see cv::MarkerTypes for more information. @param img Image. @param position The point where the crosshair is positioned. -@param markerType The specific type of marker you want to use, see cv::MarkerTypes @param color Line color. +@param markerType The specific type of marker you want to use, see cv::MarkerTypes @param thickness Line thickness. @param line_type Type of the line, see cv::LineTypes @param markerSize The length of the marker axis [default = 20 pixels] @@ -3989,6 +4476,9 @@ CV_EXPORTS void fillPoly(Mat& img, const Point** pts, const Scalar& color, int lineType = LINE_8, int shift = 0, Point offset = Point() ); +/** @example Drawing_1.cpp +An example using drawing functions + */ /** @brief Fills the area bounded by one or more polygons. The function fillPoly fills an area bounded by several polygonal contours. The function can fill @@ -4029,7 +4519,8 @@ CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts, int thickness = 1, int lineType = LINE_8, int shift = 0 ); /** @example contours2.cpp - An example using the drawContour functionality + An example program illustrates the use of cv::findContours and cv::drawContours + \image html WindowsQtContoursOutput.png "Screenshot of the program" */ /** @example segment_objects.cpp @@ -4098,6 +4589,11 @@ draws the contours, all the nested contours, all the nested-to-nested contours, parameter is only taken into account when there is hierarchy available. @param offset Optional contour shift parameter. Shift all the drawn contours by the specified \f$\texttt{offset}=(dx,dy)\f$ . +@note When thickness=CV_FILLED, the function is designed to handle connected components with holes correctly +even when no hierarchy date is provided. This is done by analyzing all the outlines together +using even-odd rule. This may give incorrect results if you have a joint collection of separately retrieved +contours. In order to solve this problem, you need to call drawContours separately for each sub-group +of contours, or iterate over the collection using contourIdx parameter. */ CV_EXPORTS_W void drawContours( InputOutputArray image, InputArrayOfArrays contours, int contourIdx, const Scalar& color, @@ -4107,15 +4603,22 @@ CV_EXPORTS_W void drawContours( InputOutputArray image, InputArrayOfArrays conto /** @brief Clips the line against the image rectangle. -The functions clipLine calculate a part of the line segment that is entirely within the specified -rectangle. They return false if the line segment is completely outside the rectangle. Otherwise, -they return true . +The function cv::clipLine calculates a part of the line segment that is entirely within the specified +rectangle. it returns false if the line segment is completely outside the rectangle. Otherwise, +it returns true . @param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) . @param pt1 First line point. @param pt2 Second line point. */ CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2); +/** @overload +@param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) . +@param pt1 First line point. +@param pt2 Second line point. +*/ +CV_EXPORTS bool clipLine(Size2l imgSize, CV_IN_OUT Point2l& pt1, CV_IN_OUT Point2l& pt2); + /** @overload @param imgRect Image rectangle. @param pt1 First line point. @@ -4126,7 +4629,7 @@ CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_ /** @brief Approximates an elliptic arc with a polyline. The function ellipse2Poly computes the vertices of a polyline that approximates the specified -elliptic arc. It is used by cv::ellipse. +elliptic arc. It is used by cv::ellipse. If `arcStart` is greater than `arcEnd`, they are swapped. @param center Center of the arc. @param axes Half of the size of the ellipse main axes. See the ellipse for details. @@ -4141,6 +4644,20 @@ CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle, int arcStart, int arcEnd, int delta, CV_OUT std::vector& pts ); +/** @overload +@param center Center of the arc. +@param axes Half of the size of the ellipse main axes. See the ellipse for details. +@param angle Rotation angle of the ellipse in degrees. See the ellipse for details. +@param arcStart Starting angle of the elliptic arc in degrees. +@param arcEnd Ending angle of the elliptic arc in degrees. +@param delta Angle between the subsequent polyline vertices. It defines the approximation +accuracy. +@param pts Output vector of polyline vertices. +*/ +CV_EXPORTS void ellipse2Poly(Point2d center, Size2d axes, int angle, + int arcStart, int arcEnd, int delta, + CV_OUT std::vector& pts); + /** @brief Draws a text string. The function putText renders the specified text string in the image. Symbols that cannot be rendered diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/imgproc/detail/distortion_model.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/detail/distortion_model.hpp similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv2/imgproc/detail/distortion_model.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/detail/distortion_model.hpp index ca293040..a9c3ddec 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/imgproc/detail/distortion_model.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/detail/distortion_model.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP__ -#define __OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP__ +#ifndef OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP +#define OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP //! @cond IGNORED @@ -120,4 +120,4 @@ void computeTiltProjectionMatrix(FLOAT tauX, //! @endcond -#endif // __OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP__ +#endif // OPENCV_IMGPROC_DETAIL_DISTORTION_MODEL_HPP diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/hal/hal.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/hal/hal.hpp new file mode 100644 index 00000000..a435fd6b --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/hal/hal.hpp @@ -0,0 +1,241 @@ +#ifndef CV_IMGPROC_HAL_HPP +#define CV_IMGPROC_HAL_HPP + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/cvstd.hpp" +#include "opencv2/core/hal/interface.h" + +namespace cv { namespace hal { + +//! @addtogroup imgproc_hal_functions +//! @{ + +//--------------------------- +//! @cond IGNORED + +struct CV_EXPORTS Filter2D +{ + CV_DEPRECATED static Ptr create(uchar * , size_t , int , + int , int , + int , int , + int , int , + int , double , + int , int , + bool , bool ); + virtual void apply(uchar * , size_t , + uchar * , size_t , + int , int , + int , int , + int , int ) = 0; + virtual ~Filter2D() {} +}; + +struct CV_EXPORTS SepFilter2D +{ + CV_DEPRECATED static Ptr create(int , int , int , + uchar * , int , + uchar * , int , + int , int , + double , int ); + virtual void apply(uchar * , size_t , + uchar * , size_t , + int , int , + int , int , + int , int ) = 0; + virtual ~SepFilter2D() {} +}; + + +struct CV_EXPORTS Morph +{ + CV_DEPRECATED static Ptr create(int , int , int , int , int , + int , uchar * , size_t , + int , int , + int , int , + int , const double *, + int , bool , bool ); + virtual void apply(uchar * , size_t , uchar * , size_t , int , int , + int , int , int , int , + int , int , int , int ) = 0; + virtual ~Morph() {} +}; + +//! @endcond +//--------------------------- + +CV_EXPORTS void filter2D(int stype, int dtype, int kernel_type, + uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int full_width, int full_height, + int offset_x, int offset_y, + uchar * kernel_data, size_t kernel_step, + int kernel_width, int kernel_height, + int anchor_x, int anchor_y, + double delta, int borderType, + bool isSubmatrix); + +CV_EXPORTS void sepFilter2D(int stype, int dtype, int ktype, + uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int full_width, int full_height, + int offset_x, int offset_y, + uchar * kernelx_data, int kernelx_len, + uchar * kernely_data, int kernely_len, + int anchor_x, int anchor_y, + double delta, int borderType); + +CV_EXPORTS void morph(int op, int src_type, int dst_type, + uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int roi_width, int roi_height, int roi_x, int roi_y, + int roi_width2, int roi_height2, int roi_x2, int roi_y2, + int kernel_type, uchar * kernel_data, size_t kernel_step, + int kernel_width, int kernel_height, int anchor_x, int anchor_y, + int borderType, const double borderValue[4], + int iterations, bool isSubmatrix); + + +CV_EXPORTS void resize(int src_type, + 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, + double inv_scale_x, double inv_scale_y, int interpolation); + +CV_EXPORTS void warpAffine(int src_type, + 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, + const double M[6], int interpolation, int borderType, const double borderValue[4]); + +CV_EXPORTS void warpPerspectve(int src_type, + 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, + const double M[9], int interpolation, int borderType, const double borderValue[4]); + +CV_EXPORTS void cvtBGRtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, int dcn, bool swapBlue); + +CV_EXPORTS void cvtBGRtoBGR5x5(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int scn, bool swapBlue, int greenBits); + +CV_EXPORTS void cvtBGR5x5toBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int dcn, bool swapBlue, int greenBits); + +CV_EXPORTS void cvtBGRtoGray(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue); + +CV_EXPORTS void cvtGraytoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn); + +CV_EXPORTS void cvtBGR5x5toGray(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int greenBits); + +CV_EXPORTS void cvtGraytoBGR5x5(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int greenBits); +CV_EXPORTS void cvtBGRtoYUV(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue, bool isCbCr); + +CV_EXPORTS void cvtYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue, bool isCbCr); + +CV_EXPORTS void cvtBGRtoXYZ(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue); + +CV_EXPORTS void cvtXYZtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue); + +CV_EXPORTS void cvtBGRtoHSV(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue, bool isFullRange, bool isHSV); + +CV_EXPORTS void cvtHSVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue, bool isFullRange, bool isHSV); + +CV_EXPORTS void cvtBGRtoLab(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue, bool isLab, bool srgb); + +CV_EXPORTS void cvtLabtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue, bool isLab, bool srgb); + +CV_EXPORTS void cvtTwoPlaneYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int dst_width, int dst_height, + int dcn, bool swapBlue, int uIdx); + +//! Separate Y and UV planes +CV_EXPORTS void cvtTwoPlaneYUVtoBGR(const uchar * y_data, const uchar * uv_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int dst_width, int dst_height, + int dcn, bool swapBlue, int uIdx); + +CV_EXPORTS void cvtThreePlaneYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int dst_width, int dst_height, + int dcn, bool swapBlue, int uIdx); + +CV_EXPORTS void cvtBGRtoThreePlaneYUV(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int scn, bool swapBlue, int uIdx); + +//! Separate Y and UV planes +CV_EXPORTS void cvtBGRtoTwoPlaneYUV(const uchar * src_data, size_t src_step, + uchar * y_data, uchar * uv_data, size_t dst_step, + int width, int height, + int scn, bool swapBlue, int uIdx); + +CV_EXPORTS void cvtOnePlaneYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int dcn, bool swapBlue, int uIdx, int ycn); + +CV_EXPORTS void cvtRGBAtoMultipliedRGBA(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height); + +CV_EXPORTS void cvtMultipliedRGBAtoRGBA(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height); + +CV_EXPORTS void integral(int depth, int sdepth, int sqdepth, + const uchar* src, size_t srcstep, + uchar* sum, size_t sumstep, + uchar* sqsum, size_t sqsumstep, + uchar* tilted, size_t tstep, + int width, int height, int cn); + +//! @} + +}} + +#endif // CV_IMGPROC_HAL_HPP diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/hal/interface.h b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/hal/interface.h new file mode 100644 index 00000000..f8dbcfe7 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/hal/interface.h @@ -0,0 +1,46 @@ +#ifndef OPENCV_IMGPROC_HAL_INTERFACE_H +#define OPENCV_IMGPROC_HAL_INTERFACE_H + +//! @addtogroup imgproc_hal_interface +//! @{ + +//! @name Interpolation modes +//! @sa cv::InterpolationFlags +//! @{ +#define CV_HAL_INTER_NEAREST 0 +#define CV_HAL_INTER_LINEAR 1 +#define CV_HAL_INTER_CUBIC 2 +#define CV_HAL_INTER_AREA 3 +#define CV_HAL_INTER_LANCZOS4 4 +//! @} + +//! @name Morphology operations +//! @sa cv::MorphTypes +//! @{ +#define CV_HAL_MORPH_ERODE 0 +#define CV_HAL_MORPH_DILATE 1 +//! @} + +//! @name Threshold types +//! @sa cv::ThresholdTypes +//! @{ +#define CV_HAL_THRESH_BINARY 0 +#define CV_HAL_THRESH_BINARY_INV 1 +#define CV_HAL_THRESH_TRUNC 2 +#define CV_HAL_THRESH_TOZERO 3 +#define CV_HAL_THRESH_TOZERO_INV 4 +#define CV_HAL_THRESH_MASK 7 +#define CV_HAL_THRESH_OTSU 8 +#define CV_HAL_THRESH_TRIANGLE 16 +//! @} + +//! @name Adaptive threshold algorithm +//! @sa cv::AdaptiveThresholdTypes +//! @{ +#define CV_HAL_ADAPTIVE_THRESH_MEAN_C 0 +#define CV_HAL_ADAPTIVE_THRESH_GAUSSIAN_C 1 +//! @} + +//! @} + +#endif diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/imgproc/imgproc.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/imgproc.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/imgproc/imgproc.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/imgproc.hpp diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/imgproc/imgproc_c.h b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/imgproc_c.h similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/imgproc/imgproc_c.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/imgproc_c.h index 87518d72..d11db4b2 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/imgproc/imgproc_c.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/imgproc_c.h @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_IMGPROC_IMGPROC_C_H__ -#define __OPENCV_IMGPROC_IMGPROC_C_H__ +#ifndef OPENCV_IMGPROC_IMGPROC_C_H +#define OPENCV_IMGPROC_IMGPROC_C_H #include "opencv2/imgproc/types_c.h" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/imgproc/types_c.h b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/types_c.h similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/imgproc/types_c.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/types_c.h index 5ecb4607..13ffe1b1 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/imgproc/types_c.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/imgproc/types_c.h @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_IMGPROC_TYPES_C_H__ -#define __OPENCV_IMGPROC_TYPES_C_H__ +#ifndef OPENCV_IMGPROC_TYPES_C_H +#define OPENCV_IMGPROC_TYPES_C_H #include "opencv2/core/core_c.h" @@ -349,7 +349,17 @@ enum CV_BayerRG2RGB_EA = CV_BayerBG2BGR_EA, CV_BayerGR2RGB_EA = CV_BayerGB2BGR_EA, - CV_COLORCVT_MAX = 139 + CV_BayerBG2BGRA =139, + CV_BayerGB2BGRA =140, + CV_BayerRG2BGRA =141, + CV_BayerGR2BGRA =142, + + CV_BayerBG2RGBA =CV_BayerRG2BGRA, + CV_BayerGB2RGBA =CV_BayerGR2BGRA, + CV_BayerRG2RGBA =CV_BayerBG2BGRA, + CV_BayerGR2RGBA =CV_BayerGB2BGRA, + + CV_COLORCVT_MAX = 143 }; @@ -491,15 +501,8 @@ enum CV_POLY_APPROX_DP = 0 }; -/** @brief Shape matching methods - -\f$A\f$ denotes object1,\f$B\f$ denotes object2 - -\f$\begin{array}{l} m^A_i = \mathrm{sign} (h^A_i) \cdot \log{h^A_i} \\ m^B_i = \mathrm{sign} (h^B_i) \cdot \log{h^B_i} \end{array}\f$ - -and \f$h^A_i, h^B_i\f$ are the Hu moments of \f$A\f$ and \f$B\f$ , respectively. -*/ -enum ShapeMatchModes +/** Shape matching methods */ +enum { CV_CONTOURS_MATCH_I1 =1, //!< \f[I_1(A,B) = \sum _{i=1...7} \left | \frac{1}{m^A_i} - \frac{1}{m^B_i} \right |\f] CV_CONTOURS_MATCH_I2 =2, //!< \f[I_2(A,B) = \sum _{i=1...7} \left | m^A_i - m^B_i \right |\f] diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/ml.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/ml.hpp similarity index 76% rename from lib/3rdParty/OpenCV3.1/include/opencv2/ml.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/ml.hpp index 862f3f95..0295a076 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/ml.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/ml.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_ML_HPP__ -#define __OPENCV_ML_HPP__ +#ifndef OPENCV_ML_HPP +#define OPENCV_ML_HPP #ifdef __cplusplus # include "opencv2/core.hpp" @@ -104,7 +104,7 @@ enum SampleTypes It is used for optimizing statmodel accuracy by varying model parameters, the accuracy estimate being computed by cross-validation. */ -class CV_EXPORTS ParamGrid +class CV_EXPORTS_W ParamGrid { public: /** @brief Default constructor */ @@ -112,8 +112,8 @@ public: /** @brief Constructor with parameters */ ParamGrid(double _minVal, double _maxVal, double _logStep); - double minVal; //!< Minimum value of the statmodel parameter. Default value is 0. - double maxVal; //!< Maximum value of the statmodel parameter. Default value is 0. + CV_PROP_RW double minVal; //!< Minimum value of the statmodel parameter. Default value is 0. + CV_PROP_RW double maxVal; //!< Maximum value of the statmodel parameter. Default value is 0. /** @brief Logarithmic step for iterating the statmodel parameter. The grid determines the following iteration sequence of the statmodel parameter values: @@ -122,7 +122,15 @@ public: \f[\texttt{minVal} * \texttt{logStep} ^n < \texttt{maxVal}\f] The grid is logarithmic, so logStep must always be greater then 1. Default value is 1. */ - double logStep; + CV_PROP_RW double logStep; + + /** @brief Creates a ParamGrid Ptr that can be given to the %SVM::trainAuto method + + @param minVal minimum value of the parameter grid + @param maxVal maximum value of the parameter grid + @param logstep Logarithmic step for iterating the statmodel parameter + */ + CV_WRAP static Ptr create(double minVal=0., double maxVal=0., double logstep=1.); }; /** @brief Class encapsulating training data. @@ -190,6 +198,7 @@ public: CV_WRAP virtual Mat getTestSampleWeights() const = 0; CV_WRAP virtual Mat getVarIdx() const = 0; CV_WRAP virtual Mat getVarType() const = 0; + CV_WRAP Mat getVarSymbolFlags() const; CV_WRAP virtual int getResponseType() const = 0; CV_WRAP virtual Mat getTrainSampleIdx() const = 0; CV_WRAP virtual Mat getTestSampleIdx() const = 0; @@ -224,6 +233,12 @@ public: CV_WRAP virtual void setTrainTestSplitRatio(double ratio, bool shuffle=true) = 0; CV_WRAP virtual void shuffleTrainTest() = 0; + /** @brief Returns matrix of test samples */ + CV_WRAP Mat getTestSamples() const; + + /** @brief Returns vector of symbolic names captured in loadFromCSV() */ + CV_WRAP void getNames(std::vector& names) const; + CV_WRAP static Mat getSubVector(const Mat& vec, const Mat& idx); /** @brief Reads the dataset from a .csv file and returns the ready-to-use training data. @@ -386,6 +401,17 @@ public: /** Creates empty model Use StatModel::train to train the model after creation. */ CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized NormalBayesClassifier from a file + * + * Use NormalBayesClassifier::save to serialize and store an NormalBayesClassifier to disk. + * Load the NormalBayesClassifier from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized NormalBayesClassifier + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); }; /****************************************************************************************\ @@ -665,14 +691,54 @@ public: the usual %SVM with parameters specified in params is executed. */ virtual bool trainAuto( const Ptr& data, int kFold = 10, - ParamGrid Cgrid = SVM::getDefaultGrid(SVM::C), - ParamGrid gammaGrid = SVM::getDefaultGrid(SVM::GAMMA), - ParamGrid pGrid = SVM::getDefaultGrid(SVM::P), - ParamGrid nuGrid = SVM::getDefaultGrid(SVM::NU), - ParamGrid coeffGrid = SVM::getDefaultGrid(SVM::COEF), - ParamGrid degreeGrid = SVM::getDefaultGrid(SVM::DEGREE), + ParamGrid Cgrid = getDefaultGrid(C), + ParamGrid gammaGrid = getDefaultGrid(GAMMA), + ParamGrid pGrid = getDefaultGrid(P), + ParamGrid nuGrid = getDefaultGrid(NU), + ParamGrid coeffGrid = getDefaultGrid(COEF), + ParamGrid degreeGrid = getDefaultGrid(DEGREE), bool balanced=false) = 0; + /** @brief Trains an %SVM with optimal parameters + + @param samples training samples + @param layout See ml::SampleTypes. + @param responses vector of responses associated with the training samples. + @param kFold Cross-validation parameter. The training set is divided into kFold subsets. One + subset is used to test the model, the others form the train set. So, the %SVM algorithm is + @param Cgrid grid for C + @param gammaGrid grid for gamma + @param pGrid grid for p + @param nuGrid grid for nu + @param coeffGrid grid for coeff + @param degreeGrid grid for degree + @param balanced If true and the problem is 2-class classification then the method creates more + balanced cross-validation subsets that is proportions between classes in subsets are close + to such proportion in the whole train dataset. + + The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, + nu, coef0, degree. Parameters are considered optimal when the cross-validation + estimate of the test set error is minimal. + + This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only + offers rudimentary parameter options. + + This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the + regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and + the usual %SVM with parameters specified in params is executed. + */ + CV_WRAP bool trainAuto(InputArray samples, + int layout, + InputArray responses, + int kFold = 10, + Ptr Cgrid = SVM::getDefaultGridPtr(SVM::C), + Ptr gammaGrid = SVM::getDefaultGridPtr(SVM::GAMMA), + Ptr pGrid = SVM::getDefaultGridPtr(SVM::P), + Ptr nuGrid = SVM::getDefaultGridPtr(SVM::NU), + Ptr coeffGrid = SVM::getDefaultGridPtr(SVM::COEF), + Ptr degreeGrid = SVM::getDefaultGridPtr(SVM::DEGREE), + bool balanced=false); + /** @brief Retrieves all the support vectors The method returns all the support vectors as a floating-point matrix, where support vectors are @@ -715,10 +781,29 @@ public: */ static ParamGrid getDefaultGrid( int param_id ); + /** @brief Generates a grid for %SVM parameters. + + @param param_id %SVM parameters IDs that must be one of the SVM::ParamTypes. The grid is + generated for the parameter with this ID. + + The function generates a grid pointer for the specified parameter of the %SVM algorithm. + The grid may be passed to the function SVM::trainAuto. + */ + CV_WRAP static Ptr getDefaultGridPtr( int param_id ); + /** Creates empty model. Use StatModel::train to train the model. Since %SVM has several parameters, you may want to find the best parameters for your problem, it can be done with SVM::trainAuto. */ CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized svm from a file + * + * Use SVM::save to serialize and store an SVM to disk. + * Load the SVM from this file again, by calling this function with the path to the file. + * + * @param filepath path to serialized svm + */ + CV_WRAP static Ptr load(const String& filepath); }; /****************************************************************************************\ @@ -802,6 +887,15 @@ public: */ CV_WRAP virtual void getCovs(CV_OUT std::vector& covs) const = 0; + /** @brief Returns posterior probabilities for the provided samples + + @param samples The input samples, floating-point matrix + @param results The optional output \f$ nSamples \times nClusters\f$ matrix of results. It contains + posterior probabilities for each sample from the input + @param flags This parameter will be ignored + */ + CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const = 0; + /** @brief Returns a likelihood logarithm value and an index of the most probable mixture component for the given sample. @@ -911,6 +1005,17 @@ public: can use one of the EM::train\* methods or load it from file using Algorithm::load\(filename). */ CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized EM from a file + * + * Use EM::save to serialize and store an EM to disk. + * Load the EM from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized EM + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); }; /****************************************************************************************\ @@ -1099,6 +1204,17 @@ public: file using Algorithm::load\(filename). */ CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized DTrees from a file + * + * Use DTree::save to serialize and store an DTree to disk. + * Load the DTree from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized DTree + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); }; /****************************************************************************************\ @@ -1148,11 +1264,33 @@ public: */ CV_WRAP virtual Mat getVarImportance() const = 0; + /** Returns the result of each individual tree in the forest. + In case the model is a regression problem, the method will return each of the trees' + results for each of the sample cases. If the model is a classifier, it will return + a Mat with samples + 1 rows, where the first row gives the class number and the + following rows return the votes each class had for each sample. + @param samples Array containg the samples for which votes will be calculated. + @param results Array where the result of the calculation will be written. + @param flags Flags for defining the type of RTrees. + */ + CV_WRAP void getVotes(InputArray samples, OutputArray results, int flags) const; + /** Creates the empty model. Use StatModel::train to train the model, StatModel::train to create and train the model, Algorithm::load to load the pre-trained model. */ CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized RTree from a file + * + * Use RTree::save to serialize and store an RTree to disk. + * Load the RTree from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized RTree + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); }; /****************************************************************************************\ @@ -1202,6 +1340,17 @@ public: /** Creates the empty model. Use StatModel::train to train the model, Algorithm::load\(filename) to load the pre-trained model. */ CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized Boost from a file + * + * Use Boost::save to serialize and store an RTree to disk. + * Load the Boost from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized Boost + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); }; /****************************************************************************************\ @@ -1257,13 +1406,14 @@ public: /** Available training methods */ enum TrainingMethods { BACKPROP=0, //!< The back-propagation algorithm. - RPROP=1 //!< The RPROP algorithm. See @cite RPROP93 for details. + RPROP = 1, //!< The RPROP algorithm. See @cite RPROP93 for details. + ANNEAL = 2 //!< The simulated annealing algorithm. See @cite Kirkpatrick83 for details. }; /** Sets training method and common parameters. @param method Default value is ANN_MLP::RPROP. See ANN_MLP::TrainingMethods. - @param param1 passed to setRpropDW0 for ANN_MLP::RPROP and to setBackpropWeightScale for ANN_MLP::BACKPROP - @param param2 passed to setRpropDWMin for ANN_MLP::RPROP and to setBackpropMomentumScale for ANN_MLP::BACKPROP. + @param param1 passed to setRpropDW0 for ANN_MLP::RPROP and to setBackpropWeightScale for ANN_MLP::BACKPROP and to initialT for ANN_MLP::ANNEAL. + @param param2 passed to setRpropDWMin for ANN_MLP::RPROP and to setBackpropMomentumScale for ANN_MLP::BACKPROP and to finalT for ANN_MLP::ANNEAL. */ CV_WRAP virtual void setTrainMethod(int method, double param1 = 0, double param2 = 0) = 0; @@ -1350,18 +1500,53 @@ public: /** @copybrief getRpropDWMax @see getRpropDWMax */ CV_WRAP virtual void setRpropDWMax(double val) = 0; + /** ANNEAL: Update initial temperature. + It must be \>=0. Default value is 10.*/ + /** @see setAnnealInitialT */ + CV_WRAP double getAnnealInitialT() const; + /** @copybrief getAnnealInitialT @see getAnnealInitialT */ + CV_WRAP void setAnnealInitialT(double val); + + /** ANNEAL: Update final temperature. + It must be \>=0 and less than initialT. Default value is 0.1.*/ + /** @see setAnnealFinalT */ + CV_WRAP double getAnnealFinalT() const; + /** @copybrief getAnnealFinalT @see getAnnealFinalT */ + CV_WRAP void setAnnealFinalT(double val); + + /** ANNEAL: Update cooling ratio. + It must be \>0 and less than 1. Default value is 0.95.*/ + /** @see setAnnealCoolingRatio */ + CV_WRAP double getAnnealCoolingRatio() const; + /** @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */ + CV_WRAP void setAnnealCoolingRatio(double val); + + /** ANNEAL: Update iteration per step. + It must be \>0 . Default value is 10.*/ + /** @see setAnnealItePerStep */ + CV_WRAP int getAnnealItePerStep() const; + /** @copybrief getAnnealItePerStep @see getAnnealItePerStep */ + CV_WRAP void setAnnealItePerStep(int val); + + /** @brief Set/initialize anneal RNG */ + void setAnnealEnergyRNG(const RNG& rng); + /** possible activation functions */ enum ActivationFunctions { /** Identity function: \f$f(x)=x\f$ */ IDENTITY = 0, - /** Symmetrical sigmoid: \f$f(x)=\beta*(1-e^{-\alpha x})/(1+e^{-\alpha x}\f$ + /** Symmetrical sigmoid: \f$f(x)=\beta*(1-e^{-\alpha x})/(1+e^{-\alpha x})\f$ @note If you are using the default sigmoid activation function with the default parameter values fparam1=0 and fparam2=0 then the function used is y = 1.7159\*tanh(2/3 \* x), so the output will range from [-1.7159, 1.7159], instead of [0,1].*/ SIGMOID_SYM = 1, /** Gaussian function: \f$f(x)=\beta e^{-\alpha x*x}\f$ */ - GAUSSIAN = 2 + GAUSSIAN = 2, + /** ReLU function: \f$f(x)=max(0,x)\f$ */ + RELU = 3, + /** Leaky ReLU function: for x>0 \f$f(x)=x \f$ and x<=0 \f$f(x)=\alpha x \f$*/ + LEAKYRELU= 4 }; /** Train options */ @@ -1389,6 +1574,16 @@ public: Note that the train method has optional flags: ANN_MLP::TrainFlags. */ CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized ANN from a file + * + * Use ANN::save to serialize and store an ANN to disk. + * Load the ANN from this file again, by calling this function with the path to the file. + * + * @param filepath path to serialized ANN + */ + CV_WRAP static Ptr load(const String& filepath); + }; /****************************************************************************************\ @@ -1475,8 +1670,189 @@ public: Creates Logistic Regression model with parameters given. */ CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized LogisticRegression from a file + * + * Use LogisticRegression::save to serialize and store an LogisticRegression to disk. + * Load the LogisticRegression from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized LogisticRegression + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); }; + +/****************************************************************************************\ +* Stochastic Gradient Descent SVM Classifier * +\****************************************************************************************/ + +/*! +@brief Stochastic Gradient Descent SVM classifier + +SVMSGD provides a fast and easy-to-use implementation of the SVM classifier using the Stochastic Gradient Descent approach, +as presented in @cite bottou2010large. + +The classifier has following parameters: +- model type, +- margin type, +- margin regularization (\f$\lambda\f$), +- initial step size (\f$\gamma_0\f$), +- step decreasing power (\f$c\f$), +- and termination criteria. + +The model type may have one of the following values: \ref SGD and \ref ASGD. + +- \ref SGD is the classic version of SVMSGD classifier: every next step is calculated by the formula + \f[w_{t+1} = w_t - \gamma(t) \frac{dQ_i}{dw} |_{w = w_t}\f] + where + - \f$w_t\f$ is the weights vector for decision function at step \f$t\f$, + - \f$\gamma(t)\f$ is the step size of model parameters at the iteration \f$t\f$, it is decreased on each step by the formula + \f$\gamma(t) = \gamma_0 (1 + \lambda \gamma_0 t) ^ {-c}\f$ + - \f$Q_i\f$ is the target functional from SVM task for sample with number \f$i\f$, this sample is chosen stochastically on each step of the algorithm. + +- \ref ASGD is Average Stochastic Gradient Descent SVM Classifier. ASGD classifier averages weights vector on each step of algorithm by the formula +\f$\widehat{w}_{t+1} = \frac{t}{1+t}\widehat{w}_{t} + \frac{1}{1+t}w_{t+1}\f$ + +The recommended model type is ASGD (following @cite bottou2010large). + +The margin type may have one of the following values: \ref SOFT_MARGIN or \ref HARD_MARGIN. + +- You should use \ref HARD_MARGIN type, if you have linearly separable sets. +- You should use \ref SOFT_MARGIN type, if you have non-linearly separable sets or sets with outliers. +- In the general case (if you know nothing about linear separability of your sets), use SOFT_MARGIN. + +The other parameters may be described as follows: +- Margin regularization parameter is responsible for weights decreasing at each step and for the strength of restrictions on outliers + (the less the parameter, the less probability that an outlier will be ignored). + Recommended value for SGD model is 0.0001, for ASGD model is 0.00001. + +- Initial step size parameter is the initial value for the step size \f$\gamma(t)\f$. + You will have to find the best initial step for your problem. + +- Step decreasing power is the power parameter for \f$\gamma(t)\f$ decreasing by the formula, mentioned above. + Recommended value for SGD model is 1, for ASGD model is 0.75. + +- Termination criteria can be TermCriteria::COUNT, TermCriteria::EPS or TermCriteria::COUNT + TermCriteria::EPS. + You will have to find the best termination criteria for your problem. + +Note that the parameters margin regularization, initial step size, and step decreasing power should be positive. + +To use SVMSGD algorithm do as follows: + +- first, create the SVMSGD object. The algoorithm will set optimal parameters by default, but you can set your own parameters via functions setSvmsgdType(), + setMarginType(), setMarginRegularization(), setInitialStepSize(), and setStepDecreasingPower(). + +- then the SVM model can be trained using the train features and the correspondent labels by the method train(). + +- after that, the label of a new feature vector can be predicted using the method predict(). + +@code +// Create empty object +cv::Ptr svmsgd = SVMSGD::create(); + +// Train the Stochastic Gradient Descent SVM +svmsgd->train(trainData); + +// Predict labels for the new samples +svmsgd->predict(samples, responses); +@endcode + +*/ + +class CV_EXPORTS_W SVMSGD : public cv::ml::StatModel +{ +public: + + /** SVMSGD type. + ASGD is often the preferable choice. */ + enum SvmsgdType + { + SGD, //!< Stochastic Gradient Descent + ASGD //!< Average Stochastic Gradient Descent + }; + + /** Margin type.*/ + enum MarginType + { + SOFT_MARGIN, //!< General case, suits to the case of non-linearly separable sets, allows outliers. + HARD_MARGIN //!< More accurate for the case of linearly separable sets. + }; + + /** + * @return the weights of the trained model (decision function f(x) = weights * x + shift). + */ + CV_WRAP virtual Mat getWeights() = 0; + + /** + * @return the shift of the trained model (decision function f(x) = weights * x + shift). + */ + CV_WRAP virtual float getShift() = 0; + + /** @brief Creates empty model. + * Use StatModel::train to train the model. Since %SVMSGD has several parameters, you may want to + * find the best parameters for your problem or use setOptimalParameters() to set some default parameters. + */ + CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized SVMSGD from a file + * + * Use SVMSGD::save to serialize and store an SVMSGD to disk. + * Load the SVMSGD from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized SVMSGD + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); + + /** @brief Function sets optimal parameters values for chosen SVM SGD model. + * @param svmsgdType is the type of SVMSGD classifier. + * @param marginType is the type of margin constraint. + */ + CV_WRAP virtual void setOptimalParameters(int svmsgdType = SVMSGD::ASGD, int marginType = SVMSGD::SOFT_MARGIN) = 0; + + /** @brief %Algorithm type, one of SVMSGD::SvmsgdType. */ + /** @see setSvmsgdType */ + CV_WRAP virtual int getSvmsgdType() const = 0; + /** @copybrief getSvmsgdType @see getSvmsgdType */ + CV_WRAP virtual void setSvmsgdType(int svmsgdType) = 0; + + /** @brief %Margin type, one of SVMSGD::MarginType. */ + /** @see setMarginType */ + CV_WRAP virtual int getMarginType() const = 0; + /** @copybrief getMarginType @see getMarginType */ + CV_WRAP virtual void setMarginType(int marginType) = 0; + + /** @brief Parameter marginRegularization of a %SVMSGD optimization problem. */ + /** @see setMarginRegularization */ + CV_WRAP virtual float getMarginRegularization() const = 0; + /** @copybrief getMarginRegularization @see getMarginRegularization */ + CV_WRAP virtual void setMarginRegularization(float marginRegularization) = 0; + + /** @brief Parameter initialStepSize of a %SVMSGD optimization problem. */ + /** @see setInitialStepSize */ + CV_WRAP virtual float getInitialStepSize() const = 0; + /** @copybrief getInitialStepSize @see getInitialStepSize */ + CV_WRAP virtual void setInitialStepSize(float InitialStepSize) = 0; + + /** @brief Parameter stepDecreasingPower of a %SVMSGD optimization problem. */ + /** @see setStepDecreasingPower */ + CV_WRAP virtual float getStepDecreasingPower() const = 0; + /** @copybrief getStepDecreasingPower @see getStepDecreasingPower */ + CV_WRAP virtual void setStepDecreasingPower(float stepDecreasingPower) = 0; + + /** @brief Termination criteria of the training algorithm. + You can specify the maximum number of iterations (maxCount) and/or how much the error could + change between the iterations to make the algorithm continue (epsilon).*/ + /** @see setTermCriteria */ + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(const cv::TermCriteria &val) = 0; +}; + + /****************************************************************************************\ * Auxilary functions declarations * \****************************************************************************************/ @@ -1494,12 +1870,92 @@ CV_EXPORTS void randMVNormal( InputArray mean, InputArray cov, int nsamples, Out CV_EXPORTS void createConcentricSpheresTestSet( int nsamples, int nfeatures, int nclasses, OutputArray samples, OutputArray responses); +/** @brief Artificial Neural Networks - Multi-Layer Perceptrons. + +@sa @ref ml_intro_ann +*/ +class CV_EXPORTS_W ANN_MLP_ANNEAL : public ANN_MLP +{ +public: + /** @see setAnnealInitialT */ + CV_WRAP virtual double getAnnealInitialT() const = 0; + /** @copybrief getAnnealInitialT @see getAnnealInitialT */ + CV_WRAP virtual void setAnnealInitialT(double val) = 0; + + /** ANNEAL: Update final temperature. + It must be \>=0 and less than initialT. Default value is 0.1.*/ + /** @see setAnnealFinalT */ + CV_WRAP virtual double getAnnealFinalT() const = 0; + /** @copybrief getAnnealFinalT @see getAnnealFinalT */ + CV_WRAP virtual void setAnnealFinalT(double val) = 0; + + /** ANNEAL: Update cooling ratio. + It must be \>0 and less than 1. Default value is 0.95.*/ + /** @see setAnnealCoolingRatio */ + CV_WRAP virtual double getAnnealCoolingRatio() const = 0; + /** @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */ + CV_WRAP virtual void setAnnealCoolingRatio(double val) = 0; + + /** ANNEAL: Update iteration per step. + It must be \>0 . Default value is 10.*/ + /** @see setAnnealItePerStep */ + CV_WRAP virtual int getAnnealItePerStep() const = 0; + /** @copybrief getAnnealItePerStep @see getAnnealItePerStep */ + CV_WRAP virtual void setAnnealItePerStep(int val) = 0; + + /** @brief Set/initialize anneal RNG */ + virtual void setAnnealEnergyRNG(const RNG& rng) = 0; +}; + + +/****************************************************************************************\ +* Simulated annealing solver * +\****************************************************************************************/ + +#ifdef CV_DOXYGEN +/** @brief This class declares example interface for system state used in simulated annealing optimization algorithm. + +@note This class is not defined in C++ code and can't be use directly - you need your own implementation with the same methods. +*/ +struct SimulatedAnnealingSolverSystem +{ + /** Give energy value for a state of system.*/ + double energy() const; + /** Function which change the state of system (random pertubation).*/ + void changeState(); + /** Function to reverse to the previous state. Can be called once only after changeState(). */ + void reverseState(); +}; +#endif // CV_DOXYGEN + +/** @brief The class implements simulated annealing for optimization. + +@cite Kirkpatrick83 for details + +@param solverSystem optimization system (see SimulatedAnnealingSolverSystem) +@param initialTemperature initial temperature +@param finalTemperature final temperature +@param coolingRatio temperature step multiplies +@param iterationsPerStep number of iterations per temperature changing step +@param lastTemperature optional output for last used temperature +@param rngEnergy specify custom random numbers generator (cv::theRNG() by default) +*/ +template +int simulatedAnnealingSolver(SimulatedAnnealingSolverSystem& solverSystem, + double initialTemperature, double finalTemperature, double coolingRatio, + size_t iterationsPerStep, + CV_OUT double* lastTemperature = NULL, + cv::RNG& rngEnergy = cv::theRNG() +); + //! @} ml } } +#include + #endif // __cplusplus -#endif // __OPENCV_ML_HPP__ +#endif // OPENCV_ML_HPP /* End of file. */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/ml/ml.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/ml/ml.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/ml/ml.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/ml/ml.hpp diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/ml/ml.inl.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/ml/ml.inl.hpp new file mode 100644 index 00000000..dc9c7839 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/ml/ml.inl.hpp @@ -0,0 +1,60 @@ +// 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. + +#ifndef OPENCV_ML_INL_HPP +#define OPENCV_ML_INL_HPP + +namespace cv { namespace ml { + +// declared in ml.hpp +template +int simulatedAnnealingSolver(SimulatedAnnealingSolverSystem& solverSystem, + double initialTemperature, double finalTemperature, double coolingRatio, + size_t iterationsPerStep, + CV_OUT double* lastTemperature, + cv::RNG& rngEnergy +) +{ + CV_Assert(finalTemperature > 0); + CV_Assert(initialTemperature > finalTemperature); + CV_Assert(iterationsPerStep > 0); + CV_Assert(coolingRatio < 1.0f); + double Ti = initialTemperature; + double previousEnergy = solverSystem.energy(); + int exchange = 0; + while (Ti > finalTemperature) + { + for (size_t i = 0; i < iterationsPerStep; i++) + { + solverSystem.changeState(); + double newEnergy = solverSystem.energy(); + if (newEnergy < previousEnergy) + { + previousEnergy = newEnergy; + exchange++; + } + else + { + double r = rngEnergy.uniform(0.0, 1.0); + if (r < std::exp(-(newEnergy - previousEnergy) / Ti)) + { + previousEnergy = newEnergy; + exchange++; + } + else + { + solverSystem.reverseState(); + } + } + } + Ti *= coolingRatio; + } + if (lastTemperature) + *lastTemperature = Ti; + return exchange; +} + +}} //namespace + +#endif // OPENCV_ML_INL_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/objdetect.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/objdetect.hpp similarity index 63% rename from lib/3rdParty/OpenCV3.1/include/opencv2/objdetect.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/objdetect.hpp index 6587b3d7..40ebf56f 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/objdetect.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/objdetect.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_OBJDETECT_HPP__ -#define __OPENCV_OBJDETECT_HPP__ +#ifndef OPENCV_OBJDETECT_HPP +#define OPENCV_OBJDETECT_HPP #include "opencv2/core.hpp" @@ -91,7 +91,7 @@ compensate for the differences in the size of areas. The sums of pixel values ov regions are calculated rapidly using integral images (see below and the integral description). To see the object detector at work, have a look at the facedetect demo: - + The following reference is for the detection part only. There is a separate application called opencv_traincascade that can train a cascade of boosted classifiers from a set of samples. @@ -124,7 +124,7 @@ public: SimilarRects(double _eps) : eps(_eps) {} inline bool operator()(const Rect& r1, const Rect& r2) const { - double delta = eps*(std::min(r1.width, r2.width) + std::min(r1.height, r2.height))*0.5; + double delta = eps * ((std::min)(r1.width, r2.width) + (std::min)(r1.height, r2.height)) * 0.5; return std::abs(r1.x - r2.x) <= delta && std::abs(r1.y - r2.y) <= delta && std::abs(r1.x + r1.width - r2.x - r2.width) <= delta && @@ -215,6 +215,10 @@ public: virtual Ptr getMaskGenerator() = 0; }; +/** @example facedetect.cpp +This program demonstrates usage of the Cascade classifier class +\image html Cascade_Classifier_Tutorial_Result_Haar.jpg "Sample screenshot" width=321 height=254 +*/ /** @brief Cascade classifier class for object detection. */ class CV_EXPORTS_W CascadeClassifier @@ -255,7 +259,7 @@ public: @param flags Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade. @param minSize Minimum possible object size. Objects smaller than that are ignored. - @param maxSize Maximum possible object size. Objects larger than that are ignored. + @param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale. The function is parallelized with the TBB library. @@ -283,7 +287,7 @@ public: @param flags Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade. @param minSize Minimum possible object size. Objects smaller than that are ignored. - @param maxSize Maximum possible object size. Objects larger than that are ignored. + @param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale. */ CV_WRAP_AS(detectMultiScale2) void detectMultiScale( InputArray image, CV_OUT std::vector& objects, @@ -294,7 +298,21 @@ public: Size maxSize=Size() ); /** @overload - if `outputRejectLevels` is `true` returns `rejectLevels` and `levelWeights` + This function allows you to retrieve the final stage decision certainty of classification. + For this, one needs to set `outputRejectLevels` on true and provide the `rejectLevels` and `levelWeights` parameter. + For each resulting detection, `levelWeights` will then contain the certainty of classification at the final stage. + This value can then be used to separate strong from weaker classifications. + + A code sample on how to use it efficiently can be found below: + @code + Mat img; + vector weights; + vector levels; + vector detections; + CascadeClassifier model("/path/to/your/model.xml"); + model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true); + cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl; + @endcode */ CV_WRAP_AS(detectMultiScale3) void detectMultiScale( InputArray image, CV_OUT std::vector& objects, @@ -334,20 +352,54 @@ struct DetectionROI std::vector confidences; }; +/**@brief Implementation of HOG (Histogram of Oriented Gradients) descriptor and object detector. + +the HOG descriptor algorithm introduced by Navneet Dalal and Bill Triggs @cite Dalal2005 . + +useful links: + +https://hal.inria.fr/inria-00548512/document/ + +https://en.wikipedia.org/wiki/Histogram_of_oriented_gradients + +https://software.intel.com/en-us/ipp-dev-reference-histogram-of-oriented-gradients-hog-descriptor + +http://www.learnopencv.com/histogram-of-oriented-gradients + +http://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python-tutorial + + */ struct CV_EXPORTS_W HOGDescriptor { public: - enum { L2Hys = 0 + enum { L2Hys = 0 //!< Default histogramNormType }; - enum { DEFAULT_NLEVELS = 64 + enum { DEFAULT_NLEVELS = 64 //!< Default nlevels value. }; + /**@brief Creates the HOG descriptor and detector with default params. + aqual to HOGDescriptor(Size(64,128), Size(16,16), Size(8,8), Size(8,8), 9, 1 ) + */ CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8), cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1), histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true), free_coef(-1.f), nlevels(HOGDescriptor::DEFAULT_NLEVELS), signedGradient(false) {} + /** @overload + @param _winSize sets winSize with given value. + @param _blockSize sets blockSize with given value. + @param _blockStride sets blockStride with given value. + @param _cellSize sets cellSize with given value. + @param _nbins sets nbins with given value. + @param _derivAperture sets derivAperture with given value. + @param _winSigma sets winSigma with given value. + @param _histogramNormType sets histogramNormType with given value. + @param _L2HysThreshold sets L2HysThreshold with given value. + @param _gammaCorrection sets gammaCorrection with given value. + @param _nlevels sets nlevels with given value. + @param _signedGradient sets signedGradient with given value. + */ CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride, Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1, int _histogramNormType=HOGDescriptor::L2Hys, @@ -359,97 +411,262 @@ public: gammaCorrection(_gammaCorrection), free_coef(-1.f), nlevels(_nlevels), signedGradient(_signedGradient) {} + /** @overload + @param filename the file name containing HOGDescriptor properties and coefficients of the trained classifier + */ CV_WRAP HOGDescriptor(const String& filename) { load(filename); } + /** @overload + @param d the HOGDescriptor which cloned to create a new one. + */ HOGDescriptor(const HOGDescriptor& d) { d.copyTo(*this); } + /**@brief Default destructor. + */ virtual ~HOGDescriptor() {} + /**@brief Returns the number of coefficients required for the classification. + */ CV_WRAP size_t getDescriptorSize() const; + + /** @brief Checks if detector size equal to descriptor size. + */ CV_WRAP bool checkDetectorSize() const; + + /** @brief Returns winSigma value + */ CV_WRAP double getWinSigma() const; + /**@example peopledetect.cpp + */ + /**@brief Sets coefficients for the linear SVM classifier. + @param _svmdetector coefficients for the linear SVM classifier. + */ CV_WRAP virtual void setSVMDetector(InputArray _svmdetector); + /** @brief Reads HOGDescriptor parameters from a file node. + @param fn File node + */ virtual bool read(FileNode& fn); + + /** @brief Stores HOGDescriptor parameters in a file storage. + @param fs File storage + @param objname Object name + */ virtual void write(FileStorage& fs, const String& objname) const; + /** @brief loads coefficients for the linear SVM classifier from a file + @param filename Name of the file to read. + @param objname The optional name of the node to read (if empty, the first top-level node will be used). + */ CV_WRAP virtual bool load(const String& filename, const String& objname = String()); + + /** @brief saves coefficients for the linear SVM classifier to a file + @param filename File name + @param objname Object name + */ CV_WRAP virtual void save(const String& filename, const String& objname = String()) const; + + /** @brief clones the HOGDescriptor + @param c cloned HOGDescriptor + */ virtual void copyTo(HOGDescriptor& c) const; + /**@example train_HOG.cpp + */ + /** @brief Computes HOG descriptors of given image. + @param img Matrix of the type CV_8U containing an image where HOG features will be calculated. + @param descriptors Matrix of the type CV_32F + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param locations Vector of Point + */ CV_WRAP virtual void compute(InputArray img, CV_OUT std::vector& descriptors, Size winStride = Size(), Size padding = Size(), const std::vector& locations = std::vector()) const; - //! with found weights output + /** @brief Performs object detection without a multi-scale window. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of point where each point contains left-top corner point of detected object boundaries. + @param weights Vector that will contain confidence values for each detected object. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specfied in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param searchLocations Vector of Point includes set of requrested locations to be evaluated. + */ CV_WRAP virtual void detect(const Mat& img, CV_OUT std::vector& foundLocations, CV_OUT std::vector& weights, double hitThreshold = 0, Size winStride = Size(), Size padding = Size(), const std::vector& searchLocations = std::vector()) const; - //! without found weights output + + /** @brief Performs object detection without a multi-scale window. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of point where each point contains left-top corner point of detected object boundaries. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specfied in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param searchLocations Vector of Point includes locations to search. + */ virtual void detect(const Mat& img, CV_OUT std::vector& foundLocations, double hitThreshold = 0, Size winStride = Size(), Size padding = Size(), const std::vector& searchLocations=std::vector()) const; - //! with result weights output + /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list + of rectangles. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of rectangles where each rectangle contains the detected object. + @param foundWeights Vector that will contain confidence values for each detected object. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specfied in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param scale Coefficient of the detection window increase. + @param finalThreshold Final threshold + @param useMeanshiftGrouping indicates grouping algorithm + */ CV_WRAP virtual void detectMultiScale(InputArray img, CV_OUT std::vector& foundLocations, CV_OUT std::vector& foundWeights, double hitThreshold = 0, Size winStride = Size(), Size padding = Size(), double scale = 1.05, double finalThreshold = 2.0,bool useMeanshiftGrouping = false) const; - //! without found weights output + + /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list + of rectangles. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of rectangles where each rectangle contains the detected object. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specfied in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param scale Coefficient of the detection window increase. + @param finalThreshold Final threshold + @param useMeanshiftGrouping indicates grouping algorithm + */ virtual void detectMultiScale(InputArray img, CV_OUT std::vector& foundLocations, double hitThreshold = 0, Size winStride = Size(), Size padding = Size(), double scale = 1.05, double finalThreshold = 2.0, bool useMeanshiftGrouping = false) const; + /** @brief Computes gradients and quantized gradient orientations. + @param img Matrix contains the image to be computed + @param grad Matrix of type CV_32FC2 contains computed gradients + @param angleOfs Matrix of type CV_8UC2 contains quantized gradient orientations + @param paddingTL Padding from top-left + @param paddingBR Padding from bottom-right + */ CV_WRAP virtual void computeGradient(const Mat& img, CV_OUT Mat& grad, CV_OUT Mat& angleOfs, Size paddingTL = Size(), Size paddingBR = Size()) const; + /** @brief Returns coefficients of the classifier trained for people detection (for 64x128 windows). + */ CV_WRAP static std::vector getDefaultPeopleDetector(); + + /**@example hog.cpp + */ + /** @brief Returns coefficients of the classifier trained for people detection (for 48x96 windows). + */ CV_WRAP static std::vector getDaimlerPeopleDetector(); + //! Detection window size. Align to block size and block stride. Default value is Size(64,128). CV_PROP Size winSize; + + //! Block size in pixels. Align to cell size. Default value is Size(16,16). CV_PROP Size blockSize; + + //! Block stride. It must be a multiple of cell size. Default value is Size(8,8). CV_PROP Size blockStride; + + //! Cell size. Default value is Size(8,8). CV_PROP Size cellSize; + + //! Number of bins used in the calculation of histogram of gradients. Default value is 9. CV_PROP int nbins; + + //! not documented CV_PROP int derivAperture; + + //! Gaussian smoothing window parameter. CV_PROP double winSigma; + + //! histogramNormType CV_PROP int histogramNormType; + + //! L2-Hys normalization method shrinkage. CV_PROP double L2HysThreshold; + + //! Flag to specify whether the gamma correction preprocessing is required or not. CV_PROP bool gammaCorrection; + + //! coefficients for the linear SVM classifier. CV_PROP std::vector svmDetector; + + //! coefficients for the linear SVM classifier used when OpenCL is enabled UMat oclSvmDetector; + + //! not documented float free_coef; + + //! Maximum number of detection window increases. Default value is 64 CV_PROP int nlevels; + + //! Indicates signed gradient will be used or not CV_PROP bool signedGradient; - - //! evaluate specified ROI and return confidence value for each location + /** @brief evaluate specified ROI and return confidence value for each location + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param locations Vector of Point + @param foundLocations Vector of Point where each Point is detected object's top-left point. + @param confidences confidences + @param hitThreshold Threshold for the distance between features and SVM classifying plane. Usually + it is 0 and should be specfied in the detector coefficients (as the last free coefficient). But if + the free coefficient is omitted (which is allowed), you can specify it manually here + @param winStride winStride + @param padding padding + */ virtual void detectROI(const cv::Mat& img, const std::vector &locations, CV_OUT std::vector& foundLocations, CV_OUT std::vector& confidences, double hitThreshold = 0, cv::Size winStride = Size(), cv::Size padding = Size()) const; - //! evaluate specified ROI and return confidence value for each location in multiple scales + /** @brief evaluate specified ROI and return confidence value for each location in multiple scales + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of rectangles where each rectangle contains the detected object. + @param locations Vector of DetectionROI + @param hitThreshold Threshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specfied + in the detector coefficients (as the last free coefficient). But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it. + */ virtual void detectMultiScaleROI(const cv::Mat& img, - CV_OUT std::vector& foundLocations, - std::vector& locations, - double hitThreshold = 0, - int groupThreshold = 0) const; + CV_OUT std::vector& foundLocations, + std::vector& locations, + double hitThreshold = 0, + int groupThreshold = 0) const; - //! read/parse Dalal's alt model file + /** @brief read/parse Dalal's alt model file + @param modelfile Path of Dalal's alt model file. + */ void readALTModel(String modelfile); + + /** @brief Groups the object candidate rectangles. + @param rectList Input/output vector of rectangles. Output vector includes retained and grouped rectangles. (The Python list is not modified in place.) + @param weights Input/output vector of weights of rectangles. Output vector includes weights of retained and grouped rectangles. (The Python list is not modified in place.) + @param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it. + @param eps Relative difference between sides of the rectangles to merge them into a group. + */ void groupRectangles(std::vector& rectList, std::vector& weights, int groupThreshold, double eps) const; }; diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/objdetect/detection_based_tracker.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/objdetect/detection_based_tracker.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/objdetect/detection_based_tracker.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/objdetect/detection_based_tracker.hpp index 1f5f1d36..07dd5874 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/objdetect/detection_based_tracker.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/objdetect/detection_based_tracker.hpp @@ -41,12 +41,14 @@ // //M*/ -#ifndef __OPENCV_OBJDETECT_DBT_HPP__ -#define __OPENCV_OBJDETECT_DBT_HPP__ +#ifndef OPENCV_OBJDETECT_DBT_HPP +#define OPENCV_OBJDETECT_DBT_HPP + +#include // After this condition removal update blacklist for bindings: modules/python/common.cmake #if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(__ANDROID__) || \ - (defined(__cplusplus) && __cplusplus > 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1700) + defined(CV_CXX11) #include @@ -59,7 +61,7 @@ namespace cv class CV_EXPORTS DetectionBasedTracker { public: - struct Parameters + struct CV_EXPORTS Parameters { int maxTrackLifetime; int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0 diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/objdetect/objdetect.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/objdetect/objdetect.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/objdetect/objdetect.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/objdetect/objdetect.hpp diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/objdetect/objdetect_c.h b/lib/3rdParty/OpenCV3.4/include/opencv2/objdetect/objdetect_c.h similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/objdetect/objdetect_c.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/objdetect/objdetect_c.h index 632a4386..67dc2f4e 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/objdetect/objdetect_c.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/objdetect/objdetect_c.h @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_OBJDETECT_C_H__ -#define __OPENCV_OBJDETECT_C_H__ +#ifndef OPENCV_OBJDETECT_C_H +#define OPENCV_OBJDETECT_C_H #include "opencv2/core/core_c.h" @@ -69,6 +69,7 @@ extern "C" { (((const CvHaarClassifierCascade*)(haar))->flags & CV_MAGIC_MASK)==CV_HAAR_MAGIC_VAL) #define CV_HAAR_FEATURE_MAX 3 +#define CV_HAAR_STAGE_MAX 1000 typedef struct CvHaarFeature { @@ -162,4 +163,4 @@ CV_EXPORTS CvSeq* cvHaarDetectObjectsForROC( const CvArr* image, #endif -#endif /* __OPENCV_OBJDETECT_C_H__ */ +#endif /* OPENCV_OBJDETECT_C_H */ diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/opencv.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/opencv.hpp new file mode 100644 index 00000000..532d7a32 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/opencv.hpp @@ -0,0 +1,136 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2010, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_ALL_HPP +#define OPENCV_ALL_HPP + +// File that defines what modules where included during the build of OpenCV +// These are purely the defines of the correct HAVE_OPENCV_modulename values +#include "opencv2/opencv_modules.hpp" + +// Then the list of defines is checked to include the correct headers +// Core library is always included --> without no OpenCV functionality available +#include "opencv2/core.hpp" + +// Then the optional modules are checked +#ifdef HAVE_OPENCV_CALIB3D +#include "opencv2/calib3d.hpp" +#endif +#ifdef HAVE_OPENCV_FEATURES2D +#include "opencv2/features2d.hpp" +#endif +#ifdef HAVE_OPENCV_FLANN +#include "opencv2/flann.hpp" +#endif +#ifdef HAVE_OPENCV_HIGHGUI +#include "opencv2/highgui.hpp" +#endif +#ifdef HAVE_OPENCV_IMGCODECS +#include "opencv2/imgcodecs.hpp" +#endif +#ifdef HAVE_OPENCV_IMGPROC +#include "opencv2/imgproc.hpp" +#endif +#ifdef HAVE_OPENCV_ML +#include "opencv2/ml.hpp" +#endif +#ifdef HAVE_OPENCV_OBJDETECT +#include "opencv2/objdetect.hpp" +#endif +#ifdef HAVE_OPENCV_PHOTO +#include "opencv2/photo.hpp" +#endif +#ifdef HAVE_OPENCV_SHAPE +#include "opencv2/shape.hpp" +#endif +#ifdef HAVE_OPENCV_STITCHING +#include "opencv2/stitching.hpp" +#endif +#ifdef HAVE_OPENCV_SUPERRES +#include "opencv2/superres.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEO +#include "opencv2/video.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEOIO +#include "opencv2/videoio.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEOSTAB +#include "opencv2/videostab.hpp" +#endif +#ifdef HAVE_OPENCV_VIZ +#include "opencv2/viz.hpp" +#endif + +// Finally CUDA specific entries are checked and added +#ifdef HAVE_OPENCV_CUDAARITHM +#include "opencv2/cudaarithm.hpp" +#endif +#ifdef HAVE_OPENCV_CUDABGSEGM +#include "opencv2/cudabgsegm.hpp" +#endif +#ifdef HAVE_OPENCV_CUDACODEC +#include "opencv2/cudacodec.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAFEATURES2D +#include "opencv2/cudafeatures2d.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAFILTERS +#include "opencv2/cudafilters.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAIMGPROC +#include "opencv2/cudaimgproc.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAOBJDETECT +#include "opencv2/cudaobjdetect.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAOPTFLOW +#include "opencv2/cudaoptflow.hpp" +#endif +#ifdef HAVE_OPENCV_CUDASTEREO +#include "opencv2/cudastereo.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAWARPING +#include "opencv2/cudawarping.hpp" +#endif + +#endif diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/opencv_modules.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/opencv_modules.hpp similarity index 74% rename from lib/3rdParty/OpenCV3.1/include/opencv2/opencv_modules.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/opencv_modules.hpp index 42dd9083..d0f2dc58 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/opencv_modules.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/opencv_modules.hpp @@ -6,8 +6,13 @@ * */ +// This definition means that OpenCV is built with enabled non-free code. +// For example, patented algorithms for non-profit/non-commercial use only. +/* #undef OPENCV_ENABLE_NONFREE */ + #define HAVE_OPENCV_CALIB3D #define HAVE_OPENCV_CORE +#define HAVE_OPENCV_DNN #define HAVE_OPENCV_FEATURES2D #define HAVE_OPENCV_FLANN #define HAVE_OPENCV_HIGHGUI diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/photo.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/photo.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/photo.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/photo.hpp index c093f655..6651ac80 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/photo.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/photo.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_PHOTO_HPP__ -#define __OPENCV_PHOTO_HPP__ +#ifndef OPENCV_PHOTO_HPP +#define OPENCV_PHOTO_HPP #include "opencv2/core.hpp" #include "opencv2/imgproc.hpp" @@ -89,7 +89,7 @@ enum /** @brief Restores the selected region in an image using the region neighborhood. -@param src Input 8-bit 1-channel or 3-channel image. +@param src Input 8-bit, 16-bit unsigned or 32-bit float 1-channel or 8-bit 3-channel image. @param inpaintMask Inpainting mask, 8-bit 1-channel image. Non-zero pixels indicate the area that needs to be inpainted. @param dst Output image with the same size and type as src . @@ -591,7 +591,7 @@ public: @param samples number of pixel locations to use @param lambda smoothness term weight. Greater values produce smoother results, but can alter the response. -@param random if true sample pixel locations are chosen at random, otherwise the form a +@param random if true sample pixel locations are chosen at random, otherwise they form a rectangular grid. */ CV_EXPORTS_W Ptr createCalibrateDebevec(int samples = 70, float lambda = 10.0f, bool random = false); @@ -730,6 +730,9 @@ CV_EXPORTS_W void decolor( InputArray src, OutputArray grayscale, OutputArray co //! @addtogroup photo_clone //! @{ +/** @example cloning_demo.cpp +An example using seamlessClone function +*/ /** @brief Image editing tasks concern either global changes (color/intensity corrections, filters, deformations) or local changes concerned to a selection. Here we are interested in achieving local changes, ones that are restricted to a region manually selected (ROI), in a seamless and effortless @@ -748,7 +751,7 @@ complex outlines into a new background consuming and often leaves an undesirable halo. Seamless cloning, even averaged with the original image, is not effective. Mixed seamless cloning based on a loose selection proves effective. -- **FEATURE_EXCHANGE** Feature exchange allows the user to easily replace certain features of +- **MONOCHROME_TRANSFER** Monochrome transfer allows the user to easily replace certain features of one object by alternative features. */ CV_EXPORTS_W void seamlessClone( InputArray src, InputArray dst, InputArray mask, Point p, @@ -833,6 +836,9 @@ CV_EXPORTS_W void edgePreservingFilter(InputArray src, OutputArray dst, int flag CV_EXPORTS_W void detailEnhance(InputArray src, OutputArray dst, float sigma_s = 10, float sigma_r = 0.15f); +/** @example npr_demo.cpp +An example using non-photorealistic line drawing functions +*/ /** @brief Pencil-like non-photorealistic line drawing @param src Input 8-bit 3-channel image. diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/photo/cuda.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/photo/cuda.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/photo/cuda.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/photo/cuda.hpp index aeac1fa8..a2f38167 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/photo/cuda.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/photo/cuda.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_PHOTO_CUDA_HPP__ -#define __OPENCV_PHOTO_CUDA_HPP__ +#ifndef OPENCV_PHOTO_CUDA_HPP +#define OPENCV_PHOTO_CUDA_HPP #include "opencv2/core/cuda.hpp" @@ -129,4 +129,4 @@ CV_EXPORTS void fastNlMeansDenoisingColored(InputArray src, OutputArray dst, }} // namespace cv { namespace cuda { -#endif /* __OPENCV_PHOTO_CUDA_HPP__ */ +#endif /* OPENCV_PHOTO_CUDA_HPP */ diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/photo/photo.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/photo/photo.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/photo/photo.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/photo/photo.hpp diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/photo/photo_c.h b/lib/3rdParty/OpenCV3.4/include/opencv2/photo/photo_c.h similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv2/photo/photo_c.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/photo/photo_c.h index 07ca9b37..cd623c19 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/photo/photo_c.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/photo/photo_c.h @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_PHOTO_C_H__ -#define __OPENCV_PHOTO_C_H__ +#ifndef OPENCV_PHOTO_C_H +#define OPENCV_PHOTO_C_H #include "opencv2/core/core_c.h" @@ -71,4 +71,4 @@ CVAPI(void) cvInpaint( const CvArr* src, const CvArr* inpaint_mask, } //extern "C" #endif -#endif //__OPENCV_PHOTO_C_H__ +#endif //OPENCV_PHOTO_C_H diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/shape.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/shape.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/shape.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/shape.hpp index 6999476a..f302b6bb 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/shape.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/shape.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_SHAPE_HPP__ -#define __OPENCV_SHAPE_HPP__ +#ifndef OPENCV_SHAPE_HPP +#define OPENCV_SHAPE_HPP #include "opencv2/shape/emdL1.hpp" #include "opencv2/shape/shape_transformer.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/shape/emdL1.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/shape/emdL1.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/shape/emdL1.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/shape/emdL1.hpp index 1dfa7581..a15d68c2 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/shape/emdL1.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/shape/emdL1.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_EMD_L1_HPP__ -#define __OPENCV_EMD_L1_HPP__ +#ifndef OPENCV_EMD_L1_HPP +#define OPENCV_EMD_L1_HPP #include "opencv2/core.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/shape/hist_cost.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/shape/hist_cost.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/shape/hist_cost.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/shape/hist_cost.hpp index 15c0a87c..21d0d680 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/shape/hist_cost.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/shape/hist_cost.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_HIST_COST_HPP__ -#define __OPENCV_HIST_COST_HPP__ +#ifndef OPENCV_HIST_COST_HPP +#define OPENCV_HIST_COST_HPP #include "opencv2/imgproc.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/shape/shape.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/shape/shape.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/shape/shape.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/shape/shape.hpp diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/shape/shape_distance.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/shape/shape_distance.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/shape/shape_distance.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/shape/shape_distance.hpp index 4b0c3b5f..3a778f05 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/shape/shape_distance.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/shape/shape_distance.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_SHAPE_SHAPE_DISTANCE_HPP__ -#define __OPENCV_SHAPE_SHAPE_DISTANCE_HPP__ +#ifndef OPENCV_SHAPE_SHAPE_DISTANCE_HPP +#define OPENCV_SHAPE_SHAPE_DISTANCE_HPP #include "opencv2/core.hpp" #include "opencv2/shape/hist_cost.hpp" #include "opencv2/shape/shape_transformer.hpp" @@ -53,6 +53,9 @@ namespace cv //! @addtogroup shape //! @{ +/** @example shape_example.cpp +An example using shape distance algorithm +*/ /** @brief Abstract base class for shape distance algorithms. */ class CV_EXPORTS_W ShapeDistanceExtractor : public Algorithm diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/shape/shape_transformer.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/shape/shape_transformer.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/shape/shape_transformer.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/shape/shape_transformer.hpp index 21806136..ace104ed 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/shape/shape_transformer.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/shape/shape_transformer.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_SHAPE_SHAPE_TRANSFORM_HPP__ -#define __OPENCV_SHAPE_SHAPE_TRANSFORM_HPP__ +#ifndef OPENCV_SHAPE_SHAPE_TRANSFORM_HPP +#define OPENCV_SHAPE_SHAPE_TRANSFORM_HPP #include #include "opencv2/core.hpp" #include "opencv2/imgproc.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching.hpp similarity index 79% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching.hpp index 96cde140..387e1dec 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_STITCHING_STITCHER_HPP__ -#define __OPENCV_STITCHING_STITCHER_HPP__ +#ifndef OPENCV_STITCHING_STITCHER_HPP +#define OPENCV_STITCHING_STITCHER_HPP #include "opencv2/core.hpp" #include "opencv2/features2d.hpp" @@ -53,6 +53,12 @@ #include "opencv2/stitching/detail/blenders.hpp" #include "opencv2/stitching/detail/camera.hpp" + +#if defined(Status) +# warning Detected X11 'Status' macro definition, it can cause build conflicts. Please, include this header before any X11 headers. +#endif + + /** @defgroup stitching Images stitching @@ -63,7 +69,29 @@ one can combine and use them separately. The implemented stitching pipeline is very similar to the one proposed in @cite BL07 . -![image](StitchingPipeline.jpg) +![stitching pipeline](StitchingPipeline.jpg) + +Camera models +------------- + +There are currently 2 camera models implemented in stitching pipeline. + +- _Homography model_ expecting perspective transformations between images + implemented in @ref cv::detail::BestOf2NearestMatcher cv::detail::HomographyBasedEstimator + cv::detail::BundleAdjusterReproj cv::detail::BundleAdjusterRay +- _Affine model_ expecting affine transformation with 6 DOF or 4 DOF implemented in + @ref cv::detail::AffineBestOf2NearestMatcher cv::detail::AffineBasedEstimator + cv::detail::BundleAdjusterAffine cv::detail::BundleAdjusterAffinePartial cv::AffineWarper + +Homography model is useful for creating photo panoramas captured by camera, +while affine-based model can be used to stitch scans and object captured by +specialized devices. Use @ref cv::Stitcher::create to get preconfigured pipeline for one +of those models. + +@note +Certain detailed settings of @ref cv::Stitcher might not make sense. Especially +you should not mix classes implementing affine model and classes implementing +Homography model, as they work with different transformations. @{ @defgroup stitching_match Features Finding and Images Matching @@ -104,6 +132,22 @@ public: ERR_HOMOGRAPHY_EST_FAIL = 2, ERR_CAMERA_PARAMS_ADJUST_FAIL = 3 }; + enum Mode + { + /** Mode for creating photo panoramas. Expects images under perspective + transformation and projects resulting pano to sphere. + + @sa detail::BestOf2NearestMatcher SphericalWarper + */ + PANORAMA = 0, + /** Mode for composing scans. Expects images under affine transformation does + not compensate exposure by default. + + @sa detail::AffineBestOf2NearestMatcher AffineWarper + */ + SCANS = 1, + + }; // Stitcher() {} /** @brief Creates a stitcher with the default parameters. @@ -112,6 +156,15 @@ public: @return Stitcher class instance. */ static Stitcher createDefault(bool try_use_gpu = false); + /** @brief Creates a Stitcher configured in one of the stitching modes. + + @param mode Scenario for stitcher operation. This is usually determined by source of images + to stitch and their transformation. Default parameters will be chosen for operation in given + scenario. + @param try_use_gpu Flag indicating whether GPU should be used whenever it's possible. + @return Stitcher class instance. + */ + static Ptr create(Mode mode = PANORAMA, bool try_use_gpu = false); CV_WRAP double registrationResol() const { return registr_resol_; } CV_WRAP void setRegistrationResol(double resol_mpx) { registr_resol_ = resol_mpx; } @@ -153,6 +206,13 @@ public: void setBundleAdjuster(Ptr bundle_adjuster) { bundle_adjuster_ = bundle_adjuster; } + /* TODO OpenCV ABI 4.x + Ptr estimator() { return estimator_; } + const Ptr estimator() const { return estimator_; } + void setEstimator(Ptr estimator) + { estimator_ = estimator; } + */ + Ptr warper() { return warper_; } const Ptr warper() const { return warper_; } void setWarper(Ptr creator) { warper_ = creator; } @@ -227,6 +287,9 @@ private: Ptr features_matcher_; cv::UMat matching_mask_; Ptr bundle_adjuster_; + /* TODO OpenCV ABI 4.x + Ptr estimator_; + */ bool do_wave_correct_; detail::WaveCorrectKind wave_correct_kind_; Ptr warper_; @@ -254,4 +317,4 @@ CV_EXPORTS_W Ptr createStitcher(bool try_use_gpu = false); } // namespace cv -#endif // __OPENCV_STITCHING_STITCHER_HPP__ +#endif // OPENCV_STITCHING_STITCHER_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/autocalib.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/autocalib.hpp similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/autocalib.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/autocalib.hpp index ccc0aa17..19705e27 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/autocalib.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/autocalib.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_STITCHING_AUTOCALIB_HPP__ -#define __OPENCV_STITCHING_AUTOCALIB_HPP__ +#ifndef OPENCV_STITCHING_AUTOCALIB_HPP +#define OPENCV_STITCHING_AUTOCALIB_HPP #include "opencv2/core.hpp" #include "matchers.hpp" @@ -83,4 +83,4 @@ bool CV_EXPORTS calibrateRotatingCamera(const std::vector &Hs, Mat &K); } // namespace detail } // namespace cv -#endif // __OPENCV_STITCHING_AUTOCALIB_HPP__ +#endif // OPENCV_STITCHING_AUTOCALIB_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/blenders.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/blenders.hpp similarity index 92% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/blenders.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/blenders.hpp index 0e607258..c89e0034 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/blenders.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/blenders.hpp @@ -40,8 +40,12 @@ // //M*/ -#ifndef __OPENCV_STITCHING_BLENDERS_HPP__ -#define __OPENCV_STITCHING_BLENDERS_HPP__ +#ifndef OPENCV_STITCHING_BLENDERS_HPP +#define OPENCV_STITCHING_BLENDERS_HPP + +#if defined(NO) +# warning Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers. +#endif #include "opencv2/core.hpp" @@ -138,6 +142,10 @@ private: Rect dst_roi_final_; bool can_use_gpu_; int weight_type_; //CV_32F or CV_16S +#if defined(HAVE_OPENCV_CUDAARITHM) && defined(HAVE_OPENCV_CUDAWARPING) + std::vector gpu_dst_pyr_laplace_; + std::vector gpu_dst_band_weights_; +#endif }; @@ -160,4 +168,4 @@ void CV_EXPORTS restoreImageFromLaplacePyrGpu(std::vector& pyr); } // namespace detail } // namespace cv -#endif // __OPENCV_STITCHING_BLENDERS_HPP__ +#endif // OPENCV_STITCHING_BLENDERS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/camera.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/camera.hpp similarity index 93% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/camera.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/camera.hpp index c231ba5e..07c6b5b0 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/camera.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/camera.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_STITCHING_CAMERA_HPP__ -#define __OPENCV_STITCHING_CAMERA_HPP__ +#ifndef OPENCV_STITCHING_CAMERA_HPP +#define OPENCV_STITCHING_CAMERA_HPP #include "opencv2/core.hpp" @@ -59,7 +59,7 @@ struct CV_EXPORTS CameraParams { CameraParams(); CameraParams(const CameraParams& other); - const CameraParams& operator =(const CameraParams& other); + CameraParams& operator =(const CameraParams& other); Mat K() const; double focal; // Focal length @@ -75,4 +75,4 @@ struct CV_EXPORTS CameraParams } // namespace detail } // namespace cv -#endif // #ifndef __OPENCV_STITCHING_CAMERA_HPP__ +#endif // #ifndef OPENCV_STITCHING_CAMERA_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/exposure_compensate.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/exposure_compensate.hpp similarity index 94% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/exposure_compensate.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/exposure_compensate.hpp index ef64e124..f5a8122b 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/exposure_compensate.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/exposure_compensate.hpp @@ -40,8 +40,12 @@ // //M*/ -#ifndef __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__ -#define __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__ +#ifndef OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP +#define OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP + +#if defined(NO) +# warning Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers. +#endif #include "opencv2/core.hpp" @@ -129,4 +133,4 @@ private: } // namespace detail } // namespace cv -#endif // __OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP__ +#endif // OPENCV_STITCHING_EXPOSURE_COMPENSATE_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/matchers.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/matchers.hpp similarity index 71% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/matchers.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/matchers.hpp index 8f34bd23..009bdd9b 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/matchers.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/matchers.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_STITCHING_MATCHERS_HPP__ -#define __OPENCV_STITCHING_MATCHERS_HPP__ +#ifndef OPENCV_STITCHING_MATCHERS_HPP +#define OPENCV_STITCHING_MATCHERS_HPP #include "opencv2/core.hpp" #include "opencv2/features2d.hpp" @@ -83,9 +83,27 @@ public: @sa detail::ImageFeatures, Rect_ */ void operator ()(InputArray image, ImageFeatures &features, const std::vector &rois); + /** @brief Finds features in the given images in parallel. + + @param images Source images + @param features Found features for each image + @param rois Regions of interest for each image + + @sa detail::ImageFeatures, Rect_ + */ + void operator ()(InputArrayOfArrays images, std::vector &features, + const std::vector > &rois); + /** @overload */ + void operator ()(InputArrayOfArrays images, std::vector &features); /** @brief Frees unused memory allocated before if there is any. */ virtual void collectGarbage() {} + /* TODO OpenCV ABI 4.x + reimplement this as public method similar to FeaturesMatcher and remove private function hack + @return True, if it's possible to use the same finder instance in parallel, false otherwise + bool isThreadSafe() const { return is_thread_safe_; } + */ + protected: /** @brief This method must implement features finding logic in order to make the wrappers detail::FeaturesFinder::operator()_ work. @@ -95,6 +113,10 @@ protected: @sa detail::ImageFeatures */ virtual void find(InputArray image, ImageFeatures &features) = 0; + /** @brief uses dynamic_cast to determine thread-safety + @return True, if it's possible to use the same finder instance in parallel, false otherwise + */ + bool isThreadSafe() const; }; /** @brief SURF features finder. @@ -131,6 +153,26 @@ private: Size grid_size; }; +/** @brief AKAZE features finder. : + +@sa detail::FeaturesFinder, AKAZE +*/ +class CV_EXPORTS AKAZEFeaturesFinder : public detail::FeaturesFinder +{ +public: + AKAZEFeaturesFinder(int descriptor_type = AKAZE::DESCRIPTOR_MLDB, + int descriptor_size = 0, + int descriptor_channels = 3, + float threshold = 0.001f, + int nOctaves = 4, + int nOctaveLayers = 4, + int diffusivity = KAZE::DIFF_PM_G2); + +private: + void find(InputArray image, detail::ImageFeatures &features); + + Ptr akaze; +}; #ifdef HAVE_OPENCV_XFEATURES2D class CV_EXPORTS SurfFeaturesFinderGpu : public FeaturesFinder @@ -156,19 +198,22 @@ private: /** @brief Structure containing information about matches between two images. -It's assumed that there is a homography between those images. +It's assumed that there is a transformation between those images. Transformation may be +homography or affine transformation based on selected matcher. + +@sa detail::FeaturesMatcher */ struct CV_EXPORTS MatchesInfo { MatchesInfo(); MatchesInfo(const MatchesInfo &other); - const MatchesInfo& operator =(const MatchesInfo &other); + MatchesInfo& operator =(const MatchesInfo &other); int src_img_idx, dst_img_idx; //!< Images indices (optional) std::vector matches; std::vector inliers_mask; //!< Geometrically consistent matches mask int num_inliers; //!< Number of geometrically consistent matches - Mat H; //!< Estimated homography + Mat H; //!< Estimated transformation double confidence; //!< Confidence two images are from the same panorama }; @@ -267,9 +312,44 @@ protected: int range_width_; }; +/** @brief Features matcher similar to cv::detail::BestOf2NearestMatcher which +finds two best matches for each feature and leaves the best one only if the +ratio between descriptor distances is greater than the threshold match_conf. + +Unlike cv::detail::BestOf2NearestMatcher this matcher uses affine +transformation (affine trasformation estimate will be placed in matches_info). + +@sa cv::detail::FeaturesMatcher cv::detail::BestOf2NearestMatcher + */ +class CV_EXPORTS AffineBestOf2NearestMatcher : public BestOf2NearestMatcher +{ +public: + /** @brief Constructs a "best of 2 nearest" matcher that expects affine trasformation + between images + + @param full_affine whether to use full affine transformation with 6 degress of freedom or reduced + transformation with 4 degrees of freedom using only rotation, translation and uniform scaling + @param try_use_gpu Should try to use GPU or not + @param match_conf Match distances ration threshold + @param num_matches_thresh1 Minimum number of matches required for the 2D affine transform + estimation used in the inliers classification step + + @sa cv::estimateAffine2D cv::estimateAffinePartial2D + */ + AffineBestOf2NearestMatcher(bool full_affine = false, bool try_use_gpu = false, + float match_conf = 0.3f, int num_matches_thresh1 = 6) : + BestOf2NearestMatcher(try_use_gpu, match_conf, num_matches_thresh1, num_matches_thresh1), + full_affine_(full_affine) {} + +protected: + void match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo &matches_info); + + bool full_affine_; +}; + //! @} stitching_match } // namespace detail } // namespace cv -#endif // __OPENCV_STITCHING_MATCHERS_HPP__ +#endif // OPENCV_STITCHING_MATCHERS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/motion_estimators.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/motion_estimators.hpp similarity index 75% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/motion_estimators.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/motion_estimators.hpp index 2c86e633..a0e69008 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/motion_estimators.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/motion_estimators.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__ -#define __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__ +#ifndef OPENCV_STITCHING_MOTION_ESTIMATORS_HPP +#define OPENCV_STITCHING_MOTION_ESTIMATORS_HPP #include "opencv2/core.hpp" #include "matchers.hpp" @@ -109,6 +109,21 @@ private: bool is_focals_estimated_; }; +/** @brief Affine transformation based estimator. + +This estimator uses pairwise tranformations estimated by matcher to estimate +final transformation for each camera. + +@sa cv::detail::HomographyBasedEstimator + */ +class CV_EXPORTS AffineBasedEstimator : public Estimator +{ +private: + virtual bool estimate(const std::vector &features, + const std::vector &pairwise_matches, + std::vector &cameras); +}; + /** @brief Base class for all camera parameters refinement methods. */ class CV_EXPORTS BundleAdjusterBase : public Estimator @@ -134,8 +149,10 @@ protected: @param num_errs_per_measurement Number of error terms (components) per match */ BundleAdjusterBase(int num_params_per_cam, int num_errs_per_measurement) - : num_params_per_cam_(num_params_per_cam), - num_errs_per_measurement_(num_errs_per_measurement) + : num_images_(0), total_num_matches_(0), + num_params_per_cam_(num_params_per_cam), + num_errs_per_measurement_(num_errs_per_measurement), + features_(0), pairwise_matches_(0), conf_thresh_(0) { setRefinementMask(Mat::ones(3, 3, CV_8U)); setConfThresh(1.); @@ -184,7 +201,7 @@ protected: // Threshold to filter out poorly matched image pairs double conf_thresh_; - //Levenberg–Marquardt algorithm termination criteria + //Levenberg-Marquardt algorithm termination criteria TermCriteria term_criteria_; // Camera parameters matrix (CV_64F) @@ -195,6 +212,26 @@ protected: }; +/** @brief Stub bundle adjuster that does nothing. + */ +class CV_EXPORTS NoBundleAdjuster : public BundleAdjusterBase +{ +public: + NoBundleAdjuster() : BundleAdjusterBase(0, 0) {} + +private: + bool estimate(const std::vector &, const std::vector &, + std::vector &) + { + return true; + } + void setUpInitialCameraParams(const std::vector &) {} + void obtainRefinedCameraParams(std::vector &) const {} + void calcError(Mat &) {} + void calcJacobian(Mat &) {} +}; + + /** @brief Implementation of the camera parameters refinement algorithm which minimizes sum of the reprojection error squares @@ -236,6 +273,54 @@ private: }; +/** @brief Bundle adjuster that expects affine transformation +represented in homogeneous coordinates in R for each camera param. Implements +camera parameters refinement algorithm which minimizes sum of the reprojection +error squares + +It estimates all transformation parameters. Refinement mask is ignored. + +@sa AffineBasedEstimator AffineBestOf2NearestMatcher BundleAdjusterAffinePartial + */ +class CV_EXPORTS BundleAdjusterAffine : public BundleAdjusterBase +{ +public: + BundleAdjusterAffine() : BundleAdjusterBase(6, 2) {} + +private: + void setUpInitialCameraParams(const std::vector &cameras); + void obtainRefinedCameraParams(std::vector &cameras) const; + void calcError(Mat &err); + void calcJacobian(Mat &jac); + + Mat err1_, err2_; +}; + + +/** @brief Bundle adjuster that expects affine transformation with 4 DOF +represented in homogeneous coordinates in R for each camera param. Implements +camera parameters refinement algorithm which minimizes sum of the reprojection +error squares + +It estimates all transformation parameters. Refinement mask is ignored. + +@sa AffineBasedEstimator AffineBestOf2NearestMatcher BundleAdjusterAffine + */ +class CV_EXPORTS BundleAdjusterAffinePartial : public BundleAdjusterBase +{ +public: + BundleAdjusterAffinePartial() : BundleAdjusterBase(4, 2) {} + +private: + void setUpInitialCameraParams(const std::vector &cameras); + void obtainRefinedCameraParams(std::vector &cameras) const; + void calcError(Mat &err); + void calcJacobian(Mat &jac); + + Mat err1_, err2_; +}; + + enum WaveCorrectKind { WAVE_CORRECT_HORIZ, @@ -271,4 +356,4 @@ void CV_EXPORTS findMaxSpanningTree( } // namespace detail } // namespace cv -#endif // __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__ +#endif // OPENCV_STITCHING_MOTION_ESTIMATORS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/seam_finders.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/seam_finders.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/seam_finders.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/seam_finders.hpp index 4ff22c40..a251f483 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/seam_finders.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/seam_finders.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_STITCHING_SEAM_FINDERS_HPP__ -#define __OPENCV_STITCHING_SEAM_FINDERS_HPP__ +#ifndef OPENCV_STITCHING_SEAM_FINDERS_HPP +#define OPENCV_STITCHING_SEAM_FINDERS_HPP #include #include "opencv2/core.hpp" @@ -282,4 +282,4 @@ private: } // namespace detail } // namespace cv -#endif // __OPENCV_STITCHING_SEAM_FINDERS_HPP__ +#endif // OPENCV_STITCHING_SEAM_FINDERS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/timelapsers.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/timelapsers.hpp similarity index 95% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/timelapsers.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/timelapsers.hpp index d64c03c2..ae37b03b 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/timelapsers.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/timelapsers.hpp @@ -41,8 +41,8 @@ //M*/ -#ifndef __OPENCV_STITCHING_TIMELAPSERS_HPP__ -#define __OPENCV_STITCHING_TIMELAPSERS_HPP__ +#ifndef OPENCV_STITCHING_TIMELAPSERS_HPP +#define OPENCV_STITCHING_TIMELAPSERS_HPP #include "opencv2/core.hpp" @@ -88,4 +88,4 @@ public: } // namespace detail } // namespace cv -#endif // __OPENCV_STITCHING_TIMELAPSERS_HPP__ +#endif // OPENCV_STITCHING_TIMELAPSERS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/util.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/util.hpp similarity index 74% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/util.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/util.hpp index 3845ba59..78301b85 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/util.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/util.hpp @@ -40,62 +40,12 @@ // //M*/ -#ifndef __OPENCV_STITCHING_UTIL_HPP__ -#define __OPENCV_STITCHING_UTIL_HPP__ +#ifndef OPENCV_STITCHING_UTIL_HPP +#define OPENCV_STITCHING_UTIL_HPP #include #include "opencv2/core.hpp" -#ifndef ENABLE_LOG -#define ENABLE_LOG 0 -#endif - -// TODO remove LOG macros, add logging class -#if ENABLE_LOG -#ifdef ANDROID - #include - #include - #include - #define LOG_STITCHING_MSG(msg) \ - do { \ - Stringstream _os; \ - _os << msg; \ - __android_log_print(ANDROID_LOG_DEBUG, "STITCHING", "%s", _os.str().c_str()); \ - } while(0); -#else - #include - #define LOG_STITCHING_MSG(msg) for(;;) { std::cout << msg; std::cout.flush(); break; } -#endif -#else - #define LOG_STITCHING_MSG(msg) -#endif - -#define LOG_(_level, _msg) \ - for(;;) \ - { \ - using namespace std; \ - if ((_level) >= ::cv::detail::stitchingLogLevel()) \ - { \ - LOG_STITCHING_MSG(_msg); \ - } \ - break; \ - } - - -#define LOG(msg) LOG_(1, msg) -#define LOG_CHAT(msg) LOG_(0, msg) - -#define LOGLN(msg) LOG(msg << std::endl) -#define LOGLN_CHAT(msg) LOG_CHAT(msg << std::endl) - -//#if DEBUG_LOG_CHAT -// #define LOG_CHAT(msg) LOG(msg) -// #define LOGLN_CHAT(msg) LOGLN(msg) -//#else -// #define LOG_CHAT(msg) do{}while(0) -// #define LOGLN_CHAT(msg) do{}while(0) -//#endif - namespace cv { namespace detail { @@ -168,4 +118,4 @@ CV_EXPORTS int& stitchingLogLevel(); #include "util_inl.hpp" -#endif // __OPENCV_STITCHING_UTIL_HPP__ +#endif // OPENCV_STITCHING_UTIL_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/util_inl.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/util_inl.hpp similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/util_inl.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/util_inl.hpp index 6ac6f8ec..dafab8b8 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/util_inl.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/util_inl.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_STITCHING_UTIL_INL_HPP__ -#define __OPENCV_STITCHING_UTIL_INL_HPP__ +#ifndef OPENCV_STITCHING_UTIL_INL_HPP +#define OPENCV_STITCHING_UTIL_INL_HPP #include #include "opencv2/core.hpp" @@ -128,4 +128,4 @@ static inline double sqr(double x) { return x * x; } //! @endcond -#endif // __OPENCV_STITCHING_UTIL_INL_HPP__ +#endif // OPENCV_STITCHING_UTIL_INL_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/warpers.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/warpers.hpp similarity index 91% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/warpers.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/warpers.hpp index ee8e824c..ddb2fb51 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/warpers.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/warpers.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_STITCHING_WARPERS_HPP__ -#define __OPENCV_STITCHING_WARPERS_HPP__ +#ifndef OPENCV_STITCHING_WARPERS_HPP +#define OPENCV_STITCHING_WARPERS_HPP #include "opencv2/core.hpp" #include "opencv2/core/cuda.hpp" @@ -138,7 +138,7 @@ struct CV_EXPORTS ProjectorBase /** @brief Base class for rotation-based warper using a detail::ProjectorBase_ derived class. */ template -class CV_EXPORTS RotationWarperBase : public RotationWarper +class CV_EXPORTS_TEMPLATE RotationWarperBase : public RotationWarper { public: Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R); @@ -205,6 +205,34 @@ protected: }; +/** @brief Affine warper that uses rotations and translations + + Uses affine transformation in homogeneous coordinates to represent both rotation and + translation in camera rotation matrix. + */ +class CV_EXPORTS AffineWarper : public PlaneWarper +{ +public: + /** @brief Construct an instance of the affine warper class. + + @param scale Projected image scale multiplier + */ + AffineWarper(float scale = 1.f) : PlaneWarper(scale) {} + + Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R); + Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap); + Point warp(InputArray src, InputArray K, InputArray R, + int interp_mode, int border_mode, OutputArray dst); + Rect warpRoi(Size src_size, InputArray K, InputArray R); + +protected: + /** @brief Extracts rotation and translation matrices from matrix H representing + affine transformation in homogeneous coordinates + */ + void getRTfromHomogeneous(InputArray H, Mat &R, Mat &T); +}; + + struct CV_EXPORTS SphericalProjector : ProjectorBase { void mapForward(float x, float y, float &u, float &v); @@ -214,7 +242,8 @@ struct CV_EXPORTS SphericalProjector : ProjectorBase /** @brief Warper that maps an image onto the unit sphere located at the origin. - Projects image onto unit sphere with origin at (0, 0, 0). + Projects image onto unit sphere with origin at (0, 0, 0) and radius scale, measured in pixels. + A 360 panorama would therefore have a resulting width of 2 * scale * PI pixels. Poles are located at (0, -1, 0) and (0, 1, 0) points. */ class CV_EXPORTS SphericalWarper : public RotationWarperBase @@ -222,7 +251,8 @@ class CV_EXPORTS SphericalWarper : public RotationWarperBase public: /** @brief Construct an instance of the spherical warper class. - @param scale Projected image scale multiplier + @param scale Radius of the projected sphere, in pixels. An image spanning the + whole sphere will have a width of 2 * scale * PI pixels. */ SphericalWarper(float scale) { projector_.scale = scale; } @@ -520,7 +550,7 @@ private: }; -struct SphericalPortraitProjector : ProjectorBase +struct CV_EXPORTS SphericalPortraitProjector : ProjectorBase { void mapForward(float x, float y, float &u, float &v); void mapBackward(float u, float v, float &x, float &y); @@ -538,7 +568,7 @@ protected: void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br); }; -struct CylindricalPortraitProjector : ProjectorBase +struct CV_EXPORTS CylindricalPortraitProjector : ProjectorBase { void mapForward(float x, float y, float &u, float &v); void mapBackward(float u, float v, float &x, float &y); @@ -557,7 +587,7 @@ protected: } }; -struct PlanePortraitProjector : ProjectorBase +struct CV_EXPORTS PlanePortraitProjector : ProjectorBase { void mapForward(float x, float y, float &u, float &v); void mapBackward(float u, float v, float &x, float &y); @@ -583,4 +613,4 @@ protected: #include "warpers_inl.hpp" -#endif // __OPENCV_STITCHING_WARPERS_HPP__ +#endif // OPENCV_STITCHING_WARPERS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/warpers_inl.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/warpers_inl.hpp similarity index 94% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/warpers_inl.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/warpers_inl.hpp index 0416ecb5..f4a19d9c 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/detail/warpers_inl.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/detail/warpers_inl.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_STITCHING_WARPERS_INL_HPP__ -#define __OPENCV_STITCHING_WARPERS_INL_HPP__ +#ifndef OPENCV_STITCHING_WARPERS_INL_HPP +#define OPENCV_STITCHING_WARPERS_INL_HPP #include "opencv2/core.hpp" #include "warpers.hpp" // Make your IDE see declarations @@ -150,10 +150,10 @@ Rect RotationWarperBase

::warpRoi(Size src_size, InputArray K, InputArray R) template void RotationWarperBase

::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) { - float tl_uf = std::numeric_limits::max(); - float tl_vf = std::numeric_limits::max(); - float br_uf = -std::numeric_limits::max(); - float br_vf = -std::numeric_limits::max(); + float tl_uf = (std::numeric_limits::max)(); + float tl_vf = (std::numeric_limits::max)(); + float br_uf = -(std::numeric_limits::max)(); + float br_vf = -(std::numeric_limits::max)(); float u, v; for (int y = 0; y < src_size.height; ++y) @@ -161,8 +161,8 @@ void RotationWarperBase

::detectResultRoi(Size src_size, Point &dst_tl, Point for (int x = 0; x < src_size.width; ++x) { projector_.mapForward(static_cast(x), static_cast(y), u, v); - tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v); - br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v); + tl_uf = (std::min)(tl_uf, u); tl_vf = (std::min)(tl_vf, v); + br_uf = (std::max)(br_uf, u); br_vf = (std::max)(br_vf, v); } } @@ -176,31 +176,31 @@ void RotationWarperBase

::detectResultRoi(Size src_size, Point &dst_tl, Point template void RotationWarperBase

::detectResultRoiByBorder(Size src_size, Point &dst_tl, Point &dst_br) { - float tl_uf = std::numeric_limits::max(); - float tl_vf = std::numeric_limits::max(); - float br_uf = -std::numeric_limits::max(); - float br_vf = -std::numeric_limits::max(); + float tl_uf = (std::numeric_limits::max)(); + float tl_vf = (std::numeric_limits::max)(); + float br_uf = -(std::numeric_limits::max)(); + float br_vf = -(std::numeric_limits::max)(); float u, v; for (float x = 0; x < src_size.width; ++x) { projector_.mapForward(static_cast(x), 0, u, v); - tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v); - br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v); + tl_uf = (std::min)(tl_uf, u); tl_vf = (std::min)(tl_vf, v); + br_uf = (std::max)(br_uf, u); br_vf = (std::max)(br_vf, v); projector_.mapForward(static_cast(x), static_cast(src_size.height - 1), u, v); - tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v); - br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v); + tl_uf = (std::min)(tl_uf, u); tl_vf = (std::min)(tl_vf, v); + br_uf = (std::max)(br_uf, u); br_vf = (std::max)(br_vf, v); } for (int y = 0; y < src_size.height; ++y) { projector_.mapForward(0, static_cast(y), u, v); - tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v); - br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v); + tl_uf = (std::min)(tl_uf, u); tl_vf = (std::min)(tl_vf, v); + br_uf = (std::max)(br_uf, u); br_vf = (std::max)(br_vf, v); projector_.mapForward(static_cast(src_size.width - 1), static_cast(y), u, v); - tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v); - br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v); + tl_uf = (std::min)(tl_uf, u); tl_vf = (std::min)(tl_vf, v); + br_uf = (std::max)(br_uf, u); br_vf = (std::max)(br_vf, v); } dst_tl.x = static_cast(tl_uf); @@ -771,4 +771,4 @@ void PlanePortraitProjector::mapBackward(float u0, float v0, float &x, float &y) //! @endcond -#endif // __OPENCV_STITCHING_WARPERS_INL_HPP__ +#endif // OPENCV_STITCHING_WARPERS_INL_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/warpers.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/warpers.hpp similarity index 93% rename from lib/3rdParty/OpenCV3.1/include/opencv2/stitching/warpers.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/stitching/warpers.hpp index 7e570d30..139e0522 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/stitching/warpers.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/stitching/warpers.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_STITCHING_WARPER_CREATORS_HPP__ -#define __OPENCV_STITCHING_WARPER_CREATORS_HPP__ +#ifndef OPENCV_STITCHING_WARPER_CREATORS_HPP +#define OPENCV_STITCHING_WARPER_CREATORS_HPP #include "opencv2/stitching/detail/warpers.hpp" @@ -68,6 +68,15 @@ public: Ptr create(float scale) const { return makePtr(scale); } }; +/** @brief Affine warper factory class. + @sa detail::AffineWarper + */ +class AffineWarper : public WarperCreator +{ +public: + Ptr create(float scale) const { return makePtr(scale); } +}; + /** @brief Cylindrical warper factory class. @sa detail::CylindricalWarper */ @@ -180,4 +189,4 @@ public: } // namespace cv -#endif // __OPENCV_STITCHING_WARPER_CREATORS_HPP__ +#endif // OPENCV_STITCHING_WARPER_CREATORS_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/superres.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/superres.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/superres.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/superres.hpp index dec8e4ed..60d4faa6 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/superres.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/superres.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_SUPERRES_HPP__ -#define __OPENCV_SUPERRES_HPP__ +#ifndef OPENCV_SUPERRES_HPP +#define OPENCV_SUPERRES_HPP #include "opencv2/core.hpp" #include "opencv2/superres/optical_flow.hpp" @@ -204,4 +204,4 @@ namespace cv } } -#endif // __OPENCV_SUPERRES_HPP__ +#endif // OPENCV_SUPERRES_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/superres/optical_flow.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/superres/optical_flow.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/superres/optical_flow.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/superres/optical_flow.hpp index d2f29a39..07e7ca9c 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/superres/optical_flow.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/superres/optical_flow.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_SUPERRES_OPTICAL_FLOW_HPP__ -#define __OPENCV_SUPERRES_OPTICAL_FLOW_HPP__ +#ifndef OPENCV_SUPERRES_OPTICAL_FLOW_HPP +#define OPENCV_SUPERRES_OPTICAL_FLOW_HPP #include "opencv2/core.hpp" @@ -200,4 +200,4 @@ namespace cv } } -#endif // __OPENCV_SUPERRES_OPTICAL_FLOW_HPP__ +#endif // OPENCV_SUPERRES_OPTICAL_FLOW_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/video.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/video.hpp similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv2/video.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/video.hpp index a5938154..aa644a93 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/video.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/video.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_VIDEO_HPP__ -#define __OPENCV_VIDEO_HPP__ +#ifndef OPENCV_VIDEO_HPP +#define OPENCV_VIDEO_HPP /** @defgroup video Video Analysis @@ -60,4 +60,4 @@ #include "opencv2/video/tracking_c.h" #endif -#endif //__OPENCV_VIDEO_HPP__ +#endif //OPENCV_VIDEO_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/video/background_segm.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/video/background_segm.hpp similarity index 93% rename from lib/3rdParty/OpenCV3.1/include/opencv2/video/background_segm.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/video/background_segm.hpp index dbeccbdc..8a2d40b1 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/video/background_segm.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/video/background_segm.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_BACKGROUND_SEGM_HPP__ -#define __OPENCV_BACKGROUND_SEGM_HPP__ +#ifndef OPENCV_BACKGROUND_SEGM_HPP +#define OPENCV_BACKGROUND_SEGM_HPP #include "opencv2/core.hpp" @@ -188,13 +188,24 @@ public: A shadow is detected if pixel is a darker version of the background. The shadow threshold (Tau in the paper) is a threshold defining how much darker the shadow can be. Tau= 0.5 means that if a pixel - is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiarra, + is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiara, *Detecting Moving Shadows...*, IEEE PAMI,2003. */ CV_WRAP virtual double getShadowThreshold() const = 0; /** @brief Sets the shadow threshold */ CV_WRAP virtual void setShadowThreshold(double threshold) = 0; + + /** @brief Computes a foreground mask. + + @param image Next video frame. Floating point frame will be used without scaling and should be in range \f$[0,255]\f$. + @param fgmask The output foreground mask as an 8-bit binary image. + @param learningRate The value between 0 and 1 that indicates how fast the background model is + learnt. Negative parameter value makes the algorithm to use some automatically chosen learning + rate. 0 means that the background model is not updated at all, 1 means that the background model + is completely reinitialized from the last frame. + */ + CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) = 0; }; /** @brief Creates MOG2 Background Subtractor @@ -278,7 +289,7 @@ public: A shadow is detected if pixel is a darker version of the background. The shadow threshold (Tau in the paper) is a threshold defining how much darker the shadow can be. Tau= 0.5 means that if a pixel - is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiarra, + is more than twice darker then it is not shadow. See Prati, Mikic, Trivedi and Cucchiara, *Detecting Moving Shadows...*, IEEE PAMI,2003. */ CV_WRAP virtual double getShadowThreshold() const = 0; diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/video/tracking.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/video/tracking.hpp similarity index 79% rename from lib/3rdParty/OpenCV3.1/include/opencv2/video/tracking.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/video/tracking.hpp index d6954fec..d397ac7a 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/video/tracking.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/video/tracking.hpp @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_TRACKING_HPP__ -#define __OPENCV_TRACKING_HPP__ +#ifndef OPENCV_TRACKING_HPP +#define OPENCV_TRACKING_HPP #include "opencv2/core.hpp" #include "opencv2/imgproc.hpp" @@ -78,7 +78,9 @@ See the OpenCV sample camshiftdemo.c that tracks colored objects. */ CV_EXPORTS_W RotatedRect CamShift( InputArray probImage, CV_IN_OUT Rect& window, TermCriteria criteria ); - +/** @example camshiftdemo.cpp +An example using the mean-shift tracking algorithm +*/ /** @brief Finds an object on a back projection image. @param probImage Back projection of the object histogram. See calcBackProject for details. @@ -97,8 +99,6 @@ projection and remove the noise. For example, you can do this by retrieving conn with findContours , throwing away contours with small area ( contourArea ), and rendering the remaining contours with drawContours. -@note -- A mean-shift tracking sample can be found at opencv_source_code/samples/cpp/camshiftdemo.cpp */ CV_EXPORTS_W int meanShift( InputArray probImage, CV_IN_OUT Rect& window, TermCriteria criteria ); @@ -123,6 +123,9 @@ CV_EXPORTS_W int buildOpticalFlowPyramid( InputArray img, OutputArrayOfArrays py int derivBorder = BORDER_CONSTANT, bool tryReuseInputImage = true ); +/** @example lkdemo.cpp +An example using the Lucas-Kanade optical flow algorithm + */ /** @brief Calculates an optical flow for a sparse feature set using the iterative Lucas-Kanade method with pyramids. @@ -226,7 +229,7 @@ CV_EXPORTS_W void calcOpticalFlowFarneback( InputArray prev, InputArray next, In @param dst Second input 2D point set of the same size and the same type as A, or another image. @param fullAffine If true, the function finds an optimal affine transformation with no additional restrictions (6 degrees of freedom). Otherwise, the class of transformations to choose from is -limited to combinations of translation, rotation, and uniform scaling (5 degrees of freedom). +limited to combinations of translation, rotation, and uniform scaling (4 degrees of freedom). The function finds an optimal affine transform *[A|b]* (a 2 x 3 floating-point matrix) that approximates best the affine transformation between: @@ -245,7 +248,7 @@ where src[i] and dst[i] are the i-th points in src and dst, respectively when fullAffine=false. @sa -getAffineTransform, getPerspectiveTransform, findHomography +estimateAffine2D, estimateAffinePartial2D, getAffineTransform, getPerspectiveTransform, findHomography */ CV_EXPORTS_W Mat estimateRigidTransform( InputArray src, InputArray dst, bool fullAffine ); @@ -258,6 +261,10 @@ enum MOTION_HOMOGRAPHY = 3 }; +/** @example image_alignment.cpp +An example using the image alignment ECC algorithm + */ + /** @brief Finds the geometric transform (warp) between two images in terms of the ECC criterion @cite EP08 . @param templateImage single-channel template image; CV_8U or CV_32F array. @@ -297,7 +304,7 @@ row is ignored. Unlike findHomography and estimateRigidTransform, the function findTransformECC implements an area-based alignment that builds on intensity similarities. In essence, the function updates the initial transformation that roughly aligns the images. If this information is missing, the identity -warp (unity matrix) should be given as input. Note that if images undergo strong +warp (unity matrix) is used as an initialization. Note that if images undergo strong displacements/rotations, an initial transformation that roughly aligns the images is necessary (e.g., a simple euclidean/similarity transform that allows for the images showing the same image content approximately). Use inverse warping in the second image to take an image close to the first @@ -306,32 +313,27 @@ sample image_alignment.cpp that demonstrates the use of the function. Note that an exception if algorithm does not converges. @sa -estimateRigidTransform, findHomography +estimateAffine2D, estimateAffinePartial2D, findHomography */ CV_EXPORTS_W double findTransformECC( InputArray templateImage, InputArray inputImage, InputOutputArray warpMatrix, int motionType = MOTION_AFFINE, TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001), InputArray inputMask = noArray()); +/** @example kalman.cpp +An example using the standard Kalman filter +*/ /** @brief Kalman filter class. The class implements a standard Kalman filter , @cite Welch95 . However, you can modify transitionMatrix, controlMatrix, and measurementMatrix to get -an extended Kalman filter functionality. See the OpenCV sample kalman.cpp. - -@note - -- An example using the standard Kalman filter can be found at - opencv_source_code/samples/cpp/kalman.cpp +an extended Kalman filter functionality. +@note In C API when CvKalman\* kalmanFilter structure is not needed anymore, it should be released +with cvReleaseKalman(&kalmanFilter) */ class CV_EXPORTS_W KalmanFilter { public: - /** @brief The constructors. - - @note In C API when CvKalman\* kalmanFilter structure is not needed anymore, it should be released - with cvReleaseKalman(&kalmanFilter) - */ CV_WRAP KalmanFilter(); /** @overload @param dynamParams Dimensionality of the state. @@ -397,6 +399,27 @@ public: CV_WRAP virtual void collectGarbage() = 0; }; +/** @brief Base interface for sparse optical flow algorithms. + */ +class CV_EXPORTS_W SparseOpticalFlow : public Algorithm +{ +public: + /** @brief Calculates a sparse optical flow. + + @param prevImg First input image. + @param nextImg Second input image of the same size and the same type as prevImg. + @param prevPts Vector of 2D points for which the flow needs to be found. + @param nextPts Output vector of 2D points containing the calculated new positions of input features in the second image. + @param status Output status vector. Each element of the vector is set to 1 if the + flow for the corresponding features has been found. Otherwise, it is set to 0. + @param err Optional output vector that contains error response for each point (inverse confidence). + */ + CV_WRAP virtual void calc(InputArray prevImg, InputArray nextImg, + InputArray prevPts, InputOutputArray nextPts, + OutputArray status, + OutputArray err = cv::noArray()) = 0; +}; + /** @brief "Dual TV L1" Optical Flow Algorithm. The class implements the "Dual TV L1" optical flow algorithm described in @cite Zach2007 and @@ -444,70 +467,160 @@ class CV_EXPORTS_W DualTVL1OpticalFlow : public DenseOpticalFlow public: //! @brief Time step of the numerical scheme /** @see setTau */ - virtual double getTau() const = 0; + CV_WRAP virtual double getTau() const = 0; /** @copybrief getTau @see getTau */ - virtual void setTau(double val) = 0; + CV_WRAP virtual void setTau(double val) = 0; //! @brief Weight parameter for the data term, attachment parameter /** @see setLambda */ - virtual double getLambda() const = 0; + CV_WRAP virtual double getLambda() const = 0; /** @copybrief getLambda @see getLambda */ - virtual void setLambda(double val) = 0; + CV_WRAP virtual void setLambda(double val) = 0; //! @brief Weight parameter for (u - v)^2, tightness parameter /** @see setTheta */ - virtual double getTheta() const = 0; + CV_WRAP virtual double getTheta() const = 0; /** @copybrief getTheta @see getTheta */ - virtual void setTheta(double val) = 0; + CV_WRAP virtual void setTheta(double val) = 0; //! @brief coefficient for additional illumination variation term /** @see setGamma */ - virtual double getGamma() const = 0; + CV_WRAP virtual double getGamma() const = 0; /** @copybrief getGamma @see getGamma */ - virtual void setGamma(double val) = 0; + CV_WRAP virtual void setGamma(double val) = 0; //! @brief Number of scales used to create the pyramid of images /** @see setScalesNumber */ - virtual int getScalesNumber() const = 0; + CV_WRAP virtual int getScalesNumber() const = 0; /** @copybrief getScalesNumber @see getScalesNumber */ - virtual void setScalesNumber(int val) = 0; + CV_WRAP virtual void setScalesNumber(int val) = 0; //! @brief Number of warpings per scale /** @see setWarpingsNumber */ - virtual int getWarpingsNumber() const = 0; + CV_WRAP virtual int getWarpingsNumber() const = 0; /** @copybrief getWarpingsNumber @see getWarpingsNumber */ - virtual void setWarpingsNumber(int val) = 0; + CV_WRAP virtual void setWarpingsNumber(int val) = 0; //! @brief Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time /** @see setEpsilon */ - virtual double getEpsilon() const = 0; + CV_WRAP virtual double getEpsilon() const = 0; /** @copybrief getEpsilon @see getEpsilon */ - virtual void setEpsilon(double val) = 0; + CV_WRAP virtual void setEpsilon(double val) = 0; //! @brief Inner iterations (between outlier filtering) used in the numerical scheme /** @see setInnerIterations */ - virtual int getInnerIterations() const = 0; + CV_WRAP virtual int getInnerIterations() const = 0; /** @copybrief getInnerIterations @see getInnerIterations */ - virtual void setInnerIterations(int val) = 0; + CV_WRAP virtual void setInnerIterations(int val) = 0; //! @brief Outer iterations (number of inner loops) used in the numerical scheme /** @see setOuterIterations */ - virtual int getOuterIterations() const = 0; + CV_WRAP virtual int getOuterIterations() const = 0; /** @copybrief getOuterIterations @see getOuterIterations */ - virtual void setOuterIterations(int val) = 0; + CV_WRAP virtual void setOuterIterations(int val) = 0; //! @brief Use initial flow /** @see setUseInitialFlow */ - virtual bool getUseInitialFlow() const = 0; + CV_WRAP virtual bool getUseInitialFlow() const = 0; /** @copybrief getUseInitialFlow @see getUseInitialFlow */ - virtual void setUseInitialFlow(bool val) = 0; + CV_WRAP virtual void setUseInitialFlow(bool val) = 0; //! @brief Step between scales (<1) /** @see setScaleStep */ - virtual double getScaleStep() const = 0; + CV_WRAP virtual double getScaleStep() const = 0; /** @copybrief getScaleStep @see getScaleStep */ - virtual void setScaleStep(double val) = 0; + CV_WRAP virtual void setScaleStep(double val) = 0; //! @brief Median filter kernel size (1 = no filter) (3 or 5) /** @see setMedianFiltering */ - virtual int getMedianFiltering() const = 0; + CV_WRAP virtual int getMedianFiltering() const = 0; /** @copybrief getMedianFiltering @see getMedianFiltering */ - virtual void setMedianFiltering(int val) = 0; + CV_WRAP virtual void setMedianFiltering(int val) = 0; + + /** @brief Creates instance of cv::DualTVL1OpticalFlow*/ + CV_WRAP static Ptr create( + double tau = 0.25, + double lambda = 0.15, + double theta = 0.3, + int nscales = 5, + int warps = 5, + double epsilon = 0.01, + int innnerIterations = 30, + int outerIterations = 10, + double scaleStep = 0.8, + double gamma = 0.0, + int medianFiltering = 5, + bool useInitialFlow = false); }; /** @brief Creates instance of cv::DenseOpticalFlow */ CV_EXPORTS_W Ptr createOptFlow_DualTVL1(); +/** @brief Class computing a dense optical flow using the Gunnar Farneback's algorithm. + */ +class CV_EXPORTS_W FarnebackOpticalFlow : public DenseOpticalFlow +{ +public: + CV_WRAP virtual int getNumLevels() const = 0; + CV_WRAP virtual void setNumLevels(int numLevels) = 0; + + CV_WRAP virtual double getPyrScale() const = 0; + CV_WRAP virtual void setPyrScale(double pyrScale) = 0; + + CV_WRAP virtual bool getFastPyramids() const = 0; + CV_WRAP virtual void setFastPyramids(bool fastPyramids) = 0; + + CV_WRAP virtual int getWinSize() const = 0; + CV_WRAP virtual void setWinSize(int winSize) = 0; + + CV_WRAP virtual int getNumIters() const = 0; + CV_WRAP virtual void setNumIters(int numIters) = 0; + + CV_WRAP virtual int getPolyN() const = 0; + CV_WRAP virtual void setPolyN(int polyN) = 0; + + CV_WRAP virtual double getPolySigma() const = 0; + CV_WRAP virtual void setPolySigma(double polySigma) = 0; + + CV_WRAP virtual int getFlags() const = 0; + CV_WRAP virtual void setFlags(int flags) = 0; + + CV_WRAP static Ptr create( + int numLevels = 5, + double pyrScale = 0.5, + bool fastPyramids = false, + int winSize = 13, + int numIters = 10, + int polyN = 5, + double polySigma = 1.1, + int flags = 0); +}; + + +/** @brief Class used for calculating a sparse optical flow. + +The class can calculate an optical flow for a sparse feature set using the +iterative Lucas-Kanade method with pyramids. + +@sa calcOpticalFlowPyrLK + +*/ +class CV_EXPORTS_W SparsePyrLKOpticalFlow : public SparseOpticalFlow +{ +public: + CV_WRAP virtual Size getWinSize() const = 0; + CV_WRAP virtual void setWinSize(Size winSize) = 0; + + CV_WRAP virtual int getMaxLevel() const = 0; + CV_WRAP virtual void setMaxLevel(int maxLevel) = 0; + + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + CV_WRAP virtual void setTermCriteria(TermCriteria& crit) = 0; + + CV_WRAP virtual int getFlags() const = 0; + CV_WRAP virtual void setFlags(int flags) = 0; + + CV_WRAP virtual double getMinEigThreshold() const = 0; + CV_WRAP virtual void setMinEigThreshold(double minEigThreshold) = 0; + + CV_WRAP static Ptr create( + Size winSize = Size(21, 21), + int maxLevel = 3, TermCriteria crit = + TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), + int flags = 0, + double minEigThreshold = 1e-4); +}; + //! @} video_track } // cv diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/video/tracking_c.h b/lib/3rdParty/OpenCV3.4/include/opencv2/video/tracking_c.h similarity index 99% rename from lib/3rdParty/OpenCV3.1/include/opencv2/video/tracking_c.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/video/tracking_c.h index b3553528..3e32fbd0 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/video/tracking_c.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/video/tracking_c.h @@ -41,8 +41,8 @@ // //M*/ -#ifndef __OPENCV_TRACKING_C_H__ -#define __OPENCV_TRACKING_C_H__ +#ifndef OPENCV_TRACKING_C_H +#define OPENCV_TRACKING_C_H #include "opencv2/imgproc/types_c.h" @@ -229,4 +229,4 @@ CVAPI(const CvMat*) cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement #endif -#endif // __OPENCV_TRACKING_C_H__ +#endif // OPENCV_TRACKING_C_H diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/video/video.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/video/video.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/video/video.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/video/video.hpp diff --git a/lib/3rdParty/OpenCV3.4/include/opencv2/videoio.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videoio.hpp new file mode 100644 index 00000000..96d8df61 --- /dev/null +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videoio.hpp @@ -0,0 +1,952 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_VIDEOIO_HPP +#define OPENCV_VIDEOIO_HPP + +#include "opencv2/core.hpp" + +/** + @defgroup videoio Video I/O + + @brief Read and write video or images sequence with OpenCV + + ### See also: + - @ref videoio_overview + - Tutorials: @ref tutorial_table_of_content_videoio + @{ + @defgroup videoio_flags_base Flags for video I/O + @defgroup videoio_flags_others Additional flags for video I/O API backends + @defgroup videoio_c C API for video I/O + @defgroup videoio_ios iOS glue for video I/O + @defgroup videoio_winrt WinRT glue for video I/O + @} +*/ + +////////////////////////////////// video io ///////////////////////////////// + +typedef struct CvCapture CvCapture; +typedef struct CvVideoWriter CvVideoWriter; + +namespace cv +{ + +//! @addtogroup videoio +//! @{ + +//! @addtogroup videoio_flags_base +//! @{ + + +/** @brief %VideoCapture API backends identifier. + +Select preferred API for a capture object. +To be used in the VideoCapture::VideoCapture() constructor or VideoCapture::open() + +@note Backends are available only if they have been built with your OpenCV binaries. +See @ref videoio_overview for more information. +*/ +enum VideoCaptureAPIs { + CAP_ANY = 0, //!< Auto detect == 0 + CAP_VFW = 200, //!< Video For Windows (platform native) + CAP_V4L = 200, //!< V4L/V4L2 capturing support via libv4l + CAP_V4L2 = CAP_V4L, //!< Same as CAP_V4L + CAP_FIREWIRE = 300, //!< IEEE 1394 drivers + CAP_FIREWARE = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE + CAP_IEEE1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE + CAP_DC1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE + CAP_CMU1394 = CAP_FIREWIRE, //!< Same as CAP_FIREWIRE + CAP_QT = 500, //!< QuickTime + CAP_UNICAP = 600, //!< Unicap drivers + CAP_DSHOW = 700, //!< DirectShow (via videoInput) + CAP_PVAPI = 800, //!< PvAPI, Prosilica GigE SDK + CAP_OPENNI = 900, //!< OpenNI (for Kinect) + CAP_OPENNI_ASUS = 910, //!< OpenNI (for Asus Xtion) + CAP_ANDROID = 1000, //!< Android - not used + CAP_XIAPI = 1100, //!< XIMEA Camera API + CAP_AVFOUNDATION = 1200, //!< AVFoundation framework for iOS (OS X Lion will have the same API) + CAP_GIGANETIX = 1300, //!< Smartek Giganetix GigEVisionSDK + CAP_MSMF = 1400, //!< Microsoft Media Foundation (via videoInput) + CAP_WINRT = 1410, //!< Microsoft Windows Runtime using Media Foundation + CAP_INTELPERC = 1500, //!< Intel Perceptual Computing SDK + CAP_OPENNI2 = 1600, //!< OpenNI2 (for Kinect) + CAP_OPENNI2_ASUS = 1610, //!< OpenNI2 (for Asus Xtion and Occipital Structure sensors) + CAP_GPHOTO2 = 1700, //!< gPhoto2 connection + CAP_GSTREAMER = 1800, //!< GStreamer + CAP_FFMPEG = 1900, //!< Open and record video file or stream using the FFMPEG library + CAP_IMAGES = 2000, //!< OpenCV Image Sequence (e.g. img_%02d.jpg) + CAP_ARAVIS = 2100, //!< Aravis SDK + CAP_OPENCV_MJPEG = 2200, //!< Built-in OpenCV MotionJPEG codec + CAP_INTEL_MFX = 2300 //!< Intel MediaSDK + }; + +/** @brief %VideoCapture generic properties identifier. + + Reading / writing properties involves many layers. Some unexpected result might happens along this chain. + Effective behaviour depends from device hardware, driver and API Backend. + @sa videoio_flags_others, VideoCapture::get(), VideoCapture::set() +*/ +enum VideoCaptureProperties { + CAP_PROP_POS_MSEC =0, //!< Current position of the video file in milliseconds. + CAP_PROP_POS_FRAMES =1, //!< 0-based index of the frame to be decoded/captured next. + CAP_PROP_POS_AVI_RATIO =2, //!< Relative position of the video file: 0=start of the film, 1=end of the film. + CAP_PROP_FRAME_WIDTH =3, //!< Width of the frames in the video stream. + CAP_PROP_FRAME_HEIGHT =4, //!< Height of the frames in the video stream. + CAP_PROP_FPS =5, //!< Frame rate. + CAP_PROP_FOURCC =6, //!< 4-character code of codec. see VideoWriter::fourcc . + CAP_PROP_FRAME_COUNT =7, //!< Number of frames in the video file. + CAP_PROP_FORMAT =8, //!< Format of the %Mat objects returned by VideoCapture::retrieve(). + CAP_PROP_MODE =9, //!< Backend-specific value indicating the current capture mode. + CAP_PROP_BRIGHTNESS =10, //!< Brightness of the image (only for those cameras that support). + CAP_PROP_CONTRAST =11, //!< Contrast of the image (only for cameras). + CAP_PROP_SATURATION =12, //!< Saturation of the image (only for cameras). + CAP_PROP_HUE =13, //!< Hue of the image (only for cameras). + CAP_PROP_GAIN =14, //!< Gain of the image (only for those cameras that support). + CAP_PROP_EXPOSURE =15, //!< Exposure (only for those cameras that support). + CAP_PROP_CONVERT_RGB =16, //!< Boolean flags indicating whether images should be converted to RGB. + CAP_PROP_WHITE_BALANCE_BLUE_U =17, //!< Currently unsupported. + CAP_PROP_RECTIFICATION =18, //!< Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently). + CAP_PROP_MONOCHROME =19, + CAP_PROP_SHARPNESS =20, + CAP_PROP_AUTO_EXPOSURE =21, //!< DC1394: exposure control done by camera, user can adjust reference level using this feature. + CAP_PROP_GAMMA =22, + CAP_PROP_TEMPERATURE =23, + CAP_PROP_TRIGGER =24, + CAP_PROP_TRIGGER_DELAY =25, + CAP_PROP_WHITE_BALANCE_RED_V =26, + CAP_PROP_ZOOM =27, + CAP_PROP_FOCUS =28, + CAP_PROP_GUID =29, + CAP_PROP_ISO_SPEED =30, + CAP_PROP_BACKLIGHT =32, + CAP_PROP_PAN =33, + CAP_PROP_TILT =34, + CAP_PROP_ROLL =35, + CAP_PROP_IRIS =36, + CAP_PROP_SETTINGS =37, //!< Pop up video/camera filter dialog (note: only supported by DSHOW backend currently. The property value is ignored) + CAP_PROP_BUFFERSIZE =38, + CAP_PROP_AUTOFOCUS =39 + }; + + +/** @brief Generic camera output modes identifier. +@note Currently, these are supported through the libv4l backend only. +*/ +enum VideoCaptureModes { + CAP_MODE_BGR = 0, //!< BGR24 (default) + CAP_MODE_RGB = 1, //!< RGB24 + CAP_MODE_GRAY = 2, //!< Y8 + CAP_MODE_YUYV = 3 //!< YUYV + }; + +/** @brief %VideoWriter generic properties identifier. + @sa VideoWriter::get(), VideoWriter::set() +*/ +enum VideoWriterProperties { + VIDEOWRITER_PROP_QUALITY = 1, //!< Current quality (0..100%) of the encoded videostream. Can be adjusted dynamically in some codecs. + VIDEOWRITER_PROP_FRAMEBYTES = 2, //!< (Read-only): Size of just encoded video frame. Note that the encoding order may be different from representation order. + VIDEOWRITER_PROP_NSTRIPES = 3 //!< Number of stripes for parallel encoding. -1 for auto detection. +}; + +//! @} videoio_flags_base + +//! @addtogroup videoio_flags_others +//! @{ + +/** @name IEEE 1394 drivers + @{ +*/ + +/** @brief Modes of the IEEE 1394 controlling registers +(can be: auto, manual, auto single push, absolute Latter allowed with any other mode) +every feature can have only one mode turned on at a time +*/ +enum { CAP_PROP_DC1394_OFF = -4, //!< turn the feature off (not controlled manually nor automatically). + CAP_PROP_DC1394_MODE_MANUAL = -3, //!< set automatically when a value of the feature is set by the user. + CAP_PROP_DC1394_MODE_AUTO = -2, + CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO = -1, + CAP_PROP_DC1394_MAX = 31 + }; + +//! @} IEEE 1394 drivers + +/** @name OpenNI (for Kinect) + @{ +*/ + +//! OpenNI map generators +enum { CAP_OPENNI_DEPTH_GENERATOR = 1 << 31, + CAP_OPENNI_IMAGE_GENERATOR = 1 << 30, + CAP_OPENNI_IR_GENERATOR = 1 << 29, + CAP_OPENNI_GENERATORS_MASK = CAP_OPENNI_DEPTH_GENERATOR + CAP_OPENNI_IMAGE_GENERATOR + CAP_OPENNI_IR_GENERATOR + }; + +//! Properties of cameras available through OpenNI backend +enum { CAP_PROP_OPENNI_OUTPUT_MODE = 100, + CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 101, //!< In mm + CAP_PROP_OPENNI_BASELINE = 102, //!< In mm + CAP_PROP_OPENNI_FOCAL_LENGTH = 103, //!< In pixels + CAP_PROP_OPENNI_REGISTRATION = 104, //!< Flag that synchronizes the remapping depth map to image map + //!< by changing depth generator's view point (if the flag is "on") or + //!< sets this view point to its normal one (if the flag is "off"). + CAP_PROP_OPENNI_REGISTRATION_ON = CAP_PROP_OPENNI_REGISTRATION, + CAP_PROP_OPENNI_APPROX_FRAME_SYNC = 105, + CAP_PROP_OPENNI_MAX_BUFFER_SIZE = 106, + CAP_PROP_OPENNI_CIRCLE_BUFFER = 107, + CAP_PROP_OPENNI_MAX_TIME_DURATION = 108, + CAP_PROP_OPENNI_GENERATOR_PRESENT = 109, + CAP_PROP_OPENNI2_SYNC = 110, + CAP_PROP_OPENNI2_MIRROR = 111 + }; + +//! OpenNI shortcuts +enum { CAP_OPENNI_IMAGE_GENERATOR_PRESENT = CAP_OPENNI_IMAGE_GENERATOR + CAP_PROP_OPENNI_GENERATOR_PRESENT, + CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CAP_OPENNI_IMAGE_GENERATOR + CAP_PROP_OPENNI_OUTPUT_MODE, + CAP_OPENNI_DEPTH_GENERATOR_PRESENT = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_GENERATOR_PRESENT, + CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_BASELINE, + CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_FOCAL_LENGTH, + CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_REGISTRATION, + CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON = CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION, + CAP_OPENNI_IR_GENERATOR_PRESENT = CAP_OPENNI_IR_GENERATOR + CAP_PROP_OPENNI_GENERATOR_PRESENT, + }; + +//! OpenNI data given from depth generator +enum { CAP_OPENNI_DEPTH_MAP = 0, //!< Depth values in mm (CV_16UC1) + CAP_OPENNI_POINT_CLOUD_MAP = 1, //!< XYZ in meters (CV_32FC3) + CAP_OPENNI_DISPARITY_MAP = 2, //!< Disparity in pixels (CV_8UC1) + CAP_OPENNI_DISPARITY_MAP_32F = 3, //!< Disparity in pixels (CV_32FC1) + CAP_OPENNI_VALID_DEPTH_MASK = 4, //!< CV_8UC1 + + CAP_OPENNI_BGR_IMAGE = 5, //!< Data given from RGB image generator + CAP_OPENNI_GRAY_IMAGE = 6, //!< Data given from RGB image generator + + CAP_OPENNI_IR_IMAGE = 7 //!< Data given from IR image generator + }; + +//! Supported output modes of OpenNI image generator +enum { CAP_OPENNI_VGA_30HZ = 0, + CAP_OPENNI_SXGA_15HZ = 1, + CAP_OPENNI_SXGA_30HZ = 2, + CAP_OPENNI_QVGA_30HZ = 3, + CAP_OPENNI_QVGA_60HZ = 4 + }; + +//! @} OpenNI + +/** @name GStreamer + @{ +*/ + +enum { CAP_PROP_GSTREAMER_QUEUE_LENGTH = 200 //!< Default is 1 + }; + +//! @} GStreamer + +/** @name PvAPI, Prosilica GigE SDK + @{ +*/ + +//! PVAPI +enum { CAP_PROP_PVAPI_MULTICASTIP = 300, //!< IP for enable multicast master mode. 0 for disable multicast. + CAP_PROP_PVAPI_FRAMESTARTTRIGGERMODE = 301, //!< FrameStartTriggerMode: Determines how a frame is initiated. + CAP_PROP_PVAPI_DECIMATIONHORIZONTAL = 302, //!< Horizontal sub-sampling of the image. + CAP_PROP_PVAPI_DECIMATIONVERTICAL = 303, //!< Vertical sub-sampling of the image. + CAP_PROP_PVAPI_BINNINGX = 304, //!< Horizontal binning factor. + CAP_PROP_PVAPI_BINNINGY = 305, //!< Vertical binning factor. + CAP_PROP_PVAPI_PIXELFORMAT = 306 //!< Pixel format. + }; + +//! PVAPI: FrameStartTriggerMode +enum { CAP_PVAPI_FSTRIGMODE_FREERUN = 0, //!< Freerun + CAP_PVAPI_FSTRIGMODE_SYNCIN1 = 1, //!< SyncIn1 + CAP_PVAPI_FSTRIGMODE_SYNCIN2 = 2, //!< SyncIn2 + CAP_PVAPI_FSTRIGMODE_FIXEDRATE = 3, //!< FixedRate + CAP_PVAPI_FSTRIGMODE_SOFTWARE = 4 //!< Software + }; + +//! PVAPI: DecimationHorizontal, DecimationVertical +enum { CAP_PVAPI_DECIMATION_OFF = 1, //!< Off + CAP_PVAPI_DECIMATION_2OUTOF4 = 2, //!< 2 out of 4 decimation + CAP_PVAPI_DECIMATION_2OUTOF8 = 4, //!< 2 out of 8 decimation + CAP_PVAPI_DECIMATION_2OUTOF16 = 8 //!< 2 out of 16 decimation + }; + +//! PVAPI: PixelFormat +enum { CAP_PVAPI_PIXELFORMAT_MONO8 = 1, //!< Mono8 + CAP_PVAPI_PIXELFORMAT_MONO16 = 2, //!< Mono16 + CAP_PVAPI_PIXELFORMAT_BAYER8 = 3, //!< Bayer8 + CAP_PVAPI_PIXELFORMAT_BAYER16 = 4, //!< Bayer16 + CAP_PVAPI_PIXELFORMAT_RGB24 = 5, //!< Rgb24 + CAP_PVAPI_PIXELFORMAT_BGR24 = 6, //!< Bgr24 + CAP_PVAPI_PIXELFORMAT_RGBA32 = 7, //!< Rgba32 + CAP_PVAPI_PIXELFORMAT_BGRA32 = 8, //!< Bgra32 + }; + +//! @} PvAPI + +/** @name XIMEA Camera API + @{ +*/ + +//! Properties of cameras available through XIMEA SDK backend +enum { CAP_PROP_XI_DOWNSAMPLING = 400, //!< Change image resolution by binning or skipping. + CAP_PROP_XI_DATA_FORMAT = 401, //!< Output data format. + CAP_PROP_XI_OFFSET_X = 402, //!< Horizontal offset from the origin to the area of interest (in pixels). + CAP_PROP_XI_OFFSET_Y = 403, //!< Vertical offset from the origin to the area of interest (in pixels). + CAP_PROP_XI_TRG_SOURCE = 404, //!< Defines source of trigger. + CAP_PROP_XI_TRG_SOFTWARE = 405, //!< Generates an internal trigger. PRM_TRG_SOURCE must be set to TRG_SOFTWARE. + CAP_PROP_XI_GPI_SELECTOR = 406, //!< Selects general purpose input. + CAP_PROP_XI_GPI_MODE = 407, //!< Set general purpose input mode. + CAP_PROP_XI_GPI_LEVEL = 408, //!< Get general purpose level. + CAP_PROP_XI_GPO_SELECTOR = 409, //!< Selects general purpose output. + CAP_PROP_XI_GPO_MODE = 410, //!< Set general purpose output mode. + CAP_PROP_XI_LED_SELECTOR = 411, //!< Selects camera signalling LED. + CAP_PROP_XI_LED_MODE = 412, //!< Define camera signalling LED functionality. + CAP_PROP_XI_MANUAL_WB = 413, //!< Calculates White Balance(must be called during acquisition). + CAP_PROP_XI_AUTO_WB = 414, //!< Automatic white balance. + CAP_PROP_XI_AEAG = 415, //!< Automatic exposure/gain. + CAP_PROP_XI_EXP_PRIORITY = 416, //!< Exposure priority (0.5 - exposure 50%, gain 50%). + CAP_PROP_XI_AE_MAX_LIMIT = 417, //!< Maximum limit of exposure in AEAG procedure. + CAP_PROP_XI_AG_MAX_LIMIT = 418, //!< Maximum limit of gain in AEAG procedure. + CAP_PROP_XI_AEAG_LEVEL = 419, //!< Average intensity of output signal AEAG should achieve(in %). + CAP_PROP_XI_TIMEOUT = 420, //!< Image capture timeout in milliseconds. + CAP_PROP_XI_EXPOSURE = 421, //!< Exposure time in microseconds. + CAP_PROP_XI_EXPOSURE_BURST_COUNT = 422, //!< Sets the number of times of exposure in one frame. + CAP_PROP_XI_GAIN_SELECTOR = 423, //!< Gain selector for parameter Gain allows to select different type of gains. + CAP_PROP_XI_GAIN = 424, //!< Gain in dB. + CAP_PROP_XI_DOWNSAMPLING_TYPE = 426, //!< Change image downsampling type. + CAP_PROP_XI_BINNING_SELECTOR = 427, //!< Binning engine selector. + CAP_PROP_XI_BINNING_VERTICAL = 428, //!< Vertical Binning - number of vertical photo-sensitive cells to combine together. + CAP_PROP_XI_BINNING_HORIZONTAL = 429, //!< Horizontal Binning - number of horizontal photo-sensitive cells to combine together. + CAP_PROP_XI_BINNING_PATTERN = 430, //!< Binning pattern type. + CAP_PROP_XI_DECIMATION_SELECTOR = 431, //!< Decimation engine selector. + CAP_PROP_XI_DECIMATION_VERTICAL = 432, //!< Vertical Decimation - vertical sub-sampling of the image - reduces the vertical resolution of the image by the specified vertical decimation factor. + CAP_PROP_XI_DECIMATION_HORIZONTAL = 433, //!< Horizontal Decimation - horizontal sub-sampling of the image - reduces the horizontal resolution of the image by the specified vertical decimation factor. + CAP_PROP_XI_DECIMATION_PATTERN = 434, //!< Decimation pattern type. + CAP_PROP_XI_TEST_PATTERN_GENERATOR_SELECTOR = 587, //!< Selects which test pattern generator is controlled by the TestPattern feature. + CAP_PROP_XI_TEST_PATTERN = 588, //!< Selects which test pattern type is generated by the selected generator. + CAP_PROP_XI_IMAGE_DATA_FORMAT = 435, //!< Output data format. + CAP_PROP_XI_SHUTTER_TYPE = 436, //!< Change sensor shutter type(CMOS sensor). + CAP_PROP_XI_SENSOR_TAPS = 437, //!< Number of taps. + CAP_PROP_XI_AEAG_ROI_OFFSET_X = 439, //!< Automatic exposure/gain ROI offset X. + CAP_PROP_XI_AEAG_ROI_OFFSET_Y = 440, //!< Automatic exposure/gain ROI offset Y. + CAP_PROP_XI_AEAG_ROI_WIDTH = 441, //!< Automatic exposure/gain ROI Width. + CAP_PROP_XI_AEAG_ROI_HEIGHT = 442, //!< Automatic exposure/gain ROI Height. + CAP_PROP_XI_BPC = 445, //!< Correction of bad pixels. + CAP_PROP_XI_WB_KR = 448, //!< White balance red coefficient. + CAP_PROP_XI_WB_KG = 449, //!< White balance green coefficient. + CAP_PROP_XI_WB_KB = 450, //!< White balance blue coefficient. + CAP_PROP_XI_WIDTH = 451, //!< Width of the Image provided by the device (in pixels). + CAP_PROP_XI_HEIGHT = 452, //!< Height of the Image provided by the device (in pixels). + CAP_PROP_XI_REGION_SELECTOR = 589, //!< Selects Region in Multiple ROI which parameters are set by width, height, ... ,region mode. + CAP_PROP_XI_REGION_MODE = 595, //!< Activates/deactivates Region selected by Region Selector. + CAP_PROP_XI_LIMIT_BANDWIDTH = 459, //!< Set/get bandwidth(datarate)(in Megabits). + CAP_PROP_XI_SENSOR_DATA_BIT_DEPTH = 460, //!< Sensor output data bit depth. + CAP_PROP_XI_OUTPUT_DATA_BIT_DEPTH = 461, //!< Device output data bit depth. + CAP_PROP_XI_IMAGE_DATA_BIT_DEPTH = 462, //!< bitdepth of data returned by function xiGetImage. + CAP_PROP_XI_OUTPUT_DATA_PACKING = 463, //!< Device output data packing (or grouping) enabled. Packing could be enabled if output_data_bit_depth > 8 and packing capability is available. + CAP_PROP_XI_OUTPUT_DATA_PACKING_TYPE = 464, //!< Data packing type. Some cameras supports only specific packing type. + CAP_PROP_XI_IS_COOLED = 465, //!< Returns 1 for cameras that support cooling. + CAP_PROP_XI_COOLING = 466, //!< Start camera cooling. + CAP_PROP_XI_TARGET_TEMP = 467, //!< Set sensor target temperature for cooling. + CAP_PROP_XI_CHIP_TEMP = 468, //!< Camera sensor temperature. + CAP_PROP_XI_HOUS_TEMP = 469, //!< Camera housing temperature. + CAP_PROP_XI_HOUS_BACK_SIDE_TEMP = 590, //!< Camera housing back side temperature. + CAP_PROP_XI_SENSOR_BOARD_TEMP = 596, //!< Camera sensor board temperature. + CAP_PROP_XI_CMS = 470, //!< Mode of color management system. + CAP_PROP_XI_APPLY_CMS = 471, //!< Enable applying of CMS profiles to xiGetImage (see XI_PRM_INPUT_CMS_PROFILE, XI_PRM_OUTPUT_CMS_PROFILE). + CAP_PROP_XI_IMAGE_IS_COLOR = 474, //!< Returns 1 for color cameras. + CAP_PROP_XI_COLOR_FILTER_ARRAY = 475, //!< Returns color filter array type of RAW data. + CAP_PROP_XI_GAMMAY = 476, //!< Luminosity gamma. + CAP_PROP_XI_GAMMAC = 477, //!< Chromaticity gamma. + CAP_PROP_XI_SHARPNESS = 478, //!< Sharpness Strength. + CAP_PROP_XI_CC_MATRIX_00 = 479, //!< Color Correction Matrix element [0][0]. + CAP_PROP_XI_CC_MATRIX_01 = 480, //!< Color Correction Matrix element [0][1]. + CAP_PROP_XI_CC_MATRIX_02 = 481, //!< Color Correction Matrix element [0][2]. + CAP_PROP_XI_CC_MATRIX_03 = 482, //!< Color Correction Matrix element [0][3]. + CAP_PROP_XI_CC_MATRIX_10 = 483, //!< Color Correction Matrix element [1][0]. + CAP_PROP_XI_CC_MATRIX_11 = 484, //!< Color Correction Matrix element [1][1]. + CAP_PROP_XI_CC_MATRIX_12 = 485, //!< Color Correction Matrix element [1][2]. + CAP_PROP_XI_CC_MATRIX_13 = 486, //!< Color Correction Matrix element [1][3]. + CAP_PROP_XI_CC_MATRIX_20 = 487, //!< Color Correction Matrix element [2][0]. + CAP_PROP_XI_CC_MATRIX_21 = 488, //!< Color Correction Matrix element [2][1]. + CAP_PROP_XI_CC_MATRIX_22 = 489, //!< Color Correction Matrix element [2][2]. + CAP_PROP_XI_CC_MATRIX_23 = 490, //!< Color Correction Matrix element [2][3]. + CAP_PROP_XI_CC_MATRIX_30 = 491, //!< Color Correction Matrix element [3][0]. + CAP_PROP_XI_CC_MATRIX_31 = 492, //!< Color Correction Matrix element [3][1]. + CAP_PROP_XI_CC_MATRIX_32 = 493, //!< Color Correction Matrix element [3][2]. + CAP_PROP_XI_CC_MATRIX_33 = 494, //!< Color Correction Matrix element [3][3]. + CAP_PROP_XI_DEFAULT_CC_MATRIX = 495, //!< Set default Color Correction Matrix. + CAP_PROP_XI_TRG_SELECTOR = 498, //!< Selects the type of trigger. + CAP_PROP_XI_ACQ_FRAME_BURST_COUNT = 499, //!< Sets number of frames acquired by burst. This burst is used only if trigger is set to FrameBurstStart. + CAP_PROP_XI_DEBOUNCE_EN = 507, //!< Enable/Disable debounce to selected GPI. + CAP_PROP_XI_DEBOUNCE_T0 = 508, //!< Debounce time (x * 10us). + CAP_PROP_XI_DEBOUNCE_T1 = 509, //!< Debounce time (x * 10us). + CAP_PROP_XI_DEBOUNCE_POL = 510, //!< Debounce polarity (pol = 1 t0 - falling edge, t1 - rising edge). + CAP_PROP_XI_LENS_MODE = 511, //!< Status of lens control interface. This shall be set to XI_ON before any Lens operations. + CAP_PROP_XI_LENS_APERTURE_VALUE = 512, //!< Current lens aperture value in stops. Examples: 2.8, 4, 5.6, 8, 11. + CAP_PROP_XI_LENS_FOCUS_MOVEMENT_VALUE = 513, //!< Lens current focus movement value to be used by XI_PRM_LENS_FOCUS_MOVE in motor steps. + CAP_PROP_XI_LENS_FOCUS_MOVE = 514, //!< Moves lens focus motor by steps set in XI_PRM_LENS_FOCUS_MOVEMENT_VALUE. + CAP_PROP_XI_LENS_FOCUS_DISTANCE = 515, //!< Lens focus distance in cm. + CAP_PROP_XI_LENS_FOCAL_LENGTH = 516, //!< Lens focal distance in mm. + CAP_PROP_XI_LENS_FEATURE_SELECTOR = 517, //!< Selects the current feature which is accessible by XI_PRM_LENS_FEATURE. + CAP_PROP_XI_LENS_FEATURE = 518, //!< Allows access to lens feature value currently selected by XI_PRM_LENS_FEATURE_SELECTOR. + CAP_PROP_XI_DEVICE_MODEL_ID = 521, //!< Returns device model id. + CAP_PROP_XI_DEVICE_SN = 522, //!< Returns device serial number. + CAP_PROP_XI_IMAGE_DATA_FORMAT_RGB32_ALPHA = 529, //!< The alpha channel of RGB32 output image format. + CAP_PROP_XI_IMAGE_PAYLOAD_SIZE = 530, //!< Buffer size in bytes sufficient for output image returned by xiGetImage. + CAP_PROP_XI_TRANSPORT_PIXEL_FORMAT = 531, //!< Current format of pixels on transport layer. + CAP_PROP_XI_SENSOR_CLOCK_FREQ_HZ = 532, //!< Sensor clock frequency in Hz. + CAP_PROP_XI_SENSOR_CLOCK_FREQ_INDEX = 533, //!< Sensor clock frequency index. Sensor with selected frequencies have possibility to set the frequency only by this index. + CAP_PROP_XI_SENSOR_OUTPUT_CHANNEL_COUNT = 534, //!< Number of output channels from sensor used for data transfer. + CAP_PROP_XI_FRAMERATE = 535, //!< Define framerate in Hz. + CAP_PROP_XI_COUNTER_SELECTOR = 536, //!< Select counter. + CAP_PROP_XI_COUNTER_VALUE = 537, //!< Counter status. + CAP_PROP_XI_ACQ_TIMING_MODE = 538, //!< Type of sensor frames timing. + CAP_PROP_XI_AVAILABLE_BANDWIDTH = 539, //!< Calculate and returns available interface bandwidth(int Megabits). + CAP_PROP_XI_BUFFER_POLICY = 540, //!< Data move policy. + CAP_PROP_XI_LUT_EN = 541, //!< Activates LUT. + CAP_PROP_XI_LUT_INDEX = 542, //!< Control the index (offset) of the coefficient to access in the LUT. + CAP_PROP_XI_LUT_VALUE = 543, //!< Value at entry LUTIndex of the LUT. + CAP_PROP_XI_TRG_DELAY = 544, //!< Specifies the delay in microseconds (us) to apply after the trigger reception before activating it. + CAP_PROP_XI_TS_RST_MODE = 545, //!< Defines how time stamp reset engine will be armed. + CAP_PROP_XI_TS_RST_SOURCE = 546, //!< Defines which source will be used for timestamp reset. Writing this parameter will trigger settings of engine (arming). + CAP_PROP_XI_IS_DEVICE_EXIST = 547, //!< Returns 1 if camera connected and works properly. + CAP_PROP_XI_ACQ_BUFFER_SIZE = 548, //!< Acquisition buffer size in buffer_size_unit. Default bytes. + CAP_PROP_XI_ACQ_BUFFER_SIZE_UNIT = 549, //!< Acquisition buffer size unit in bytes. Default 1. E.g. Value 1024 means that buffer_size is in KiBytes. + CAP_PROP_XI_ACQ_TRANSPORT_BUFFER_SIZE = 550, //!< Acquisition transport buffer size in bytes. + CAP_PROP_XI_BUFFERS_QUEUE_SIZE = 551, //!< Queue of field/frame buffers. + CAP_PROP_XI_ACQ_TRANSPORT_BUFFER_COMMIT = 552, //!< Number of buffers to commit to low level. + CAP_PROP_XI_RECENT_FRAME = 553, //!< GetImage returns most recent frame. + CAP_PROP_XI_DEVICE_RESET = 554, //!< Resets the camera to default state. + CAP_PROP_XI_COLUMN_FPN_CORRECTION = 555, //!< Correction of column FPN. + CAP_PROP_XI_ROW_FPN_CORRECTION = 591, //!< Correction of row FPN. + CAP_PROP_XI_SENSOR_MODE = 558, //!< Current sensor mode. Allows to select sensor mode by one integer. Setting of this parameter affects: image dimensions and downsampling. + CAP_PROP_XI_HDR = 559, //!< Enable High Dynamic Range feature. + CAP_PROP_XI_HDR_KNEEPOINT_COUNT = 560, //!< The number of kneepoints in the PWLR. + CAP_PROP_XI_HDR_T1 = 561, //!< Position of first kneepoint(in % of XI_PRM_EXPOSURE). + CAP_PROP_XI_HDR_T2 = 562, //!< Position of second kneepoint (in % of XI_PRM_EXPOSURE). + CAP_PROP_XI_KNEEPOINT1 = 563, //!< Value of first kneepoint (% of sensor saturation). + CAP_PROP_XI_KNEEPOINT2 = 564, //!< Value of second kneepoint (% of sensor saturation). + CAP_PROP_XI_IMAGE_BLACK_LEVEL = 565, //!< Last image black level counts. Can be used for Offline processing to recall it. + CAP_PROP_XI_HW_REVISION = 571, //!< Returns hardware revision number. + CAP_PROP_XI_DEBUG_LEVEL = 572, //!< Set debug level. + CAP_PROP_XI_AUTO_BANDWIDTH_CALCULATION = 573, //!< Automatic bandwidth calculation. + CAP_PROP_XI_FFS_FILE_ID = 594, //!< File number. + CAP_PROP_XI_FFS_FILE_SIZE = 580, //!< Size of file. + CAP_PROP_XI_FREE_FFS_SIZE = 581, //!< Size of free camera FFS. + CAP_PROP_XI_USED_FFS_SIZE = 582, //!< Size of used camera FFS. + CAP_PROP_XI_FFS_ACCESS_KEY = 583, //!< Setting of key enables file operations on some cameras. + CAP_PROP_XI_SENSOR_FEATURE_SELECTOR = 585, //!< Selects the current feature which is accessible by XI_PRM_SENSOR_FEATURE_VALUE. + CAP_PROP_XI_SENSOR_FEATURE_VALUE = 586, //!< Allows access to sensor feature value currently selected by XI_PRM_SENSOR_FEATURE_SELECTOR. + }; + +//! @} XIMEA + +/** @name AVFoundation framework for iOS + OS X Lion will have the same API + @{ +*/ + +//! Properties of cameras available through AVFOUNDATION backend +enum { CAP_PROP_IOS_DEVICE_FOCUS = 9001, + CAP_PROP_IOS_DEVICE_EXPOSURE = 9002, + CAP_PROP_IOS_DEVICE_FLASH = 9003, + CAP_PROP_IOS_DEVICE_WHITEBALANCE = 9004, + CAP_PROP_IOS_DEVICE_TORCH = 9005 + }; + +/** @name Smartek Giganetix GigEVisionSDK + @{ +*/ + +//! Properties of cameras available through Smartek Giganetix Ethernet Vision backend +/* --- Vladimir Litvinenko (litvinenko.vladimir@gmail.com) --- */ +enum { CAP_PROP_GIGA_FRAME_OFFSET_X = 10001, + CAP_PROP_GIGA_FRAME_OFFSET_Y = 10002, + CAP_PROP_GIGA_FRAME_WIDTH_MAX = 10003, + CAP_PROP_GIGA_FRAME_HEIGH_MAX = 10004, + CAP_PROP_GIGA_FRAME_SENS_WIDTH = 10005, + CAP_PROP_GIGA_FRAME_SENS_HEIGH = 10006 + }; + +//! @} Smartek + +/** @name Intel Perceptual Computing SDK + @{ +*/ +enum { CAP_PROP_INTELPERC_PROFILE_COUNT = 11001, + CAP_PROP_INTELPERC_PROFILE_IDX = 11002, + CAP_PROP_INTELPERC_DEPTH_LOW_CONFIDENCE_VALUE = 11003, + CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE = 11004, + CAP_PROP_INTELPERC_DEPTH_CONFIDENCE_THRESHOLD = 11005, + CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_HORZ = 11006, + CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_VERT = 11007 + }; + +//! Intel Perceptual Streams +enum { CAP_INTELPERC_DEPTH_GENERATOR = 1 << 29, + CAP_INTELPERC_IMAGE_GENERATOR = 1 << 28, + CAP_INTELPERC_GENERATORS_MASK = CAP_INTELPERC_DEPTH_GENERATOR + CAP_INTELPERC_IMAGE_GENERATOR + }; + +enum { CAP_INTELPERC_DEPTH_MAP = 0, //!< Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian depth. + CAP_INTELPERC_UVDEPTH_MAP = 1, //!< Each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of depth coordinates to the color coordinates. + CAP_INTELPERC_IR_MAP = 2, //!< Each pixel is a 16-bit integer. The value indicates the intensity of the reflected laser beam. + CAP_INTELPERC_IMAGE = 3 + }; + +//! @} Intel Perceptual + +/** @name gPhoto2 connection + @{ +*/ + +/** @brief gPhoto2 properties + +If `propertyId` is less than 0 then work on widget with that __additive inversed__ camera setting ID +Get IDs by using CAP_PROP_GPHOTO2_WIDGET_ENUMERATE. +@see CvCaptureCAM_GPHOTO2 for more info +*/ +enum { CAP_PROP_GPHOTO2_PREVIEW = 17001, //!< Capture only preview from liveview mode. + CAP_PROP_GPHOTO2_WIDGET_ENUMERATE = 17002, //!< Readonly, returns (const char *). + CAP_PROP_GPHOTO2_RELOAD_CONFIG = 17003, //!< Trigger, only by set. Reload camera settings. + CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE = 17004, //!< Reload all settings on set. + CAP_PROP_GPHOTO2_COLLECT_MSGS = 17005, //!< Collect messages with details. + CAP_PROP_GPHOTO2_FLUSH_MSGS = 17006, //!< Readonly, returns (const char *). + CAP_PROP_SPEED = 17007, //!< Exposure speed. Can be readonly, depends on camera program. + CAP_PROP_APERTURE = 17008, //!< Aperture. Can be readonly, depends on camera program. + CAP_PROP_EXPOSUREPROGRAM = 17009, //!< Camera exposure program. + CAP_PROP_VIEWFINDER = 17010 //!< Enter liveview mode. + }; + +//! @} gPhoto2 + + +/** @name Images backend + @{ +*/ + +/** @brief Images backend properties + +*/ +enum { CAP_PROP_IMAGES_BASE = 18000, + CAP_PROP_IMAGES_LAST = 19000 // excluding + }; + +//! @} Images + +//! @} videoio_flags_others + + +class IVideoCapture; + +/** @brief Class for video capturing from video files, image sequences or cameras. + +The class provides C++ API for capturing video from cameras or for reading video files and image sequences. + +Here is how the class can be used: +@include samples/cpp/videocapture_basic.cpp + +@note In @ref videoio_c "C API" the black-box structure `CvCapture` is used instead of %VideoCapture. +@note +- (C++) A basic sample on using the %VideoCapture interface can be found at + `OPENCV_SOURCE_CODE/samples/cpp/videocapture_starter.cpp` +- (Python) A basic sample on using the %VideoCapture interface can be found at + `OPENCV_SOURCE_CODE/samples/python/video.py` +- (Python) A multi threaded video processing sample can be found at + `OPENCV_SOURCE_CODE/samples/python/video_threaded.py` +- (Python) %VideoCapture sample showcasing some features of the Video4Linux2 backend + `OPENCV_SOURCE_CODE/samples/python/video_v4l2.py` + */ +class CV_EXPORTS_W VideoCapture +{ +public: + /** @brief Default constructor + @note In @ref videoio_c "C API", when you finished working with video, release CvCapture structure with + cvReleaseCapture(), or use Ptr\ that calls cvReleaseCapture() automatically in the + destructor. + */ + CV_WRAP VideoCapture(); + + /** @overload + @brief Open video file or a capturing device or a IP video stream for video capturing + + Same as VideoCapture(const String& filename, int apiPreference) but using default Capture API backends + */ + CV_WRAP VideoCapture(const String& filename); + + /** @overload + @brief Open video file or a capturing device or a IP video stream for video capturing with API Preference + + @param filename it can be: + - name of video file (eg. `video.avi`) + - or image sequence (eg. `img_%02d.jpg`, which will read samples like `img_00.jpg, img_01.jpg, img_02.jpg, ...`) + - or URL of video stream (eg. `protocol://host:port/script_name?script_params|auth`). + Note that each video stream or IP camera feed has its own URL scheme. Please refer to the + documentation of source stream to know the right URL. + @param apiPreference preferred Capture API backends to use. Can be used to enforce a specific reader + implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. + @sa The list of supported API backends cv::VideoCaptureAPIs + */ + CV_WRAP VideoCapture(const String& filename, int apiPreference); + + /** @overload + @brief Open a camera for video capturing + + @param index camera_id + domain_offset (CAP_*) id of the video capturing device to open. To open default camera using default backend just pass 0. + Use a `domain_offset` to enforce a specific reader implementation if multiple are available like cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. + e.g. to open Camera 1 using the MS Media Foundation API use `index = 1 + cv::CAP_MSMF` + + @sa The list of supported API backends cv::VideoCaptureAPIs + */ + CV_WRAP VideoCapture(int index); + + /** @brief Default destructor + + The method first calls VideoCapture::release to close the already opened file or camera. + */ + virtual ~VideoCapture(); + + /** @brief Open video file or a capturing device or a IP video stream for video capturing + + @overload + + Parameters are same as the constructor VideoCapture(const String& filename) + @return `true` if the file has been successfully opened + + The method first calls VideoCapture::release to close the already opened file or camera. + */ + CV_WRAP virtual bool open(const String& filename); + + /** @brief Open a camera for video capturing + + @overload + + Parameters are same as the constructor VideoCapture(int index) + @return `true` if the camera has been successfully opened. + + The method first calls VideoCapture::release to close the already opened file or camera. + */ + CV_WRAP virtual bool open(int index); + + /** @brief Open a camera for video capturing + + @overload + + Parameters are similar as the constructor VideoCapture(int index),except it takes an additional argument apiPreference. + Definitely, is same as open(int index) where `index=cameraNum + apiPreference` + @return `true` if the camera has been successfully opened. + */ + CV_WRAP bool open(int cameraNum, int apiPreference); + + /** @brief Returns true if video capturing has been initialized already. + + If the previous call to VideoCapture constructor or VideoCapture::open() succeeded, the method returns + true. + */ + CV_WRAP virtual bool isOpened() const; + + /** @brief Closes video file or capturing device. + + The method is automatically called by subsequent VideoCapture::open and by VideoCapture + destructor. + + The C function also deallocates memory and clears \*capture pointer. + */ + CV_WRAP virtual void release(); + + /** @brief Grabs the next frame from video file or capturing device. + + @return `true` (non-zero) in the case of success. + + The method/function grabs the next frame from video file or camera and returns true (non-zero) in + the case of success. + + The primary use of the function is in multi-camera environments, especially when the cameras do not + have hardware synchronization. That is, you call VideoCapture::grab() for each camera and after that + call the slower method VideoCapture::retrieve() to decode and get frame from each camera. This way + the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames + from different cameras will be closer in time. + + Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the + correct way of retrieving data from it is to call VideoCapture::grab() first and then call + VideoCapture::retrieve() one or more times with different values of the channel parameter. + + @ref tutorial_kinect_openni + */ + CV_WRAP virtual bool grab(); + + /** @brief Decodes and returns the grabbed video frame. + + @param [out] image the video frame is returned here. If no frames has been grabbed the image will be empty. + @param flag it could be a frame index or a driver specific flag + @return `false` if no frames has been grabbed + + The method decodes and returns the just grabbed frame. If no frames has been grabbed + (camera has been disconnected, or there are no more frames in video file), the method returns false + and the function returns an empty image (with %cv::Mat, test it with Mat::empty()). + + @sa read() + + @note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video + capturing structure. It is not allowed to modify or release the image! You can copy the frame using + :ocvcvCloneImage and then do whatever you want with the copy. + */ + CV_WRAP virtual bool retrieve(OutputArray image, int flag = 0); + + /** @brief Stream operator to read the next video frame. + @sa read() + */ + virtual VideoCapture& operator >> (CV_OUT Mat& image); + + /** @overload + @sa read() + */ + virtual VideoCapture& operator >> (CV_OUT UMat& image); + + /** @brief Grabs, decodes and returns the next video frame. + + @param [out] image the video frame is returned here. If no frames has been grabbed the image will be empty. + @return `false` if no frames has been grabbed + + The method/function combines VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the + most convenient method for reading video files or capturing data from decode and returns the just + grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more + frames in video file), the method returns false and the function returns empty image (with %cv::Mat, test it with Mat::empty()). + + @note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video + capturing structure. It is not allowed to modify or release the image! You can copy the frame using + :ocvcvCloneImage and then do whatever you want with the copy. + */ + CV_WRAP virtual bool read(OutputArray image); + + /** @brief Sets a property in the VideoCapture. + + @param propId Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) + or one from @ref videoio_flags_others + @param value Value of the property. + @return `true` if the property is supported by backend used by the VideoCapture instance. + @note Even if it returns `true` this doesn't ensure that the property + value has been accepted by the capture device. See note in VideoCapture::get() + */ + CV_WRAP virtual bool set(int propId, double value); + + /** @brief Returns the specified VideoCapture property + + @param propId Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) + or one from @ref videoio_flags_others + @return Value for the specified property. Value 0 is returned when querying a property that is + not supported by the backend used by the VideoCapture instance. + + @note Reading / writing properties involves many layers. Some unexpected result might happens + along this chain. + @code {.txt} + `VideoCapture -> API Backend -> Operating System -> Device Driver -> Device Hardware` + @endcode + The returned value might be different from what really used by the device or it could be encoded + using device dependant rules (eg. steps or percentage). Effective behaviour depends from device + driver and API Backend + + */ + CV_WRAP virtual double get(int propId) const; + + /** @brief Open video file or a capturing device or a IP video stream for video capturing with API Preference + + @overload + + Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference) + @return `true` if the file has been successfully opened + + The method first calls VideoCapture::release to close the already opened file or camera. + */ + CV_WRAP virtual bool open(const String& filename, int apiPreference); + +protected: + Ptr cap; + Ptr icap; +}; + +class IVideoWriter; + +/** @example videowriter_basic.cpp +An example using VideoCapture and VideoWriter class + */ +/** @brief Video writer class. + +The class provides C++ API for writing video files or image sequences. + */ +class CV_EXPORTS_W VideoWriter +{ +public: + /** @brief Default constructors + + The constructors/functions initialize video writers. + - On Linux FFMPEG is used to write videos; + - On Windows FFMPEG or VFW is used; + - On MacOSX QTKit is used. + */ + CV_WRAP VideoWriter(); + + /** @overload + @param filename Name of the output video file. + @param fourcc 4-character code of codec used to compress the frames. For example, + VideoWriter::fourcc('P','I','M','1') is a MPEG-1 codec, VideoWriter::fourcc('M','J','P','G') is a + motion-jpeg codec etc. List of codes can be obtained at [Video Codecs by + FOURCC](http://www.fourcc.org/codecs.php) page. FFMPEG backend with MP4 container natively uses + other values as fourcc code: see [ObjectType](http://www.mp4ra.org/codecs.html), + so you may receive a warning message from OpenCV about fourcc code conversion. + @param fps Framerate of the created video stream. + @param frameSize Size of the video frames. + @param isColor If it is not zero, the encoder will expect and encode color frames, otherwise it + will work with grayscale frames (the flag is currently supported on Windows only). + + @b Tips: + - With some backends `fourcc=-1` pops up the codec selection dialog from the system. + - To save image sequence use a proper filename (eg. `img_%02d.jpg`) and `fourcc=0` + OR `fps=0`. Use uncompressed image format (eg. `img_%02d.BMP`) to save raw frames. + - Most codecs are lossy. If you want lossless video file you need to use a lossless codecs + (eg. FFMPEG FFV1, Huffman HFYU, Lagarith LAGS, etc...) + - If FFMPEG is enabled, using `codec=0; fps=0;` you can create an uncompressed (raw) video file. + */ + CV_WRAP VideoWriter(const String& filename, int fourcc, double fps, + Size frameSize, bool isColor = true); + + /** @overload + The `apiPreference` parameter allows to specify API backends to use. Can be used to enforce a specific reader implementation + if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_GSTREAMER. + */ + CV_WRAP VideoWriter(const String& filename, int apiPreference, int fourcc, double fps, + Size frameSize, bool isColor = true); + + /** @brief Default destructor + + The method first calls VideoWriter::release to close the already opened file. + */ + virtual ~VideoWriter(); + + /** @brief Initializes or reinitializes video writer. + + The method opens video writer. Parameters are the same as in the constructor + VideoWriter::VideoWriter. + @return `true` if video writer has been successfully initialized + + The method first calls VideoWriter::release to close the already opened file. + */ + CV_WRAP virtual bool open(const String& filename, int fourcc, double fps, + Size frameSize, bool isColor = true); + + /** @overload + */ + CV_WRAP bool open(const String& filename, int apiPreference, int fourcc, double fps, + Size frameSize, bool isColor = true); + + /** @brief Returns true if video writer has been successfully initialized. + */ + CV_WRAP virtual bool isOpened() const; + + /** @brief Closes the video writer. + + The method is automatically called by subsequent VideoWriter::open and by the VideoWriter + destructor. + */ + CV_WRAP virtual void release(); + + /** @brief Stream operator to write the next video frame. + @sa write + */ + virtual VideoWriter& operator << (const Mat& image); + + /** @brief Writes the next video frame + + @param image The written frame + + The function/method writes the specified image to video file. It must have the same size as has + been specified when opening the video writer. + */ + CV_WRAP virtual void write(const Mat& image); + + /** @brief Sets a property in the VideoWriter. + + @param propId Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) + or one of @ref videoio_flags_others + + @param value Value of the property. + @return `true` if the property is supported by the backend used by the VideoWriter instance. + */ + CV_WRAP virtual bool set(int propId, double value); + + /** @brief Returns the specified VideoWriter property + + @param propId Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) + or one of @ref videoio_flags_others + + @return Value for the specified property. Value 0 is returned when querying a property that is + not supported by the backend used by the VideoWriter instance. + */ + CV_WRAP virtual double get(int propId) const; + + /** @brief Concatenates 4 chars to a fourcc code + + @return a fourcc code + + This static method constructs the fourcc code of the codec to be used in the constructor + VideoWriter::VideoWriter or VideoWriter::open. + */ + CV_WRAP static int fourcc(char c1, char c2, char c3, char c4); + +protected: + Ptr writer; + Ptr iwriter; + + static Ptr create(const String& filename, int fourcc, double fps, + Size frameSize, bool isColor = true); +}; + +template<> CV_EXPORTS void DefaultDeleter::operator ()(CvCapture* obj) const; +template<> CV_EXPORTS void DefaultDeleter::operator ()(CvVideoWriter* obj) const; + +//! @} videoio + +} // cv + +#endif //OPENCV_VIDEOIO_HPP diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videoio/cap_ios.h b/lib/3rdParty/OpenCV3.4/include/opencv2/videoio/cap_ios.h similarity index 73% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videoio/cap_ios.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/videoio/cap_ios.h index 1a9875b2..0691420c 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videoio/cap_ios.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videoio/cap_ios.h @@ -39,33 +39,15 @@ @class CvAbstractCamera; -@interface CvAbstractCamera : NSObject +CV_EXPORTS @interface CvAbstractCamera : NSObject { - AVCaptureSession* captureSession; - AVCaptureConnection* videoCaptureConnection; - AVCaptureVideoPreviewLayer *captureVideoPreviewLayer; - UIDeviceOrientation currentDeviceOrientation; BOOL cameraAvailable; - BOOL captureSessionLoaded; - BOOL running; - BOOL useAVCaptureVideoPreviewLayer; - - AVCaptureDevicePosition defaultAVCaptureDevicePosition; - AVCaptureVideoOrientation defaultAVCaptureVideoOrientation; - NSString *const defaultAVCaptureSessionPreset; - - int defaultFPS; - - UIView* parentView; - - int imageWidth; - int imageHeight; } -@property (nonatomic, retain) AVCaptureSession* captureSession; -@property (nonatomic, retain) AVCaptureConnection* videoCaptureConnection; +@property (nonatomic, strong) AVCaptureSession* captureSession; +@property (nonatomic, strong) AVCaptureConnection* videoCaptureConnection; @property (nonatomic, readonly) BOOL running; @property (nonatomic, readonly) BOOL captureSessionLoaded; @@ -80,7 +62,7 @@ @property (nonatomic, assign) int imageWidth; @property (nonatomic, assign) int imageHeight; -@property (nonatomic, retain) UIView* parentView; +@property (nonatomic, strong) UIView* parentView; - (void)start; - (void)stop; @@ -105,7 +87,7 @@ @class CvVideoCamera; -@protocol CvVideoCameraDelegate +CV_EXPORTS @protocol CvVideoCameraDelegate #ifdef __cplusplus // delegate method for processing image frames @@ -114,33 +96,25 @@ @end -@interface CvVideoCamera : CvAbstractCamera +CV_EXPORTS @interface CvVideoCamera : CvAbstractCamera { AVCaptureVideoDataOutput *videoDataOutput; dispatch_queue_t videoDataOutputQueue; CALayer *customPreviewLayer; - BOOL grayscaleMode; - - BOOL recordVideo; - BOOL rotateVideo; - AVAssetWriterInput* recordAssetWriterInput; - AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor; - AVAssetWriter* recordAssetWriter; - CMTime lastSampleTime; } -@property (nonatomic, assign) id delegate; +@property (nonatomic, weak) id delegate; @property (nonatomic, assign) BOOL grayscaleMode; @property (nonatomic, assign) BOOL recordVideo; @property (nonatomic, assign) BOOL rotateVideo; -@property (nonatomic, retain) AVAssetWriterInput* recordAssetWriterInput; -@property (nonatomic, retain) AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor; -@property (nonatomic, retain) AVAssetWriter* recordAssetWriter; +@property (nonatomic, strong) AVAssetWriterInput* recordAssetWriterInput; +@property (nonatomic, strong) AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor; +@property (nonatomic, strong) AVAssetWriter* recordAssetWriter; - (void)adjustLayoutToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; - (void)layoutPreviewLayer; @@ -155,19 +129,19 @@ @class CvPhotoCamera; -@protocol CvPhotoCameraDelegate +CV_EXPORTS @protocol CvPhotoCameraDelegate - (void)photoCamera:(CvPhotoCamera*)photoCamera capturedImage:(UIImage *)image; - (void)photoCameraCancel:(CvPhotoCamera*)photoCamera; @end -@interface CvPhotoCamera : CvAbstractCamera +CV_EXPORTS @interface CvPhotoCamera : CvAbstractCamera { AVCaptureStillImageOutput *stillImageOutput; } -@property (nonatomic, assign) id delegate; +@property (nonatomic, weak) id delegate; - (void)takePicture; diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videoio/videoio.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videoio/videoio.hpp similarity index 100% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videoio/videoio.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videoio/videoio.hpp diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videoio/videoio_c.h b/lib/3rdParty/OpenCV3.4/include/opencv2/videoio/videoio_c.h similarity index 88% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videoio/videoio_c.h rename to lib/3rdParty/OpenCV3.4/include/opencv2/videoio/videoio_c.h index 47f46fa7..024633c8 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videoio/videoio_c.h +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videoio/videoio_c.h @@ -39,8 +39,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOIO_H__ -#define __OPENCV_VIDEOIO_H__ +#ifndef OPENCV_VIDEOIO_H +#define OPENCV_VIDEOIO_H #include "opencv2/core/core_c.h" @@ -57,13 +57,18 @@ extern "C" { * Working with Video Files and Cameras * \****************************************************************************************/ -/* "black box" capture structure */ +/** @brief "black box" capture structure + +In C++ use cv::VideoCapture +*/ typedef struct CvCapture CvCapture; -/* start capturing frames from video file */ +/** @brief start capturing frames from video file +*/ CVAPI(CvCapture*) cvCreateFileCapture( const char* filename ); -/* start capturing frames from video file. allows specifying a preferred API to use */ +/** @brief start capturing frames from video file. allows specifying a preferred API to use +*/ CVAPI(CvCapture*) cvCreateFileCaptureWithPreference( const char* filename , int apiPreference); enum @@ -117,27 +122,37 @@ enum CV_CAP_GPHOTO2 = 1700, CV_CAP_GSTREAMER = 1800, // GStreamer CV_CAP_FFMPEG = 1900, // FFMPEG - CV_CAP_IMAGES = 2000 // OpenCV Image Sequence (e.g. img_%02d.jpg) + CV_CAP_IMAGES = 2000, // OpenCV Image Sequence (e.g. img_%02d.jpg) + + CV_CAP_ARAVIS = 2100 // Aravis GigE SDK }; -/* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */ +/** @brief start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) +*/ CVAPI(CvCapture*) cvCreateCameraCapture( int index ); -/* grab a frame, return 1 on success, 0 on fail. - this function is thought to be fast */ +/** @brief grab a frame, return 1 on success, 0 on fail. + + this function is thought to be fast +*/ CVAPI(int) cvGrabFrame( CvCapture* capture ); -/* get the frame grabbed with cvGrabFrame(..) +/** @brief get the frame grabbed with cvGrabFrame(..) + This function may apply some frame processing like frame decompression, flipping etc. - !!!DO NOT RELEASE or MODIFY the retrieved frame!!! */ + @warning !!!DO NOT RELEASE or MODIFY the retrieved frame!!! +*/ CVAPI(IplImage*) cvRetrieveFrame( CvCapture* capture, int streamIdx CV_DEFAULT(0) ); -/* Just a combination of cvGrabFrame and cvRetrieveFrame - !!!DO NOT RELEASE or MODIFY the retrieved frame!!! */ +/** @brief Just a combination of cvGrabFrame and cvRetrieveFrame + + @warning !!!DO NOT RELEASE or MODIFY the retrieved frame!!! +*/ CVAPI(IplImage*) cvQueryFrame( CvCapture* capture ); -/* stop capturing/reading and free resources */ +/** @brief stop capturing/reading and free resources +*/ CVAPI(void) cvReleaseCapture( CvCapture** capture ); enum @@ -200,7 +215,8 @@ enum // OpenNI map generators CV_CAP_OPENNI_DEPTH_GENERATOR = 1 << 31, CV_CAP_OPENNI_IMAGE_GENERATOR = 1 << 30, - CV_CAP_OPENNI_GENERATORS_MASK = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_OPENNI_IMAGE_GENERATOR, + CV_CAP_OPENNI_IR_GENERATOR = 1 << 29, + CV_CAP_OPENNI_GENERATORS_MASK = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_OPENNI_IR_GENERATOR, // Properties of cameras available through OpenNI interfaces CV_CAP_PROP_OPENNI_OUTPUT_MODE = 100, @@ -222,10 +238,12 @@ enum CV_CAP_OPENNI_IMAGE_GENERATOR_PRESENT = CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_PROP_OPENNI_GENERATOR_PRESENT, CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_PROP_OPENNI_OUTPUT_MODE, + CV_CAP_OPENNI_DEPTH_GENERATOR_PRESENT = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_GENERATOR_PRESENT, CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_BASELINE, CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_FOCAL_LENGTH, CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_REGISTRATION, CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON = CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION, + CV_CAP_OPENNI_IR_GENERATOR_PRESENT = CV_CAP_OPENNI_IR_GENERATOR + CV_CAP_PROP_OPENNI_GENERATOR_PRESENT, // Properties of cameras available through GStreamer interface CV_CAP_GSTREAMER_QUEUE_LENGTH = 200, // default is 1 @@ -274,6 +292,8 @@ enum CV_CAP_PROP_XI_DECIMATION_VERTICAL = 432, // Vertical Decimation - vertical sub-sampling of the image - reduces the vertical resolution of the image by the specified vertical decimation factor. CV_CAP_PROP_XI_DECIMATION_HORIZONTAL = 433, // Horizontal Decimation - horizontal sub-sampling of the image - reduces the horizontal resolution of the image by the specified vertical decimation factor. CV_CAP_PROP_XI_DECIMATION_PATTERN = 434, // Decimation pattern type. + CV_CAP_PROP_XI_TEST_PATTERN_GENERATOR_SELECTOR = 587, // Selects which test pattern generator is controlled by the TestPattern feature. + CV_CAP_PROP_XI_TEST_PATTERN = 588, // Selects which test pattern type is generated by the selected generator. CV_CAP_PROP_XI_IMAGE_DATA_FORMAT = 435, // Output data format. CV_CAP_PROP_XI_SHUTTER_TYPE = 436, // Change sensor shutter type(CMOS sensor). CV_CAP_PROP_XI_SENSOR_TAPS = 437, // Number of taps @@ -287,6 +307,8 @@ enum CV_CAP_PROP_XI_WB_KB = 450, // White balance blue coefficient CV_CAP_PROP_XI_WIDTH = 451, // Width of the Image provided by the device (in pixels). CV_CAP_PROP_XI_HEIGHT = 452, // Height of the Image provided by the device (in pixels). + CV_CAP_PROP_XI_REGION_SELECTOR = 589, // Selects Region in Multiple ROI which parameters are set by width, height, ... ,region mode + CV_CAP_PROP_XI_REGION_MODE = 595, // Activates/deactivates Region selected by Region Selector CV_CAP_PROP_XI_LIMIT_BANDWIDTH = 459, // Set/get bandwidth(datarate)(in Megabits) CV_CAP_PROP_XI_SENSOR_DATA_BIT_DEPTH = 460, // Sensor output data bit depth. CV_CAP_PROP_XI_OUTPUT_DATA_BIT_DEPTH = 461, // Device output data bit depth. @@ -298,6 +320,8 @@ enum CV_CAP_PROP_XI_TARGET_TEMP = 467, // Set sensor target temperature for cooling. CV_CAP_PROP_XI_CHIP_TEMP = 468, // Camera sensor temperature CV_CAP_PROP_XI_HOUS_TEMP = 469, // Camera housing tepmerature + CV_CAP_PROP_XI_HOUS_BACK_SIDE_TEMP = 590, // Camera housing back side tepmerature + CV_CAP_PROP_XI_SENSOR_BOARD_TEMP = 596, // Camera sensor board temperature CV_CAP_PROP_XI_CMS = 470, // Mode of color management system. CV_CAP_PROP_XI_APPLY_CMS = 471, // Enable applying of CMS profiles to xiGetImage (see XI_PRM_INPUT_CMS_PROFILE, XI_PRM_OUTPUT_CMS_PROFILE). CV_CAP_PROP_XI_IMAGE_IS_COLOR = 474, // Returns 1 for color cameras. @@ -365,6 +389,7 @@ enum CV_CAP_PROP_XI_RECENT_FRAME = 553, // GetImage returns most recent frame CV_CAP_PROP_XI_DEVICE_RESET = 554, // Resets the camera to default state. CV_CAP_PROP_XI_COLUMN_FPN_CORRECTION = 555, // Correction of column FPN + CV_CAP_PROP_XI_ROW_FPN_CORRECTION = 591, // Correction of row FPN CV_CAP_PROP_XI_SENSOR_MODE = 558, // Current sensor mode. Allows to select sensor mode by one integer. Setting of this parameter affects: image dimensions and downsampling. CV_CAP_PROP_XI_HDR = 559, // Enable High Dynamic Range feature. CV_CAP_PROP_XI_HDR_KNEEPOINT_COUNT = 560, // The number of kneepoints in the PWLR. @@ -376,12 +401,15 @@ enum CV_CAP_PROP_XI_HW_REVISION = 571, // Returns hardware revision number. CV_CAP_PROP_XI_DEBUG_LEVEL = 572, // Set debug level CV_CAP_PROP_XI_AUTO_BANDWIDTH_CALCULATION = 573, // Automatic bandwidth calculation, + CV_CAP_PROP_XI_FFS_FILE_ID = 594, // File number. + CV_CAP_PROP_XI_FFS_FILE_SIZE = 580, // Size of file. CV_CAP_PROP_XI_FREE_FFS_SIZE = 581, // Size of free camera FFS. CV_CAP_PROP_XI_USED_FFS_SIZE = 582, // Size of used camera FFS. CV_CAP_PROP_XI_FFS_ACCESS_KEY = 583, // Setting of key enables file operations on some cameras. CV_CAP_PROP_XI_SENSOR_FEATURE_SELECTOR = 585, // Selects the current feature which is accessible by XI_PRM_SENSOR_FEATURE_VALUE. CV_CAP_PROP_XI_SENSOR_FEATURE_VALUE = 586, // Allows access to sensor feature value currently selected by XI_PRM_SENSOR_FEATURE_SELECTOR. + // Properties for Android cameras CV_CAP_PROP_ANDROID_FLASH_MODE = 8001, CV_CAP_PROP_ANDROID_FOCUS_MODE = 8002, @@ -445,7 +473,10 @@ enum // Data given from RGB image generator. CV_CAP_OPENNI_BGR_IMAGE = 5, - CV_CAP_OPENNI_GRAY_IMAGE = 6 + CV_CAP_OPENNI_GRAY_IMAGE = 6, + + // Data given from IR image generator. + CV_CAP_OPENNI_IR_IMAGE = 7 }; // Supported output modes of OpenNI image generator @@ -483,51 +514,74 @@ enum CV_CAP_PROP_VIEWFINDER = 17010 // Enter liveview mode. }; -/* retrieve or set capture properties */ +/** @brief retrieve capture properties +*/ CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id ); +/** @brief set capture properties +*/ CVAPI(int) cvSetCaptureProperty( CvCapture* capture, int property_id, double value ); -// Return the type of the capturer (eg, CV_CAP_V4W, CV_CAP_UNICAP), which is unknown if created with CV_CAP_ANY +/** @brief Return the type of the capturer (eg, ::CV_CAP_VFW, ::CV_CAP_UNICAP) + +It is unknown if created with ::CV_CAP_ANY +*/ CVAPI(int) cvGetCaptureDomain( CvCapture* capture); -/* "black box" video file writer structure */ +/** @brief "black box" video file writer structure + +In C++ use cv::VideoWriter +*/ typedef struct CvVideoWriter CvVideoWriter; +//! Macro to construct the fourcc code of the codec. Same as CV_FOURCC() #define CV_FOURCC_MACRO(c1, c2, c3, c4) (((c1) & 255) + (((c2) & 255) << 8) + (((c3) & 255) << 16) + (((c4) & 255) << 24)) +/** @brief Constructs the fourcc code of the codec function + +Simply call it with 4 chars fourcc code like `CV_FOURCC('I', 'Y', 'U', 'V')` + +List of codes can be obtained at [Video Codecs by FOURCC](http://www.fourcc.org/codecs.php) page. +FFMPEG backend with MP4 container natively uses other values as fourcc code: +see [ObjectType](http://www.mp4ra.org/codecs.html). +*/ CV_INLINE int CV_FOURCC(char c1, char c2, char c3, char c4) { return CV_FOURCC_MACRO(c1, c2, c3, c4); } -#define CV_FOURCC_PROMPT -1 /* Open Codec Selection Dialog (Windows only) */ -#define CV_FOURCC_DEFAULT CV_FOURCC('I', 'Y', 'U', 'V') /* Use default codec for specified filename (Linux only) */ +//! (Windows only) Open Codec Selection Dialog +#define CV_FOURCC_PROMPT -1 +//! (Linux only) Use default codec for specified filename +#define CV_FOURCC_DEFAULT CV_FOURCC('I', 'Y', 'U', 'V') -/* initialize video file writer */ +/** @brief initialize video file writer +*/ CVAPI(CvVideoWriter*) cvCreateVideoWriter( const char* filename, int fourcc, double fps, CvSize frame_size, int is_color CV_DEFAULT(1)); -/* write frame to video file */ +/** @brief write frame to video file +*/ CVAPI(int) cvWriteFrame( CvVideoWriter* writer, const IplImage* image ); -/* close video file writer */ +/** @brief close video file writer +*/ CVAPI(void) cvReleaseVideoWriter( CvVideoWriter** writer ); -/****************************************************************************************\ -* Obsolete functions/synonyms * -\****************************************************************************************/ +// *************************************************************************************** +//! @name Obsolete functions/synonyms +//! @{ +#define cvCaptureFromCAM cvCreateCameraCapture //!< @deprecated use cvCreateCameraCapture() instead +#define cvCaptureFromFile cvCreateFileCapture //!< @deprecated use cvCreateFileCapture() instead +#define cvCaptureFromAVI cvCaptureFromFile //!< @deprecated use cvCreateFileCapture() instead +#define cvCreateAVIWriter cvCreateVideoWriter //!< @deprecated use cvCreateVideoWriter() instead +#define cvWriteToAVI cvWriteFrame //!< @deprecated use cvWriteFrame() instead +//! @} Obsolete... -#define cvCaptureFromFile cvCreateFileCapture -#define cvCaptureFromCAM cvCreateCameraCapture -#define cvCaptureFromAVI cvCaptureFromFile -#define cvCreateAVIWriter cvCreateVideoWriter -#define cvWriteToAVI cvWriteFrame - -/** @} videoio_c */ +//! @} videoio_c #ifdef __cplusplus } #endif -#endif //__OPENCV_VIDEOIO_H__ +#endif //OPENCV_VIDEOIO_H diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab.hpp similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab.hpp index 17b061f8..ca3f5ade 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab.hpp @@ -40,15 +40,15 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_HPP__ -#define __OPENCV_VIDEOSTAB_HPP__ +#ifndef OPENCV_VIDEOSTAB_HPP +#define OPENCV_VIDEOSTAB_HPP /** @defgroup videostab Video Stabilization The video stabilization module contains a set of functions and classes that can be used to solve the -problem of video stabilization. There are a few methods implemented, most of them are descibed in -the papers @cite OF06 and @cite G11 . However, there are some extensions and deviations from the orginal +problem of video stabilization. There are a few methods implemented, most of them are described in +the papers @cite OF06 and @cite G11 . However, there are some extensions and deviations from the original paper methods. ### References diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/deblurring.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/deblurring.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/deblurring.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/deblurring.hpp index 8028c1d8..b383f0d4 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/deblurring.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/deblurring.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_DEBLURRING_HPP__ -#define __OPENCV_VIDEOSTAB_DEBLURRING_HPP__ +#ifndef OPENCV_VIDEOSTAB_DEBLURRING_HPP +#define OPENCV_VIDEOSTAB_DEBLURRING_HPP #include #include "opencv2/core.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/fast_marching.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/fast_marching.hpp similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/fast_marching.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/fast_marching.hpp index c0c7985a..43f8e4a7 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/fast_marching.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/fast_marching.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_FAST_MARCHING_HPP__ -#define __OPENCV_VIDEOSTAB_FAST_MARCHING_HPP__ +#ifndef OPENCV_VIDEOSTAB_FAST_MARCHING_HPP +#define OPENCV_VIDEOSTAB_FAST_MARCHING_HPP #include #include @@ -63,7 +63,7 @@ namespace videostab class CV_EXPORTS FastMarchingMethod { public: - FastMarchingMethod() : inf_(1e6f) {} + FastMarchingMethod() : inf_(1e6f), size_(0) {} /** @brief Template method that runs the Fast Marching Method. diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/fast_marching_inl.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/fast_marching_inl.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/fast_marching_inl.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/fast_marching_inl.hpp index 6388e696..fdd488aa 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/fast_marching_inl.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/fast_marching_inl.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_FAST_MARCHING_INL_HPP__ -#define __OPENCV_VIDEOSTAB_FAST_MARCHING_INL_HPP__ +#ifndef OPENCV_VIDEOSTAB_FAST_MARCHING_INL_HPP +#define OPENCV_VIDEOSTAB_FAST_MARCHING_INL_HPP #include "opencv2/videostab/fast_marching.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/frame_source.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/frame_source.hpp similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/frame_source.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/frame_source.hpp index 612fbdb3..e4e00b59 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/frame_source.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/frame_source.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_FRAME_SOURCE_HPP__ -#define __OPENCV_VIDEOSTAB_FRAME_SOURCE_HPP__ +#ifndef OPENCV_VIDEOSTAB_FRAME_SOURCE_HPP +#define OPENCV_VIDEOSTAB_FRAME_SOURCE_HPP #include #include "opencv2/core.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/global_motion.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/global_motion.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/global_motion.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/global_motion.hpp index 5d51e423..1fbe0c84 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/global_motion.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/global_motion.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP__ -#define __OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP__ +#ifndef OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP +#define OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP #include #include @@ -236,6 +236,7 @@ public: Ptr outlierRejector() const { return outlierRejector_; } virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0); + Mat estimate(InputArray frame0, InputArray frame1, bool *ok = 0); private: Ptr motionEstimator_; @@ -287,7 +288,7 @@ private: @param from Source frame index. @param to Destination frame index. @param motions Pair-wise motions. motions[i] denotes motion from the frame i to the frame i+1 -@return Motion from the frame from to the frame to. +@return Motion from the Source frame to the Destination frame. */ CV_EXPORTS Mat getMotion(int from, int to, const std::vector &motions); diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/inpainting.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/inpainting.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/inpainting.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/inpainting.hpp index 844c68c7..61eeec35 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/inpainting.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/inpainting.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_INPAINTINT_HPP__ -#define __OPENCV_VIDEOSTAB_INPAINTINT_HPP__ +#ifndef OPENCV_VIDEOSTAB_INPAINTINT_HPP +#define OPENCV_VIDEOSTAB_INPAINTINT_HPP #include #include "opencv2/core.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/log.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/log.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/log.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/log.hpp index 28625ed2..81c634a3 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/log.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/log.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_LOG_HPP__ -#define __OPENCV_VIDEOSTAB_LOG_HPP__ +#ifndef OPENCV_VIDEOSTAB_LOG_HPP +#define OPENCV_VIDEOSTAB_LOG_HPP #include "opencv2/core.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/motion_core.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/motion_core.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/motion_core.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/motion_core.hpp index 17448e3c..4525cc7b 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/motion_core.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/motion_core.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_MOTION_CORE_HPP__ -#define __OPENCV_VIDEOSTAB_MOTION_CORE_HPP__ +#ifndef OPENCV_VIDEOSTAB_MOTION_CORE_HPP +#define OPENCV_VIDEOSTAB_MOTION_CORE_HPP #include #include "opencv2/core.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/motion_stabilizing.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/motion_stabilizing.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/motion_stabilizing.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/motion_stabilizing.hpp index 3bdbfbd0..5ea5a65a 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/motion_stabilizing.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/motion_stabilizing.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP__ -#define __OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP__ +#ifndef OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP +#define OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP #include #include diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/optical_flow.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/optical_flow.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/optical_flow.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/optical_flow.hpp index 41d19535..d6314889 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/optical_flow.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/optical_flow.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_OPTICAL_FLOW_HPP__ -#define __OPENCV_VIDEOSTAB_OPTICAL_FLOW_HPP__ +#ifndef OPENCV_VIDEOSTAB_OPTICAL_FLOW_HPP +#define OPENCV_VIDEOSTAB_OPTICAL_FLOW_HPP #include "opencv2/core.hpp" #include "opencv2/opencv_modules.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/outlier_rejection.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/outlier_rejection.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/outlier_rejection.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/outlier_rejection.hpp index 9e40f854..9b9b3844 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/outlier_rejection.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/outlier_rejection.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_OUTLIER_REJECTION_HPP__ -#define __OPENCV_VIDEOSTAB_OUTLIER_REJECTION_HPP__ +#ifndef OPENCV_VIDEOSTAB_OUTLIER_REJECTION_HPP +#define OPENCV_VIDEOSTAB_OUTLIER_REJECTION_HPP #include #include "opencv2/core.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/ring_buffer.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/ring_buffer.hpp similarity index 96% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/ring_buffer.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/ring_buffer.hpp index 7cc3f03e..55d52444 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/ring_buffer.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/ring_buffer.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_RING_BUFFER_HPP__ -#define __OPENCV_VIDEOSTAB_RING_BUFFER_HPP__ +#ifndef OPENCV_VIDEOSTAB_RING_BUFFER_HPP +#define OPENCV_VIDEOSTAB_RING_BUFFER_HPP #include #include "opencv2/imgproc.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/stabilizer.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/stabilizer.hpp similarity index 98% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/stabilizer.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/stabilizer.hpp index c18d3141..b78b4eae 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/stabilizer.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/stabilizer.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_STABILIZER_HPP__ -#define __OPENCV_VIDEOSTAB_STABILIZER_HPP__ +#ifndef OPENCV_VIDEOSTAB_STABILIZER_HPP +#define OPENCV_VIDEOSTAB_STABILIZER_HPP #include #include diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/wobble_suppression.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/wobble_suppression.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/videostab/wobble_suppression.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/videostab/wobble_suppression.hpp index 3f0a9432..a44410bf 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/videostab/wobble_suppression.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/videostab/wobble_suppression.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_VIDEOSTAB_WOBBLE_SUPPRESSION_HPP__ -#define __OPENCV_VIDEOSTAB_WOBBLE_SUPPRESSION_HPP__ +#ifndef OPENCV_VIDEOSTAB_WOBBLE_SUPPRESSION_HPP +#define OPENCV_VIDEOSTAB_WOBBLE_SUPPRESSION_HPP #include #include "opencv2/core.hpp" diff --git a/lib/3rdParty/OpenCV3.1/include/opencv2/world.hpp b/lib/3rdParty/OpenCV3.4/include/opencv2/world.hpp similarity index 97% rename from lib/3rdParty/OpenCV3.1/include/opencv2/world.hpp rename to lib/3rdParty/OpenCV3.4/include/opencv2/world.hpp index 2442f2c2..4902c2f2 100644 --- a/lib/3rdParty/OpenCV3.1/include/opencv2/world.hpp +++ b/lib/3rdParty/OpenCV3.4/include/opencv2/world.hpp @@ -40,8 +40,8 @@ // //M*/ -#ifndef __OPENCV_WORLD_HPP__ -#define __OPENCV_WORLD_HPP__ +#ifndef OPENCV_WORLD_HPP +#define OPENCV_WORLD_HPP #include "opencv2/core.hpp" diff --git a/lib/3rdParty/OpenCV3.1/openCV3.1.props b/lib/3rdParty/OpenCV3.4/openCV3.4.props similarity index 59% rename from lib/3rdParty/OpenCV3.1/openCV3.1.props rename to lib/3rdParty/OpenCV3.4/openCV3.4.props index 7e18201f..82104c0e 100644 --- a/lib/3rdParty/OpenCV3.1/openCV3.1.props +++ b/lib/3rdParty/OpenCV3.4/openCV3.4.props @@ -5,17 +5,17 @@ - $(SolutionDir)lib\3rdParty\OpenCV3.1\include\opencv;$(SolutionDir)lib\3rdParty\OpenCV3.1\include;%(AdditionalIncludeDirectories) + $(SolutionDir)lib\3rdParty\OpenCV3.4\include\opencv;$(SolutionDir)lib\3rdParty\OpenCV3.4\include;%(AdditionalIncludeDirectories) - $(SolutionDir)lib\3rdParty\OpenCV3.1\$(PlatformTarget)\$(PlatformToolset)\lib;%(AdditionalLibraryDirectories) - opencv_world310.lib;%(AdditionalDependencies) + $(SolutionDir)lib\3rdParty\OpenCV3.4\$(PlatformTarget)\$(PlatformToolset)\lib;%(AdditionalLibraryDirectories) + opencv_world340.lib;%(AdditionalDependencies) - xcopy /I /E /Y /D /C "$(SolutionDir)lib\3rdParty\OpenCV3.1\$(PlatformTarget)\$(PlatformToolset)\bin\opencv_world310.dll" "$(OutDir)" -xcopy /I /E /Y /D /C "$(SolutionDir)lib\3rdParty\OpenCV3.1\bin\opencv_ffmpeg310.dll" "$(OutDir)" -xcopy /I /E /Y /D /C "$(SolutionDir)lib\3rdParty\OpenCV3.1\bin\opencv_ffmpeg310_64.dll" "$(OutDir)" -xcopy /I /E /Y /D /C "$(SolutionDir)lib\3rdParty\OpenCV3.1\classifiers" "$(OutDir)classifiers" + xcopy /I /E /Y /D /C "$(SolutionDir)lib\3rdParty\OpenCV3.4\$(PlatformTarget)\$(PlatformToolset)\bin\opencv_world340.dll" "$(OutDir)" +xcopy /I /E /Y /D /C "$(SolutionDir)lib\3rdParty\OpenCV3.4\bin\opencv_ffmpeg340.dll" "$(OutDir)" +xcopy /I /E /Y /D /C "$(SolutionDir)lib\3rdParty\OpenCV3.4\bin\opencv_ffmpeg340_64.dll" "$(OutDir)" +xcopy /I /E /Y /D /C "$(SolutionDir)lib\3rdParty\OpenCV3.4\classifiers" "$(OutDir)classifiers" diff --git a/lib/3rdParty/OpenCV3.1/x64/v140/bin/opencv_world310.dll b/lib/3rdParty/OpenCV3.4/x64/v140/bin/opencv_world340.dll similarity index 52% rename from lib/3rdParty/OpenCV3.1/x64/v140/bin/opencv_world310.dll rename to lib/3rdParty/OpenCV3.4/x64/v140/bin/opencv_world340.dll index 317a474d..8836c529 100644 Binary files a/lib/3rdParty/OpenCV3.1/x64/v140/bin/opencv_world310.dll and b/lib/3rdParty/OpenCV3.4/x64/v140/bin/opencv_world340.dll differ diff --git a/lib/local/CppInerop/CppInerop.vcxproj b/lib/local/CppInerop/CppInerop.vcxproj index dc3bf9fb..04cb0f69 100644 --- a/lib/local/CppInerop/CppInerop.vcxproj +++ b/lib/local/CppInerop/CppInerop.vcxproj @@ -62,35 +62,35 @@ - + - + - + - + diff --git a/lib/local/FaceAnalyser/FaceAnalyser.vcxproj b/lib/local/FaceAnalyser/FaceAnalyser.vcxproj index 8e042725..cea3d317 100644 --- a/lib/local/FaceAnalyser/FaceAnalyser.vcxproj +++ b/lib/local/FaceAnalyser/FaceAnalyser.vcxproj @@ -56,34 +56,34 @@ - + - + - + - + diff --git a/lib/local/FaceAnalyser/include/FaceAnalyser.h b/lib/local/FaceAnalyser/include/FaceAnalyser.h index 4a66d884..118a89e6 100644 --- a/lib/local/FaceAnalyser/include/FaceAnalyser.h +++ b/lib/local/FaceAnalyser/include/FaceAnalyser.h @@ -143,10 +143,10 @@ private: // Use histograms for quick (but approximate) median computation // Use the same for - std::vector > hog_desc_hist; + std::vector > hog_desc_hist; // This is not being used at the moment as it is a bit slow - std::vector > face_image_hist; + std::vector > face_image_hist; std::vector face_image_hist_sum; std::vector head_orientations; @@ -162,7 +162,7 @@ private: cv::Mat_ geom_descriptor_median; int geom_hist_sum; - cv::Mat_ geom_desc_hist; + cv::Mat_ geom_desc_hist; int num_bins_geom; double min_val_geom; double max_val_geom; @@ -186,8 +186,8 @@ private: // A utility function for keeping track of approximate running medians used for AU and emotion inference using a set of histograms (the histograms are evenly spaced from min_val to max_val) // Descriptor has to be a row vector // TODO this duplicates some other code - void UpdateRunningMedian(cv::Mat_& histogram, int& hist_sum, cv::Mat_& median, const cv::Mat_& descriptor, bool update, int num_bins, double min_val, double max_val); - void ExtractMedian(cv::Mat_& histogram, int hist_count, cv::Mat_& median, int num_bins, double min_val, double max_val); + void UpdateRunningMedian(cv::Mat_& histogram, int& hist_sum, cv::Mat_& median, const cv::Mat_& descriptor, bool update, int num_bins, double min_val, double max_val); + void ExtractMedian(cv::Mat_& histogram, int hist_count, cv::Mat_& median, int num_bins, double min_val, double max_val); // The linear SVR regressors SVR_static_lin_regressors AU_SVR_static_appearance_lin_regressors; @@ -199,14 +199,14 @@ private: // The AUs predicted by the model are not always 0 calibrated to a person. That is they don't always predict 0 for a neutral expression // Keeping track of the predictions we can correct for this, by assuming that at least "ratio" of frames are neutral and subtract that value of prediction, only perform the correction after min_frames - void UpdatePredictionTrack(cv::Mat_& prediction_corr_histogram, int& prediction_correction_count, + void UpdatePredictionTrack(cv::Mat_& prediction_corr_histogram, int& prediction_correction_count, std::vector& correction, const std::vector>& predictions, double ratio=0.25, int num_bins = 200, double min_val = -3, double max_val = 5, int min_frames = 10); - void GetSampleHist(cv::Mat_& prediction_corr_histogram, int prediction_correction_count, + void GetSampleHist(cv::Mat_& prediction_corr_histogram, int prediction_correction_count, std::vector& sample, double ratio, int num_bins = 200, double min_val = 0, double max_val = 5); void PostprocessPredictions(); - std::vector> au_prediction_correction_histogram; + std::vector> au_prediction_correction_histogram; std::vector au_prediction_correction_count; // Some dynamic scaling (the logic is that before the extreme versions of expression or emotion are shown, diff --git a/lib/local/FaceAnalyser/src/FaceAnalyser.cpp b/lib/local/FaceAnalyser/src/FaceAnalyser.cpp index e262809f..7409e74a 100644 --- a/lib/local/FaceAnalyser/src/FaceAnalyser.cpp +++ b/lib/local/FaceAnalyser/src/FaceAnalyser.cpp @@ -720,20 +720,20 @@ void FaceAnalyser::Reset() for( size_t i = 0; i < hog_desc_hist.size(); ++i) { - this->hog_desc_hist[i] = cv::Mat_(hog_desc_hist[i].rows, hog_desc_hist[i].cols, (unsigned int)0); + this->hog_desc_hist[i] = cv::Mat_(hog_desc_hist[i].rows, hog_desc_hist[i].cols, (int)0); this->hog_hist_sum[i] = 0; - this->face_image_hist[i] = cv::Mat_(face_image_hist[i].rows, face_image_hist[i].cols, (unsigned int)0); + this->face_image_hist[i] = cv::Mat_(face_image_hist[i].rows, face_image_hist[i].cols, (int)0); this->face_image_hist_sum[i] = 0; // 0 callibration predictions this->au_prediction_correction_count[i] = 0; - this->au_prediction_correction_histogram[i] = cv::Mat_(au_prediction_correction_histogram[i].rows, au_prediction_correction_histogram[i].cols, (unsigned int)0); + this->au_prediction_correction_histogram[i] = cv::Mat_(au_prediction_correction_histogram[i].rows, au_prediction_correction_histogram[i].cols, (int)0); } this->geom_descriptor_median.setTo(cv::Scalar(0)); - this->geom_desc_hist = cv::Mat_(geom_desc_hist.rows, geom_desc_hist.cols, (unsigned int)0); + this->geom_desc_hist = cv::Mat_(geom_desc_hist.rows, geom_desc_hist.cols, (int)0); geom_hist_sum = 0; // Reset the predictions @@ -758,7 +758,7 @@ void FaceAnalyser::Reset() frames_tracking_succ = 0; } -void FaceAnalyser::UpdateRunningMedian(cv::Mat_& histogram, int& hist_count, cv::Mat_& median, const cv::Mat_& descriptor, bool update, int num_bins, double min_val, double max_val) +void FaceAnalyser::UpdateRunningMedian(cv::Mat_& histogram, int& hist_count, cv::Mat_& median, const cv::Mat_& descriptor, bool update, int num_bins, double min_val, double max_val) { double length = max_val - min_val; @@ -768,7 +768,7 @@ void FaceAnalyser::UpdateRunningMedian(cv::Mat_& histogram, int& h // The median update if(histogram.empty()) { - histogram = cv::Mat_(descriptor.cols, num_bins, (unsigned int)0); + histogram = cv::Mat_(descriptor.cols, num_bins, (int)0); median = descriptor.clone(); } @@ -784,7 +784,7 @@ void FaceAnalyser::UpdateRunningMedian(cv::Mat_& histogram, int& h for(int i = 0; i < histogram.rows; ++i) { int index = (int)converted_descriptor.at(i); - histogram.at(i, index)++; + histogram.at(i, index)++; } // Update the histogram count @@ -806,7 +806,7 @@ void FaceAnalyser::UpdateRunningMedian(cv::Mat_& histogram, int& h int cummulative_sum = 0; for(int j = 0; j < histogram.cols; ++j) { - cummulative_sum += histogram.at(i, j); + cummulative_sum += histogram.at(i, j); if(cummulative_sum >= cutoff_point) { median.at(i) = min_val + ((double)j) * (length/((double)num_bins)) + (0.5*(length)/ ((double)num_bins)); @@ -818,7 +818,7 @@ void FaceAnalyser::UpdateRunningMedian(cv::Mat_& histogram, int& h } -void FaceAnalyser::ExtractMedian(cv::Mat_& histogram, int hist_count, cv::Mat_& median, int num_bins, double min_val, double max_val) +void FaceAnalyser::ExtractMedian(cv::Mat_& histogram, int hist_count, cv::Mat_& median, int num_bins, double min_val, double max_val) { double length = max_val - min_val; @@ -846,7 +846,7 @@ void FaceAnalyser::ExtractMedian(cv::Mat_& histogram, int hist_cou int cummulative_sum = 0; for(int j = 0; j < histogram.cols; ++j) { - cummulative_sum += histogram.at(i, j); + cummulative_sum += histogram.at(i, j); if(cummulative_sum > cutoff_point) { median.at(i) = min_val + j * (max_val/num_bins) + (0.5*(length)/num_bins); @@ -1125,7 +1125,7 @@ void FaceAnalyser::ReadAU(std::string au_model_location) } -void FaceAnalyser::UpdatePredictionTrack(cv::Mat_& prediction_corr_histogram, int& prediction_correction_count, vector& correction, const vector>& predictions, double ratio, int num_bins, double min_val, double max_val, int min_frames) +void FaceAnalyser::UpdatePredictionTrack(cv::Mat_& prediction_corr_histogram, int& prediction_correction_count, vector& correction, const vector>& predictions, double ratio, int num_bins, double min_val, double max_val, int min_frames) { double length = max_val - min_val; if(length < 0) @@ -1136,7 +1136,7 @@ void FaceAnalyser::UpdatePredictionTrack(cv::Mat_& prediction_corr // The median update if(prediction_corr_histogram.empty()) { - prediction_corr_histogram = cv::Mat_((int)predictions.size(), num_bins, (unsigned int)0); + prediction_corr_histogram = cv::Mat_((int)predictions.size(), num_bins, (int)0); } for(int i = 0; i < prediction_corr_histogram.rows; ++i) @@ -1151,7 +1151,7 @@ void FaceAnalyser::UpdatePredictionTrack(cv::Mat_& prediction_corr { index = num_bins - 1; } - prediction_corr_histogram.at(i, index)++; + prediction_corr_histogram.at(i, index)++; } // Update the histogram count @@ -1168,7 +1168,7 @@ void FaceAnalyser::UpdatePredictionTrack(cv::Mat_& prediction_corr int cummulative_sum = 0; for(int j = 0; j < prediction_corr_histogram.cols; ++j) { - cummulative_sum += prediction_corr_histogram.at(i, j); + cummulative_sum += prediction_corr_histogram.at(i, j); if(cummulative_sum > cutoff_point) { double corr = min_val + j * (length/num_bins); @@ -1180,7 +1180,7 @@ void FaceAnalyser::UpdatePredictionTrack(cv::Mat_& prediction_corr } } -void FaceAnalyser::GetSampleHist(cv::Mat_& prediction_corr_histogram, int prediction_correction_count, vector& sample, double ratio, int num_bins, double min_val, double max_val) +void FaceAnalyser::GetSampleHist(cv::Mat_& prediction_corr_histogram, int prediction_correction_count, vector& sample, double ratio, int num_bins, double min_val, double max_val) { double length = max_val - min_val; @@ -1198,7 +1198,7 @@ void FaceAnalyser::GetSampleHist(cv::Mat_& prediction_corr_histogr int cummulative_sum = 0; for(int j = 0; j < prediction_corr_histogram.cols; ++j) { - cummulative_sum += prediction_corr_histogram.at(i, j); + cummulative_sum += prediction_corr_histogram.at(i, j); if(cummulative_sum > cutoff_point) { double corr = min_val + j * (length/num_bins); diff --git a/lib/local/GazeAnalyser/GazeAnalyser.vcxproj b/lib/local/GazeAnalyser/GazeAnalyser.vcxproj index 844f347f..3ddf6d9e 100644 --- a/lib/local/GazeAnalyser/GazeAnalyser.vcxproj +++ b/lib/local/GazeAnalyser/GazeAnalyser.vcxproj @@ -57,27 +57,27 @@ - + - + - + - + diff --git a/lib/local/LandmarkDetector/LandmarkDetector.vcxproj b/lib/local/LandmarkDetector/LandmarkDetector.vcxproj index dc9bfe31..699fda42 100644 --- a/lib/local/LandmarkDetector/LandmarkDetector.vcxproj +++ b/lib/local/LandmarkDetector/LandmarkDetector.vcxproj @@ -55,32 +55,32 @@ - + - + - + - + @@ -111,7 +111,7 @@ xcopy /I /E /Y /D "$(SolutionDir)lib\local\LandmarkDetector\model" "$(OutDir)model" -xcopy /I /E /Y /D "$(SolutionDir)lib\3rdParty\OpenCV3.1\classifiers" "$(OutDir)classifiers" +xcopy /I /E /Y /D "$(SolutionDir)lib\3rdParty\OpenCV3.4\classifiers" "$(OutDir)classifiers" @@ -134,7 +134,7 @@ xcopy /I /E /Y /D "$(SolutionDir)lib\3rdParty\OpenCV3.1\classifiers" "$(OutDir)c xcopy /I /E /Y /D "$(SolutionDir)lib\local\LandmarkDetector\model" "$(OutDir)model" -xcopy /I /E /Y /D "$(SolutionDir)lib\3rdParty\OpenCV3.1\classifiers" "$(OutDir)classifiers" +xcopy /I /E /Y /D "$(SolutionDir)lib\3rdParty\OpenCV3.4\classifiers" "$(OutDir)classifiers" @@ -159,7 +159,7 @@ xcopy /I /E /Y /D "$(SolutionDir)lib\3rdParty\OpenCV3.1\classifiers" "$(OutDir)c xcopy /I /E /Y /D "$(SolutionDir)lib\local\LandmarkDetector\model" "$(OutDir)model" -xcopy /I /E /Y /D "$(SolutionDir)lib\3rdParty\OpenCV3.1\classifiers" "$(OutDir)classifiers" +xcopy /I /E /Y /D "$(SolutionDir)lib\3rdParty\OpenCV3.4\classifiers" "$(OutDir)classifiers" @@ -185,7 +185,7 @@ xcopy /I /E /Y /D "$(SolutionDir)lib\3rdParty\OpenCV3.1\classifiers" "$(OutDir)c xcopy /I /E /Y /D "$(SolutionDir)lib\local\LandmarkDetector\model" "$(OutDir)model" -xcopy /I /E /Y /D "$(SolutionDir)lib\3rdParty\OpenCV3.1\classifiers" "$(OutDir)classifiers" +xcopy /I /E /Y /D "$(SolutionDir)lib\3rdParty\OpenCV3.4\classifiers" "$(OutDir)classifiers" diff --git a/lib/local/Utilities/Utilities.vcxproj b/lib/local/Utilities/Utilities.vcxproj index 5ec041f3..72a65512 100644 --- a/lib/local/Utilities/Utilities.vcxproj +++ b/lib/local/Utilities/Utilities.vcxproj @@ -59,31 +59,31 @@ - + - + - + - +