From 2c6ab654767f25a200fde8e2ed141888320fd5dc Mon Sep 17 00:00:00 2001 From: Dmitry Matveev Date: Fri, 28 Sep 2018 18:42:09 +0300 Subject: [PATCH] Merge pull request #12674 from dmatveev:gapi_upd270918 * Update G-API code base to 27-Sep-18 Changes mostly improve standalone build support * G-API code base update 28-09-2018 * Windows/Documentation warnings should be fixed * Fixed stability issues in Fluid backend * Fixed precompiled headers issues in G-API source files * G-API code base update 28-09-18 EOD * Fixed several static analysis issues * Fixed issues found when G-API is built in a standalone mode --- .../opencv2/gapi/fluid/gfluidbuffer.hpp | 17 +- .../opencv2/gapi/fluid/gfluidkernel.hpp | 16 +- modules/gapi/include/opencv2/gapi/garg.hpp | 34 ++- .../gapi/include/opencv2/gapi/gcompiled.hpp | 6 +- .../include/opencv2/gapi/gcomputation.hpp | 6 +- modules/gapi/include/opencv2/gapi/gmat.hpp | 16 +- modules/gapi/include/opencv2/gapi/gscalar.hpp | 7 +- .../include/opencv2/gapi/gtype_traits.hpp | 4 +- modules/gapi/include/opencv2/gapi/gtyped.hpp | 3 +- .../include/opencv2/gapi/opencv_includes.hpp | 13 +- .../gapi/include/opencv2/gapi/own/convert.hpp | 7 +- .../gapi/include/opencv2/gapi/own/cvdefs.hpp | 146 ++++++++++++ modules/gapi/include/opencv2/gapi/own/mat.hpp | 159 ++++++++++++- .../include/opencv2/gapi/own/saturate.hpp | 88 +++++++ .../gapi/include/opencv2/gapi/own/scalar.hpp | 4 +- .../gapi/include/opencv2/gapi/own/types.hpp | 12 +- .../gapi/include/opencv2/gapi/util/any.hpp | 27 +++ .../perf/cpu/gapi_core_perf_tests_cpu.cpp | 1 + .../perf/cpu/gapi_imgproc_perf_tests_cpu.cpp | 1 + modules/gapi/src/api/gapi_priv.cpp | 1 + modules/gapi/src/api/garray.cpp | 1 + modules/gapi/src/api/gbackend.cpp | 16 +- modules/gapi/src/api/gcall.cpp | 1 + modules/gapi/src/api/gcomputation.cpp | 18 +- modules/gapi/src/api/gkernel.cpp | 2 +- modules/gapi/src/api/gmat.cpp | 3 + modules/gapi/src/api/gnode.cpp | 1 + modules/gapi/src/api/gproto.cpp | 11 +- modules/gapi/src/api/gscalar.cpp | 14 +- modules/gapi/src/api/kernels_core.cpp | 2 + modules/gapi/src/api/kernels_imgproc.cpp | 2 + modules/gapi/src/api/operators.cpp | 2 + .../src/backends/common/gcompoundbackend.cpp | 2 + .../src/backends/common/gcompoundkernel.cpp | 2 + modules/gapi/src/backends/cpu/gcpubackend.cpp | 2 + modules/gapi/src/backends/cpu/gcpukernel.cpp | 2 + .../gapi/src/backends/fluid/gfluidbackend.cpp | 34 +-- .../gapi/src/backends/fluid/gfluidbuffer.cpp | 74 +++--- .../src/backends/fluid/gfluidbuffer_priv.hpp | 34 +-- .../gapi/src/backends/fluid/gfluidcore.cpp | 5 + .../gapi/src/backends/fluid/gfluidimgproc.cpp | 5 + .../gapi/src/backends/fluid/gfluidutils.hpp | 73 +----- modules/gapi/src/compiler/gcompiled.cpp | 5 + modules/gapi/src/compiler/gcompiler.cpp | 16 +- modules/gapi/src/compiler/gislandmodel.cpp | 2 + modules/gapi/src/compiler/gmodel.cpp | 2 + modules/gapi/src/compiler/gmodelbuilder.cpp | 2 + modules/gapi/src/compiler/passes/dump_dot.cpp | 2 + modules/gapi/src/compiler/passes/exec.cpp | 3 +- modules/gapi/src/compiler/passes/helpers.cpp | 2 + modules/gapi/src/compiler/passes/islands.cpp | 2 + modules/gapi/src/compiler/passes/kernels.cpp | 2 + modules/gapi/src/compiler/passes/meta.cpp | 2 + modules/gapi/src/compiler/transactions.hpp | 8 +- modules/gapi/src/executor/gexecutor.cpp | 17 +- modules/gapi/src/logger.hpp | 18 +- modules/gapi/src/precomp.hpp | 10 +- modules/gapi/test/common/gapi_core_tests.cpp | 1 + .../gapi/test/common/gapi_imgproc_tests.cpp | 1 + .../gapi/test/common/gapi_operators_tests.cpp | 1 + .../test/cpu/gapi_operators_tests_fluid.cpp | 1 + modules/gapi/test/gapi_fluid_test.cpp | 8 +- modules/gapi/test/gapi_fluid_test_kernels.cpp | 2 + modules/gapi/test/own/mat_tests.cpp | 223 ++++++++++++++++++ 64 files changed, 981 insertions(+), 223 deletions(-) create mode 100644 modules/gapi/include/opencv2/gapi/own/cvdefs.hpp create mode 100644 modules/gapi/include/opencv2/gapi/own/saturate.hpp diff --git a/modules/gapi/include/opencv2/gapi/fluid/gfluidbuffer.hpp b/modules/gapi/include/opencv2/gapi/fluid/gfluidbuffer.hpp index dbed85ac9e..1b94bbae5d 100644 --- a/modules/gapi/include/opencv2/gapi/fluid/gfluidbuffer.hpp +++ b/modules/gapi/include/opencv2/gapi/fluid/gfluidbuffer.hpp @@ -14,10 +14,12 @@ #include // uint8_t #include +#include #include #include "opencv2/gapi/util/optional.hpp" #include "opencv2/gapi/own/scalar.hpp" +#include "opencv2/gapi/own/mat.hpp" namespace cv { namespace gapi { @@ -25,9 +27,10 @@ namespace fluid { struct Border { -#if 1 +#if !defined(GAPI_STANDALONE) + // This constructor is required to support existing kernels which are part of G-API Border(int _type, cv::Scalar _val) : type(_type), value(to_own(_val)) {}; -#endif +#endif // !defined(GAPI_STANDALONE) Border(int _type, cv::gapi::own::Scalar _val) : type(_type), value(_val) {}; int type; cv::gapi::own::Scalar value; @@ -45,7 +48,7 @@ public: View() = default; const uint8_t* InLineB(int index) const; // -(w-1)/2...0...+(w-1)/2 for Filters - template const T* InLine(int i) const + template const inline T* InLine(int i) const { const uint8_t* ptr = this->InLineB(i); return reinterpret_cast(ptr); @@ -56,7 +59,7 @@ public: int length() const; int y() const; - GMatDesc meta() const; + const GMatDesc& meta() const; class GAPI_EXPORTS Priv; // internal use only Priv& priv(); // internal use only @@ -84,10 +87,10 @@ public: int wlpi, BorderOpt border); // Constructor for in/out buffers (for tests) - Buffer(const cv::Mat &data, bool is_input); + Buffer(const cv::gapi::own::Mat &data, bool is_input); uint8_t* OutLineB(int index = 0); - template T* OutLine(int index = 0) + template inline T* OutLine(int index = 0) { uint8_t* ptr = this->OutLineB(index); return reinterpret_cast(ptr); @@ -100,7 +103,7 @@ public: int length() const; int lpi() const; // LPI for WRITER - GMatDesc meta() const; + const GMatDesc& meta() const; View mkView(int lineConsumption, int borderSize, BorderOpt border, bool ownStorage); diff --git a/modules/gapi/include/opencv2/gapi/fluid/gfluidkernel.hpp b/modules/gapi/include/opencv2/gapi/fluid/gfluidkernel.hpp index 220b64187f..fbe0436134 100644 --- a/modules/gapi/include/opencv2/gapi/fluid/gfluidkernel.hpp +++ b/modules/gapi/include/opencv2/gapi/fluid/gfluidkernel.hpp @@ -102,22 +102,30 @@ template<> struct fluid_get_in { static const cv::gapi::fluid::View& get(const cv::GArgs &in_args, int idx) { - return in_args[idx].get(); + return in_args[idx].unsafe_get(); } }; template<> struct fluid_get_in { + // FIXME: change to return by reference when moved to own::Scalar +#if !defined(GAPI_STANDALONE) static const cv::Scalar get(const cv::GArgs &in_args, int idx) { - return cv::gapi::own::to_ocv(in_args[idx].get()); + return cv::gapi::own::to_ocv(in_args[idx].unsafe_get()); } +#else + static const cv::gapi::own::Scalar get(const cv::GArgs &in_args, int idx) + { + return in_args[idx].get(); + } +#endif // !defined(GAPI_STANDALONE) }; template struct fluid_get_in { - static T get(const cv::GArgs &in_args, int idx) + static const T& get(const cv::GArgs &in_args, int idx) { - return in_args[idx].get(); + return in_args[idx].unsafe_get(); } }; diff --git a/modules/gapi/include/opencv2/gapi/garg.hpp b/modules/gapi/include/opencv2/gapi/garg.hpp index 26c0d0a069..4a9e27d193 100644 --- a/modules/gapi/include/opencv2/gapi/garg.hpp +++ b/modules/gapi/include/opencv2/gapi/garg.hpp @@ -56,16 +56,26 @@ public: { } - template T& get() + template inline T& get() { return util::any_cast::type>(value); } - template const T& get() const + template inline const T& get() const { return util::any_cast::type>(value); } + template inline T& unsafe_get() + { + return util::unsafe_any_cast::type>(value); + } + + template inline const T& unsafe_get() const + { + return util::unsafe_any_cast::type>(value); + } + detail::ArgKind kind = detail::ArgKind::OPAQUE; protected: @@ -76,10 +86,26 @@ using GArgs = std::vector; // FIXME: Express as M::type // FIXME: Move to a separate file! -using GRunArg = util::variant; +using GRunArg = util::variant< +#if !defined(GAPI_STANDALONE) + cv::Mat, + cv::Scalar, +#endif // !defined(GAPI_STANDALONE) + cv::gapi::own::Mat, + cv::gapi::own::Scalar, + cv::detail::VectorRef + >; using GRunArgs = std::vector; -using GRunArgP = util::variant; +using GRunArgP = util::variant< +#if !defined(GAPI_STANDALONE) + cv::Mat*, + cv::Scalar*, +#endif // !defined(GAPI_STANDALONE) + cv::gapi::own::Mat*, + cv::gapi::own::Scalar*, + cv::detail::VectorRef + >; using GRunArgsP = std::vector; diff --git a/modules/gapi/include/opencv2/gapi/gcompiled.hpp b/modules/gapi/include/opencv2/gapi/gcompiled.hpp index 05e32b12a8..e0f95b52bd 100644 --- a/modules/gapi/include/opencv2/gapi/gcompiled.hpp +++ b/modules/gapi/include/opencv2/gapi/gcompiled.hpp @@ -10,9 +10,8 @@ #include +#include "opencv2/gapi/opencv_includes.hpp" #include "opencv2/gapi/own/assert.hpp" -#include "opencv2/core/mat.hpp" - #include "opencv2/gapi/garg.hpp" namespace cv { @@ -36,13 +35,14 @@ public: GCompiled(); void operator() (GRunArgs &&ins, GRunArgsP &&outs); // Generic arg-to-arg +#if !defined(GAPI_STANDALONE) void operator() (cv::Mat in, cv::Mat &out); // Unary overload void operator() (cv::Mat in, cv::Scalar &out); // Unary overload (scalar) void operator() (cv::Mat in1, cv::Mat in2, cv::Mat &out); // Binary overload void operator() (cv::Mat in1, cv::Mat in2, cv::Scalar &out); // Binary overload (scalar) void operator() (const std::vector &ins, // Compatibility overload const std::vector &outs); - +#endif // !defined(GAPI_STANDALONE) Priv& priv(); explicit operator bool () const; // Check if GCompiled is runnable or empty diff --git a/modules/gapi/include/opencv2/gapi/gcomputation.hpp b/modules/gapi/include/opencv2/gapi/gcomputation.hpp index d5d5fd678e..4457cfae8f 100644 --- a/modules/gapi/include/opencv2/gapi/gcomputation.hpp +++ b/modules/gapi/include/opencv2/gapi/gcomputation.hpp @@ -58,8 +58,12 @@ public: // Various versions of apply(): //////////////////////////////////////////// // 1. Generic apply() void apply(GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args = {}); // Arg-to-arg overload + void apply(const std::vector& ins, // Compatibility overload + const std::vector& outs, + GCompileArgs &&args = {}); // 2. Syntax sugar and compatibility overloads +#if !defined(GAPI_STANDALONE) void apply(cv::Mat in, cv::Mat &out, GCompileArgs &&args = {}); // Unary overload void apply(cv::Mat in, cv::Scalar &out, GCompileArgs &&args = {}); // Unary overload (scalar) void apply(cv::Mat in1, cv::Mat in2, cv::Mat &out, GCompileArgs &&args = {}); // Binary overload @@ -67,7 +71,7 @@ public: void apply(const std::vector& ins, // Compatibility overload const std::vector& outs, GCompileArgs &&args = {}); - +#endif // !defined(GAPI_STANDALONE) // Various versions of compile(): ////////////////////////////////////////// // 1. Generic compile() - requires metas to be passed as vector GCompiled compile(GMetaArgs &&in_metas, GCompileArgs &&args = {}); diff --git a/modules/gapi/include/opencv2/gapi/gmat.hpp b/modules/gapi/include/opencv2/gapi/gmat.hpp index cfe4e51e56..106f09f22c 100644 --- a/modules/gapi/include/opencv2/gapi/gmat.hpp +++ b/modules/gapi/include/opencv2/gapi/gmat.hpp @@ -65,12 +65,17 @@ struct GAPI_EXPORTS GMatDesc desc.size += delta; return desc; } - +#if !defined(GAPI_STANDALONE) GMatDesc withSizeDelta(cv::Size delta) const { return withSizeDelta(to_own(delta)); } + GMatDesc withSize(cv::Size sz) const + { + return withSize(to_own(sz)); + } +#endif // !defined(GAPI_STANDALONE) // Meta combinator: return a new GMatDesc which differs in size by delta // (all other fields are taken unchanged from this GMatDesc) // @@ -87,11 +92,6 @@ struct GAPI_EXPORTS GMatDesc return desc; } - GMatDesc withSize(cv::Size sz) const - { - return withSize(to_own(sz)); - } - // Meta combinator: return a new GMatDesc with specified data depth. // (all other fields are taken unchanged from this GMatDesc) GMatDesc withDepth(int ddepth) const @@ -116,12 +116,14 @@ struct GAPI_EXPORTS GMatDesc static inline GMatDesc empty_gmat_desc() { return GMatDesc{-1,-1,{-1,-1}}; } +#if !defined(GAPI_STANDALONE) class Mat; GAPI_EXPORTS GMatDesc descr_of(const cv::Mat &mat); +#endif // !defined(GAPI_STANDALONE) namespace gapi { namespace own { class Mat; - CV_EXPORTS GMatDesc descr_of(const Mat &mat); + GAPI_EXPORTS GMatDesc descr_of(const Mat &mat); }}//gapi::own std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc); diff --git a/modules/gapi/include/opencv2/gapi/gscalar.hpp b/modules/gapi/include/opencv2/gapi/gscalar.hpp index 030b2e116a..944f179f3b 100644 --- a/modules/gapi/include/opencv2/gapi/gscalar.hpp +++ b/modules/gapi/include/opencv2/gapi/gscalar.hpp @@ -14,9 +14,7 @@ #include // GShape #include #include "opencv2/gapi/own/scalar.hpp" -#include -// TODO GAPI_EXPORTS or so namespace cv { // Forward declaration; GNode and GOrigin are an internal @@ -30,7 +28,9 @@ public: GScalar(); // Empty constructor explicit GScalar(const cv::gapi::own::Scalar& s); // Constant value constructor from cv::gapi::own::Scalar explicit GScalar(cv::gapi::own::Scalar&& s); // Constant value move-constructor from cv::gapi::own::Scalar +#if !defined(GAPI_STANDALONE) explicit GScalar(const cv::Scalar& s); // Constant value constructor from cv::Scalar +#endif // !defined(GAPI_STANDALONE) GScalar(double v0); // Constant value constructor from double GScalar(const GNode &n, std::size_t out); // Operation result constructor @@ -59,7 +59,10 @@ struct GScalarDesc static inline GScalarDesc empty_scalar_desc() { return GScalarDesc(); } GAPI_EXPORTS GScalarDesc descr_of(const cv::gapi::own::Scalar &scalar); + +#if !defined(GAPI_STANDALONE) GAPI_EXPORTS GScalarDesc descr_of(const cv::Scalar &scalar); +#endif // !defined(GAPI_STANDALONE) std::ostream& operator<<(std::ostream& os, const cv::GScalarDesc &desc); diff --git a/modules/gapi/include/opencv2/gapi/gtype_traits.hpp b/modules/gapi/include/opencv2/gapi/gtype_traits.hpp index fcedefc718..d05e02e0ec 100644 --- a/modules/gapi/include/opencv2/gapi/gtype_traits.hpp +++ b/modules/gapi/include/opencv2/gapi/gtype_traits.hpp @@ -77,9 +77,11 @@ namespace detail // Resolve a Host type back to its associated G-Type. // FIXME: Probably it can be avoided template struct GTypeOf; +#if !defined(GAPI_STANDALONE) template<> struct GTypeOf { using type = cv::GMat; }; - template<> struct GTypeOf { using type = cv::GMat; }; template<> struct GTypeOf { using type = cv::GScalar; }; +#endif // !defined(GAPI_STANDALONE) + template<> struct GTypeOf { using type = cv::GMat; }; template<> struct GTypeOf { using type = cv::GScalar; }; template struct GTypeOf > { using type = cv::GArray; }; template using g_type_of_t = typename GTypeOf::type; diff --git a/modules/gapi/include/opencv2/gapi/gtyped.hpp b/modules/gapi/include/opencv2/gapi/gtyped.hpp index d691aeec09..a966f263fc 100644 --- a/modules/gapi/include/opencv2/gapi/gtyped.hpp +++ b/modules/gapi/include/opencv2/gapi/gtyped.hpp @@ -7,6 +7,7 @@ #ifndef OPENCV_GAPI_GTYPED_HPP #define OPENCV_GAPI_GTYPED_HPP +#if !defined(GAPI_STANDALONE) #include @@ -182,5 +183,5 @@ public: }; } // namespace cv - +#endif // !defined(GAPI_STANDALONE) #endif // OPENCV_GAPI_GTYPED_HPP diff --git a/modules/gapi/include/opencv2/gapi/opencv_includes.hpp b/modules/gapi/include/opencv2/gapi/opencv_includes.hpp index 9d45a7fb2e..5acf28023d 100644 --- a/modules/gapi/include/opencv2/gapi/opencv_includes.hpp +++ b/modules/gapi/include/opencv2/gapi/opencv_includes.hpp @@ -1,4 +1,5 @@ // This file is part of OpenCV project. + // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // @@ -8,9 +9,13 @@ #ifndef OPENCV_GAPI_OPENCV_INCLUDES_HPP #define OPENCV_GAPI_OPENCV_INCLUDES_HPP -#include -#include -#include -#include +#if !defined(GAPI_STANDALONE) +# include +# include +# include +# include +#else // Without OpenCV +# include +#endif // !defined(GAPI_STANDALONE) #endif // OPENCV_GAPI_OPENCV_INCLUDES_HPP diff --git a/modules/gapi/include/opencv2/gapi/own/convert.hpp b/modules/gapi/include/opencv2/gapi/own/convert.hpp index fc32e19fd4..8c1feb408b 100644 --- a/modules/gapi/include/opencv2/gapi/own/convert.hpp +++ b/modules/gapi/include/opencv2/gapi/own/convert.hpp @@ -8,8 +8,9 @@ #ifndef OPENCV_GAPI_OWN_CONVERT_HPP #define OPENCV_GAPI_OWN_CONVERT_HPP -#include -#include +#if !defined(GAPI_STANDALONE) + +#include #include #include #include "opencv2/gapi/own/scalar.hpp" @@ -44,4 +45,6 @@ namespace own } // namespace gapi } // namespace cv +#endif // !defined(GAPI_STANDALONE) + #endif // OPENCV_GAPI_OWN_CONVERT_HPP diff --git a/modules/gapi/include/opencv2/gapi/own/cvdefs.hpp b/modules/gapi/include/opencv2/gapi/own/cvdefs.hpp new file mode 100644 index 0000000000..e110536929 --- /dev/null +++ b/modules/gapi/include/opencv2/gapi/own/cvdefs.hpp @@ -0,0 +1,146 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_CV_DEFS_HPP +#define OPENCV_GAPI_CV_DEFS_HPP + +#if defined(GAPI_STANDALONE) + +// Simulate OpenCV definitions taken from various +// OpenCV interface headers if G-API is built in a +// standalone mode. + +// interface.h: + +typedef unsigned char uchar; +typedef char schar; + +typedef unsigned short ushort; + +#define CV_CN_MAX 512 +#define CV_CN_SHIFT 3 +#define CV_DEPTH_MAX (1 << CV_CN_SHIFT) + + +#define CV_8U 0 +#define CV_8S 1 +#define CV_16U 2 +#define CV_16S 3 +#define CV_32S 4 +#define CV_32F 5 +#define CV_64F 6 +#define CV_USRTYPE1 7 + +#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1) +#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK) + +#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)) +#define CV_MAKE_TYPE CV_MAKETYPE + +#define CV_8UC1 CV_MAKETYPE(CV_8U,1) +#define CV_8UC2 CV_MAKETYPE(CV_8U,2) +#define CV_8UC3 CV_MAKETYPE(CV_8U,3) +#define CV_8UC4 CV_MAKETYPE(CV_8U,4) +#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n)) + +#define CV_8SC1 CV_MAKETYPE(CV_8S,1) +#define CV_8SC2 CV_MAKETYPE(CV_8S,2) +#define CV_8SC3 CV_MAKETYPE(CV_8S,3) +#define CV_8SC4 CV_MAKETYPE(CV_8S,4) +#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n)) + +#define CV_16UC1 CV_MAKETYPE(CV_16U,1) +#define CV_16UC2 CV_MAKETYPE(CV_16U,2) +#define CV_16UC3 CV_MAKETYPE(CV_16U,3) +#define CV_16UC4 CV_MAKETYPE(CV_16U,4) +#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n)) + +#define CV_16SC1 CV_MAKETYPE(CV_16S,1) +#define CV_16SC2 CV_MAKETYPE(CV_16S,2) +#define CV_16SC3 CV_MAKETYPE(CV_16S,3) +#define CV_16SC4 CV_MAKETYPE(CV_16S,4) +#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n)) + +#define CV_32SC1 CV_MAKETYPE(CV_32S,1) +#define CV_32SC2 CV_MAKETYPE(CV_32S,2) +#define CV_32SC3 CV_MAKETYPE(CV_32S,3) +#define CV_32SC4 CV_MAKETYPE(CV_32S,4) +#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n)) + +#define CV_32FC1 CV_MAKETYPE(CV_32F,1) +#define CV_32FC2 CV_MAKETYPE(CV_32F,2) +#define CV_32FC3 CV_MAKETYPE(CV_32F,3) +#define CV_32FC4 CV_MAKETYPE(CV_32F,4) +#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n)) + +#define CV_64FC1 CV_MAKETYPE(CV_64F,1) +#define CV_64FC2 CV_MAKETYPE(CV_64F,2) +#define CV_64FC3 CV_MAKETYPE(CV_64F,3) +#define CV_64FC4 CV_MAKETYPE(CV_64F,4) +#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n)) + +// cvdef.h: + +#define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT) +#define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1) +#define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1) +#define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK) +#define CV_MAT_CONT_FLAG_SHIFT 14 +#define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT) +#define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG) +#define CV_IS_CONT_MAT CV_IS_MAT_CONT +#define CV_SUBMAT_FLAG_SHIFT 15 +#define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT) +#define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG) + +///** Size of each channel item, +// 0x8442211 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */ +//#define CV_ELEM_SIZE1(type) \ +// ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15) + +#define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK) + +/** 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */ +#define CV_ELEM_SIZE(type) \ + (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3)) + +// base.h: +namespace cv +{ +enum BorderTypes { + BORDER_CONSTANT = 0, //!< `iiiiii|abcdefgh|iiiiiii` with some specified `i` + BORDER_REPLICATE = 1, //!< `aaaaaa|abcdefgh|hhhhhhh` + BORDER_REFLECT = 2, //!< `fedcba|abcdefgh|hgfedcb` + BORDER_WRAP = 3, //!< `cdefgh|abcdefgh|abcdefg` + BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba` + BORDER_TRANSPARENT = 5, //!< `uvwxyz|abcdefgh|ijklmno` + + BORDER_REFLECT101 = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 + BORDER_DEFAULT = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 + BORDER_ISOLATED = 16 //!< do not look outside of ROI +}; +// imgproc.hpp: +enum InterpolationFlags{ + INTER_NEAREST = 0, + INTER_LINEAR = 1, + INTER_CUBIC = 2, + INTER_AREA = 3, + INTER_LANCZOS4 = 4, + INTER_LINEAR_EXACT = 5, + INTER_MAX = 7, +}; +} // namespace cv + +static inline int cvFloor( double value ) +{ + int i = (int)value; + return i - (i > value); +} + +#endif // defined(GAPI_STANDALONE) + +#endif // OPENCV_GAPI_CV_DEFS_HPP diff --git a/modules/gapi/include/opencv2/gapi/own/mat.hpp b/modules/gapi/include/opencv2/gapi/own/mat.hpp index 8cccc7ca8b..c3ff7df347 100644 --- a/modules/gapi/include/opencv2/gapi/own/mat.hpp +++ b/modules/gapi/include/opencv2/gapi/own/mat.hpp @@ -5,15 +5,34 @@ // Copyright (C) 2018 Intel Corporation -#ifndef INCLUDE_OPENCV2_GAPI_OWN_MAT_HPP -#define INCLUDE_OPENCV2_GAPI_OWN_MAT_HPP +#ifndef OPENCV_GAPI_OWN_MAT_HPP +#define OPENCV_GAPI_OWN_MAT_HPP -#include "opencv2/core/cvdef.h" +#include "opencv2/gapi/opencv_includes.hpp" #include "opencv2/gapi/own/types.hpp" +#include "opencv2/gapi/own/scalar.hpp" +#include "opencv2/gapi/own/saturate.hpp" +#include "opencv2/gapi/own/assert.hpp" + #include //std::shared_ptr +#include //std::memcpy +#include "opencv2/gapi/util/throw.hpp" namespace cv { namespace gapi { namespace own { namespace detail { + template + void assign_row(void* ptr, int cols, Scalar const& s) + { + auto p = static_cast(ptr); + for (int c = 0; c < cols; c++) + { + for (int ch = 0; ch < channels; ch++) + { + p[c * channels + ch] = saturate(s[ch], roundd); + } + } + } + inline size_t default_step(int type, int cols) { return CV_ELEM_SIZE(type) * cols; @@ -81,12 +100,66 @@ namespace cv { namespace gapi { namespace own { : MatHeader (_rows, _cols, _type, _data, _step) {} + Mat(Mat const& src, const Rect& roi ) + : Mat(src) + { + rows = roi.height; + cols = roi.width; + data = ptr(roi.y, roi.x); + } + Mat(Mat const& src) = default; Mat(Mat&& src) = default; Mat& operator=(Mat const& src) = default; Mat& operator=(Mat&& src) = default; + /** @brief Sets all or some of the array elements to the specified value. + @param s Assigned scalar converted to the actual array type. + */ + Mat& operator = (const Scalar& s) + { + static constexpr unsigned max_channels = 4; //Scalar can't fit more than 4 + GAPI_Assert(static_cast(channels()) <= max_channels); + + using func_p_t = void (*)(void*, int, Scalar const&); + using detail::assign_row; + #define TABLE_ENTRY(type) {assign_row, assign_row, assign_row, assign_row} + static constexpr func_p_t func_tbl[][max_channels] = { + TABLE_ENTRY(uchar), + TABLE_ENTRY(schar), + TABLE_ENTRY(ushort), + TABLE_ENTRY(short), + TABLE_ENTRY(int), + TABLE_ENTRY(float), + TABLE_ENTRY(double) + }; + #undef TABLE_ENTRY + + static_assert(CV_8U == 0 && CV_8S == 1 && CV_16U == 2 && CV_16S == 3 + && CV_32S == 4 && CV_32F == 5 && CV_64F == 6, + "OCV type ids used as indexes to array, thus exact numbers are important!" + ); + + GAPI_Assert(static_cast(depth()) < sizeof(func_tbl)/sizeof(func_tbl[0])); + + for (int r = 0; r < rows; ++r) + { + auto* f = func_tbl[depth()][channels() -1]; + (*f)(static_cast(ptr(r)), cols, s ); + } + return *this; + } + + /** @brief Returns the matrix element size in bytes. + + The method returns the matrix element size in bytes. For example, if the matrix type is CV_16SC3 , + the method returns 3\*sizeof(short) or 6. + */ + size_t elemSize() const + { + return CV_ELEM_SIZE(type()); + } /** @brief Returns the type of a matrix element. The method returns a matrix element type. This is an identifier compatible with the CvMat type @@ -115,13 +188,22 @@ namespace cv { namespace gapi { namespace own { */ int channels() const {return CV_MAT_CN(flags);} + /** + @param _rows New number of rows. + @param _cols New number of columns. + @param _type New matrix type. + */ + void create(int _rows, int _cols, int _type) + { + create({_cols, _rows}, _type); + } /** @overload @param _size Alternative new matrix size specification: Size(cols, rows) @param _type New matrix type. */ - void create(cv::gapi::own::Size _size, int _type) + void create(Size _size, int _type) { - if (_size != cv::gapi::own::Size{cols, rows} ) + if (_size != Size{cols, rows} ) { Mat tmp{_size.height, _size.width, _type, nullptr}; tmp.memory.reset(new uchar[ tmp.step * tmp.rows], [](uchar * p){delete[] p;}); @@ -130,6 +212,71 @@ namespace cv { namespace gapi { namespace own { *this = std::move(tmp); } } + + /** @brief Copies the matrix to another one. + + The method copies the matrix data to another matrix. Before copying the data, the method invokes : + @code + m.create(this->size(), this->type()); + @endcode + so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the + function does not handle the case of a partial overlap between the source and the destination + matrices. + */ + void copyTo(Mat& dst) const + { + dst.create(rows, cols, type()); + for (int r = 0; r < rows; ++r) + { + std::memcpy(dst.ptr(r), ptr(r), detail::default_step(type(),cols)); + } + } + + /** @brief Returns true if the array has no elements. + + The method returns true if Mat::total() is 0 or if Mat::data is NULL. Because of pop_back() and + resize() methods `M.total() == 0` does not imply that `M.data == NULL`. + */ + bool empty() const; + + /** @brief Returns the total number of array elements. + + The method returns the number of array elements (a number of pixels if the array represents an + image). + */ + size_t total() const + { + return static_cast(rows * cols); + } + + + /** @overload + @param roi Extracted submatrix specified as a rectangle. + */ + Mat operator()( const Rect& roi ) const + { + return Mat{*this, roi}; + } + + + /** @brief Returns a pointer to the specified matrix row. + + The methods return `uchar*` or typed pointer to the specified matrix row. See the sample in + Mat::isContinuous to know how to use these methods. + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + uchar* ptr(int row, int col = 0) + { + return const_cast(const_cast(this)->ptr(row,col)); + } + /** @overload */ + const uchar* ptr(int row, int col = 0) const + { + return data + step * row + CV_ELEM_SIZE(type()) * col; + } + + private: //actual memory allocated for storage, or nullptr if object is non owning view to over memory std::shared_ptr memory; @@ -139,4 +286,4 @@ namespace cv { namespace gapi { namespace own { } //namespace gapi } //namespace cv -#endif /* INCLUDE_OPENCV2_GAPI_OWN_MAT_HPP */ +#endif /* OPENCV_GAPI_OWN_MAT_HPP */ diff --git a/modules/gapi/include/opencv2/gapi/own/saturate.hpp b/modules/gapi/include/opencv2/gapi/own/saturate.hpp new file mode 100644 index 0000000000..d08896b71d --- /dev/null +++ b/modules/gapi/include/opencv2/gapi/own/saturate.hpp @@ -0,0 +1,88 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OWN_SATURATE_HPP +#define OPENCV_GAPI_OWN_SATURATE_HPP + +#include +#include + +#include + +namespace cv { namespace gapi { namespace own { +//----------------------------- +// +// Numeric cast with saturation +// +//----------------------------- + +template +static inline DST saturate(SRC x) +{ + // only integral types please! + GAPI_DbgAssert(std::is_integral::value && + std::is_integral::value); + + if (std::is_same::value) + return static_cast(x); + + if (sizeof(DST) > sizeof(SRC)) + return static_cast(x); + + // compiler must recognize this saturation, + // so compile saturate(a + b) with adds + // instruction (e.g.: _mm_adds_epi16 if x86) + return x < std::numeric_limits::min()? + std::numeric_limits::min(): + x > std::numeric_limits::max()? + std::numeric_limits::max(): + static_cast(x); +} + +// Note, that OpenCV rounds differently: +// - like std::round() for add, subtract +// - like std::rint() for multiply, divide +template +static inline DST saturate(SRC x, R round) +{ + if (std::is_floating_point::value) + { + return static_cast(x); + } + else if (std::is_integral::value) + { + GAPI_DbgAssert(std::is_integral::value && + std::is_integral::value); + return saturate(x); + } + else + { + GAPI_DbgAssert(std::is_integral::value && + std::is_floating_point::value); +#ifdef _WIN32 +// Suppress warning about convering x to floating-point +// Note that x is already floating-point at this point +#pragma warning(disable: 4244) +#endif + int ix = static_cast(round(x)); +#ifdef _WIN32 +#pragma warning(default: 4244) +#endif + return saturate(ix); + } +} + +// explicit suffix 'd' for double type +inline double ceild(double x) { return std::ceil(x); } +inline double floord(double x) { return std::floor(x); } +inline double roundd(double x) { return std::round(x); } +inline double rintd(double x) { return std::rint(x); } + +} //namespace own +} //namespace gapi +} //namespace cv +#endif /* OPENCV_GAPI_OWN_SATURATE_HPP */ diff --git a/modules/gapi/include/opencv2/gapi/own/scalar.hpp b/modules/gapi/include/opencv2/gapi/own/scalar.hpp index 52a45af332..bda91c83b5 100644 --- a/modules/gapi/include/opencv2/gapi/own/scalar.hpp +++ b/modules/gapi/include/opencv2/gapi/own/scalar.hpp @@ -8,6 +8,8 @@ #ifndef OPENCV_GAPI_GAPI_OWN_SCALAR_HPP #define OPENCV_GAPI_GAPI_OWN_SCALAR_HPP +#include + namespace cv { namespace gapi @@ -15,7 +17,7 @@ namespace gapi namespace own { -class CV_EXPORTS Scalar +class GAPI_EXPORTS Scalar { public: Scalar() = default; diff --git a/modules/gapi/include/opencv2/gapi/own/types.hpp b/modules/gapi/include/opencv2/gapi/own/types.hpp index 2f909a4982..20445ee0fd 100644 --- a/modules/gapi/include/opencv2/gapi/own/types.hpp +++ b/modules/gapi/include/opencv2/gapi/own/types.hpp @@ -9,9 +9,7 @@ #define OPENCV_GAPI_TYPES_HPP #include // std::max, std::min - -#include "opencv2/core/base.hpp" //for CV_DbgAssert -#include "opencv2/gapi/own/assert.hpp" +#include namespace cv { @@ -35,7 +33,7 @@ class Rect public: Rect() = default; Rect(int _x, int _y, int _width, int _height) : x(_x), y(_y), width(_width), height(_height) {}; -#if 1 +#if !defined(GAPI_STANDALONE) Rect(const cv::Rect& other) : x(other.x), y(other.y), width(other.width), height(other.height) {}; inline Rect& operator=(const cv::Rect& other) { @@ -45,7 +43,7 @@ public: height = other.height; return *this; } -#endif +#endif // !defined(GAPI_STANDALONE) int x = 0; //!< x coordinate of the top-left corner int y = 0; //!< y coordinate of the top-left corner @@ -92,7 +90,7 @@ class Size public: Size() = default; Size(int _width, int _height) : width(_width), height(_height) {}; -#if 1 +#if !defined(GAPI_STANDALONE) Size(const cv::Size& other) : width(other.width), height(other.height) {}; inline Size& operator=(const cv::Size& rhs) { @@ -100,7 +98,7 @@ public: height = rhs.height; return *this; } -#endif +#endif // !defined(GAPI_STANDALONE) int width = 0; int height = 0; diff --git a/modules/gapi/include/opencv2/gapi/util/any.hpp b/modules/gapi/include/opencv2/gapi/util/any.hpp index 31e401181c..3146cb6fdc 100644 --- a/modules/gapi/include/opencv2/gapi/util/any.hpp +++ b/modules/gapi/include/opencv2/gapi/util/any.hpp @@ -97,6 +97,12 @@ namespace util template friend const value_t* any_cast(const any* operand); + template + friend value_t& unsafe_any_cast(any& operand); + + template + friend const value_t& unsafe_any_cast(const any& operand); + friend void swap(any & lhs, any& rhs) { swap(lhs.hldr, rhs.hldr); @@ -148,6 +154,27 @@ namespace util throw_error(bad_any_cast()); } + + template + inline value_t& unsafe_any_cast(any& operand) + { +#ifdef DEBUG + return any_cast(operand); +#else + return static_cast::type> *>(operand.hldr.get())->v; +#endif + } + + template + inline const value_t& unsafe_any_cast(const any& operand) + { +#ifdef DEBUG + return any_cast(operand); +#else + return static_cast::type> *>(operand.hldr.get())->v; +#endif + } + } // namespace util } // namespace cv diff --git a/modules/gapi/perf/cpu/gapi_core_perf_tests_cpu.cpp b/modules/gapi/perf/cpu/gapi_core_perf_tests_cpu.cpp index 405d7f305d..52e17b250c 100644 --- a/modules/gapi/perf/cpu/gapi_core_perf_tests_cpu.cpp +++ b/modules/gapi/perf/cpu/gapi_core_perf_tests_cpu.cpp @@ -5,6 +5,7 @@ // Copyright (C) 2018 Intel Corporation +#include "../perf_precomp.hpp" #include "../common/gapi_core_perf_tests.hpp" namespace opencv_test diff --git a/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp b/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp index ba61af5907..5d42d8b5e5 100644 --- a/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp +++ b/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp @@ -5,6 +5,7 @@ // Copyright (C) 2018 Intel Corporation +#include "../perf_precomp.hpp" #include "../common/gapi_imgproc_perf_tests.hpp" namespace opencv_test diff --git a/modules/gapi/src/api/gapi_priv.cpp b/modules/gapi/src/api/gapi_priv.cpp index 38f17e9f53..744db16715 100644 --- a/modules/gapi/src/api/gapi_priv.cpp +++ b/modules/gapi/src/api/gapi_priv.cpp @@ -5,6 +5,7 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" #include #include "api/gapi_priv.hpp" diff --git a/modules/gapi/src/api/garray.cpp b/modules/gapi/src/api/garray.cpp index e2a346c0bd..0fd19a7e65 100644 --- a/modules/gapi/src/api/garray.cpp +++ b/modules/gapi/src/api/garray.cpp @@ -5,6 +5,7 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" #include "opencv2/gapi/garray.hpp" #include "api/gapi_priv.hpp" // GOrigin diff --git a/modules/gapi/src/api/gbackend.cpp b/modules/gapi/src/api/gbackend.cpp index 72cdcad728..095e76f53d 100644 --- a/modules/gapi/src/api/gbackend.cpp +++ b/modules/gapi/src/api/gbackend.cpp @@ -5,6 +5,7 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" #include // unique_ptr #include "opencv2/gapi/gkernel.hpp" @@ -15,8 +16,6 @@ #include "compiler/gobjref.hpp" #include "compiler/gislandmodel.hpp" - - // GBackend private implementation ///////////////////////////////////////////// void cv::gapi::GBackend::Priv::unpackKernel(ade::Graph & /*graph */ , const ade::NodeHandle & /*op_node*/ , @@ -94,19 +93,24 @@ void bindInArg(Mag& mag, const RcDesc &rc, const GRunArg &arg) switch (arg.index()) { case GRunArg::index_of() : mag_mat = util::get(arg); break; +#if !defined(GAPI_STANDALONE) case GRunArg::index_of() : mag_mat = to_own(util::get(arg)); break; +#endif // !defined(GAPI_STANDALONE) default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?")); } break; } + case GShape::GSCALAR: { auto& mag_scalar = mag.template slot()[rc.id]; switch (arg.index()) { case GRunArg::index_of() : mag_scalar = util::get(arg); break; +#if !defined(GAPI_STANDALONE) case GRunArg::index_of() : mag_scalar = to_own(util::get(arg)); break; +#endif // !defined(GAPI_STANDALONE) default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?")); } break; @@ -131,7 +135,9 @@ void bindOutArg(Mag& mag, const RcDesc &rc, const GRunArgP &arg) switch (arg.index()) { case GRunArgP::index_of() : mag_mat = * util::get(arg); break; +#if !defined(GAPI_STANDALONE) case GRunArgP::index_of() : mag_mat = to_own(* util::get(arg)); break; +#endif // !defined(GAPI_STANDALONE) default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?")); } break; @@ -143,7 +149,9 @@ void bindOutArg(Mag& mag, const RcDesc &rc, const GRunArgP &arg) switch (arg.index()) { case GRunArgP::index_of() : mag_scalar = *util::get(arg); break; +#if !defined(GAPI_STANDALONE) case GRunArgP::index_of() : mag_scalar = to_own(*util::get(arg)); break; +#endif // !defined(GAPI_STANDALONE) default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?")); } break; @@ -238,7 +246,9 @@ void writeBack(const Mag& mag, const RcDesc &rc, GRunArgP &g_arg) switch (g_arg.index()) { case GRunArgP::index_of() : out_arg_data = util::get(g_arg)->data; break; +#if !defined(GAPI_STANDALONE) case GRunArgP::index_of() : out_arg_data = util::get(g_arg)->data; break; +#endif // !defined(GAPI_STANDALONE) default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?")); } @@ -252,7 +262,9 @@ void writeBack(const Mag& mag, const RcDesc &rc, GRunArgP &g_arg) switch (g_arg.index()) { case GRunArgP::index_of() : *util::get(g_arg) = mag.template slot().at(rc.id); break; +#if !defined(GAPI_STANDALONE) case GRunArgP::index_of() : *util::get(g_arg) = cv::gapi::own::to_ocv(mag.template slot().at(rc.id)); break; +#endif // !defined(GAPI_STANDALONE) default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?")); } break; diff --git a/modules/gapi/src/api/gcall.cpp b/modules/gapi/src/api/gcall.cpp index bc23ec8854..2dd823daa6 100644 --- a/modules/gapi/src/api/gcall.cpp +++ b/modules/gapi/src/api/gcall.cpp @@ -5,6 +5,7 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" #include #include "opencv2/gapi/gcall.hpp" #include "api/gcall_priv.hpp" diff --git a/modules/gapi/src/api/gcomputation.cpp b/modules/gapi/src/api/gcomputation.cpp index 817da8fd29..96640e296e 100644 --- a/modules/gapi/src/api/gcomputation.cpp +++ b/modules/gapi/src/api/gcomputation.cpp @@ -5,11 +5,11 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" #include // remove_if #include // isspace (non-locale version) #include -#include "opencv2/core/cvdef.h" #include "logger.hpp" // GAPI_LOG #include "opencv2/gapi/gcomputation.hpp" @@ -89,6 +89,21 @@ void cv::GComputation::apply(GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&ar m_priv->m_lastCompiled(std::move(ins), std::move(outs)); } +void cv::GComputation::apply(const std::vector &ins, + const std::vector &outs, + GCompileArgs &&args) +{ + GRunArgs call_ins; + GRunArgsP call_outs; + + auto tmp = outs; + for (const cv::gapi::own::Mat &m : ins) { call_ins.emplace_back(m); } + for ( cv::gapi::own::Mat &m : tmp) { call_outs.emplace_back(&m); } + + apply(std::move(call_ins), std::move(call_outs), std::move(args)); +} + +#if !defined(GAPI_STANDALONE) void cv::GComputation::apply(cv::Mat in, cv::Mat &out, GCompileArgs &&args) { apply(cv::gin(in), cv::gout(out), std::move(args)); @@ -126,6 +141,7 @@ void cv::GComputation::apply(const std::vector &ins, apply(std::move(call_ins), std::move(call_outs), std::move(args)); } +#endif // !defined(GAPI_STANDALONE) cv::GComputation::Priv& cv::GComputation::priv() { diff --git a/modules/gapi/src/api/gkernel.cpp b/modules/gapi/src/api/gkernel.cpp index 812877b1fe..5dc98f0a59 100644 --- a/modules/gapi/src/api/gkernel.cpp +++ b/modules/gapi/src/api/gkernel.cpp @@ -5,13 +5,13 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" #include // cerr #include // hash #include // accumulate #include -#include "opencv2/core/cvdef.h" #include "logger.hpp" #include "opencv2/gapi/gkernel.hpp" diff --git a/modules/gapi/src/api/gmat.cpp b/modules/gapi/src/api/gmat.cpp index 5b3aa0758d..3dd8277905 100644 --- a/modules/gapi/src/api/gmat.cpp +++ b/modules/gapi/src/api/gmat.cpp @@ -5,6 +5,7 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" #include #include //gapi::own::Mat @@ -32,10 +33,12 @@ const cv::GOrigin& cv::GMat::priv() const return *m_priv; } +#if !defined(GAPI_STANDALONE) cv::GMatDesc cv::descr_of(const cv::Mat &mat) { return GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}}; } +#endif cv::GMatDesc cv::gapi::own::descr_of(const cv::gapi::own::Mat &mat) { diff --git a/modules/gapi/src/api/gnode.cpp b/modules/gapi/src/api/gnode.cpp index 4255ea6c7e..efda5d5427 100644 --- a/modules/gapi/src/api/gnode.cpp +++ b/modules/gapi/src/api/gnode.cpp @@ -5,6 +5,7 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" #include #include "api/gnode.hpp" diff --git a/modules/gapi/src/api/gproto.cpp b/modules/gapi/src/api/gproto.cpp index 13da40e5d1..6f6fad407b 100644 --- a/modules/gapi/src/api/gproto.cpp +++ b/modules/gapi/src/api/gproto.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include #include "opencv2/gapi/util/throw.hpp" #include "opencv2/gapi/garg.hpp" @@ -86,11 +88,16 @@ cv::GMetaArg cv::descr_of(const cv::GRunArg &arg) { switch (arg.index()) { +#if !defined(GAPI_STANDALONE) case GRunArg::index_of(): return cv::GMetaArg(descr_of(util::get(arg))); case GRunArg::index_of(): return cv::GMetaArg(descr_of(util::get(arg))); +#endif // !defined(GAPI_STANDALONE) + + case GRunArg::index_of(): + return cv::GMetaArg(descr_of(util::get(arg))); case GRunArg::index_of(): return cv::GMetaArg(descr_of(util::get(arg))); @@ -113,9 +120,11 @@ cv::GMetaArg cv::descr_of(const cv::GRunArgP &argp) { switch (argp.index()) { +#if !defined(GAPI_STANDALONE) case GRunArgP::index_of(): return GMetaArg(descr_of(*util::get(argp))); - case GRunArgP::index_of(): return GMetaArg(descr_of(*util::get(argp))); case GRunArgP::index_of(): return GMetaArg(descr_of(*util::get(argp))); +#endif // !defined(GAPI_STANDALONE) + case GRunArgP::index_of(): return GMetaArg(descr_of(*util::get(argp))); case GRunArgP::index_of(): return GMetaArg(descr_of(*util::get(argp))); case GRunArgP::index_of(): return GMetaArg(util::get(argp).descr_of()); default: util::throw_error(std::logic_error("Unsupported GRunArgP type")); diff --git a/modules/gapi/src/api/gscalar.cpp b/modules/gapi/src/api/gscalar.cpp index d8d73cd732..30f3dc9447 100644 --- a/modules/gapi/src/api/gscalar.cpp +++ b/modules/gapi/src/api/gscalar.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include "opencv2/gapi/gscalar.hpp" #include "opencv2/gapi/own/convert.hpp" #include "api/gapi_priv.hpp" // GOrigin @@ -30,11 +32,6 @@ cv::GScalar::GScalar(cv::gapi::own::Scalar&& s) { } -cv::GScalar::GScalar(const cv::Scalar& s) - : m_priv(new GOrigin(GShape::GSCALAR, cv::gimpl::ConstVal(to_own(s)))) -{ -} - cv::GScalar::GScalar(double v0) : m_priv(new GOrigin(GShape::GSCALAR, cv::gimpl::ConstVal(cv::gapi::own::Scalar(v0)))) { @@ -55,10 +52,17 @@ cv::GScalarDesc cv::descr_of(const cv::gapi::own::Scalar &) return empty_scalar_desc(); } +#if !defined(GAPI_STANDALONE) +cv::GScalar::GScalar(const cv::Scalar& s) + : m_priv(new GOrigin(GShape::GSCALAR, cv::gimpl::ConstVal(to_own(s)))) +{ +} + cv::GScalarDesc cv::descr_of(const cv::Scalar& s) { return cv::descr_of(to_own(s)); } +#endif // !defined(GAPI_STANDALONE) namespace cv { std::ostream& operator<<(std::ostream& os, const cv::GScalarDesc &) diff --git a/modules/gapi/src/api/kernels_core.cpp b/modules/gapi/src/api/kernels_core.cpp index 9a58706e0a..c4f8d89abb 100644 --- a/modules/gapi/src/api/kernels_core.cpp +++ b/modules/gapi/src/api/kernels_core.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include "opencv2/gapi/gcall.hpp" #include "opencv2/gapi/gscalar.hpp" #include "opencv2/gapi/gkernel.hpp" diff --git a/modules/gapi/src/api/kernels_imgproc.cpp b/modules/gapi/src/api/kernels_imgproc.cpp index 0cd2b5a865..f37ee00a45 100644 --- a/modules/gapi/src/api/kernels_imgproc.cpp +++ b/modules/gapi/src/api/kernels_imgproc.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include "opencv2/gapi/gscalar.hpp" #include "opencv2/gapi/gcall.hpp" #include "opencv2/gapi/gkernel.hpp" diff --git a/modules/gapi/src/api/operators.cpp b/modules/gapi/src/api/operators.cpp index 78a883e771..44fc4fa527 100644 --- a/modules/gapi/src/api/operators.cpp +++ b/modules/gapi/src/api/operators.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include "opencv2/gapi/imgproc.hpp" #include "opencv2/gapi/core.hpp" #include "opencv2/gapi/gscalar.hpp" diff --git a/modules/gapi/src/backends/common/gcompoundbackend.cpp b/modules/gapi/src/backends/common/gcompoundbackend.cpp index 25fa8a2ace..948898f28d 100644 --- a/modules/gapi/src/backends/common/gcompoundbackend.cpp +++ b/modules/gapi/src/backends/common/gcompoundbackend.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include "opencv2/gapi/gcompoundkernel.hpp" // compound::backend() #include "api/gbackend_priv.hpp" diff --git a/modules/gapi/src/backends/common/gcompoundkernel.cpp b/modules/gapi/src/backends/common/gcompoundkernel.cpp index fd9609e4db..89abcef59d 100644 --- a/modules/gapi/src/backends/common/gcompoundkernel.cpp +++ b/modules/gapi/src/backends/common/gcompoundkernel.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include // util::indexed #include "opencv2/gapi/gcompoundkernel.hpp" #include "compiler/gobjref.hpp" diff --git a/modules/gapi/src/backends/cpu/gcpubackend.cpp b/modules/gapi/src/backends/cpu/gcpubackend.cpp index 42e580b950..5cc8bb0b70 100644 --- a/modules/gapi/src/backends/cpu/gcpubackend.cpp +++ b/modules/gapi/src/backends/cpu/gcpubackend.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include #include diff --git a/modules/gapi/src/backends/cpu/gcpukernel.cpp b/modules/gapi/src/backends/cpu/gcpukernel.cpp index a672892953..af13eed6c2 100644 --- a/modules/gapi/src/backends/cpu/gcpukernel.cpp +++ b/modules/gapi/src/backends/cpu/gcpukernel.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include #include "opencv2/gapi/cpu/gcpukernel.hpp" diff --git a/modules/gapi/src/backends/fluid/gfluidbackend.cpp b/modules/gapi/src/backends/fluid/gfluidbackend.cpp index 758f84e920..3c2a32f510 100644 --- a/modules/gapi/src/backends/fluid/gfluidbackend.cpp +++ b/modules/gapi/src/backends/fluid/gfluidbackend.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include #include #include // std::fixed, std::setprecision @@ -191,7 +193,7 @@ static int calcGcd (int n1, int n2) static int calcResizeWindow(int inH, int outH) { - CV_Assert(inH >= outH); + GAPI_Assert(inH >= outH); auto gcd = calcGcd(inH, outH); int inPeriodH = inH/gcd; int outPeriodH = outH/gcd; @@ -222,7 +224,7 @@ static int maxReadWindow(const cv::GFluidKernel& k, int inH, int outH) return (inH == 1) ? 1 : 2; } } break; - default: CV_Assert(false); return 0; + default: GAPI_Assert(false); return 0; } } @@ -233,7 +235,7 @@ static int borderSize(const cv::GFluidKernel& k) case cv::GFluidKernel::Kind::Filter: return (k.m_window - 1) / 2; break; // Resize never reads from border pixels case cv::GFluidKernel::Kind::Resize: return 0; break; - default: CV_Assert(false); return 0; + default: GAPI_Assert(false); return 0; } } @@ -261,7 +263,7 @@ double inCoordUpscale(int outCoord, double ratio) int upscaleWindowStart(int outCoord, double ratio) { int start = static_cast(inCoordUpscale(outCoord, ratio)); - CV_Assert(start >= 0); + GAPI_DbgAssert(start >= 0); return start; } @@ -331,7 +333,7 @@ int cv::gimpl::FluidUpscaleAgent::linesRead() const bool cv::gimpl::FluidAgent::canRead() const { // An agent can work if every input buffer have enough data to start - for (auto in_view : in_views) + for (const auto& in_view : in_views) { if (in_view) { @@ -346,7 +348,7 @@ bool cv::gimpl::FluidAgent::canWrite() const { // An agent can work if there is space to write in its output // allocated buffers - CV_Assert(!out_buffers.empty()); + GAPI_DbgAssert(!out_buffers.empty()); auto out_begin = out_buffers.begin(); auto out_end = out_buffers.end(); if (k.m_scratch) out_end--; @@ -367,15 +369,15 @@ bool cv::gimpl::FluidAgent::canWork() const void cv::gimpl::FluidAgent::doWork() { - GAPI_Assert(m_outputLines > m_producedLines); - for (auto in_view : in_views) + GAPI_DbgAssert(m_outputLines > m_producedLines); + for (auto& in_view : in_views) { if (in_view) in_view.priv().prepareToRead(); } k.m_f(in_args, out_buffers); - for (auto in_view : in_views) + for (auto& in_view : in_views) { if (in_view) in_view.priv().readDone(linesRead(), nextWindow()); } @@ -462,7 +464,7 @@ cv::gimpl::GFluidExecutable::GFluidExecutable(const ade::Graph &g, m_agents.emplace_back(new FluidUpscaleAgent(m_g, nh)); } } break; - default: CV_Assert(false); + default: GAPI_Assert(false); } // NB.: in_buffer_ids size is equal to Arguments size, not Edges size!!! m_agents.back()->in_buffer_ids.resize(m_gm.metadata(nh).get().args.size(), -1); @@ -517,7 +519,7 @@ cv::gimpl::GFluidExecutable::GFluidExecutable(const ade::Graph &g, if (proto.outputs.size() != m_outputRois.size()) { - CV_Assert(m_outputRois.size() == 0); + GAPI_Assert(m_outputRois.size() == 0); m_outputRois.resize(proto.outputs.size()); } @@ -623,7 +625,7 @@ cv::gimpl::GFluidExecutable::GFluidExecutable(const ade::Graph &g, { case GFluidKernel::Kind::Filter: resized = produced; break; case GFluidKernel::Kind::Resize: resized = adjResizeRoi(produced, in_meta.size, meta.size); break; - default: CV_Assert(false); + default: GAPI_Assert(false); } int readStart = resized.y; @@ -773,7 +775,7 @@ void cv::gimpl::GFluidExecutable::bindInArg(const cv::gimpl::RcDesc &rc, const G { switch (rc.shape) { - case GShape::GMAT: m_buffers[m_id_map.at(rc.id)].priv().bindTo(to_ocv(util::get(arg)), true); break; + case GShape::GMAT: m_buffers[m_id_map.at(rc.id)].priv().bindTo(util::get(arg), true); break; case GShape::GSCALAR: m_res.slot()[rc.id] = util::get(arg); break; default: util::throw_error(std::logic_error("Unsupported GShape type")); } @@ -790,7 +792,7 @@ void cv::gimpl::GFluidExecutable::bindOutArg(const cv::gimpl::RcDesc &rc, const auto &outMat = *util::get(arg); GAPI_Assert(outMat.data != nullptr); GAPI_Assert(descr_of(outMat) == desc && "Output argument was not preallocated as it should be ?"); - m_buffers[m_id_map.at(rc.id)].priv().bindTo(to_ocv(outMat), false); + m_buffers[m_id_map.at(rc.id)].priv().bindTo(outMat, false); break; } default: util::throw_error(std::logic_error("Unsupported return GShape type")); @@ -839,7 +841,7 @@ void cv::gimpl::GFluidExecutable::run(std::vector &&input_objs, for (auto scratch_i : m_scratch_users) { auto &agent = m_agents[scratch_i]; - GAPI_Assert(agent->k.m_scratch); + GAPI_DbgAssert(agent->k.m_scratch); agent->k.m_rs(*agent->out_buffers.back()); } @@ -983,7 +985,7 @@ void GFluidBackendImpl::addBackendPasses(ade::ExecutionEngineSetupContext &ectx) } } - CV_Assert(in_hs.size() == 1 && out_ws.size() == 1 && out_hs.size() == 1); + GAPI_Assert(in_hs.size() == 1 && out_ws.size() == 1 && out_hs.size() == 1); auto in_h = *in_hs .cbegin(); auto out_h = *out_hs.cbegin(); diff --git a/modules/gapi/src/backends/fluid/gfluidbuffer.cpp b/modules/gapi/src/backends/fluid/gfluidbuffer.cpp index 6614091587..83671b9202 100644 --- a/modules/gapi/src/backends/fluid/gfluidbuffer.cpp +++ b/modules/gapi/src/backends/fluid/gfluidbuffer.cpp @@ -5,9 +5,12 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include // hex, dec (debug) #include "opencv2/gapi/own/convert.hpp" +#include "opencv2/gapi/own/types.hpp" #include "opencv2/gapi/fluid/gfluidbuffer.hpp" #include "backends/fluid/gfluidbuffer_priv.hpp" @@ -18,6 +21,11 @@ namespace cv { namespace gapi { +//namespace own { +// class Mat; +// CV_EXPORTS cv::GMatDesc descr_of(const Mat &mat); +//}//own + namespace fluid { bool operator == (const fluid::Border& b1, const fluid::Border& b2) { @@ -79,7 +87,7 @@ void fillConstBorderRow(uint8_t* row, int length, int chan, int borderSize, cv:: } // Fills const border pixels in the whole mat -void fillBorderConstant(int borderSize, cv::gapi::own::Scalar borderValue, cv::Mat& mat) +void fillBorderConstant(int borderSize, cv::gapi::own::Scalar borderValue, cv::gapi::own::Mat& mat) { // cv::Scalar can contain maximum 4 chan GAPI_Assert(mat.channels() > 0 && mat.channels() <= 4); @@ -91,7 +99,7 @@ void fillBorderConstant(int borderSize, cv::gapi::own::Scalar borderValue, cv::M case CV_16S: return &fillConstBorderRow< int16_t>; break; case CV_16U: return &fillConstBorderRow; break; case CV_32F: return &fillConstBorderRow< float >; break; - default: CV_Assert(false); return &fillConstBorderRow; + default: GAPI_Assert(false); return &fillConstBorderRow; } }; @@ -105,7 +113,7 @@ void fillBorderConstant(int borderSize, cv::gapi::own::Scalar borderValue, cv::M fluid::BorderHandler::BorderHandler(int border_size) { - CV_Assert(border_size > 0); + GAPI_Assert(border_size > 0); m_border_size = border_size; } @@ -122,7 +130,7 @@ fluid::BorderHandlerT::BorderHandlerT(int border_size, int data_type case CV_16S: return &fillBorderReplicateRow< int16_t>; break; case CV_16U: return &fillBorderReplicateRow; break; case CV_32F: return &fillBorderReplicateRow< float >; break; - default: CV_Assert(!"Unsupported data type"); return &fillBorderReplicateRow; + default: GAPI_Assert(!"Unsupported data type"); return &fillBorderReplicateRow; } } else if (border == cv::BORDER_REFLECT_101) @@ -133,12 +141,12 @@ fluid::BorderHandlerT::BorderHandlerT(int border_size, int data_type case CV_16S: return &fillBorderReflectRow< int16_t>; break; case CV_16U: return &fillBorderReflectRow; break; case CV_32F: return &fillBorderReflectRow< float >; break; - default: CV_Assert(!"Unsupported data type"); return &fillBorderReflectRow; + default: GAPI_Assert(!"Unsupported data type"); return &fillBorderReflectRow; } } else { - CV_Assert(!"Unsupported border type"); + GAPI_Assert(!"Unsupported border type"); return &fillBorderReflectRow; } }; @@ -171,7 +179,7 @@ fluid::BorderHandlerT::BorderHandlerT(int border_size, cv:: : BorderHandler(border_size), m_border_value(border_value) { m_const_border.create(1, desc_width + 2*m_border_size, data_type); - m_const_border = cv::gapi::own::to_ocv(border_value); + m_const_border = border_value; } const uint8_t* fluid::BorderHandlerT::inLineB(int /*log_idx*/, const BufferStorageWithBorder& /*data*/, int /*desc_height*/) const @@ -218,7 +226,7 @@ void fluid::BufferStorageWithBorder::create(int capacity, int desc_width, int dt case cv::BORDER_REFLECT_101: m_borderHandler.reset(new BorderHandlerT(border_size, dtype)); break; default: - CV_Assert(false); + GAPI_Assert(false); } m_borderHandler->fillCompileTimeBorder(*this); @@ -249,11 +257,10 @@ const uint8_t* fluid::BufferStorageWithoutBorder::inLineB(int log_idx, int /*des return ptr(log_idx); } -static void copyWithoutBorder(const cv::Mat& src, int src_border_size, cv::Mat& dst, int dst_border_size, int startSrcLine, int startDstLine, int lpi) +static void copyWithoutBorder(const cv::gapi::own::Mat& src, int src_border_size, cv::gapi::own::Mat& dst, int dst_border_size, int startSrcLine, int startDstLine, int lpi) { - // FIXME use cv::gapi::own::Rect when implement cv::gapi::own::Mat - auto subSrc = src(cv::Rect{src_border_size, startSrcLine, src.cols - 2*src_border_size, lpi}); - auto subDst = dst(cv::Rect{dst_border_size, startDstLine, dst.cols - 2*dst_border_size, lpi}); + auto subSrc = src(cv::gapi::own::Rect{src_border_size, startSrcLine, src.cols - 2*src_border_size, lpi}); + auto subDst = dst(cv::gapi::own::Rect{dst_border_size, startDstLine, dst.cols - 2*dst_border_size, lpi}); subSrc.copyTo(subDst); } @@ -337,8 +344,8 @@ std::unique_ptr createStorage(int capacity, int desc_width return std::move(storage); } -std::unique_ptr createStorage(const cv::Mat& data, cv::gapi::own::Rect roi); -std::unique_ptr createStorage(const cv::Mat& data, cv::gapi::own::Rect roi) +std::unique_ptr createStorage(const cv::gapi::own::Mat& data, cv::gapi::own::Rect roi); +std::unique_ptr createStorage(const cv::gapi::own::Mat& data, cv::gapi::own::Rect roi) { std::unique_ptr storage(new BufferStorageWithoutBorder); storage->attach(data, roi); @@ -359,7 +366,7 @@ void fluid::View::Priv::reset(int linesForFirstIteration) void fluid::View::Priv::readDone(int linesRead, int linesForNextIteration) { - CV_DbgAssert(m_p); + GAPI_DbgAssert(m_p); m_read_caret += linesRead; m_read_caret %= m_p->meta().size.height; m_lines_next_iter = linesForNextIteration; @@ -380,7 +387,7 @@ bool fluid::View::Priv::ready() const fluid::ViewPrivWithoutOwnBorder::ViewPrivWithoutOwnBorder(const Buffer *parent, int borderSize) { - CV_Assert(parent); + GAPI_Assert(parent); m_p = parent; m_border_size = borderSize; } @@ -391,8 +398,8 @@ const uint8_t* fluid::ViewPrivWithoutOwnBorder::InLineB(int index) const const auto &p_priv = m_p->priv(); - CV_Assert( index >= -m_border_size - && index < -m_border_size + m_lines_next_iter); + GAPI_DbgAssert(index >= -m_border_size + && index < -m_border_size + m_lines_next_iter); const int log_idx = m_read_caret + index; @@ -439,9 +446,8 @@ std::size_t fluid::ViewPrivWithOwnBorder::size() const const uint8_t* fluid::ViewPrivWithOwnBorder::InLineB(int index) const { GAPI_DbgAssert(m_p); - - GAPI_Assert( index >= -m_border_size - && index < -m_border_size + m_lines_next_iter); + GAPI_DbgAssert(index >= -m_border_size + && index < -m_border_size + m_lines_next_iter); const int log_idx = m_read_caret + index; @@ -473,7 +479,7 @@ int fluid::View::y() const return m_priv->m_read_caret - m_priv->m_border_size; } -cv::GMatDesc fluid::View::meta() const +const GMatDesc& fluid::View::meta() const { // FIXME: cover with test! return m_priv->m_p->meta(); @@ -522,16 +528,8 @@ void fluid::Buffer::Priv::allocate(BorderOpt border) // Init physical buffer - // FIXME? combine with skew? - auto maxRead = m_line_consumption + m_skew; - auto maxWritten = m_writer_lpi; - - auto max = std::max(maxRead, maxWritten); - auto min = std::min(maxRead, maxWritten); - - // FIXME: - // Fix the deadlock (completely)!!! - auto data_height = static_cast(std::ceil((double)max / min) * min); + // FIXME? combine line_consumption with skew? + auto data_height = std::max(m_line_consumption, m_skew) + m_writer_lpi - 1; m_storage = createStorage(data_height, m_desc.size.width, @@ -543,12 +541,12 @@ void fluid::Buffer::Priv::allocate(BorderOpt border) m_write_caret = 0; } -void fluid::Buffer::Priv::bindTo(const cv::Mat &data, bool is_input) +void fluid::Buffer::Priv::bindTo(const cv::gapi::own::Mat &data, bool is_input) { // FIXME: move all these fields into a separate structure GAPI_Assert(m_skew == 0); - GAPI_Assert(m_desc == cv::descr_of(data)); - if ( is_input) CV_Assert(m_writer_lpi == 1); + GAPI_Assert(m_desc == descr_of(data)); + if ( is_input) GAPI_Assert(m_writer_lpi == 1); m_storage = createStorage(data, m_roi); @@ -617,7 +615,7 @@ int fluid::Buffer::Priv::linesReady() const uint8_t* fluid::Buffer::Priv::OutLineB(int index) { - GAPI_Assert(index >= 0 && index < m_writer_lpi); + GAPI_DbgAssert(index >= 0 && index < m_writer_lpi); return m_storage->ptr(m_write_caret + index); } @@ -658,7 +656,7 @@ fluid::Buffer::Buffer(const cv::GMatDesc &desc, m_priv->allocate(border); } -fluid::Buffer::Buffer(const cv::Mat &data, bool is_input) +fluid::Buffer::Buffer(const cv::gapi::own::Mat &data, bool is_input) : m_priv(new Priv()) { int lineConsumption = 1; @@ -688,7 +686,7 @@ int fluid::Buffer::lpi() const return m_priv->lpi(); } -cv::GMatDesc fluid::Buffer::meta() const +const GMatDesc& fluid::Buffer::meta() const { return m_priv->meta(); } diff --git a/modules/gapi/src/backends/fluid/gfluidbuffer_priv.hpp b/modules/gapi/src/backends/fluid/gfluidbuffer_priv.hpp index f8b03d10d9..d1f339b63b 100644 --- a/modules/gapi/src/backends/fluid/gfluidbuffer_priv.hpp +++ b/modules/gapi/src/backends/fluid/gfluidbuffer_priv.hpp @@ -12,6 +12,12 @@ #include "opencv2/gapi/fluid/gfluidbuffer.hpp" #include "opencv2/gapi/own/convert.hpp" // cv::gapi::own::to_ocv +#include "opencv2/gapi/own/exports.hpp" // GAPI_EXPORTS + +namespace gapi { namespace own { + class Mat; + GAPI_EXPORTS cv::GMatDesc descr_of(const Mat &mat); +}}//gapi::own namespace cv { namespace gapi { @@ -30,13 +36,13 @@ public: virtual const uint8_t* inLineB(int log_idx, const BufferStorageWithBorder &data, int desc_height) const = 0; // Fills border pixels after buffer allocation (if possible (for const border)) - virtual void fillCompileTimeBorder(BufferStorageWithBorder &) const { /* nothing */ } + inline virtual void fillCompileTimeBorder(BufferStorageWithBorder &) const { /* nothing */ } // Fills required border lines - virtual void updateBorderPixels(BufferStorageWithBorder& /*data*/, int /*startLine*/, int /*lpi*/) const { /* nothing */ } + inline virtual void updateBorderPixels(BufferStorageWithBorder& /*data*/, int /*startLine*/, int /*lpi*/) const { /* nothing */ } inline int borderSize() const { return m_border_size; } - virtual std::size_t size() const { return 0; } + inline virtual std::size_t size() const { return 0; } }; template @@ -53,7 +59,7 @@ template<> class BorderHandlerT : public BorderHandler { cv::gapi::own::Scalar m_border_value; - cv::Mat m_const_border; + cv::gapi::own::Mat m_const_border; public: BorderHandlerT(int border_size, cv::gapi::own::Scalar border_value, int data_type, int desc_width); @@ -65,7 +71,7 @@ public: class BufferStorage { protected: - cv::Mat m_data; + cv::gapi::own::Mat m_data; public: virtual void copyTo(BufferStorageWithBorder &dst, int startLine, int nLines) const = 0; @@ -77,8 +83,8 @@ public: inline bool empty() const { return m_data.empty(); } - inline const cv::Mat& data() const { return m_data; } - inline cv::Mat& data() { return m_data; } + inline const cv::gapi::own::Mat& data() const { return m_data; } + inline cv::gapi::own::Mat& data() { return m_data; } inline int rows() const { return m_data.rows; } inline int cols() const { return m_data.cols; } @@ -114,9 +120,9 @@ public: return m_data.ptr(physIdx(idx), 0); } - inline void attach(const cv::Mat& _data, const cv::gapi::own::Rect& _roi) + inline void attach(const cv::gapi::own::Mat& _data, cv::gapi::own::Rect _roi) { - m_data = _data(cv::gapi::own::to_ocv(_roi)); + m_data = _data(_roi); m_roi = _roi; m_is_virtual = false; } @@ -198,9 +204,9 @@ public: // API used by actors/backend ViewPrivWithoutOwnBorder(const Buffer *p, int borderSize); - virtual void prepareToRead() override { /* nothing */ } + inline virtual void prepareToRead() override { /* nothing */ } - virtual std::size_t size() const override { return 0; } + inline virtual std::size_t size() const override { return 0; } // API used (indirectly) by user code virtual const uint8_t* InLineB(int index) const override; @@ -264,11 +270,11 @@ public: cv::gapi::own::Rect roi); void allocate(BorderOpt border); - void bindTo(const cv::Mat &data, bool is_input); + void bindTo(const cv::gapi::own::Mat &data, bool is_input); - void addView(const View& view) { m_views.push_back(view); } + inline void addView(const View& view) { m_views.push_back(view); } - const GMatDesc meta() const { return m_desc; } + inline const GMatDesc& meta() const { return m_desc; } bool full() const; void writeDone(); diff --git a/modules/gapi/src/backends/fluid/gfluidcore.cpp b/modules/gapi/src/backends/fluid/gfluidcore.cpp index f6d1e5b7d1..3b6e7bdf1b 100644 --- a/modules/gapi/src/backends/fluid/gfluidcore.cpp +++ b/modules/gapi/src/backends/fluid/gfluidcore.cpp @@ -4,6 +4,9 @@ // // Copyright (C) 2018 Intel Corporation +#if !defined(GAPI_STANDALONE) + +#include "precomp.hpp" #include "opencv2/gapi/own/assert.hpp" #include "opencv2/core/traits.hpp" @@ -2119,3 +2122,5 @@ cv::gapi::GKernelPackage cv::gapi::core::fluid::kernels() #endif >(); } + +#endif // !defined(GAPI_STANDALONE) diff --git a/modules/gapi/src/backends/fluid/gfluidimgproc.cpp b/modules/gapi/src/backends/fluid/gfluidimgproc.cpp index 1dd291ad51..58321f332c 100644 --- a/modules/gapi/src/backends/fluid/gfluidimgproc.cpp +++ b/modules/gapi/src/backends/fluid/gfluidimgproc.cpp @@ -4,6 +4,9 @@ // // Copyright (C) 2018 Intel Corporation +#if !defined(GAPI_STANDALONE) + +#include "precomp.hpp" #include "opencv2/gapi/own/assert.hpp" #include "opencv2/core/traits.hpp" @@ -1323,3 +1326,5 @@ cv::gapi::GKernelPackage cv::gapi::imgproc::fluid::kernels() #endif >(); } + +#endif // !defined(GAPI_STANDALONE) diff --git a/modules/gapi/src/backends/fluid/gfluidutils.hpp b/modules/gapi/src/backends/fluid/gfluidutils.hpp index 2749525dde..a38b2f132e 100644 --- a/modules/gapi/src/backends/fluid/gfluidutils.hpp +++ b/modules/gapi/src/backends/fluid/gfluidutils.hpp @@ -11,78 +11,17 @@ #include #include #include //UNUSED +#include namespace cv { namespace gapi { namespace fluid { -//----------------------------- -// -// Numeric cast with saturation -// -//----------------------------- - -template -static inline DST saturate(SRC x) -{ - // only integral types please! - GAPI_DbgAssert(std::is_integral::value && - std::is_integral::value); - - if (std::is_same::value) - return static_cast(x); - - if (sizeof(DST) > sizeof(SRC)) - return static_cast(x); - - // compiler must recognize this saturation, - // so compile saturate(a + b) with adds - // instruction (e.g.: _mm_adds_epi16 if x86) - return x < std::numeric_limits::min()? - std::numeric_limits::min(): - x > std::numeric_limits::max()? - std::numeric_limits::max(): - static_cast(x); -} - -// Note, that OpenCV rounds differently: -// - like std::round() for add, subtract -// - like std::rint() for multiply, divide -template -static inline DST saturate(SRC x, R round) -{ - if (std::is_floating_point::value) - { - return static_cast(x); - } - else if (std::is_integral::value) - { - GAPI_DbgAssert(std::is_integral::value && - std::is_integral::value); - return saturate(x); - } - else - { - GAPI_DbgAssert(std::is_integral::value && - std::is_floating_point::value); -#ifdef _WIN32 -// Suppress warning about convering x to floating-point -// Note that x is already floating-point at this point -#pragma warning(disable: 4244) -#endif - int ix = static_cast(round(x)); -#ifdef _WIN32 -#pragma warning(default: 4244) -#endif - return saturate(ix); - } -} - -// explicit suffix 'd' for double type -static inline double ceild(double x) { return std::ceil(x); } -static inline double floord(double x) { return std::floor(x); } -static inline double roundd(double x) { return std::round(x); } -static inline double rintd(double x) { return std::rint(x); } +using cv::gapi::own::saturate; +using cv::gapi::own::ceild; +using cv::gapi::own::floord; +using cv::gapi::own::roundd; +using cv::gapi::own::rintd; //-------------------------------- // diff --git a/modules/gapi/src/compiler/gcompiled.cpp b/modules/gapi/src/compiler/gcompiled.cpp index 49f5ed877e..4bcca9fedd 100644 --- a/modules/gapi/src/compiler/gcompiled.cpp +++ b/modules/gapi/src/compiler/gcompiled.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include #include "opencv2/gapi/gproto.hpp" // descr_of @@ -80,6 +82,7 @@ void cv::GCompiled::operator() (GRunArgs &&ins, GRunArgsP &&outs) m_priv->run(cv::gimpl::GRuntimeArgs{std::move(ins),std::move(outs)}); } +#if !defined(GAPI_STANDALONE) void cv::GCompiled::operator ()(cv::Mat in, cv::Mat &out) { (*this)(cv::gin(in), cv::gout(out)); @@ -113,6 +116,8 @@ void cv::GCompiled::operator ()(const std::vector &ins, (*this)(std::move(call_ins), std::move(call_outs)); } +#endif // !defined(GAPI_STANDALONE) + const cv::GMetaArgs& cv::GCompiled::metas() const { diff --git a/modules/gapi/src/compiler/gcompiler.cpp b/modules/gapi/src/compiler/gcompiler.cpp index e1c0d3ace5..e37301a135 100644 --- a/modules/gapi/src/compiler/gcompiler.cpp +++ b/modules/gapi/src/compiler/gcompiler.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include #include #include @@ -32,22 +34,28 @@ #include "backends/common/gbackend.hpp" // +#if !defined(GAPI_STANDALONE) #include "opencv2/gapi/cpu/core.hpp" // Also directly refer to Core #include "opencv2/gapi/cpu/imgproc.hpp" // ...and Imgproc kernel implementations +#endif // !defined(GAPI_STANDALONE) // #include "opencv2/gapi/gcompoundkernel.hpp" // compound::backend() -#include "opencv2/core/cvdef.h" #include "logger.hpp" namespace { cv::gapi::GKernelPackage getKernelPackage(cv::GCompileArgs &args) { - static auto ocv_pkg = combine(cv::gapi::core::cpu::kernels(), - cv::gapi::imgproc::cpu::kernels(), - cv::unite_policy::KEEP); + static auto ocv_pkg = +#if !defined(GAPI_STANDALONE) + combine(cv::gapi::core::cpu::kernels(), + cv::gapi::imgproc::cpu::kernels(), + cv::unite_policy::KEEP); +#else + cv::gapi::GKernelPackage(); +#endif // !defined(GAPI_STANDALONE) auto user_pkg = cv::gimpl::getCompileArg(args); return combine(ocv_pkg, user_pkg.value_or(cv::gapi::GKernelPackage{}), cv::unite_policy::REPLACE); } diff --git a/modules/gapi/src/compiler/gislandmodel.cpp b/modules/gapi/src/compiler/gislandmodel.cpp index f51709931c..8e20302a35 100644 --- a/modules/gapi/src/compiler/gislandmodel.cpp +++ b/modules/gapi/src/compiler/gislandmodel.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include #include #include diff --git a/modules/gapi/src/compiler/gmodel.cpp b/modules/gapi/src/compiler/gmodel.cpp index cda1cf1af2..4b2455219b 100644 --- a/modules/gapi/src/compiler/gmodel.cpp +++ b/modules/gapi/src/compiler/gmodel.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include #include // used in GModel::log diff --git a/modules/gapi/src/compiler/gmodelbuilder.cpp b/modules/gapi/src/compiler/gmodelbuilder.cpp index 90a73bd6b2..c9b2fbbdfd 100644 --- a/modules/gapi/src/compiler/gmodelbuilder.cpp +++ b/modules/gapi/src/compiler/gmodelbuilder.cpp @@ -11,6 +11,8 @@ // - Dmitry // //////////////////////////////////////////////////////////////////////////////// +#include "precomp.hpp" + #include // tuple #include // stack #include // vector diff --git a/modules/gapi/src/compiler/passes/dump_dot.cpp b/modules/gapi/src/compiler/passes/dump_dot.cpp index 333afa5e73..8741089ba2 100644 --- a/modules/gapi/src/compiler/passes/dump_dot.cpp +++ b/modules/gapi/src/compiler/passes/dump_dot.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include // cout #include // stringstream #include // ofstream diff --git a/modules/gapi/src/compiler/passes/exec.cpp b/modules/gapi/src/compiler/passes/exec.cpp index 137bbc18e3..7119e3411c 100644 --- a/modules/gapi/src/compiler/passes/exec.cpp +++ b/modules/gapi/src/compiler/passes/exec.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include #include // list #include // setw, etc @@ -16,7 +18,6 @@ #include // chain #include "opencv2/gapi/util/optional.hpp" // util::optional -#include "opencv2/core/cvdef.h" #include "logger.hpp" // GAPI_LOG #include "compiler/gmodel.hpp" diff --git a/modules/gapi/src/compiler/passes/helpers.cpp b/modules/gapi/src/compiler/passes/helpers.cpp index e77a72b70e..60bf36afdc 100644 --- a/modules/gapi/src/compiler/passes/helpers.cpp +++ b/modules/gapi/src/compiler/passes/helpers.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include // copy #include #include diff --git a/modules/gapi/src/compiler/passes/islands.cpp b/modules/gapi/src/compiler/passes/islands.cpp index 8773f2c189..942f738bd8 100644 --- a/modules/gapi/src/compiler/passes/islands.cpp +++ b/modules/gapi/src/compiler/passes/islands.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include #include #include diff --git a/modules/gapi/src/compiler/passes/kernels.cpp b/modules/gapi/src/compiler/passes/kernels.cpp index ad8555b408..2703149e7d 100644 --- a/modules/gapi/src/compiler/passes/kernels.cpp +++ b/modules/gapi/src/compiler/passes/kernels.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include // util::indexed #include #include diff --git a/modules/gapi/src/compiler/passes/meta.cpp b/modules/gapi/src/compiler/passes/meta.cpp index 0be6cac62f..0a5bb5aead 100644 --- a/modules/gapi/src/compiler/passes/meta.cpp +++ b/modules/gapi/src/compiler/passes/meta.cpp @@ -5,6 +5,8 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include // util::indexed #include #include diff --git a/modules/gapi/src/compiler/transactions.hpp b/modules/gapi/src/compiler/transactions.hpp index 6b1800f018..54af8a6e69 100644 --- a/modules/gapi/src/compiler/transactions.hpp +++ b/modules/gapi/src/compiler/transactions.hpp @@ -14,7 +14,7 @@ #include -#include "opencv2/core/base.hpp" +#include "opencv2/gapi/own/assert.hpp" enum class Direction: int {Invalid, In, Out}; @@ -71,7 +71,7 @@ namespace Change { case Direction::In: g.link(m_sibling, m_node); break; case Direction::Out: g.link(m_node, m_sibling); break; - default: CV_Assert(false); + default: GAPI_Assert(false); } } }; @@ -104,8 +104,8 @@ namespace Change { // According to the semantic, node should be disconnected // manually before it is dropped - CV_Assert(m_node->inEdges().size() == 0); - CV_Assert(m_node->outEdges().size() == 0); + GAPI_Assert(m_node->inEdges().size() == 0); + GAPI_Assert(m_node->outEdges().size() == 0); } virtual void commit(ade::Graph &g) override diff --git a/modules/gapi/src/executor/gexecutor.cpp b/modules/gapi/src/executor/gexecutor.cpp index 4709f9d0c1..3885820bed 100644 --- a/modules/gapi/src/executor/gexecutor.cpp +++ b/modules/gapi/src/executor/gexecutor.cpp @@ -5,11 +5,13 @@ // Copyright (C) 2018 Intel Corporation +#include "precomp.hpp" + #include #include -#include "opencv2/core/types.hpp" +#include "opencv2/gapi/opencv_includes.hpp" #include "executor/gexecutor.hpp" cv::gimpl::GExecutor::GExecutor(std::unique_ptr &&g_model) @@ -150,8 +152,21 @@ void cv::gimpl::GExecutor::run(cv::gimpl::GRuntimeArgs &&args) using cv::util::get; const auto desc = get(d.meta); const auto type = CV_MAKETYPE(desc.depth, desc.chan); + +#if !defined(GAPI_STANDALONE) + // Building as part of OpenCV - follow OpenCV behavior + // if output buffer is not enough to hold the result, reallocate it auto& out_mat = *get(args.outObjs.at(index)); out_mat.create(cv::gapi::own::to_ocv(desc.size), type); +#else + // Building standalone - output buffer should always exist, + // and _exact_ match our inferred metadata + auto& out_mat = *get(args.outObjs.at(index)); + GAPI_Assert( out_mat.type() == type + && out_mat.data != nullptr + && out_mat.rows == desc.size.height + && out_mat.cols == desc.size.width) +#endif // !defined(GAPI_STANDALONE) } } // Update storage with user-passed objects diff --git a/modules/gapi/src/logger.hpp b/modules/gapi/src/logger.hpp index 047f6e4106..ff4c7591b9 100644 --- a/modules/gapi/src/logger.hpp +++ b/modules/gapi/src/logger.hpp @@ -8,17 +8,15 @@ #ifndef __OPENCV_GAPI_LOGGER_HPP__ #define __OPENCV_GAPI_LOGGER_HPP__ -#if 1 -#include "opencv2/core/utils/logger.hpp" - -#define GAPI_LOG_INFO(tag, ...) CV_LOG_INFO(tag, __VA_ARGS__) -#define GAPI_LOG_WARNING(tag, ...) CV_LOG_WARNING(tag, __VA_ARGS__) - +#if !defined(GAPI_STANDALONE) +# include "opencv2/core/cvdef.h" +# include "opencv2/core/utils/logger.hpp" +# define GAPI_LOG_INFO(tag, ...) CV_LOG_INFO(tag, __VA_ARGS__) +# define GAPI_LOG_WARNING(tag, ...) CV_LOG_WARNING(tag, __VA_ARGS__) #else -#define GAPI_LOG_INFO(tag, ...) -#define GAPI_LOG_WARNING(tag, ...) - -#endif +# define GAPI_LOG_INFO(tag, ...) +# define GAPI_LOG_WARNING(tag, ...) +#endif // !defined(GAPI_STANDALONE) #endif // __OPENCV_GAPI_LOGGER_HPP__ diff --git a/modules/gapi/src/precomp.hpp b/modules/gapi/src/precomp.hpp index ad15bc4dcc..eebe9d8968 100644 --- a/modules/gapi/src/precomp.hpp +++ b/modules/gapi/src/precomp.hpp @@ -8,12 +8,14 @@ #ifndef __OPENCV_GAPI_PRECOMP_HPP__ #define __OPENCV_GAPI_PRECOMP_HPP__ -#include "opencv2/core.hpp" -#include "opencv2/imgproc.hpp" +#if !defined(GAPI_STANDALONE) +# include "opencv2/core.hpp" +# include "opencv2/imgproc.hpp" +# include "opencv2/gapi/core.hpp" +# include "opencv2/gapi/imgproc.hpp" +#endif // !defined(GAPI_STANDALONE) #include "opencv2/gapi.hpp" #include "opencv2/gapi/gkernel.hpp" -#include "opencv2/gapi/core.hpp" -#include "opencv2/gapi/imgproc.hpp" #endif // __OPENCV_GAPI_PRECOMP_HPP__ diff --git a/modules/gapi/test/common/gapi_core_tests.cpp b/modules/gapi/test/common/gapi_core_tests.cpp index 1b3e7f7896..eb77612485 100644 --- a/modules/gapi/test/common/gapi_core_tests.cpp +++ b/modules/gapi/test/common/gapi_core_tests.cpp @@ -5,4 +5,5 @@ // Copyright (C) 2018 Intel Corporation +#include "test_precomp.hpp" #include "gapi_core_tests_inl.hpp" diff --git a/modules/gapi/test/common/gapi_imgproc_tests.cpp b/modules/gapi/test/common/gapi_imgproc_tests.cpp index ea84191a44..b7c0279086 100644 --- a/modules/gapi/test/common/gapi_imgproc_tests.cpp +++ b/modules/gapi/test/common/gapi_imgproc_tests.cpp @@ -5,4 +5,5 @@ // Copyright (C) 2018 Intel Corporation +#include "test_precomp.hpp" #include "gapi_imgproc_tests_inl.hpp" diff --git a/modules/gapi/test/common/gapi_operators_tests.cpp b/modules/gapi/test/common/gapi_operators_tests.cpp index 3fcf3f5641..1f6f0ce20f 100644 --- a/modules/gapi/test/common/gapi_operators_tests.cpp +++ b/modules/gapi/test/common/gapi_operators_tests.cpp @@ -5,4 +5,5 @@ // Copyright (C) 2018 Intel Corporation +#include "test_precomp.hpp" #include "gapi_operators_tests_inl.hpp" diff --git a/modules/gapi/test/cpu/gapi_operators_tests_fluid.cpp b/modules/gapi/test/cpu/gapi_operators_tests_fluid.cpp index 7ad834bd4b..d6f23ef04a 100644 --- a/modules/gapi/test/cpu/gapi_operators_tests_fluid.cpp +++ b/modules/gapi/test/cpu/gapi_operators_tests_fluid.cpp @@ -5,6 +5,7 @@ // Copyright (C) 2018 Intel Corporation +#include "test_precomp.hpp" #include "../common/gapi_operators_tests.hpp" #include "opencv2/gapi/cpu/core.hpp" diff --git a/modules/gapi/test/gapi_fluid_test.cpp b/modules/gapi/test/gapi_fluid_test.cpp index 0996a8f5a5..57d2085e28 100644 --- a/modules/gapi/test/gapi_fluid_test.cpp +++ b/modules/gapi/test/gapi_fluid_test.cpp @@ -50,7 +50,7 @@ TEST(FluidBuffer, InputTest) const cv::Size buffer_size = {8,8}; cv::Mat in_mat = cv::Mat::eye(buffer_size, CV_8U); - cv::gapi::fluid::Buffer buffer(in_mat, true); + cv::gapi::fluid::Buffer buffer(to_own(in_mat), true); cv::gapi::fluid::View view = buffer.mkView(1, 0, {}, false); view.priv().reset(1); int this_y = 0; @@ -152,7 +152,7 @@ TEST(FluidBuffer, OutputTest) const cv::Size buffer_size = {8,16}; cv::Mat out_mat = cv::Mat(buffer_size, CV_8U); - cv::gapi::fluid::Buffer buffer(out_mat, false); + cv::gapi::fluid::Buffer buffer(to_own(out_mat), false); int num_writes = 0; while (num_writes < buffer_size.height) { @@ -417,7 +417,7 @@ TEST(Fluid, MultipleReaders_DifferentLatency) EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); } -TEST(Fluid, DISABLED_MultipleOutputs) +TEST(Fluid, MultipleOutputs) { // in -> AddC -> a -> AddC ------------------> out1 // `--> Id7x7 --> b --> AddC -> out2 @@ -464,7 +464,7 @@ TEST(Fluid, EmptyOutputMatTest) } struct LPISequenceTest : public TestWithParam{}; -TEST_P(LPISequenceTest, DISABLED_LPISequenceTest) +TEST_P(LPISequenceTest, LPISequenceTest) { // in -> AddC -> a -> Blur (2lpi) -> out diff --git a/modules/gapi/test/gapi_fluid_test_kernels.cpp b/modules/gapi/test/gapi_fluid_test_kernels.cpp index 058d9f3f96..6bd06fe271 100644 --- a/modules/gapi/test/gapi_fluid_test_kernels.cpp +++ b/modules/gapi/test/gapi_fluid_test_kernels.cpp @@ -4,6 +4,8 @@ // // Copyright (C) 2018 Intel Corporation +#include "test_precomp.hpp" + #include #include "gapi_fluid_test_kernels.hpp" #include diff --git a/modules/gapi/test/own/mat_tests.cpp b/modules/gapi/test/own/mat_tests.cpp index ffefe0c344..ba2cd2df4f 100644 --- a/modules/gapi/test/own/mat_tests.cpp +++ b/modules/gapi/test/own/mat_tests.cpp @@ -33,12 +33,46 @@ TEST(OwnMat, Create) ASSERT_NE(m.data, nullptr); ASSERT_EQ((cv::gapi::own::Size{m.cols, m.rows}), size); + ASSERT_EQ(m.total(), static_cast(size.height*size.width)); ASSERT_EQ(m.type(), CV_8UC1); ASSERT_EQ(m.depth(), CV_8U); ASSERT_EQ(m.channels(), 1); + ASSERT_EQ(m.elemSize(), sizeof(uint8_t)); ASSERT_EQ(m.step, sizeof(uint8_t) * m.cols); } +TEST(OwnMat, CreateOverload) +{ + auto size = cv::gapi::own::Size{32,16}; + Mat m; + m.create(size.height,size.width, CV_8UC1); + + ASSERT_NE(m.data, nullptr); + ASSERT_EQ((cv::Size{m.cols, m.rows}), size); + + ASSERT_EQ(m.total(), static_cast(size.height*size.width)); + ASSERT_EQ(m.type(), CV_8UC1); + ASSERT_EQ(m.depth(), CV_8U); + ASSERT_EQ(m.channels(), 1); + ASSERT_EQ(m.elemSize(), sizeof(uint8_t)); + ASSERT_EQ(m.step, sizeof(uint8_t) * m.cols); +} +TEST(OwnMat, Create3chan) +{ + auto size = cv::Size{32,16}; + Mat m; + m.create(size, CV_8UC3); + + ASSERT_NE(m.data, nullptr); + ASSERT_EQ((cv::Size{m.cols, m.rows}), size); + + ASSERT_EQ(m.type(), CV_8UC3); + ASSERT_EQ(m.depth(), CV_8U); + ASSERT_EQ(m.channels(), 3); + ASSERT_EQ(m.elemSize(), 3 * sizeof(uint8_t)); + ASSERT_EQ(m.step, 3* sizeof(uint8_t) * m.cols); +} + struct NonEmptyMat { cv::gapi::own::Size size{32,16}; Mat m; @@ -160,5 +194,194 @@ TEST(OwnMatConversion, WithStep) << (cvMat != cvMatFromOwn); } +TEST(OwnMat, PtrWithStep) +{ + constexpr int width = 8; + constexpr int height = 8; + constexpr int stepInPixels = 16; + std::array data; + for (size_t i = 0; i < data.size(); i++) + { + data[i] = static_cast(i); + } + Mat mat(height, width, CV_32S, data.data(), stepInPixels * sizeof(int)); + + EXPECT_EQ(& data[0], reinterpret_cast(mat.ptr(0))); + EXPECT_EQ(& data[1], reinterpret_cast(mat.ptr(0, 1))); + EXPECT_EQ(& data[stepInPixels], reinterpret_cast(mat.ptr(1))); + EXPECT_EQ(& data[stepInPixels +1], reinterpret_cast(mat.ptr(1,1))); + + auto const& cmat = mat; + + EXPECT_EQ(& data[0], reinterpret_cast(cmat.ptr(0))); + EXPECT_EQ(& data[1], reinterpret_cast(cmat.ptr(0, 1))); + EXPECT_EQ(& data[stepInPixels], reinterpret_cast(cmat.ptr(1))); + EXPECT_EQ(& data[stepInPixels +1], reinterpret_cast(cmat.ptr(1,1))); +} + +TEST(OwnMat, CopyToWithStep) +{ + constexpr int width = 8; + constexpr int height = 8; + constexpr int stepInPixels = 16; + + std::array data; + for (size_t i = 0; i < data.size(); i++) + { + data[i] = static_cast(i); + } + Mat mat(height, width, CV_32S, data.data(), stepInPixels * sizeof(int)); + + Mat dst; + mat.copyTo(dst); + + EXPECT_NE(mat.data, dst.data); + EXPECT_EQ(0, cv::countNonZero(to_ocv(mat) != to_ocv(dst))) + << to_ocv(mat) << std::endl + << (to_ocv(mat) != to_ocv(dst)); +} + +TEST(OwnMat, ScalarAssign32SC1) +{ + constexpr int width = 8; + constexpr int height = 8; + constexpr int stepInPixels = 16; + + std::array data; + for (size_t i = 0; i < data.size(); i++) + { + data[i] = static_cast(i); + } + Mat mat(height, width, CV_32S, data.data(), stepInPixels * sizeof(data[0])); + + mat = cv::gapi::own::Scalar{-1}; + + std::array expected; + + for (size_t row = 0; row < height; row++) + { + for (size_t col = 0; col < stepInPixels; col++) + { + auto index = row*stepInPixels + col; + expected[index] = col < width ? -1 : static_cast(index); + } + } + + auto cmp_result_mat = (cv::Mat{height, stepInPixels, CV_32S, data.data()} != cv::Mat{height, stepInPixels, CV_32S, expected.data()}); + EXPECT_EQ(0, cv::countNonZero(cmp_result_mat)) + << cmp_result_mat << std::endl; +} + +TEST(OwnMat, ScalarAssign8UC1) +{ + constexpr int width = 8; + constexpr int height = 8; + constexpr int stepInPixels = 16; + + std::array data; + for (size_t i = 0; i < data.size(); i++) + { + data[i] = static_cast(i); + } + Mat mat(height, width, CV_8U, data.data(), stepInPixels * sizeof(data[0])); + + mat = cv::gapi::own::Scalar{-1}; + + std::array expected; + + for (size_t row = 0; row < height; row++) + { + for (size_t col = 0; col < stepInPixels; col++) + { + auto index = row*stepInPixels + col; + expected[index] = col < width ? cv::saturate_cast(-1) : static_cast(index); + } + } + + auto cmp_result_mat = (cv::Mat{height, stepInPixels, CV_8U, data.data()} != cv::Mat{height, stepInPixels, CV_8U, expected.data()}); + EXPECT_EQ(0, cv::countNonZero(cmp_result_mat)) + << cmp_result_mat << std::endl; +} + +TEST(OwnMat, ScalarAssign8UC3) +{ + constexpr auto cv_type = CV_8SC3; + constexpr int channels = 3; + constexpr int width = 8; + constexpr int height = 8; + constexpr int stepInPixels = 16; + + std::array data; + for (size_t i = 0; i < data.size(); i+= channels) + { + data[i + 0] = static_cast(10 * i + 0); + data[i + 1] = static_cast(10 * i + 1); + data[i + 2] = static_cast(10 * i + 2); + } + + Mat mat(height, width, cv_type, data.data(), channels * stepInPixels * sizeof(data[0])); + + mat = cv::gapi::own::Scalar{-10, -11, -12}; + + std::array expected; + + for (size_t row = 0; row < height; row++) + { + for (size_t col = 0; col < stepInPixels; col++) + { + int index = static_cast(channels * (row*stepInPixels + col)); + expected[index + 0] = static_cast(col < width ? -10 : 10 * index + 0); + expected[index + 1] = static_cast(col < width ? -11 : 10 * index + 1); + expected[index + 2] = static_cast(col < width ? -12 : 10 * index + 2); + } + } + + auto cmp_result_mat = (cv::Mat{height, stepInPixels, cv_type, data.data()} != cv::Mat{height, stepInPixels, cv_type, expected.data()}); + EXPECT_EQ(0, cv::countNonZero(cmp_result_mat)) + << cmp_result_mat << std::endl + << "data : " << std::endl + << cv::Mat{height, stepInPixels, cv_type, data.data()} << std::endl + << "expected : " << std::endl + << cv::Mat{height, stepInPixels, cv_type, expected.data()} << std::endl; +} + +TEST(OwnMat, ROIView) +{ + constexpr int width = 8; + constexpr int height = 8; + constexpr int stepInPixels = 16; + + std::array data; + for (size_t i = 0; i < data.size(); i++) + { + data[i] = static_cast(i); + } + + +// std::cout< expected; + + for (size_t row = 0; row < 4; row++) + { + for (size_t col = 0; col < 4; col++) + { + expected[row*4 +col] = static_cast(stepInPixels * (2 + row) + 2 + col); + } + } + + Mat mat(height, width, CV_8U, data.data(), stepInPixels * sizeof(data[0])); + Mat roi_view (mat, cv::gapi::own::Rect{2,2,4,4}); + +// std::cout<