From ef5579dc8667e5eb5e149acc4af898421eed99da Mon Sep 17 00:00:00 2001 From: Hamdi Sahloul <42140441+cv3d@users.noreply.github.com> Date: Sat, 22 Sep 2018 00:12:35 +0900 Subject: [PATCH] Merge pull request #12310 from cv3d:chunks/enum_interface * Cleanup macros and enable expansion of `__VA_ARGS__` for Visual Studio * Macros for enum-arguments backwards compatibility * Convert struct Param to enum struct * Enabled ParamType.type for enum types * Enabled `cv.read` and `cv.write` for enum types * Rename unnamed enum to AAKAZE.DescriptorType * Rename unnamed enum to AccessFlag * Rename unnamed enum to AgastFeatureDetector.DetectorType * Convert struct DrawMatchesFlags to enum struct * Rename unnamed enum to FastFeatureDetector.DetectorType * Rename unnamed enum to Formatter.FormatType * Rename unnamed enum to HOGDescriptor.HistogramNormType * Rename unnamed enum to DescriptorMatcher.MatcherType * Rename unnamed enum to KAZE.DiffusivityType * Rename unnamed enum to ORB.ScoreType * Rename unnamed enum to UMatData.MemoryFlag * Rename unnamed enum to _InputArray.KindFlag * Rename unnamed enum to _OutputArray.DepthMask * Convert normType enums to static const NormTypes * Avoid conflicts with ElemType * Rename unnamed enum to DescriptorStorageFormat --- modules/core/include/opencv2/core.hpp | 46 +++-- modules/core/include/opencv2/core/base.hpp | 24 +-- modules/core/include/opencv2/core/cvdef.h | 138 ++++++++++++++- modules/core/include/opencv2/core/mat.hpp | 36 ++-- modules/core/include/opencv2/core/mat.inl.hpp | 44 ++--- modules/core/include/opencv2/core/opengl.hpp | 2 +- .../core/include/opencv2/core/operations.hpp | 2 +- .../core/include/opencv2/core/persistence.hpp | 14 ++ modules/core/include/opencv2/core/utility.hpp | 4 +- modules/core/misc/python/pyopencv_umat.hpp | 2 + modules/core/misc/python/shadow_umat.hpp | 2 +- modules/core/src/arithm.cpp | 10 +- modules/core/src/command_line_parser.cpp | 8 +- modules/core/src/cuda_host_mem.cpp | 4 +- modules/core/src/matrix.cpp | 10 +- modules/core/src/matrix_wrap.cpp | 89 +++++----- modules/core/src/ocl.cpp | 36 ++-- modules/core/src/opengl.cpp | 4 +- modules/core/src/out.cpp | 2 +- modules/core/src/precomp.hpp | 4 +- modules/core/src/umatrix.cpp | 16 +- modules/core/test/test_mat.cpp | 6 +- modules/dnn/include/opencv2/dnn/dict.hpp | 4 +- modules/dnn/include/opencv2/dnn/dnn.inl.hpp | 22 ++- .../features2d/include/opencv2/features2d.hpp | 163 ++++++++++-------- .../misc/python/pyopencv_features2d.hpp | 21 +++ modules/features2d/src/agast.cpp | 16 +- modules/features2d/src/agast_score.cpp | 4 +- modules/features2d/src/agast_score.hpp | 6 +- modules/features2d/src/akaze.cpp | 24 +-- modules/features2d/src/draw.cpp | 16 +- modules/features2d/src/fast.cpp | 20 +-- modules/features2d/src/hal_replacement.hpp | 4 +- modules/features2d/src/kaze.cpp | 12 +- modules/features2d/src/kaze/AKAZEConfig.h | 4 +- modules/features2d/src/kaze/AKAZEFeatures.cpp | 4 +- modules/features2d/src/kaze/KAZEConfig.h | 2 +- modules/features2d/src/matchers.cpp | 2 +- modules/features2d/src/orb.cpp | 12 +- modules/features2d/test/test_agast.cpp | 4 +- modules/features2d/test/test_fast.cpp | 4 +- modules/features2d/test/test_orb.cpp | 2 +- .../objdetect/include/opencv2/objdetect.hpp | 8 +- .../misc/python/pyopencv_objdetect.hpp | 13 ++ modules/objdetect/src/hog.cpp | 10 +- modules/python/src2/cv2.cpp | 4 +- .../opencv2/stitching/detail/matchers.hpp | 4 +- modules/stitching/src/matchers.cpp | 4 +- modules/ts/include/opencv2/ts.hpp | 2 +- modules/ts/src/ts_func.cpp | 2 +- modules/video/src/lkpyramid.cpp | 4 +- 51 files changed, 567 insertions(+), 333 deletions(-) create mode 100644 modules/objdetect/misc/python/pyopencv_objdetect.hpp diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index 1e271a6fd3..c8216b28f3 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -2997,7 +2997,8 @@ public: class CV_EXPORTS Formatter { public: - enum { FMT_DEFAULT = 0, + enum FormatType { + FMT_DEFAULT = 0, FMT_MATLAB = 1, FMT_CSV = 2, FMT_PYTHON = 3, @@ -3014,7 +3015,7 @@ public: virtual void set64fPrecision(int p = 16) = 0; virtual void setMultiline(bool ml = true) = 0; - static Ptr get(int fmt = FMT_DEFAULT); + static Ptr get(Formatter::FormatType fmt = FMT_DEFAULT); }; @@ -3037,7 +3038,7 @@ String& operator << (String& out, const Mat& mtx) class CV_EXPORTS Algorithm; -template struct ParamType {}; +template struct ParamType {}; /** @brief This is a base class for all more or less complex algorithms in OpenCV @@ -3150,9 +3151,9 @@ protected: void writeFormat(FileStorage& fs) const; }; -struct Param { - enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7, - UNSIGNED_INT=8, UINT64=9, UCHAR=11, SCALAR=12 }; +enum struct Param { + INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7, + UNSIGNED_INT=8, UINT64=9, UCHAR=11, SCALAR=12 }; @@ -3162,7 +3163,7 @@ template<> struct ParamType typedef bool const_param_type; typedef bool member_type; - enum { type = Param::BOOLEAN }; + static const Param type = Param::BOOLEAN; }; template<> struct ParamType @@ -3170,7 +3171,7 @@ template<> struct ParamType typedef int const_param_type; typedef int member_type; - enum { type = Param::INT }; + static const Param type = Param::INT; }; template<> struct ParamType @@ -3178,7 +3179,7 @@ template<> struct ParamType typedef double const_param_type; typedef double member_type; - enum { type = Param::REAL }; + static const Param type = Param::REAL; }; template<> struct ParamType @@ -3186,7 +3187,7 @@ template<> struct ParamType typedef const String& const_param_type; typedef String member_type; - enum { type = Param::STRING }; + static const Param type = Param::STRING; }; template<> struct ParamType @@ -3194,7 +3195,7 @@ template<> struct ParamType typedef const Mat& const_param_type; typedef Mat member_type; - enum { type = Param::MAT }; + static const Param type = Param::MAT; }; template<> struct ParamType > @@ -3202,7 +3203,7 @@ template<> struct ParamType > typedef const std::vector& const_param_type; typedef std::vector member_type; - enum { type = Param::MAT_VECTOR }; + static const Param type = Param::MAT_VECTOR; }; template<> struct ParamType @@ -3210,7 +3211,7 @@ template<> struct ParamType typedef const Ptr& const_param_type; typedef Ptr member_type; - enum { type = Param::ALGORITHM }; + static const Param type = Param::ALGORITHM; }; template<> struct ParamType @@ -3218,7 +3219,7 @@ template<> struct ParamType typedef float const_param_type; typedef float member_type; - enum { type = Param::FLOAT }; + static const Param type = Param::FLOAT; }; template<> struct ParamType @@ -3226,7 +3227,7 @@ template<> struct ParamType typedef unsigned const_param_type; typedef unsigned member_type; - enum { type = Param::UNSIGNED_INT }; + static const Param type = Param::UNSIGNED_INT; }; template<> struct ParamType @@ -3234,7 +3235,7 @@ template<> struct ParamType typedef uint64 const_param_type; typedef uint64 member_type; - enum { type = Param::UINT64 }; + static const Param type = Param::UINT64; }; template<> struct ParamType @@ -3242,7 +3243,7 @@ template<> struct ParamType typedef uchar const_param_type; typedef uchar member_type; - enum { type = Param::UCHAR }; + static const Param type = Param::UCHAR; }; template<> struct ParamType @@ -3250,7 +3251,16 @@ template<> struct ParamType typedef const Scalar& const_param_type; typedef Scalar member_type; - enum { type = Param::SCALAR }; + static const Param type = Param::SCALAR; +}; + +template +struct ParamType<_Tp, typename std::enable_if< std::is_enum<_Tp>::value >::type> +{ + typedef typename std::underlying_type<_Tp>::type const_param_type; + typedef typename std::underlying_type<_Tp>::type member_type; + + static const Param type = Param::INT; }; //! @} core_basic diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index 24f92b5413..e5770553f7 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -440,17 +440,17 @@ configurations while CV_DbgAssert is only retained in the Debug configuration. #endif #define CV_Assert_1 CV_Assert -#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_N(...) do { __CV_CAT(CV_Assert_, __CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__); } while(0) +#define CV_Assert_2( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_1( __VA_ARGS__ )) +#define CV_Assert_3( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_2( __VA_ARGS__ )) +#define CV_Assert_4( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_3( __VA_ARGS__ )) +#define CV_Assert_5( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_4( __VA_ARGS__ )) +#define CV_Assert_6( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_5( __VA_ARGS__ )) +#define CV_Assert_7( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_6( __VA_ARGS__ )) +#define CV_Assert_8( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_7( __VA_ARGS__ )) +#define CV_Assert_9( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_8( __VA_ARGS__ )) +#define CV_Assert_10( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_9( __VA_ARGS__ )) + +#define CV_Assert_N(...) do { __CV_EXPAND(__CV_CAT(CV_Assert_, __CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__)); } while(0) //! @endcond @@ -467,7 +467,7 @@ configurations while CV_DbgAssert is only retained in the Debug configuration. */ struct CV_EXPORTS Hamming { - enum { normType = NORM_HAMMING }; + static const NormTypes normType = NORM_HAMMING; typedef unsigned char ValueType; typedef int ResultType; diff --git a/modules/core/include/opencv2/core/cvdef.h b/modules/core/include/opencv2/core/cvdef.h index 8c4ae7d9f9..cf97d53de8 100644 --- a/modules/core/include/opencv2/core/cvdef.h +++ b/modules/core/include/opencv2/core/cvdef.h @@ -80,7 +80,7 @@ namespace cv { namespace debug_build_guard { } using namespace debug_build_guard #endif #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_VA_NUM_ARGS(...) __CV_EXPAND(__CV_VA_NUM_ARGS_HELPER(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)) // undef problematic defines sometimes defined by system headers (windows.h in particular) #undef small @@ -330,6 +330,142 @@ Cv64suf; # define MAX(a,b) ((a) < (b) ? (b) : (a)) #endif +///////////////////////////////////////// Enum operators /////////////////////////////////////// + +/** + +Provides compatibility operators for both classical and C++11 enum classes, +as well as exposing the C++11 enum class members for backwards compatibility + +@code + // Provides operators required for flag enums + CV_ENUM_FLAGS(AccessFlag); + + // Exposes the listed members of the enum class AccessFlag to the current namespace + CV_ENUM_CLASS_EXPOSE(AccessFlag, ACCESS_READ [, ACCESS_WRITE [, ...] ]); +@endcode +*/ + +#define __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST) \ +static const EnumType MEMBER_CONST = EnumType::MEMBER_CONST; \ + +#define __CV_ENUM_CLASS_EXPOSE_2(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_1(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_3(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_2(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_4(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_3(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_5(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_4(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_6(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_5(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_7(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_6(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_8(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_7(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_9(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_8(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_FLAGS_LOGICAL_NOT(EnumType) \ +static inline bool operator!(const EnumType& val) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return !static_cast(val); \ +} \ + +#define __CV_ENUM_FLAGS_LOGICAL_NOT_EQ(Arg1Type, Arg2Type) \ +static inline bool operator!=(const Arg1Type& a, const Arg2Type& b) \ +{ \ + return static_cast(a) != static_cast(b); \ +} \ + +#define __CV_ENUM_FLAGS_LOGICAL_EQ(Arg1Type, Arg2Type) \ +static inline bool operator==(const Arg1Type& a, const Arg2Type& b) \ +{ \ + return static_cast(a) == static_cast(b); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_NOT(EnumType) \ +static inline EnumType operator~(const EnumType& val) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(~static_cast(val)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_OR(EnumType, Arg1Type, Arg2Type) \ +static inline EnumType operator|(const Arg1Type& a, const Arg2Type& b) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(static_cast(a) | static_cast(b)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_AND(EnumType, Arg1Type, Arg2Type) \ +static inline EnumType operator&(const Arg1Type& a, const Arg2Type& b) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(static_cast(a) & static_cast(b)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_XOR(EnumType, Arg1Type, Arg2Type) \ +static inline EnumType operator^(const Arg1Type& a, const Arg2Type& b) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(static_cast(a) ^ static_cast(b)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_OR_EQ(EnumType, Arg1Type) \ +static inline EnumType& operator|=(EnumType& _this, const Arg1Type& val) \ +{ \ + _this = static_cast(static_cast(_this) | static_cast(val)); \ + return _this; \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_AND_EQ(EnumType, Arg1Type) \ +static inline EnumType& operator&=(EnumType& _this, const Arg1Type& val) \ +{ \ + _this = static_cast(static_cast(_this) & static_cast(val)); \ + return _this; \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_XOR_EQ(EnumType, Arg1Type) \ +static inline EnumType& operator^=(EnumType& _this, const Arg1Type& val) \ +{ \ + _this = static_cast(static_cast(_this) ^ static_cast(val)); \ + return _this; \ +} \ + +#define CV_ENUM_CLASS_EXPOSE(EnumType, ...) \ +__CV_EXPAND(__CV_CAT(__CV_ENUM_CLASS_EXPOSE_, __CV_VA_NUM_ARGS(__VA_ARGS__))(EnumType, __VA_ARGS__)); \ + +#define CV_ENUM_FLAGS(EnumType) \ +__CV_ENUM_FLAGS_LOGICAL_NOT (EnumType); \ +__CV_ENUM_FLAGS_LOGICAL_EQ (EnumType, int); \ +__CV_ENUM_FLAGS_LOGICAL_NOT_EQ (EnumType, int); \ + \ +__CV_ENUM_FLAGS_BITWISE_NOT (EnumType); \ +__CV_ENUM_FLAGS_BITWISE_OR (EnumType, EnumType, EnumType); \ +__CV_ENUM_FLAGS_BITWISE_AND (EnumType, EnumType, EnumType); \ +__CV_ENUM_FLAGS_BITWISE_XOR (EnumType, EnumType, EnumType); \ + \ +__CV_ENUM_FLAGS_BITWISE_OR_EQ (EnumType, EnumType); \ +__CV_ENUM_FLAGS_BITWISE_AND_EQ (EnumType, EnumType); \ +__CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType); \ + /****************************************************************************************\ * static analysys * \****************************************************************************************/ diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index 2efcf17b6c..178ecd4938 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -61,8 +61,10 @@ namespace cv //! @addtogroup core_basic //! @{ -enum { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25, +enum AccessFlag { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25, ACCESS_RW=3<<24, ACCESS_MASK=ACCESS_RW, ACCESS_FAST=1<<26 }; +CV_ENUM_FLAGS(AccessFlag); +__CV_ENUM_FLAGS_BITWISE_AND(AccessFlag, int, AccessFlag); CV__DEBUG_NS_BEGIN @@ -156,7 +158,7 @@ Custom type is wrapped as Mat-compatible `CV_8UC` values (N = sizeof(T), N <= class CV_EXPORTS _InputArray { public: - enum { + enum KindFlag { KIND_SHIFT = 16, FIXED_TYPE = 0x8000 << KIND_SHIFT, FIXED_SIZE = 0x4000 << KIND_SHIFT, @@ -221,7 +223,7 @@ public: void* getObj() const; Size getSz() const; - int kind() const; + _InputArray::KindFlag kind() const; int dims(int i=-1) const; int cols(int i=-1) const; int rows(int i=-1) const; @@ -257,7 +259,8 @@ protected: void init(int _flags, const void* _obj); void init(int _flags, const void* _obj, Size _sz); }; - +CV_ENUM_FLAGS(_InputArray::KindFlag); +__CV_ENUM_FLAGS_BITWISE_AND(_InputArray::KindFlag, int, _InputArray::KindFlag); /** @brief This type is very similar to InputArray except that it is used for input/output and output function parameters. @@ -287,7 +290,7 @@ generators: class CV_EXPORTS _OutputArray : public _InputArray { public: - enum + enum DepthMask { DEPTH_MASK_8U = 1 << CV_8U, DEPTH_MASK_8S = 1 << CV_8S, @@ -356,9 +359,9 @@ public: std::vector& getGpuMatVecRef() const; ogl::Buffer& getOGlBufferRef() const; cuda::HostMem& getHostMemRef() const; - void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; - void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; - void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; + void create(Size sz, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; + void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; + void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; void createSameSize(const _InputArray& arr, int mtype) const; void release() const; void clear() const; @@ -467,10 +470,10 @@ public: // uchar*& datastart, uchar*& data, size_t* step) = 0; //virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0; virtual UMatData* allocate(int dims, const int* sizes, int type, - void* data, size_t* step, int flags, UMatUsageFlags usageFlags) const = 0; - virtual bool allocate(UMatData* data, int accessflags, UMatUsageFlags usageFlags) const = 0; + void* data, size_t* step, AccessFlag flags, UMatUsageFlags usageFlags) const = 0; + virtual bool allocate(UMatData* data, AccessFlag accessflags, UMatUsageFlags usageFlags) const = 0; virtual void deallocate(UMatData* data) const = 0; - virtual void map(UMatData* data, int accessflags) const; + virtual void map(UMatData* data, AccessFlag accessflags) const; virtual void unmap(UMatData* data) const; virtual void download(UMatData* data, void* dst, int dims, const size_t sz[], const size_t srcofs[], const size_t srcstep[], @@ -523,7 +526,7 @@ protected: // it should be explicitly initialized using init(). struct CV_EXPORTS UMatData { - enum { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2, + enum MemoryFlag { 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, ASYNC_CLEANUP=128 @@ -553,13 +556,14 @@ struct CV_EXPORTS UMatData uchar* origdata; size_t size; - int flags; + UMatData::MemoryFlag flags; void* handle; void* userdata; int allocatorFlags_; int mapcount; UMatData* originalUMatData; }; +CV_ENUM_FLAGS(UMatData::MemoryFlag); struct CV_EXPORTS MatSize @@ -1061,7 +1065,7 @@ public: Mat& operator = (const MatExpr& expr); //! retrieve UMat from Mat - UMat getUMat(int accessFlags, UMatUsageFlags usageFlags = USAGE_DEFAULT) const; + UMat getUMat(AccessFlag accessFlags, UMatUsageFlags usageFlags = USAGE_DEFAULT) const; /** @brief Creates a matrix header for the specified matrix row. @@ -2420,7 +2424,7 @@ public: //! assignment operators UMat& operator = (const UMat& m); - Mat getMat(int flags) const; + Mat getMat(AccessFlag flags) const; //! returns a new matrix header for the specified row UMat row(int y) const; @@ -2546,7 +2550,7 @@ public: 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* handle(AccessFlag accessFlags) const; void ndoffset(size_t* ofs) const; enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG }; diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index d28a6251d7..0ef6405bb9 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -83,7 +83,7 @@ inline void* _InputArray::getObj() const { return obj; } inline int _InputArray::getFlags() const { return flags; } inline Size _InputArray::getSz() const { return sz; } -inline _InputArray::_InputArray() { init(NONE, 0); } +inline _InputArray::_InputArray() { init(0 + NONE, 0); } inline _InputArray::_InputArray(int _flags, void* _obj) { init(_flags, _obj); } inline _InputArray::_InputArray(const Mat& m) { init(MAT+ACCESS_READ, &m); } inline _InputArray::_InputArray(const std::vector& vec) { init(STD_VECTOR_MAT+ACCESS_READ, &vec); } @@ -185,12 +185,12 @@ inline bool _InputArray::isGpuMatVector() const { return kind() == _InputArray:: //////////////////////////////////////////////////////////////////////////////////////// -inline _OutputArray::_OutputArray() { init(ACCESS_WRITE, 0); } -inline _OutputArray::_OutputArray(int _flags, void* _obj) { init(_flags|ACCESS_WRITE, _obj); } +inline _OutputArray::_OutputArray() { init(NONE + ACCESS_WRITE, 0); } +inline _OutputArray::_OutputArray(int _flags, void* _obj) { init(_flags + ACCESS_WRITE, _obj); } inline _OutputArray::_OutputArray(Mat& m) { init(MAT+ACCESS_WRITE, &m); } -inline _OutputArray::_OutputArray(std::vector& vec) { init(STD_VECTOR_MAT+ACCESS_WRITE, &vec); } -inline _OutputArray::_OutputArray(UMat& m) { init(UMAT+ACCESS_WRITE, &m); } -inline _OutputArray::_OutputArray(std::vector& vec) { init(STD_VECTOR_UMAT+ACCESS_WRITE, &vec); } +inline _OutputArray::_OutputArray(std::vector& vec) { init(STD_VECTOR_MAT + ACCESS_WRITE, &vec); } +inline _OutputArray::_OutputArray(UMat& m) { init(UMAT + ACCESS_WRITE, &m); } +inline _OutputArray::_OutputArray(std::vector& vec) { init(STD_VECTOR_UMAT + ACCESS_WRITE, &vec); } template inline _OutputArray::_OutputArray(std::vector<_Tp>& vec) @@ -311,8 +311,8 @@ _OutputArray _OutputArray::rawOut(std::array<_Tp, _Nm>& arr) /////////////////////////////////////////////////////////////////////////////////////////// -inline _InputOutputArray::_InputOutputArray() { init(ACCESS_RW, 0); } -inline _InputOutputArray::_InputOutputArray(int _flags, void* _obj) { init(_flags|ACCESS_RW, _obj); } +inline _InputOutputArray::_InputOutputArray() { init(0+ACCESS_RW, 0); } +inline _InputOutputArray::_InputOutputArray(int _flags, void* _obj) { init(_flags+ACCESS_RW, _obj); } inline _InputOutputArray::_InputOutputArray(Mat& m) { init(MAT+ACCESS_RW, &m); } inline _InputOutputArray::_InputOutputArray(std::vector& vec) { init(STD_VECTOR_MAT+ACCESS_RW, &vec); } inline _InputOutputArray::_InputOutputArray(UMat& m) { init(UMAT+ACCESS_RW, &m); } @@ -600,7 +600,7 @@ 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 | traits::Type<_Tp>::value | 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), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) { if(vec.empty()) @@ -637,7 +637,7 @@ Mat::Mat(const std::initializer_list sizes, const std::initializer_list<_Tp 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()), + : 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()) @@ -654,7 +654,7 @@ Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData) template inline Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0), + : 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 ) @@ -670,7 +670,7 @@ Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) template inline Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0), + : 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 ) @@ -686,7 +686,7 @@ Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData) template inline Mat::Mat(const Point_<_Tp>& pt, bool copyData) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0), + : 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 ) @@ -705,7 +705,7 @@ Mat::Mat(const Point_<_Tp>& pt, bool copyData) template inline Mat::Mat(const Point3_<_Tp>& pt, bool copyData) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0), + : 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 ) @@ -725,7 +725,7 @@ Mat::Mat(const Point3_<_Tp>& pt, bool copyData) template inline Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer) - : flags(MAGIC_VAL | traits::Type<_Tp>::value | 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>(); @@ -1554,7 +1554,7 @@ template inline Mat_<_Tp>::Mat_() : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; } template inline @@ -1611,7 +1611,7 @@ template inline Mat_<_Tp>::Mat_(const Mat& m) : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; *this = m; } @@ -1751,7 +1751,7 @@ void Mat_<_Tp>::release() { Mat::release(); #ifdef _DEBUG - flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; #endif } @@ -2069,7 +2069,7 @@ template inline Mat_<_Tp>::Mat_(Mat&& m) : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; *this = m; } @@ -2095,7 +2095,7 @@ template inline Mat_<_Tp>::Mat_(MatExpr&& e) : Mat() { - flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; *this = Mat(e); } @@ -2431,7 +2431,7 @@ SparseMatConstIterator_<_Tp> SparseMat::end() const template inline SparseMat_<_Tp>::SparseMat_() { - flags = MAGIC_VAL | traits::Type<_Tp>::value; + flags = MAGIC_VAL + traits::Type<_Tp>::value; } template inline @@ -3654,7 +3654,7 @@ UMat::UMat(const UMat& m) template inline UMat::UMat(const std::vector<_Tp>& vec, bool copyData) -: flags(MAGIC_VAL | traits::Type<_Tp>::value | 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()) diff --git a/modules/core/include/opencv2/core/opengl.hpp b/modules/core/include/opencv2/core/opengl.hpp index 5e88cb8ce4..ddc0db6943 100644 --- a/modules/core/include/opencv2/core/opengl.hpp +++ b/modules/core/include/opencv2/core/opengl.hpp @@ -548,7 +548,7 @@ calling unmapGLBuffer() function. @param accessFlags - data access flags (ACCESS_READ|ACCESS_WRITE). @return Returns UMat object */ -CV_EXPORTS UMat mapGLBuffer(const Buffer& buffer, int accessFlags = ACCESS_READ|ACCESS_WRITE); +CV_EXPORTS UMat mapGLBuffer(const Buffer& buffer, AccessFlag accessFlags = ACCESS_READ | ACCESS_WRITE); /** @brief Unmaps Buffer object (releases UMat, previously mapped from Buffer). diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index d706d9664e..0d28b6c944 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -392,7 +392,7 @@ CV_EXPORTS String format( const char* fmt, ... ); ///////////////////////////////// Formatted output of cv::Mat ///////////////////////////////// static inline -Ptr format(InputArray mtx, int fmt) +Ptr format(InputArray mtx, Formatter::FormatType fmt) { return Formatter::get(fmt)->format(mtx.getMat()); } diff --git a/modules/core/include/opencv2/core/persistence.hpp b/modules/core/include/opencv2/core/persistence.hpp index 22e611ea36..948b568ca1 100644 --- a/modules/core/include/opencv2/core/persistence.hpp +++ b/modules/core/include/opencv2/core/persistence.hpp @@ -1049,6 +1049,12 @@ void write(FileStorage& fs, const String& name, const DMatch& m) write(fs, m.distance); } +template::value >::type* = nullptr> +static inline void write( FileStorage& fs, const String& name, const _Tp& val ) +{ + write(fs, name, static_cast(val)); +} + template static inline void write( FileStorage& fs, const String& name, const std::vector<_Tp>& vec ) { @@ -1137,6 +1143,14 @@ void read( FileNodeIterator& it, std::vector<_Tp>& vec, size_t maxCount = (size_ r(vec, maxCount); } +template::value >::type* = nullptr> +static inline void read(const FileNode& node, _Tp& value, const _Tp& default_value = static_cast<_Tp>(0)) +{ + int temp; + read(node, temp, static_cast(default_value)); + value = static_cast<_Tp>(temp); +} + template static inline void read( const FileNode& node, std::vector<_Tp>& vec, const std::vector<_Tp>& default_value = std::vector<_Tp>() ) { diff --git a/modules/core/include/opencv2/core/utility.hpp b/modules/core/include/opencv2/core/utility.hpp index 03f5d44ecb..4174de8f5d 100644 --- a/modules/core/include/opencv2/core/utility.hpp +++ b/modules/core/include/opencv2/core/utility.hpp @@ -943,8 +943,8 @@ public: void printErrors() const; protected: - void getByName(const String& name, bool space_delete, int type, void* dst) const; - void getByIndex(int index, bool space_delete, int type, void* dst) const; + void getByName(const String& name, bool space_delete, Param type, void* dst) const; + void getByIndex(int index, bool space_delete, Param type, void* dst) const; struct Impl; Impl* impl; diff --git a/modules/core/misc/python/pyopencv_umat.hpp b/modules/core/misc/python/pyopencv_umat.hpp index b49b71b10c..003dce04fc 100644 --- a/modules/core/misc/python/pyopencv_umat.hpp +++ b/modules/core/misc/python/pyopencv_umat.hpp @@ -7,6 +7,8 @@ typedef std::vector vector_Range; CV_PY_TO_CLASS(UMat); CV_PY_FROM_CLASS(UMat); CV_PY_TO_ENUM(UMatUsageFlags); +CV_PY_FROM_ENUM(AccessFlag); +CV_PY_TO_ENUM(AccessFlag); static bool cv_mappable_to(const Ptr& src, Ptr& dst) { diff --git a/modules/core/misc/python/shadow_umat.hpp b/modules/core/misc/python/shadow_umat.hpp index 107aedb928..39ffef1d47 100644 --- a/modules/core/misc/python/shadow_umat.hpp +++ b/modules/core/misc/python/shadow_umat.hpp @@ -50,7 +50,7 @@ public: 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. */ - CV_WRAP void* handle(int accessFlags) const; + CV_WRAP void* handle(AccessFlag accessFlags) const; // offset of the submatrix (or 0) CV_PROP_RW size_t offset; diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index dcebf6c1e4..ce943e0ffb 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -167,7 +167,7 @@ static void binary_op( InputArray _src1, InputArray _src2, OutputArray _dst, bool bitwise, int oclop ) { const _InputArray *psrc1 = &_src1, *psrc2 = &_src2; - int kind1 = psrc1->kind(), kind2 = psrc2->kind(); + _InputArray::KindFlag kind1 = psrc1->kind(), kind2 = psrc2->kind(); int type1 = psrc1->type(), depth1 = CV_MAT_DEPTH(type1), cn = CV_MAT_CN(type1); int type2 = psrc2->type(), depth2 = CV_MAT_DEPTH(type2), cn2 = CV_MAT_CN(type2); int dims1 = psrc1->dims(), dims2 = psrc2->dims(); @@ -600,7 +600,7 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, void* usrdata=0, int oclop=-1 ) { const _InputArray *psrc1 = &_src1, *psrc2 = &_src2; - int kind1 = psrc1->kind(), kind2 = psrc2->kind(); + _InputArray::KindFlag kind1 = psrc1->kind(), kind2 = psrc2->kind(); bool haveMask = !_mask.empty(); bool reallocate = false; int type1 = psrc1->type(), depth1 = CV_MAT_DEPTH(type1), cn = CV_MAT_CN(type1); @@ -1214,7 +1214,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op) CV_OCL_RUN(_src1.dims() <= 2 && _src2.dims() <= 2 && OCL_PERFORMANCE_CHECK(_dst.isUMat()), ocl_compare(_src1, _src2, _dst, op, haveScalar)) - int kind1 = _src1.kind(), kind2 = _src2.kind(); + _InputArray::KindFlag kind1 = _src1.kind(), kind2 = _src2.kind(); Mat src1 = _src1.getMat(), src2 = _src2.getMat(); if( kind1 == kind2 && src1.dims <= 2 && src2.dims <= 2 && src1.size() == src2.size() && src1.type() == src2.type() ) @@ -1587,7 +1587,7 @@ static bool ocl_inRange( InputArray _src, InputArray _lowerb, InputArray _upperb, OutputArray _dst ) { const ocl::Device & d = ocl::Device::getDefault(); - int skind = _src.kind(), lkind = _lowerb.kind(), ukind = _upperb.kind(); + _InputArray::KindFlag skind = _src.kind(), lkind = _lowerb.kind(), ukind = _upperb.kind(); Size ssize = _src.size(), lsize = _lowerb.size(), usize = _upperb.size(); int stype = _src.type(), ltype = _lowerb.type(), utype = _upperb.type(); int sdepth = CV_MAT_DEPTH(stype), ldepth = CV_MAT_DEPTH(ltype), udepth = CV_MAT_DEPTH(utype); @@ -1712,7 +1712,7 @@ void cv::inRange(InputArray _src, InputArray _lowerb, _upperb.dims() <= 2 && OCL_PERFORMANCE_CHECK(_dst.isUMat()), ocl_inRange(_src, _lowerb, _upperb, _dst)) - int skind = _src.kind(), lkind = _lowerb.kind(), ukind = _upperb.kind(); + _InputArray::KindFlag skind = _src.kind(), lkind = _lowerb.kind(), ukind = _upperb.kind(); Mat src = _src.getMat(), lb = _lowerb.getMat(), ub = _upperb.getMat(); bool lbScalar = false, ubScalar = false; diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp index 6ef24d2cd0..3d55404e37 100644 --- a/modules/core/src/command_line_parser.cpp +++ b/modules/core/src/command_line_parser.cpp @@ -53,7 +53,7 @@ struct CommandLineParser::Impl }; -static const char* get_type_name(int type) +static const char* get_type_name(Param type) { if( type == Param::INT ) return "int"; @@ -81,7 +81,7 @@ static bool parse_bool(std::string str) return b; } -static void from_str(const String& str, int type, void* dst) +static void from_str(const String& str, Param type, void* dst) { std::stringstream ss(str.c_str()); if( type == Param::INT ) @@ -117,7 +117,7 @@ static void from_str(const String& str, int type, void* dst) } } -void CommandLineParser::getByName(const String& name, bool space_delete, int type, void* dst) const +void CommandLineParser::getByName(const String& name, bool space_delete, Param type, void* dst) const { CV_TRY { @@ -154,7 +154,7 @@ void CommandLineParser::getByName(const String& name, bool space_delete, int typ } -void CommandLineParser::getByIndex(int index, bool space_delete, int type, void* dst) const +void CommandLineParser::getByIndex(int index, bool space_delete, Param type, void* dst) const { CV_TRY { diff --git a/modules/core/src/cuda_host_mem.cpp b/modules/core/src/cuda_host_mem.cpp index 6a79320d7c..0c120f82f9 100644 --- a/modules/core/src/cuda_host_mem.cpp +++ b/modules/core/src/cuda_host_mem.cpp @@ -60,7 +60,7 @@ public: UMatData* allocate(int dims, const int* sizes, int type, void* data0, size_t* step, - int /*flags*/, UMatUsageFlags /*usageFlags*/) const CV_OVERRIDE + AccessFlag /*flags*/, UMatUsageFlags /*usageFlags*/) const CV_OVERRIDE { size_t total = CV_ELEM_SIZE(type); for (int i = dims-1; i >= 0; i--) @@ -100,7 +100,7 @@ public: return u; } - bool allocate(UMatData* u, int /*accessFlags*/, UMatUsageFlags /*usageFlags*/) const CV_OVERRIDE + bool allocate(UMatData* u, AccessFlag /*accessFlags*/, UMatUsageFlags /*usageFlags*/) const CV_OVERRIDE { return (u != NULL); } diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 5edf252c87..a353eee8c4 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -7,7 +7,7 @@ namespace cv { -void MatAllocator::map(UMatData*, int) const +void MatAllocator::map(UMatData*, AccessFlag) const { } @@ -127,7 +127,7 @@ class StdMatAllocator CV_FINAL : public MatAllocator { public: UMatData* allocate(int dims, const int* sizes, int type, - void* data0, size_t* step, int /*flags*/, UMatUsageFlags /*usageFlags*/) const CV_OVERRIDE + void* data0, size_t* step, AccessFlag /*flags*/, UMatUsageFlags /*usageFlags*/) const CV_OVERRIDE { size_t total = CV_ELEM_SIZE(type); for( int i = dims-1; i >= 0; i-- ) @@ -154,7 +154,7 @@ public: return u; } - bool allocate(UMatData* u, int /*accessFlags*/, UMatUsageFlags /*usageFlags*/) const CV_OVERRIDE + bool allocate(UMatData* u, AccessFlag /*accessFlags*/, UMatUsageFlags /*usageFlags*/) const CV_OVERRIDE { if(!u) return false; return true; @@ -357,13 +357,13 @@ void Mat::create(int d, const int* _sizes, int _type) a = a0; CV_TRY { - u = a->allocate(dims, size, _type, 0, step.p, 0, USAGE_DEFAULT); + u = a->allocate(dims, size, _type, 0, step.p, ACCESS_RW /* ignored */, USAGE_DEFAULT); CV_Assert(u != 0); } CV_CATCH_ALL { if(a != a0) - u = a0->allocate(dims, size, _type, 0, step.p, 0, USAGE_DEFAULT); + u = a0->allocate(dims, size, _type, 0, step.p, ACCESS_RW /* ignored */, USAGE_DEFAULT); CV_Assert(u != 0); } CV_Assert( step[dims-1] == (size_t)CV_ELEM_SIZE(flags) ); diff --git a/modules/core/src/matrix_wrap.cpp b/modules/core/src/matrix_wrap.cpp index e64d097aad..5ee7ab3696 100644 --- a/modules/core/src/matrix_wrap.cpp +++ b/modules/core/src/matrix_wrap.cpp @@ -14,8 +14,8 @@ namespace cv { Mat _InputArray::getMat_(int i) const { - int k = kind(); - int accessFlags = flags & ACCESS_MASK; + _InputArray::KindFlag k = kind(); + AccessFlag accessFlags = flags & ACCESS_MASK; if( k == MAT ) { @@ -132,8 +132,8 @@ Mat _InputArray::getMat_(int i) const UMat _InputArray::getUMat(int i) const { - int k = kind(); - int accessFlags = flags & ACCESS_MASK; + _InputArray::KindFlag k = kind(); + AccessFlag accessFlags = flags & ACCESS_MASK; if( k == UMAT ) { @@ -164,8 +164,8 @@ UMat _InputArray::getUMat(int i) const void _InputArray::getMatVector(std::vector& mv) const { - int k = kind(); - int accessFlags = flags & ACCESS_MASK; + _InputArray::KindFlag k = kind(); + AccessFlag accessFlags = flags & ACCESS_MASK; if( k == MAT ) { @@ -272,8 +272,8 @@ void _InputArray::getMatVector(std::vector& mv) const void _InputArray::getUMatVector(std::vector& umv) const { - int k = kind(); - int accessFlags = flags & ACCESS_MASK; + _InputArray::KindFlag k = kind(); + AccessFlag accessFlags = flags & ACCESS_MASK; if( k == NONE ) { @@ -334,7 +334,7 @@ void _InputArray::getUMatVector(std::vector& umv) const cuda::GpuMat _InputArray::getGpuMat() const { - int k = kind(); + _InputArray::KindFlag k = kind(); if (k == CUDA_GPU_MAT) { @@ -360,7 +360,7 @@ cuda::GpuMat _InputArray::getGpuMat() const } void _InputArray::getGpuMatVector(std::vector& gpumv) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if (k == STD_VECTOR_CUDA_GPU_MAT) { gpumv = *(std::vector*)obj; @@ -368,7 +368,7 @@ void _InputArray::getGpuMatVector(std::vector& gpumv) const } ogl::Buffer _InputArray::getOGlBuffer() const { - int k = kind(); + _InputArray::KindFlag k = kind(); CV_Assert(k == OPENGL_BUFFER); @@ -376,7 +376,7 @@ ogl::Buffer _InputArray::getOGlBuffer() const return *gl_buf; } -int _InputArray::kind() const +_InputArray::KindFlag _InputArray::kind() const { return flags & KIND_MASK; } @@ -393,7 +393,7 @@ int _InputArray::cols(int i) const Size _InputArray::size(int i) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT ) { @@ -515,7 +515,8 @@ Size _InputArray::size(int i) const int _InputArray::sizend(int* arrsz, int i) const { - int j, d=0, k = kind(); + int j, d = 0; + _InputArray::KindFlag k = kind(); if( k == NONE ) ; @@ -583,7 +584,7 @@ int _InputArray::sizend(int* arrsz, int i) const bool _InputArray::sameSize(const _InputArray& arr) const { - int k1 = kind(), k2 = arr.kind(); + _InputArray::KindFlag k1 = kind(), k2 = arr.kind(); Size sz1; if( k1 == MAT ) @@ -617,7 +618,7 @@ bool _InputArray::sameSize(const _InputArray& arr) const int _InputArray::dims(int i) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT ) { @@ -714,7 +715,7 @@ int _InputArray::dims(int i) const size_t _InputArray::total(int i) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT ) { @@ -763,7 +764,7 @@ size_t _InputArray::total(int i) const int _InputArray::type(int i) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT ) return ((const Mat*)obj)->type(); @@ -852,7 +853,7 @@ int _InputArray::channels(int i) const bool _InputArray::empty() const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT ) return ((const Mat*)obj)->empty(); @@ -924,7 +925,7 @@ bool _InputArray::empty() const bool _InputArray::isContinuous(int i) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT ) return i < 0 ? ((const Mat*)obj)->isContinuous() : true; @@ -965,7 +966,7 @@ bool _InputArray::isContinuous(int i) const bool _InputArray::isSubmatrix(int i) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT ) return i < 0 ? ((const Mat*)obj)->isSubmatrix() : false; @@ -1003,7 +1004,7 @@ bool _InputArray::isSubmatrix(int i) const size_t _InputArray::offset(int i) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT ) { @@ -1067,7 +1068,7 @@ size_t _InputArray::offset(int i) const size_t _InputArray::step(int i) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT ) { @@ -1127,7 +1128,7 @@ size_t _InputArray::step(int i) const void _InputArray::copyTo(const _OutputArray& arr) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == NONE ) arr.release(); @@ -1156,7 +1157,7 @@ void _InputArray::copyTo(const _OutputArray& arr) const void _InputArray::copyTo(const _OutputArray& arr, const _InputArray & mask) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == NONE ) arr.release(); @@ -1185,9 +1186,9 @@ bool _OutputArray::fixedType() const return (flags & FIXED_TYPE) == FIXED_TYPE; } -void _OutputArray::create(Size _sz, int mtype, int i, bool allowTransposed, int fixedDepthMask) const +void _OutputArray::create(Size _sz, int mtype, int i, bool allowTransposed, _OutputArray::DepthMask fixedDepthMask) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT && i < 0 && !allowTransposed && fixedDepthMask == 0 ) { CV_Assert(!fixedSize() || ((Mat*)obj)->size.operator()() == _sz); @@ -1227,9 +1228,9 @@ void _OutputArray::create(Size _sz, int mtype, int i, bool allowTransposed, int create(2, sizes, mtype, i, allowTransposed, fixedDepthMask); } -void _OutputArray::create(int _rows, int _cols, int mtype, int i, bool allowTransposed, int fixedDepthMask) const +void _OutputArray::create(int _rows, int _cols, int mtype, int i, bool allowTransposed, _OutputArray::DepthMask fixedDepthMask) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT && i < 0 && !allowTransposed && fixedDepthMask == 0 ) { CV_Assert(!fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows)); @@ -1270,7 +1271,7 @@ void _OutputArray::create(int _rows, int _cols, int mtype, int i, bool allowTran } void _OutputArray::create(int d, const int* sizes, int mtype, int i, - bool allowTransposed, int fixedDepthMask) const + bool allowTransposed, _OutputArray::DepthMask fixedDepthMask) const { int sizebuf[2]; if(d == 1) @@ -1280,7 +1281,7 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i, sizebuf[1] = 1; sizes = sizebuf; } - int k = kind(); + _InputArray::KindFlag k = kind(); mtype = CV_MAT_TYPE(mtype); if( k == MAT ) @@ -1667,7 +1668,7 @@ void _OutputArray::release() const { CV_Assert(!fixedSize()); - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT ) { @@ -1735,7 +1736,7 @@ void _OutputArray::release() const void _OutputArray::clear() const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == MAT ) { @@ -1754,7 +1755,7 @@ bool _OutputArray::needed() const Mat& _OutputArray::getMatRef(int i) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( i < 0 ) { CV_Assert( k == MAT ); @@ -1779,7 +1780,7 @@ Mat& _OutputArray::getMatRef(int i) const UMat& _OutputArray::getUMatRef(int i) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( i < 0 ) { CV_Assert( k == UMAT ); @@ -1796,34 +1797,34 @@ UMat& _OutputArray::getUMatRef(int i) const cuda::GpuMat& _OutputArray::getGpuMatRef() const { - int k = kind(); + _InputArray::KindFlag k = kind(); CV_Assert( k == CUDA_GPU_MAT ); return *(cuda::GpuMat*)obj; } std::vector& _OutputArray::getGpuMatVecRef() const { - int k = kind(); + _InputArray::KindFlag k = kind(); CV_Assert(k == STD_VECTOR_CUDA_GPU_MAT); return *(std::vector*)obj; } ogl::Buffer& _OutputArray::getOGlBufferRef() const { - int k = kind(); + _InputArray::KindFlag k = kind(); CV_Assert( k == OPENGL_BUFFER ); return *(ogl::Buffer*)obj; } cuda::HostMem& _OutputArray::getHostMemRef() const { - int k = kind(); + _InputArray::KindFlag k = kind(); CV_Assert( k == CUDA_HOST_MEM ); return *(cuda::HostMem*)obj; } void _OutputArray::setTo(const _InputArray& arr, const _InputArray & mask) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if( k == NONE ) ; @@ -1847,7 +1848,7 @@ void _OutputArray::setTo(const _InputArray& arr, const _InputArray & mask) const void _OutputArray::assign(const UMat& u) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if (k == UMAT) { *(UMat*)obj = u; @@ -1869,7 +1870,7 @@ void _OutputArray::assign(const UMat& u) const void _OutputArray::assign(const Mat& m) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if (k == UMAT) { m.copyTo(*(UMat*)obj); // TODO check m.getUMat() @@ -1891,7 +1892,7 @@ void _OutputArray::assign(const Mat& m) const void _OutputArray::assign(const std::vector& v) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if (k == STD_VECTOR_UMAT) { std::vector& this_v = *(std::vector*)obj; @@ -1929,7 +1930,7 @@ void _OutputArray::assign(const std::vector& v) const void _OutputArray::assign(const std::vector& v) const { - int k = kind(); + _InputArray::KindFlag k = kind(); if (k == STD_VECTOR_UMAT) { std::vector& this_v = *(std::vector*)obj; diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 9bf02a1bb6..50dd13b533 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -2972,8 +2972,8 @@ int Kernel::set(int i, const KernelArg& arg) cl_int status = 0; if( arg.m ) { - int accessFlags = ((arg.flags & KernelArg::READ_ONLY) ? ACCESS_READ : 0) + - ((arg.flags & KernelArg::WRITE_ONLY) ? ACCESS_WRITE : 0); + AccessFlag accessFlags = ((arg.flags & KernelArg::READ_ONLY) ? ACCESS_READ : static_cast(0)) | + ((arg.flags & KernelArg::WRITE_ONLY) ? ACCESS_WRITE : static_cast(0)); bool ptronly = (arg.flags & KernelArg::PTR_ONLY) != 0; cl_mem h = (cl_mem)arg.m->handle(accessFlags); @@ -3050,7 +3050,7 @@ int Kernel::set(int i, const KernelArg& arg) i += 3; } } - p->addUMat(*arg.m, (accessFlags & ACCESS_WRITE) != 0); + p->addUMat(*arg.m, !!(accessFlags & ACCESS_WRITE)); return i; } status = clSetKernelArg(p->handle, (cl_uint)i, arg.sz, arg.obj); @@ -4516,13 +4516,13 @@ public: } UMatData* defaultAllocate(int dims, const int* sizes, int type, void* data, size_t* step, - int flags, UMatUsageFlags usageFlags) const + AccessFlag flags, UMatUsageFlags usageFlags) const { UMatData* u = matStdAllocator->allocate(dims, sizes, type, data, step, flags, usageFlags); return u; } - void getBestFlags(const Context& ctx, int /*flags*/, UMatUsageFlags usageFlags, int& createFlags, int& flags0) const + void getBestFlags(const Context& ctx, AccessFlag /*flags*/, UMatUsageFlags usageFlags, int& createFlags, UMatData::MemoryFlag& flags0) const { const Device& dev = ctx.device(0); createFlags = 0; @@ -4530,13 +4530,13 @@ public: createFlags |= CL_MEM_ALLOC_HOST_PTR; if( dev.hostUnifiedMemory() ) - flags0 = 0; + flags0 = static_cast(0); else flags0 = UMatData::COPY_ON_MAP; } UMatData* allocate(int dims, const int* sizes, int type, - void* data, size_t* step, int flags, UMatUsageFlags usageFlags) const CV_OVERRIDE + void* data, size_t* step, AccessFlag flags, UMatUsageFlags usageFlags) const CV_OVERRIDE { if(!useOpenCL()) return defaultAllocate(dims, sizes, type, data, step, flags, usageFlags); @@ -4552,7 +4552,8 @@ public: Context& ctx = Context::getDefault(); flushCleanupQueue(); - int createFlags = 0, flags0 = 0; + int createFlags = 0; + UMatData::MemoryFlag flags0 = static_cast(0); getBestFlags(ctx, flags, usageFlags, createFlags, flags0); void* handle = NULL; @@ -4600,7 +4601,7 @@ public: return u; } - bool allocate(UMatData* u, int accessFlags, UMatUsageFlags usageFlags) const CV_OVERRIDE + bool allocate(UMatData* u, AccessFlag accessFlags, UMatUsageFlags usageFlags) const CV_OVERRIDE { if(!u) return false; @@ -4613,12 +4614,13 @@ public: { CV_Assert(u->origdata != 0); Context& ctx = Context::getDefault(); - int createFlags = 0, flags0 = 0; + int createFlags = 0; + UMatData::MemoryFlag flags0 = static_cast(0); getBestFlags(ctx, accessFlags, usageFlags, createFlags, flags0); cl_context ctx_handle = (cl_context)ctx.ptr(); int allocatorFlags = 0; - int tempUMatFlags = 0; + UMatData::MemoryFlag tempUMatFlags = static_cast(0); void* handle = NULL; cl_int retval = CL_SUCCESS; @@ -4703,7 +4705,7 @@ public: u->flags |= tempUMatFlags; u->allocatorFlags_ = allocatorFlags; } - if(accessFlags & ACCESS_WRITE) + if (!!(accessFlags & ACCESS_WRITE)) u->markHostCopyObsolete(true); return true; } @@ -4749,7 +4751,7 @@ public: CV_Assert(u->handle != 0); CV_Assert(u->mapcount == 0); - if (u->flags & UMatData::ASYNC_CLEANUP) + if (!!(u->flags & UMatData::ASYNC_CLEANUP)) addToCleanupQueue(u); else deallocate_(u); @@ -4924,11 +4926,11 @@ public: } // synchronized call (external UMatDataAutoLock, see UMat::getMat) - void map(UMatData* u, int accessFlags) const CV_OVERRIDE + void map(UMatData* u, AccessFlag accessFlags) const CV_OVERRIDE { CV_Assert(u && u->handle); - if(accessFlags & ACCESS_WRITE) + if (!!(accessFlags & ACCESS_WRITE)) u->markDeviceCopyObsolete(true); cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr(); @@ -4995,7 +4997,7 @@ public: } } - if( (accessFlags & ACCESS_READ) != 0 && u->hostCopyObsolete() ) + if (!!(accessFlags & ACCESS_READ) && u->hostCopyObsolete()) { AlignedDataPtr alignedPtr(u->data, u->size, CV_OPENCL_DATA_PTR_ALIGNMENT); #ifdef HAVE_OPENCL_SVM @@ -5735,7 +5737,7 @@ void convertFromBuffer(void* cl_mem_buffer, size_t step, int rows, int cols, int dst.u = new UMatData(getOpenCLAllocator()); dst.u->data = 0; dst.u->allocatorFlags_ = 0; // not allocated from any OpenCV buffer pool - dst.u->flags = 0; + dst.u->flags = static_cast(0); dst.u->handle = cl_mem_buffer; dst.u->origdata = 0; dst.u->prevAllocator = 0; diff --git a/modules/core/src/opengl.cpp b/modules/core/src/opengl.cpp index 3b05636363..dc122f2fd7 100644 --- a/modules/core/src/opengl.cpp +++ b/modules/core/src/opengl.cpp @@ -1804,8 +1804,8 @@ void convertFromGLTexture2D(const Texture2D& texture, OutputArray dst) #endif } -//void mapGLBuffer(const Buffer& buffer, UMat& dst, int accessFlags) -UMat mapGLBuffer(const Buffer& buffer, int accessFlags) +//void mapGLBuffer(const Buffer& buffer, UMat& dst, AccessFlag accessFlags) +UMat mapGLBuffer(const Buffer& buffer, AccessFlag accessFlags) { CV_UNUSED(buffer); CV_UNUSED(accessFlags); #if !defined(HAVE_OPENGL) diff --git a/modules/core/src/out.cpp b/modules/core/src/out.cpp index 89770fe33f..aad8429e2d 100644 --- a/modules/core/src/out.cpp +++ b/modules/core/src/out.cpp @@ -372,7 +372,7 @@ namespace cv Formatted::~Formatted() {} Formatter::~Formatter() {} - Ptr Formatter::get(int fmt) + Ptr Formatter::get(Formatter::FormatType fmt) { switch(fmt) { diff --git a/modules/core/src/precomp.hpp b/modules/core/src/precomp.hpp index a7d901d806..796edb98ec 100644 --- a/modules/core/src/precomp.hpp +++ b/modules/core/src/precomp.hpp @@ -210,7 +210,7 @@ enum { BLOCK_SIZE = 1024 }; #define ARITHM_USE_IPP 0 #endif -inline bool checkScalar(const Mat& sc, int atype, int sckind, int akind) +inline bool checkScalar(const Mat& sc, int atype, _InputArray::KindFlag sckind, _InputArray::KindFlag akind) { if( sc.dims > 2 || !sc.isContinuous() ) return false; @@ -224,7 +224,7 @@ inline bool checkScalar(const Mat& sc, int atype, int sckind, int akind) (sz == Size(1, 4) && sc.type() == CV_64F && cn <= 4); } -inline bool checkScalar(InputArray sc, int atype, int sckind, int akind) +inline bool checkScalar(InputArray sc, int atype, _InputArray::KindFlag sckind, _InputArray::KindFlag akind) { if( sc.dims() > 2 || !sc.isContinuous() ) return false; diff --git a/modules/core/src/umatrix.cpp b/modules/core/src/umatrix.cpp index 27d587b186..5e60d2c1ba 100644 --- a/modules/core/src/umatrix.cpp +++ b/modules/core/src/umatrix.cpp @@ -64,7 +64,7 @@ UMatData::UMatData(const MatAllocator* allocator) urefcount = refcount = mapcount = 0; data = origdata = 0; size = 0; - flags = 0; + flags = static_cast(0); handle = 0; userdata = 0; allocatorFlags_ = 0; @@ -78,7 +78,7 @@ UMatData::~UMatData() CV_Assert(mapcount == 0); data = origdata = 0; size = 0; - flags = 0; + flags = static_cast(0); handle = 0; userdata = 0; allocatorFlags_ = 0; @@ -333,7 +333,7 @@ void finalizeHdr(UMat& m) } -UMat Mat::getUMat(int accessFlags, UMatUsageFlags usageFlags) const +UMat Mat::getUMat(AccessFlag accessFlags, UMatUsageFlags usageFlags) const { UMat hdr; if(!data) @@ -444,13 +444,13 @@ void UMat::create(int d, const int* _sizes, int _type, UMatUsageFlags _usageFlag } CV_TRY { - u = a->allocate(dims, size, _type, 0, step.p, 0, usageFlags); + u = a->allocate(dims, size, _type, 0, step.p, ACCESS_RW /* ignored */, usageFlags); CV_Assert(u != 0); } CV_CATCH_ALL { if(a != a0) - u = a0->allocate(dims, size, _type, 0, step.p, 0, usageFlags); + u = a0->allocate(dims, size, _type, 0, step.p, ACCESS_RW /* ignored */, usageFlags); CV_Assert(u != 0); } CV_Assert( step[dims-1] == (size_t)CV_ELEM_SIZE(flags) ); @@ -813,7 +813,7 @@ UMat UMat::reshape(int _cn, int _newndims, const int* _newsz) const CV_Error(CV_StsNotImplemented, "Reshaping of n-dimensional non-continuous matrices is not supported yet"); } -Mat UMat::getMat(int accessFlags) const +Mat UMat::getMat(AccessFlag accessFlags) const { if(!u) return Mat(); @@ -840,7 +840,7 @@ Mat UMat::getMat(int accessFlags) const } } -void* UMat::handle(int accessFlags) const +void* UMat::handle(AccessFlag accessFlags) const { if( !u ) return 0; @@ -852,7 +852,7 @@ void* UMat::handle(int accessFlags) const u->currAllocator->unmap(u); } - if ((accessFlags & ACCESS_WRITE) != 0) + if (!!(accessFlags & ACCESS_WRITE)) u->markHostCopyObsolete(true); return u->handle; diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index dab8373d5e..32b83d431b 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -946,7 +946,7 @@ void Core_ArrayOpTest::run( int /* start_from */) } -template +template int calcDiffElemCountImpl(const vector& mv, const Mat& m) { int diffElemCount = 0; @@ -955,12 +955,12 @@ int calcDiffElemCountImpl(const vector& mv, const Mat& m) { for(int x = 0; x < m.cols; x++) { - const ElemType* mElem = &m.at(y,x*mChannels); + const T* mElem = &m.at(y, x*mChannels); size_t loc = 0; for(size_t i = 0; i < mv.size(); i++) { const size_t mvChannel = mv[i].channels(); - const ElemType* mvElem = &mv[i].at(y,x*(int)mvChannel); + const T* mvElem = &mv[i].at(y, x*(int)mvChannel); for(size_t li = 0; li < mvChannel; li++) if(mElem[loc + li] != mvElem[li]) diffElemCount++; diff --git a/modules/dnn/include/opencv2/dnn/dict.hpp b/modules/dnn/include/opencv2/dnn/dict.hpp index eb069f743d..72ae5e3a15 100644 --- a/modules/dnn/include/opencv2/dnn/dict.hpp +++ b/modules/dnn/include/opencv2/dnn/dict.hpp @@ -95,7 +95,7 @@ struct CV_EXPORTS_W DictValue private: - int type; + Param type; union { @@ -105,7 +105,7 @@ private: void *pv; }; - DictValue(int _type, void *_p) : type(_type), pv(_p) {} + DictValue(Param _type, void *_p) : type(_type), pv(_p) {} void release(); }; diff --git a/modules/dnn/include/opencv2/dnn/dnn.inl.hpp b/modules/dnn/include/opencv2/dnn/dnn.inl.hpp index 8982db4530..d6809ce3fd 100644 --- a/modules/dnn/include/opencv2/dnn/dnn.inl.hpp +++ b/modules/dnn/include/opencv2/dnn/dnn.inl.hpp @@ -199,6 +199,16 @@ inline void DictValue::release() case Param::REAL: delete pd; break; + case Param::BOOLEAN: + case Param::MAT: + case Param::MAT_VECTOR: + case Param::ALGORITHM: + case Param::FLOAT: + case Param::UNSIGNED_INT: + case Param::UINT64: + case Param::UCHAR: + case Param::SCALAR: + break; // unhandled } } @@ -273,8 +283,18 @@ inline int DictValue::size() const return (int)ps->size(); case Param::REAL: return (int)pd->size(); + case Param::BOOLEAN: + case Param::MAT: + case Param::MAT_VECTOR: + case Param::ALGORITHM: + case Param::FLOAT: + case Param::UNSIGNED_INT: + case Param::UINT64: + case Param::UCHAR: + case Param::SCALAR: + break; // unhandled } - CV_Error(Error::StsInternal, ""); + CV_Error_(Error::StsInternal, ("Unhandled type (%d)", static_cast(type))); } inline std::ostream &operator<<(std::ostream &stream, const DictValue &dictv) diff --git a/modules/features2d/include/opencv2/features2d.hpp b/modules/features2d/include/opencv2/features2d.hpp index 1ba4f0da26..254a82f40c 100644 --- a/modules/features2d/include/opencv2/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d.hpp @@ -293,7 +293,8 @@ k-tuples) are rotated according to the measured orientation). class CV_EXPORTS_W ORB : public Feature2D { public: - enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 }; + enum ScoreType { HARRIS_SCORE=0, FAST_SCORE=1 }; + static const int kBytes = 32; /** @brief The ORB constructor @@ -327,7 +328,7 @@ public: @param fastThreshold */ CV_WRAP static Ptr create(int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31, - int firstLevel=0, int WTA_K=2, int scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20); + int firstLevel=0, int WTA_K=2, ORB::ScoreType scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20); CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0; CV_WRAP virtual int getMaxFeatures() const = 0; @@ -347,8 +348,8 @@ public: CV_WRAP virtual void setWTA_K(int wta_k) = 0; CV_WRAP virtual int getWTA_K() const = 0; - CV_WRAP virtual void setScoreType(int scoreType) = 0; - CV_WRAP virtual int getScoreType() const = 0; + CV_WRAP virtual void setScoreType(ORB::ScoreType scoreType) = 0; + CV_WRAP virtual ORB::ScoreType getScoreType() const = 0; CV_WRAP virtual void setPatchSize(int patchSize) = 0; CV_WRAP virtual int getPatchSize() const = 0; @@ -418,6 +419,41 @@ public: CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; }; +//! @} features2d_main + +//! @addtogroup features2d_main +//! @{ + +/** @brief Wrapping class for feature detection using the FAST method. : + */ +class CV_EXPORTS_W FastFeatureDetector : public Feature2D +{ +public: + enum DetectorType + { + TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2 + }; + enum + { + THRESHOLD = 10000, NONMAX_SUPPRESSION=10001, FAST_N=10002 + }; + + + CV_WRAP static Ptr create( int threshold=10, + bool nonmaxSuppression=true, + FastFeatureDetector::DetectorType type=FastFeatureDetector::TYPE_9_16 ); + + CV_WRAP virtual void setThreshold(int threshold) = 0; + CV_WRAP virtual int getThreshold() const = 0; + + CV_WRAP virtual void setNonmaxSuppression(bool f) = 0; + CV_WRAP virtual bool getNonmaxSuppression() const = 0; + + CV_WRAP virtual void setType(FastFeatureDetector::DetectorType type) = 0; + CV_WRAP virtual FastFeatureDetector::DetectorType getType() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + /** @overload */ CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector& keypoints, int threshold, bool nonmaxSuppression=true ); @@ -441,27 +477,31 @@ cv2.FAST_FEATURE_DETECTOR_TYPE_7_12 and cv2.FAST_FEATURE_DETECTOR_TYPE_9_16. For detection, use cv2.FAST.detect() method. */ CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector& keypoints, - int threshold, bool nonmaxSuppression, int type ); + int threshold, bool nonmaxSuppression, FastFeatureDetector::DetectorType type ); //! @} features2d_main //! @addtogroup features2d_main //! @{ -/** @brief Wrapping class for feature detection using the FAST method. : +/** @brief Wrapping class for feature detection using the AGAST method. : */ -class CV_EXPORTS_W FastFeatureDetector : public Feature2D +class CV_EXPORTS_W AgastFeatureDetector : public Feature2D { public: + enum DetectorType + { + AGAST_5_8 = 0, AGAST_7_12d = 1, AGAST_7_12s = 2, OAST_9_16 = 3, + }; + enum { - TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2, - THRESHOLD = 10000, NONMAX_SUPPRESSION=10001, FAST_N=10002, + THRESHOLD = 10000, NONMAX_SUPPRESSION = 10001, }; - CV_WRAP static Ptr create( int threshold=10, - bool nonmaxSuppression=true, - int type=FastFeatureDetector::TYPE_9_16 ); + CV_WRAP static Ptr create( int threshold=10, + bool nonmaxSuppression=true, + AgastFeatureDetector::DetectorType type = AgastFeatureDetector::OAST_9_16); CV_WRAP virtual void setThreshold(int threshold) = 0; CV_WRAP virtual int getThreshold() const = 0; @@ -469,8 +509,8 @@ public: CV_WRAP virtual void setNonmaxSuppression(bool f) = 0; CV_WRAP virtual bool getNonmaxSuppression() const = 0; - CV_WRAP virtual void setType(int type) = 0; - CV_WRAP virtual int getType() const = 0; + CV_WRAP virtual void setType(AgastFeatureDetector::DetectorType type) = 0; + CV_WRAP virtual AgastFeatureDetector::DetectorType getType() const = 0; CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; }; @@ -497,37 +537,7 @@ Detects corners using the AGAST algorithm by @cite mair2010_agast . */ CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector& keypoints, - int threshold, bool nonmaxSuppression, int type ); -//! @} features2d_main - -//! @addtogroup features2d_main -//! @{ - -/** @brief Wrapping class for feature detection using the AGAST method. : - */ -class CV_EXPORTS_W AgastFeatureDetector : public Feature2D -{ -public: - enum - { - AGAST_5_8 = 0, AGAST_7_12d = 1, AGAST_7_12s = 2, OAST_9_16 = 3, - THRESHOLD = 10000, NONMAX_SUPPRESSION = 10001, - }; - - CV_WRAP static Ptr create( int threshold=10, - bool nonmaxSuppression=true, - int type=AgastFeatureDetector::OAST_9_16 ); - - CV_WRAP virtual void setThreshold(int threshold) = 0; - CV_WRAP virtual int getThreshold() const = 0; - - CV_WRAP virtual void setNonmaxSuppression(bool f) = 0; - CV_WRAP virtual bool getNonmaxSuppression() const = 0; - - CV_WRAP virtual void setType(int type) = 0; - CV_WRAP virtual int getType() const = 0; - CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; -}; + int threshold, bool nonmaxSuppression, AgastFeatureDetector::DetectorType type ); /** @brief Wrapping class for feature detection using the goodFeaturesToTrack function. : */ @@ -639,7 +649,7 @@ F. Alcantarilla, Adrien Bartoli and Andrew J. Davison. In European Conference on class CV_EXPORTS_W KAZE : public Feature2D { public: - enum + enum DiffusivityType { DIFF_PM_G1 = 0, DIFF_PM_G2 = 1, @@ -660,7 +670,7 @@ public: CV_WRAP static Ptr create(bool extended=false, bool upright=false, float threshold = 0.001f, int nOctaves = 4, int nOctaveLayers = 4, - int diffusivity = KAZE::DIFF_PM_G2); + KAZE::DiffusivityType diffusivity = KAZE::DIFF_PM_G2); CV_WRAP virtual void setExtended(bool extended) = 0; CV_WRAP virtual bool getExtended() const = 0; @@ -677,8 +687,8 @@ public: CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0; CV_WRAP virtual int getNOctaveLayers() const = 0; - CV_WRAP virtual void setDiffusivity(int diff) = 0; - CV_WRAP virtual int getDiffusivity() const = 0; + CV_WRAP virtual void setDiffusivity(KAZE::DiffusivityType diff) = 0; + CV_WRAP virtual KAZE::DiffusivityType getDiffusivity() const = 0; CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; }; @@ -702,7 +712,7 @@ class CV_EXPORTS_W AKAZE : public Feature2D { public: // AKAZE descriptor type - enum + enum DescriptorType { DESCRIPTOR_KAZE_UPRIGHT = 2, ///< Upright descriptors, not invariant to rotation DESCRIPTOR_KAZE = 3, @@ -722,13 +732,13 @@ public: @param diffusivity Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or DIFF_CHARBONNIER */ - CV_WRAP static Ptr create(int descriptor_type=AKAZE::DESCRIPTOR_MLDB, + CV_WRAP static Ptr create(AKAZE::DescriptorType 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); + int nOctaveLayers = 4, KAZE::DiffusivityType diffusivity = KAZE::DIFF_PM_G2); - CV_WRAP virtual void setDescriptorType(int dtype) = 0; - CV_WRAP virtual int getDescriptorType() const = 0; + CV_WRAP virtual void setDescriptorType(AKAZE::DescriptorType dtype) = 0; + CV_WRAP virtual AKAZE::DescriptorType getDescriptorType() const = 0; CV_WRAP virtual void setDescriptorSize(int dsize) = 0; CV_WRAP virtual int getDescriptorSize() const = 0; @@ -745,8 +755,8 @@ public: CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0; CV_WRAP virtual int getNOctaveLayers() const = 0; - CV_WRAP virtual void setDiffusivity(int diff) = 0; - CV_WRAP virtual int getDiffusivity() const = 0; + CV_WRAP virtual void setDiffusivity(KAZE::DiffusivityType diff) = 0; + CV_WRAP virtual KAZE::DiffusivityType getDiffusivity() const = 0; CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; }; @@ -773,7 +783,7 @@ template<> struct Accumulator { typedef float Type; }; template struct CV_EXPORTS SL2 { - enum { normType = NORM_L2SQR }; + static const NormTypes normType = NORM_L2SQR; typedef T ValueType; typedef typename Accumulator::Type ResultType; @@ -789,7 +799,7 @@ struct CV_EXPORTS SL2 template struct L2 { - enum { normType = NORM_L2 }; + static const NormTypes normType = NORM_L2; typedef T ValueType; typedef typename Accumulator::Type ResultType; @@ -805,7 +815,7 @@ struct L2 template struct L1 { - enum { normType = NORM_L1 }; + static const NormTypes normType = NORM_L1; typedef T ValueType; typedef typename Accumulator::Type ResultType; @@ -830,7 +840,7 @@ an image set. class CV_EXPORTS_W DescriptorMatcher : public Algorithm { public: - enum + enum MatcherType { FLANNBASED = 1, BRUTEFORCE = 2, @@ -839,6 +849,7 @@ public: BRUTEFORCE_HAMMINGLUT = 5, BRUTEFORCE_SL2 = 6 }; + virtual ~DescriptorMatcher(); /** @brief Adds descriptors to train a CPU(trainDescCollectionis) or GPU(utrainDescCollectionis) descriptor @@ -1016,7 +1027,7 @@ public: */ CV_WRAP static Ptr create( const String& descriptorMatcherType ); - CV_WRAP static Ptr create( int matcherType ); + CV_WRAP static Ptr create( const DescriptorMatcher::MatcherType& matcherType ); // see corresponding cv::Algorithm method @@ -1171,20 +1182,20 @@ protected: //! @addtogroup features2d_draw //! @{ -struct CV_EXPORTS DrawMatchesFlags +enum struct DrawMatchesFlags { - enum{ DEFAULT = 0, //!< Output image matrix will be created (Mat::create), - //!< i.e. existing memory of output image may be reused. - //!< Two source image, matches and single keypoints will be drawn. - //!< For each keypoint only the center point will be drawn (without - //!< the circle around keypoint with keypoint size and orientation). - DRAW_OVER_OUTIMG = 1, //!< Output image matrix will not be created (Mat::create). - //!< Matches will be drawn on existing content of output image. - NOT_DRAW_SINGLE_POINTS = 2, //!< Single keypoints will not be drawn. - DRAW_RICH_KEYPOINTS = 4 //!< For each keypoint the circle around keypoint with keypoint size and - //!< orientation will be drawn. - }; + DEFAULT = 0, //!< Output image matrix will be created (Mat::create), + //!< i.e. existing memory of output image may be reused. + //!< Two source image, matches and single keypoints will be drawn. + //!< For each keypoint only the center point will be drawn (without + //!< the circle around keypoint with keypoint size and orientation). + DRAW_OVER_OUTIMG = 1, //!< Output image matrix will not be created (Mat::create). + //!< Matches will be drawn on existing content of output image. + NOT_DRAW_SINGLE_POINTS = 2, //!< Single keypoints will not be drawn. + DRAW_RICH_KEYPOINTS = 4 //!< For each keypoint the circle around keypoint with keypoint size and + //!< orientation will be drawn. }; +CV_ENUM_FLAGS(DrawMatchesFlags); /** @brief Draws keypoints. @@ -1202,7 +1213,7 @@ cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS, cv2.DRAW_MATCHES_FLAGS_DRAW_OVER_OUT cv2.DRAW_MATCHES_FLAGS_NOT_DRAW_SINGLE_POINTS */ CV_EXPORTS_W void drawKeypoints( InputArray image, const std::vector& keypoints, InputOutputArray outImage, - const Scalar& color=Scalar::all(-1), int flags=DrawMatchesFlags::DEFAULT ); + const Scalar& color=Scalar::all(-1), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT ); /** @brief Draws the found matches of keypoints from two images. @@ -1230,14 +1241,14 @@ CV_EXPORTS_W void drawMatches( InputArray img1, const std::vector& key InputArray img2, const std::vector& keypoints2, const std::vector& matches1to2, InputOutputArray outImg, const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1), - const std::vector& matchesMask=std::vector(), int flags=DrawMatchesFlags::DEFAULT ); + const std::vector& matchesMask=std::vector(), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT ); /** @overload */ CV_EXPORTS_AS(drawMatchesKnn) void drawMatches( InputArray img1, const std::vector& keypoints1, InputArray img2, const std::vector& keypoints2, const std::vector >& matches1to2, InputOutputArray outImg, const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1), - const std::vector >& matchesMask=std::vector >(), int flags=DrawMatchesFlags::DEFAULT ); + const std::vector >& matchesMask=std::vector >(), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT ); //! @} features2d_draw diff --git a/modules/features2d/misc/python/pyopencv_features2d.hpp b/modules/features2d/misc/python/pyopencv_features2d.hpp index b865e361b6..ae43995eff 100644 --- a/modules/features2d/misc/python/pyopencv_features2d.hpp +++ b/modules/features2d/misc/python/pyopencv_features2d.hpp @@ -1,3 +1,24 @@ #ifdef HAVE_OPENCV_FEATURES2D typedef SimpleBlobDetector::Params SimpleBlobDetector_Params; +typedef AKAZE::DescriptorType AKAZE_DescriptorType; +typedef AgastFeatureDetector::DetectorType AgastFeatureDetector_DetectorType; +typedef FastFeatureDetector::DetectorType FastFeatureDetector_DetectorType; +typedef DescriptorMatcher::MatcherType DescriptorMatcher_MatcherType; +typedef KAZE::DiffusivityType KAZE_DiffusivityType; +typedef ORB::ScoreType ORB_ScoreType; + +CV_PY_FROM_ENUM(AKAZE::DescriptorType); +CV_PY_TO_ENUM(AKAZE::DescriptorType); +CV_PY_FROM_ENUM(AgastFeatureDetector::DetectorType); +CV_PY_TO_ENUM(AgastFeatureDetector::DetectorType); +CV_PY_FROM_ENUM(DrawMatchesFlags); +CV_PY_TO_ENUM(DrawMatchesFlags); +CV_PY_FROM_ENUM(FastFeatureDetector::DetectorType); +CV_PY_TO_ENUM(FastFeatureDetector::DetectorType); +CV_PY_FROM_ENUM(DescriptorMatcher::MatcherType); +CV_PY_TO_ENUM(DescriptorMatcher::MatcherType); +CV_PY_FROM_ENUM(KAZE::DiffusivityType); +CV_PY_TO_ENUM(KAZE::DiffusivityType); +CV_PY_FROM_ENUM(ORB::ScoreType); +CV_PY_TO_ENUM(ORB::ScoreType); #endif \ No newline at end of file diff --git a/modules/features2d/src/agast.cpp b/modules/features2d/src/agast.cpp index 507ed1b97a..e99ceec416 100644 --- a/modules/features2d/src/agast.cpp +++ b/modules/features2d/src/agast.cpp @@ -7446,7 +7446,7 @@ static void OAST_9_16(InputArray _img, std::vector& keypoints, int thr #else // !(defined __i386__ || defined(_M_IX86) || defined __x86_64__ || defined(_M_X64)) -static void AGAST_ALL(InputArray _img, std::vector& keypoints, int threshold, int agasttype) +static void AGAST_ALL(InputArray _img, std::vector& keypoints, int threshold, AgastFeatureDetector::DetectorType agasttype) { cv::Mat img; if(!_img.getMat().isContinuous()) @@ -7944,8 +7944,8 @@ void AGAST(InputArray _img, std::vector& keypoints, int threshold, boo class AgastFeatureDetector_Impl CV_FINAL : public AgastFeatureDetector { public: - AgastFeatureDetector_Impl( int _threshold, bool _nonmaxSuppression, int _type ) - : threshold(_threshold), nonmaxSuppression(_nonmaxSuppression), type((short)_type) + AgastFeatureDetector_Impl( int _threshold, bool _nonmaxSuppression, DetectorType _type ) + : threshold(_threshold), nonmaxSuppression(_nonmaxSuppression), type(_type) {} void detect( InputArray _image, std::vector& keypoints, InputArray _mask ) CV_OVERRIDE @@ -7998,20 +7998,20 @@ public: void setNonmaxSuppression(bool f) CV_OVERRIDE { nonmaxSuppression = f; } bool getNonmaxSuppression() const CV_OVERRIDE { return nonmaxSuppression; } - void setType(int type_) CV_OVERRIDE { type = type_; } - int getType() const CV_OVERRIDE { return type; } + void setType(DetectorType type_) CV_OVERRIDE{ type = type_; } + DetectorType getType() const CV_OVERRIDE{ return type; } int threshold; bool nonmaxSuppression; - int type; + DetectorType type; }; -Ptr AgastFeatureDetector::create( int threshold, bool nonmaxSuppression, int type ) +Ptr AgastFeatureDetector::create( int threshold, bool nonmaxSuppression, AgastFeatureDetector::DetectorType type ) { return makePtr(threshold, nonmaxSuppression, type); } -void AGAST(InputArray _img, std::vector& keypoints, int threshold, bool nonmax_suppression, int type) +void AGAST(InputArray _img, std::vector& keypoints, int threshold, bool nonmax_suppression, AgastFeatureDetector::DetectorType type) { CV_INSTRUMENT_REGION(); diff --git a/modules/features2d/src/agast_score.cpp b/modules/features2d/src/agast_score.cpp index 92a34a758e..ff40da4a81 100644 --- a/modules/features2d/src/agast_score.cpp +++ b/modules/features2d/src/agast_score.cpp @@ -47,7 +47,7 @@ The references are: namespace cv { -void makeAgastOffsets(int pixel[16], int rowStride, int type) +void makeAgastOffsets(int pixel[16], int rowStride, AgastFeatureDetector::DetectorType type) { static const int offsets16[][2] = { @@ -9400,7 +9400,7 @@ int agast_tree_search(const uint32_t table_struct32[], int pixel_[], const unsig } // universal pixel mask -int AGAST_ALL_SCORE(const uchar* ptr, const int pixel[], int threshold, int agasttype) +int AGAST_ALL_SCORE(const uchar* ptr, const int pixel[], int threshold, AgastFeatureDetector::DetectorType agasttype) { int bmin = threshold; int bmax = 255; diff --git a/modules/features2d/src/agast_score.hpp b/modules/features2d/src/agast_score.hpp index f7d668ba73..7f876466ec 100644 --- a/modules/features2d/src/agast_score.hpp +++ b/modules/features2d/src/agast_score.hpp @@ -54,13 +54,13 @@ namespace cv #if !(defined __i386__ || defined(_M_IX86) || defined __x86_64__ || defined(_M_X64)) int agast_tree_search(const uint32_t table_struct32[], int pixel_[], const unsigned char* const ptr, int threshold); -int AGAST_ALL_SCORE(const uchar* ptr, const int pixel[], int threshold, int agasttype); +int AGAST_ALL_SCORE(const uchar* ptr, const int pixel[], int threshold, AgastFeatureDetector::DetectorType agasttype); #endif //!(defined __i386__ || defined(_M_IX86) || defined __x86_64__ || defined(_M_X64)) -void makeAgastOffsets(int pixel[16], int row_stride, int type); +void makeAgastOffsets(int pixel[16], int row_stride, AgastFeatureDetector::DetectorType type); -template +template int agast_cornerScore(const uchar* ptr, const int pixel[], int threshold); diff --git a/modules/features2d/src/akaze.cpp b/modules/features2d/src/akaze.cpp index 49f3c2efa6..623738eed4 100644 --- a/modules/features2d/src/akaze.cpp +++ b/modules/features2d/src/akaze.cpp @@ -60,8 +60,8 @@ namespace cv class AKAZE_Impl : public AKAZE { public: - AKAZE_Impl(int _descriptor_type, int _descriptor_size, int _descriptor_channels, - float _threshold, int _octaves, int _sublevels, int _diffusivity) + AKAZE_Impl(DescriptorType _descriptor_type, int _descriptor_size, int _descriptor_channels, + float _threshold, int _octaves, int _sublevels, KAZE::DiffusivityType _diffusivity) : descriptor(_descriptor_type) , descriptor_channels(_descriptor_channels) , descriptor_size(_descriptor_size) @@ -77,8 +77,8 @@ namespace cv } - void setDescriptorType(int dtype) CV_OVERRIDE { descriptor = dtype; } - int getDescriptorType() const CV_OVERRIDE { return descriptor; } + void setDescriptorType(DescriptorType dtype) CV_OVERRIDE{ descriptor = dtype; } + DescriptorType getDescriptorType() const CV_OVERRIDE{ return descriptor; } void setDescriptorSize(int dsize) CV_OVERRIDE { descriptor_size = dsize; } int getDescriptorSize() const CV_OVERRIDE { return descriptor_size; } @@ -95,8 +95,8 @@ namespace cv void setNOctaveLayers(int octaveLayers_) CV_OVERRIDE { sublevels = octaveLayers_; } int getNOctaveLayers() const CV_OVERRIDE { return sublevels; } - void setDiffusivity(int diff_) CV_OVERRIDE { diffusivity = diff_; } - int getDiffusivity() const CV_OVERRIDE { return diffusivity; } + void setDiffusivity(KAZE::DiffusivityType diff_) CV_OVERRIDE{ diffusivity = diff_; } + KAZE::DiffusivityType getDiffusivity() const CV_OVERRIDE{ return diffusivity; } // returns the descriptor size in bytes int descriptorSize() const CV_OVERRIDE @@ -218,28 +218,28 @@ namespace cv void read(const FileNode& fn) CV_OVERRIDE { - descriptor = (int)fn["descriptor"]; + descriptor = static_cast((int)fn["descriptor"]); descriptor_channels = (int)fn["descriptor_channels"]; descriptor_size = (int)fn["descriptor_size"]; threshold = (float)fn["threshold"]; octaves = (int)fn["octaves"]; sublevels = (int)fn["sublevels"]; - diffusivity = (int)fn["diffusivity"]; + diffusivity = static_cast((int)fn["diffusivity"]); } - int descriptor; + DescriptorType descriptor; int descriptor_channels; int descriptor_size; float threshold; int octaves; int sublevels; - int diffusivity; + KAZE::DiffusivityType diffusivity; }; - Ptr AKAZE::create(int descriptor_type, + Ptr AKAZE::create(DescriptorType descriptor_type, int descriptor_size, int descriptor_channels, float threshold, int octaves, - int sublevels, int diffusivity) + int sublevels, KAZE::DiffusivityType diffusivity) { return makePtr(descriptor_type, descriptor_size, descriptor_channels, threshold, octaves, sublevels, diffusivity); diff --git a/modules/features2d/src/draw.cpp b/modules/features2d/src/draw.cpp index 21d2f35d1b..2132d17b42 100644 --- a/modules/features2d/src/draw.cpp +++ b/modules/features2d/src/draw.cpp @@ -50,12 +50,12 @@ namespace cv /* * Functions to draw keypoints and matches. */ -static inline void _drawKeypoint( InputOutputArray img, const KeyPoint& p, const Scalar& color, int flags ) +static inline void _drawKeypoint( InputOutputArray img, const KeyPoint& p, const Scalar& color, DrawMatchesFlags flags ) { CV_Assert( !img.empty() ); Point center( cvRound(p.pt.x * draw_multiplier), cvRound(p.pt.y * draw_multiplier) ); - if( flags & DrawMatchesFlags::DRAW_RICH_KEYPOINTS ) + if( !!(flags & DrawMatchesFlags::DRAW_RICH_KEYPOINTS) ) { int radius = cvRound(p.size/2 * draw_multiplier); // KeyPoint::size is a diameter @@ -89,7 +89,7 @@ static inline void _drawKeypoint( InputOutputArray img, const KeyPoint& p, const } void drawKeypoints( InputArray image, const std::vector& keypoints, InputOutputArray outImage, - const Scalar& _color, int flags ) + const Scalar& _color, DrawMatchesFlags flags ) { CV_INSTRUMENT_REGION(); @@ -125,12 +125,12 @@ void drawKeypoints( InputArray image, const std::vector& keypoints, In static void _prepareImgAndDrawKeypoints( InputArray img1, const std::vector& keypoints1, InputArray img2, const std::vector& keypoints2, InputOutputArray _outImg, Mat& outImg1, Mat& outImg2, - const Scalar& singlePointColor, int flags ) + const Scalar& singlePointColor, DrawMatchesFlags flags ) { Mat outImg; Size img1size = img1.size(), img2size = img2.size(); Size size( img1size.width + img2size.width, MAX(img1size.height, img2size.height) ); - if( flags & DrawMatchesFlags::DRAW_OVER_OUTIMG ) + if( !!(flags & DrawMatchesFlags::DRAW_OVER_OUTIMG) ) { outImg = _outImg.getMat(); if( size.width > outImg.cols || size.height > outImg.rows ) @@ -169,7 +169,7 @@ static void _prepareImgAndDrawKeypoints( InputArray img1, const std::vector& keypoints1, InputArray img2, const std::vector& keypoints2, const std::vector& matches1to2, InputOutputArray outImg, const Scalar& matchColor, const Scalar& singlePointColor, - const std::vector& matchesMask, int flags ) + const std::vector& matchesMask, DrawMatchesFlags flags ) { if( !matchesMask.empty() && matchesMask.size() != matches1to2.size() ) CV_Error( Error::StsBadSize, "matchesMask must have the same size as matches1to2" ); @@ -221,7 +221,7 @@ void drawMatches( InputArray img1, const std::vector& keypoints1, InputArray img2, const std::vector& keypoints2, const std::vector >& matches1to2, InputOutputArray outImg, const Scalar& matchColor, const Scalar& singlePointColor, - const std::vector >& matchesMask, int flags ) + const std::vector >& matchesMask, DrawMatchesFlags flags ) { if( !matchesMask.empty() && matchesMask.size() != matches1to2.size() ) CV_Error( Error::StsBadSize, "matchesMask must have the same size as matches1to2" ); diff --git a/modules/features2d/src/fast.cpp b/modules/features2d/src/fast.cpp index 8082e4bd6a..79c2a26334 100644 --- a/modules/features2d/src/fast.cpp +++ b/modules/features2d/src/fast.cpp @@ -415,7 +415,7 @@ static bool openvx_FAST(InputArray _img, std::vector& keypoints, #endif -static inline int hal_FAST(cv::Mat& src, std::vector& keypoints, int threshold, bool nonmax_suppression, int type) +static inline int hal_FAST(cv::Mat& src, std::vector& keypoints, int threshold, bool nonmax_suppression, FastFeatureDetector::DetectorType type) { if (threshold > 20) return CV_HAL_ERROR_NOT_IMPLEMENTED; @@ -472,7 +472,7 @@ static inline int hal_FAST(cv::Mat& src, std::vector& keypoints, int t return CV_HAL_ERROR_OK; } -void FAST(InputArray _img, std::vector& keypoints, int threshold, bool nonmax_suppression, int type) +void FAST(InputArray _img, std::vector& keypoints, int threshold, bool nonmax_suppression, FastFeatureDetector::DetectorType type) { CV_INSTRUMENT_REGION(); @@ -514,8 +514,8 @@ void FAST(InputArray _img, std::vector& keypoints, int threshold, bool class FastFeatureDetector_Impl CV_FINAL : public FastFeatureDetector { public: - FastFeatureDetector_Impl( int _threshold, bool _nonmaxSuppression, int _type ) - : threshold(_threshold), nonmaxSuppression(_nonmaxSuppression), type((short)_type) + FastFeatureDetector_Impl( int _threshold, bool _nonmaxSuppression, FastFeatureDetector::DetectorType _type ) + : threshold(_threshold), nonmaxSuppression(_nonmaxSuppression), type(_type) {} void detect( InputArray _image, std::vector& keypoints, InputArray _mask ) CV_OVERRIDE @@ -548,7 +548,7 @@ public: else if(prop == NONMAX_SUPPRESSION) nonmaxSuppression = value != 0; else if(prop == FAST_N) - type = cvRound(value); + type = static_cast(cvRound(value)); else CV_Error(Error::StsBadArg, ""); } @@ -560,7 +560,7 @@ public: if(prop == NONMAX_SUPPRESSION) return nonmaxSuppression; if(prop == FAST_N) - return type; + return static_cast(type); CV_Error(Error::StsBadArg, ""); return 0; } @@ -571,15 +571,15 @@ public: void setNonmaxSuppression(bool f) CV_OVERRIDE { nonmaxSuppression = f; } bool getNonmaxSuppression() const CV_OVERRIDE { return nonmaxSuppression; } - void setType(int type_) CV_OVERRIDE { type = type_; } - int getType() const CV_OVERRIDE { return type; } + void setType(FastFeatureDetector::DetectorType type_) CV_OVERRIDE{ type = type_; } + FastFeatureDetector::DetectorType getType() const CV_OVERRIDE{ return type; } int threshold; bool nonmaxSuppression; - int type; + FastFeatureDetector::DetectorType type; }; -Ptr FastFeatureDetector::create( int threshold, bool nonmaxSuppression, int type ) +Ptr FastFeatureDetector::create( int threshold, bool nonmaxSuppression, FastFeatureDetector::DetectorType type ) { return makePtr(threshold, nonmaxSuppression, type); } diff --git a/modules/features2d/src/hal_replacement.hpp b/modules/features2d/src/hal_replacement.hpp index 7780aa4a24..951b7b62ec 100644 --- a/modules/features2d/src/hal_replacement.hpp +++ b/modules/features2d/src/hal_replacement.hpp @@ -66,7 +66,7 @@ @param width,height Source image dimensions @param type FAST type */ -inline int hal_ni_FAST_dense(const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_FAST_dense(const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, cv::FastFeatureDetector::DetectorType type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } //! @cond IGNORED #define cv_hal_FAST_dense hal_ni_FAST_dense @@ -94,7 +94,7 @@ inline int hal_ni_FAST_NMS(const uchar* src_data, size_t src_step, uchar* dst_da @param nonmax_suppression Indicates if make nonmaxima suppression or not. @param type FAST type */ -inline int hal_ni_FAST(const uchar* src_data, size_t src_step, int width, int height, uchar* keypoints_data, size_t* keypoints_count, int threshold, bool nonmax_suppression, int type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } +inline int hal_ni_FAST(const uchar* src_data, size_t src_step, int width, int height, uchar* keypoints_data, size_t* keypoints_count, int threshold, bool nonmax_suppression, int /*cv::FastFeatureDetector::DetectorType*/ type) { return CV_HAL_ERROR_NOT_IMPLEMENTED; } //! @cond IGNORED #define cv_hal_FAST hal_ni_FAST diff --git a/modules/features2d/src/kaze.cpp b/modules/features2d/src/kaze.cpp index 833b92a367..0d841b7f7b 100644 --- a/modules/features2d/src/kaze.cpp +++ b/modules/features2d/src/kaze.cpp @@ -57,7 +57,7 @@ namespace cv { public: KAZE_Impl(bool _extended, bool _upright, float _threshold, int _octaves, - int _sublevels, int _diffusivity) + int _sublevels, KAZE::DiffusivityType _diffusivity) : extended(_extended) , upright(_upright) , threshold(_threshold) @@ -84,8 +84,8 @@ namespace cv void setNOctaveLayers(int octaveLayers_) CV_OVERRIDE { sublevels = octaveLayers_; } int getNOctaveLayers() const CV_OVERRIDE { return sublevels; } - void setDiffusivity(int diff_) CV_OVERRIDE { diffusivity = diff_; } - int getDiffusivity() const CV_OVERRIDE { return diffusivity; } + void setDiffusivity(KAZE::DiffusivityType diff_) CV_OVERRIDE{ diffusivity = diff_; } + KAZE::DiffusivityType getDiffusivity() const CV_OVERRIDE{ return diffusivity; } // returns the descriptor size in bytes int descriptorSize() const CV_OVERRIDE @@ -178,7 +178,7 @@ namespace cv threshold = (float)fn["threshold"]; octaves = (int)fn["octaves"]; sublevels = (int)fn["sublevels"]; - diffusivity = (int)fn["diffusivity"]; + diffusivity = static_cast((int)fn["diffusivity"]); } bool extended; @@ -186,13 +186,13 @@ namespace cv float threshold; int octaves; int sublevels; - int diffusivity; + KAZE::DiffusivityType diffusivity; }; Ptr KAZE::create(bool extended, bool upright, float threshold, int octaves, int sublevels, - int diffusivity) + KAZE::DiffusivityType diffusivity) { return makePtr(extended, upright, threshold, octaves, sublevels, diffusivity); } diff --git a/modules/features2d/src/kaze/AKAZEConfig.h b/modules/features2d/src/kaze/AKAZEConfig.h index 806d25c801..c9fbc51234 100644 --- a/modules/features2d/src/kaze/AKAZEConfig.h +++ b/modules/features2d/src/kaze/AKAZEConfig.h @@ -45,12 +45,12 @@ struct AKAZEOptions { float soffset; ///< Base scale offset (sigma units) float derivative_factor; ///< Factor for the multiscale derivatives float sderivatives; ///< Smoothing factor for the derivatives - int diffusivity; ///< Diffusivity type + KAZE::DiffusivityType diffusivity; ///< Diffusivity type float dthreshold; ///< Detector response threshold to accept point float min_dthreshold; ///< Minimum detector threshold to accept a point - int descriptor; ///< Type of descriptor + AKAZE::DescriptorType descriptor; ///< Type of descriptor int descriptor_size; ///< Size of the descriptor in bits. 0->Full size int descriptor_channels; ///< Number of channels in the descriptor (1, 2, 3) int descriptor_pattern_size; ///< Actual patch size is 2*pattern_size*point.scale diff --git a/modules/features2d/src/kaze/AKAZEFeatures.cpp b/modules/features2d/src/kaze/AKAZEFeatures.cpp index 9b0d8311b0..bfba23aa29 100644 --- a/modules/features2d/src/kaze/AKAZEFeatures.cpp +++ b/modules/features2d/src/kaze/AKAZEFeatures.cpp @@ -377,7 +377,7 @@ ocl_pm_g2(InputArray Lx_, InputArray Ly_, OutputArray Lflow_, float kcontrast) #endif // HAVE_OPENCL static inline void -compute_diffusivity(InputArray Lx, InputArray Ly, OutputArray Lflow, float kcontrast, int diffusivity) +compute_diffusivity(InputArray Lx, InputArray Ly, OutputArray Lflow, float kcontrast, KAZE::DiffusivityType diffusivity) { CV_INSTRUMENT_REGION(); @@ -398,7 +398,7 @@ compute_diffusivity(InputArray Lx, InputArray Ly, OutputArray Lflow, float kcont charbonnier_diffusivity(Lx, Ly, Lflow, kcontrast); break; default: - CV_Error(diffusivity, "Diffusivity is not supported"); + CV_Error_(Error::StsError, ("Diffusivity is not supported: %d", static_cast(diffusivity))); break; } } diff --git a/modules/features2d/src/kaze/KAZEConfig.h b/modules/features2d/src/kaze/KAZEConfig.h index 5f2f8dcecd..35f8d54b95 100644 --- a/modules/features2d/src/kaze/KAZEConfig.h +++ b/modules/features2d/src/kaze/KAZEConfig.h @@ -36,7 +36,7 @@ struct KAZEOptions { { } - int diffusivity; + KAZE::DiffusivityType diffusivity; float soffset; int omax; int nsublevels; diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index d78000b459..3a2d48c21b 100644 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -1049,7 +1049,7 @@ Ptr DescriptorMatcher::create( const String& descriptorMatche return dm; } -Ptr DescriptorMatcher::create(int matcherType) +Ptr DescriptorMatcher::create( const MatcherType& matcherType ) { diff --git a/modules/features2d/src/orb.cpp b/modules/features2d/src/orb.cpp index e3468af60b..ac0655fe12 100644 --- a/modules/features2d/src/orb.cpp +++ b/modules/features2d/src/orb.cpp @@ -655,7 +655,7 @@ class ORB_Impl CV_FINAL : public ORB { public: explicit ORB_Impl(int _nfeatures, float _scaleFactor, int _nlevels, int _edgeThreshold, - int _firstLevel, int _WTA_K, int _scoreType, int _patchSize, int _fastThreshold) : + int _firstLevel, int _WTA_K, ORB::ScoreType _scoreType, int _patchSize, int _fastThreshold) : nfeatures(_nfeatures), scaleFactor(_scaleFactor), nlevels(_nlevels), edgeThreshold(_edgeThreshold), firstLevel(_firstLevel), wta_k(_WTA_K), scoreType(_scoreType), patchSize(_patchSize), fastThreshold(_fastThreshold) @@ -679,8 +679,8 @@ public: void setWTA_K(int wta_k_) CV_OVERRIDE { wta_k = wta_k_; } int getWTA_K() const CV_OVERRIDE { return wta_k; } - void setScoreType(int scoreType_) CV_OVERRIDE { scoreType = scoreType_; } - int getScoreType() const CV_OVERRIDE { return scoreType; } + void setScoreType(ORB::ScoreType scoreType_) CV_OVERRIDE{ scoreType = scoreType_; } + ORB::ScoreType getScoreType() const CV_OVERRIDE{ return scoreType; } void setPatchSize(int patchSize_) CV_OVERRIDE { patchSize = patchSize_; } int getPatchSize() const CV_OVERRIDE { return patchSize; } @@ -707,7 +707,7 @@ protected: int edgeThreshold; int firstLevel; int wta_k; - int scoreType; + ORB::ScoreType scoreType; int patchSize; int fastThreshold; }; @@ -775,7 +775,7 @@ static void computeKeyPoints(const Mat& imagePyramid, const std::vector& layerScale, std::vector& allKeypoints, int nfeatures, double scaleFactor, - int edgeThreshold, int patchSize, int scoreType, + int edgeThreshold, int patchSize, ORB::ScoreType scoreType, bool useOCL, int fastThreshold ) { #ifndef HAVE_OPENCL @@ -1195,7 +1195,7 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask, } Ptr ORB::create(int nfeatures, float scaleFactor, int nlevels, int edgeThreshold, - int firstLevel, int wta_k, int scoreType, int patchSize, int fastThreshold) + int firstLevel, int wta_k, ORB::ScoreType scoreType, int patchSize, int fastThreshold) { CV_Assert(firstLevel >= 0); return makePtr(nfeatures, scaleFactor, nlevels, edgeThreshold, diff --git a/modules/features2d/test/test_agast.cpp b/modules/features2d/test/test_agast.cpp index 9bb15390f0..64fa750714 100644 --- a/modules/features2d/test/test_agast.cpp +++ b/modules/features2d/test/test_agast.cpp @@ -75,8 +75,8 @@ void CV_AgastTest::run( int ) vector keypoints1; vector keypoints2; - AGAST(gray1, keypoints1, 30, true, type); - AGAST(gray2, keypoints2, (type > 0 ? 30 : 20), true, type); + AGAST(gray1, keypoints1, 30, true, static_cast(type)); + AGAST(gray2, keypoints2, (type > 0 ? 30 : 20), true, static_cast(type)); for(size_t i = 0; i < keypoints1.size(); ++i) { diff --git a/modules/features2d/test/test_fast.cpp b/modules/features2d/test/test_fast.cpp index 05741f507a..2fc5602be5 100644 --- a/modules/features2d/test/test_fast.cpp +++ b/modules/features2d/test/test_fast.cpp @@ -75,8 +75,8 @@ void CV_FastTest::run( int ) vector keypoints1; vector keypoints2; - FAST(gray1, keypoints1, 30, true, type); - FAST(gray2, keypoints2, (type > 0 ? 30 : 20), true, type); + FAST(gray1, keypoints1, 30, true, static_cast(type)); + FAST(gray2, keypoints2, (type > 0 ? 30 : 20), true, static_cast(type)); for(size_t i = 0; i < keypoints1.size(); ++i) { diff --git a/modules/features2d/test/test_orb.cpp b/modules/features2d/test/test_orb.cpp index 01d1746863..868bee354c 100644 --- a/modules/features2d/test/test_orb.cpp +++ b/modules/features2d/test/test_orb.cpp @@ -100,7 +100,7 @@ TEST(Features2D_ORB, crash) int edgeThreshold = 4; int firstLevel = 0; int WTA_K = 2; - int scoreType = cv::ORB::HARRIS_SCORE; + ORB::ScoreType scoreType = cv::ORB::HARRIS_SCORE; int patchSize = 47; int fastThreshold = 20; diff --git a/modules/objdetect/include/opencv2/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect.hpp index f0396d976b..59af3f919e 100644 --- a/modules/objdetect/include/opencv2/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect.hpp @@ -372,10 +372,12 @@ http://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python- struct CV_EXPORTS_W HOGDescriptor { public: - enum { L2Hys = 0 //!< Default histogramNormType + enum HistogramNormType { L2Hys = 0 //!< Default histogramNormType }; enum { DEFAULT_NLEVELS = 64 //!< Default nlevels value. }; + enum DescriptorStorageFormat { DESCR_FORMAT_COL_BY_COL, DESCR_FORMAT_ROW_BY_ROW }; + /**@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 ) @@ -402,7 +404,7 @@ public: */ CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride, Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1, - int _histogramNormType=HOGDescriptor::L2Hys, + HOGDescriptor::HistogramNormType _histogramNormType=HOGDescriptor::L2Hys, double _L2HysThreshold=0.2, bool _gammaCorrection=false, int _nlevels=HOGDescriptor::DEFAULT_NLEVELS, bool _signedGradient=false) : winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize), @@ -603,7 +605,7 @@ public: CV_PROP double winSigma; //! histogramNormType - CV_PROP int histogramNormType; + CV_PROP HOGDescriptor::HistogramNormType histogramNormType; //! L2-Hys normalization method shrinkage. CV_PROP double L2HysThreshold; diff --git a/modules/objdetect/misc/python/pyopencv_objdetect.hpp b/modules/objdetect/misc/python/pyopencv_objdetect.hpp new file mode 100644 index 0000000000..3d09ae16bf --- /dev/null +++ b/modules/objdetect/misc/python/pyopencv_objdetect.hpp @@ -0,0 +1,13 @@ +#ifdef HAVE_OPENCV_OBJDETECT + +#include "opencv2/objdetect.hpp" + +typedef HOGDescriptor::HistogramNormType HOGDescriptor_HistogramNormType; +typedef HOGDescriptor::DescriptorStorageFormat HOGDescriptor_DescriptorStorageFormat; + +CV_PY_FROM_ENUM(HOGDescriptor::HistogramNormType); +CV_PY_TO_ENUM(HOGDescriptor::HistogramNormType); +CV_PY_FROM_ENUM(HOGDescriptor::DescriptorStorageFormat); +CV_PY_TO_ENUM(HOGDescriptor::DescriptorStorageFormat); + +#endif diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index 3060d61fbf..aec2febaa2 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -63,8 +63,6 @@ namespace cv #define NTHREADS 256 -enum {DESCR_FORMAT_COL_BY_COL, DESCR_FORMAT_ROW_BY_ROW}; - static int numPartsWithin(int size, int part_size, int stride) { return (size - part_size + stride) / stride; @@ -1515,7 +1513,7 @@ static bool ocl_extract_descrs_by_cols(int win_height, int win_width, int block_ return k.run(2, globalThreads, localThreads, false); } -static bool ocl_compute(InputArray _img, Size win_stride, std::vector& _descriptors, int descr_format, Size blockSize, +static bool ocl_compute(InputArray _img, Size win_stride, std::vector& _descriptors, HOGDescriptor::DescriptorStorageFormat descr_format, Size blockSize, Size cellSize, int nbins, Size blockStride, Size winSize, float sigma, bool gammaCorrection, double L2HysThreshold, bool signedGradient) { Size imgSize = _img.size(); @@ -1564,13 +1562,13 @@ static bool ocl_compute(InputArray _img, Size win_stride, std::vector& _d UMat descriptors(wins_per_img.area(), static_cast(blocks_per_win.area() * block_hist_size), CV_32F); switch (descr_format) { - case DESCR_FORMAT_ROW_BY_ROW: + case HOGDescriptor::DESCR_FORMAT_ROW_BY_ROW: if(!ocl_extract_descrs_by_rows(winSize.height, winSize.width, blockStride.height, blockStride.width, win_stride.height, win_stride.width, effect_size.height, effect_size.width, block_hists, descriptors, (int)block_hist_size, descr_size, descr_width)) return false; break; - case DESCR_FORMAT_COL_BY_COL: + case HOGDescriptor::DESCR_FORMAT_COL_BY_COL: if(!ocl_extract_descrs_by_cols(winSize.height, winSize.width, blockStride.height, blockStride.width, win_stride.height, win_stride.width, effect_size.height, effect_size.width, block_hists, descriptors, (int)block_hist_size, descr_size, blocks_per_win.width, blocks_per_win.height)) @@ -1602,7 +1600,7 @@ void HOGDescriptor::compute(InputArray _img, std::vector& descriptors, Size paddedImgSize(imgSize.width + padding.width*2, imgSize.height + padding.height*2); CV_OCL_RUN(_img.dims() <= 2 && _img.type() == CV_8UC1 && _img.isUMat(), - ocl_compute(_img, winStride, descriptors, DESCR_FORMAT_COL_BY_COL, blockSize, + ocl_compute(_img, winStride, descriptors, HOGDescriptor::DESCR_FORMAT_COL_BY_COL, blockSize, cellSize, nbins, blockStride, winSize, (float)getWinSigma(), gammaCorrection, L2HysThreshold, signedGradient)) Mat img = _img.getMat(); diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 2c5124fcf4..5ae963a94f 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -252,7 +252,7 @@ public: return u; } - UMatData* allocate(int dims0, const int* sizes, int type, void* data, size_t* step, int flags, UMatUsageFlags usageFlags) const CV_OVERRIDE + UMatData* allocate(int dims0, const int* sizes, int type, void* data, size_t* step, AccessFlag flags, UMatUsageFlags usageFlags) const CV_OVERRIDE { if( data != 0 ) { @@ -281,7 +281,7 @@ public: return allocate(o, dims0, sizes, type, step); } - bool allocate(UMatData* u, int accessFlags, UMatUsageFlags usageFlags) const CV_OVERRIDE + bool allocate(UMatData* u, AccessFlag accessFlags, UMatUsageFlags usageFlags) const CV_OVERRIDE { return stdAllocator->allocate(u, accessFlags, usageFlags); } diff --git a/modules/stitching/include/opencv2/stitching/detail/matchers.hpp b/modules/stitching/include/opencv2/stitching/detail/matchers.hpp index 25c0f2ab1e..5c0123833f 100644 --- a/modules/stitching/include/opencv2/stitching/detail/matchers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/matchers.hpp @@ -175,13 +175,13 @@ private: class CV_EXPORTS AKAZEFeaturesFinder : public detail::FeaturesFinder { public: - AKAZEFeaturesFinder(int descriptor_type = AKAZE::DESCRIPTOR_MLDB, + AKAZEFeaturesFinder(AKAZE::DescriptorType 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); + KAZE::DiffusivityType diffusivity = KAZE::DIFF_PM_G2); private: void find(InputArray image, ImageFeatures &features) CV_OVERRIDE; diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index 5fa32ae2f1..6d583c8a6a 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -576,13 +576,13 @@ void OrbFeaturesFinder::find(InputArray image, ImageFeatures &features) } } -AKAZEFeaturesFinder::AKAZEFeaturesFinder(int descriptor_type, +AKAZEFeaturesFinder::AKAZEFeaturesFinder(AKAZE::DescriptorType descriptor_type, int descriptor_size, int descriptor_channels, float threshold, int nOctaves, int nOctaveLayers, - int diffusivity) + KAZE::DiffusivityType diffusivity) { akaze = AKAZE::create(descriptor_type, descriptor_size, descriptor_channels, threshold, nOctaves, nOctaveLayers, diffusivity); diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index da9cfca873..be08238336 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -184,7 +184,7 @@ double getMaxVal(int depth); Size randomSize(RNG& rng, double maxSizeLog); void randomSize(RNG& rng, int minDims, int maxDims, double maxSizeLog, vector& sz); -int randomType(RNG& rng, int typeMask, int minChannels, int maxChannels); +int randomType(RNG& rng, cv::_OutputArray::DepthMask typeMask, int minChannels, int maxChannels); Mat randomMat(RNG& rng, Size size, int type, double minVal, double maxVal, bool useRoi); Mat randomMat(RNG& rng, const vector& size, int type, double minVal, double maxVal, bool useRoi); void add(const Mat& a, double alpha, const Mat& b, double beta, diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 3b9e0198f2..c404759fd4 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -68,7 +68,7 @@ void randomSize(RNG& rng, int minDims, int maxDims, double maxSizeLog, vector 2 && winSize.height > 2 ); int pyrstep = withDerivatives ? 2 : 1; - pyramid.create(1, (maxLevel + 1) * pyrstep, 0 /*type*/, -1, true, 0); + pyramid.create(1, (maxLevel + 1) * pyrstep, 0 /*type*/, -1, true); int derivType = CV_MAKETYPE(DataType::depth, img.channels() * 2); @@ -783,7 +783,7 @@ int cv::buildOpticalFlowPyramid(InputArray _img, OutputArrayOfArrays pyramid, Si sz = Size((sz.width+1)/2, (sz.height+1)/2); if( sz.width <= winSize.width || sz.height <= winSize.height ) { - pyramid.create(1, (level + 1) * pyrstep, 0 /*type*/, -1, true, 0);//check this + pyramid.create(1, (level + 1) * pyrstep, 0 /*type*/, -1, true);//check this return level; }