diff --git a/modules/gapi/include/opencv2/gapi/gmat.hpp b/modules/gapi/include/opencv2/gapi/gmat.hpp index ce5d1a5604..b6dbf4f575 100644 --- a/modules/gapi/include/opencv2/gapi/gmat.hpp +++ b/modules/gapi/include/opencv2/gapi/gmat.hpp @@ -133,8 +133,6 @@ static inline GMatDesc empty_gmat_desc() { return GMatDesc{-1,-1,{-1,-1}}; } class Mat; GAPI_EXPORTS GMatDesc descr_of(const cv::Mat &mat); GAPI_EXPORTS GMatDesc descr_of(const cv::UMat &mat); -GAPI_EXPORTS std::vector descr_of(const std::vector &vec); -GAPI_EXPORTS std::vector descr_of(const std::vector &vec); #endif // !defined(GAPI_STANDALONE) /** @} */ @@ -142,10 +140,9 @@ GAPI_EXPORTS std::vector descr_of(const std::vector &vec); namespace gapi { namespace own { class Mat; GAPI_EXPORTS GMatDesc descr_of(const Mat &mat); - GAPI_EXPORTS std::vector descr_of(const std::vector &vec); }}//gapi::own -std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc); +GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc); } // namespace cv diff --git a/modules/gapi/include/opencv2/gapi/gmetaarg.hpp b/modules/gapi/include/opencv2/gapi/gmetaarg.hpp index 473be342ed..abdea752eb 100644 --- a/modules/gapi/include/opencv2/gapi/gmetaarg.hpp +++ b/modules/gapi/include/opencv2/gapi/gmetaarg.hpp @@ -37,7 +37,7 @@ using GMetaArg = util::variant , GScalarDesc , GArrayDesc >; -std::ostream& operator<<(std::ostream& os, const GMetaArg &); +GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const GMetaArg &); using GMetaArgs = std::vector; @@ -61,6 +61,15 @@ namespace detail } // namespace detail +class Mat; +class UMat; +GAPI_EXPORTS cv::GMetaArgs descr_of(const std::vector &vec); +GAPI_EXPORTS cv::GMetaArgs descr_of(const std::vector &vec); +namespace gapi { namespace own { + class Mat; + GAPI_EXPORTS cv::GMetaArgs descr_of(const std::vector &vec); +}} // namespace gapi::own + } // namespace cv #endif // OPENCV_GAPI_GMETAARG_HPP diff --git a/modules/gapi/src/api/gmat.cpp b/modules/gapi/src/api/gmat.cpp index 0bb58dfe55..dc8fc734d8 100644 --- a/modules/gapi/src/api/gmat.cpp +++ b/modules/gapi/src/api/gmat.cpp @@ -33,15 +33,19 @@ const cv::GOrigin& cv::GMat::priv() const return *m_priv; } -template std::vector vec_descr_of(const std::vector &vec) -{ - std::vector vec_descr; - for(auto& mat : vec){ - vec_descr.emplace_back(descr_of(mat)); +namespace{ + template cv::GMetaArgs vec_descr_of(const std::vector &vec) + { + cv::GMetaArgs vec_descr; + vec_descr.reserve(vec.size()); + for(auto& mat : vec){ + vec_descr.emplace_back(descr_of(mat)); + } + return vec_descr; } - return vec_descr; } + #if !defined(GAPI_STANDALONE) cv::GMatDesc cv::descr_of(const cv::Mat &mat) { @@ -53,12 +57,12 @@ cv::GMatDesc cv::descr_of(const cv::UMat &mat) return GMatDesc{ mat.depth(), mat.channels(),{ mat.cols, mat.rows } }; } -std::vector cv::descr_of(const std::vector &vec) +cv::GMetaArgs cv::descr_of(const std::vector &vec) { return vec_descr_of(vec); } -std::vector cv::descr_of(const std::vector &vec) +cv::GMetaArgs cv::descr_of(const std::vector &vec) { return vec_descr_of(vec); } @@ -69,7 +73,7 @@ cv::GMatDesc cv::gapi::own::descr_of(const cv::gapi::own::Mat &mat) return GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}}; } -std::vector cv::gapi::own::descr_of(const std::vector &vec) +cv::GMetaArgs cv::gapi::own::descr_of(const std::vector &vec) { return vec_descr_of(vec); } diff --git a/modules/gapi/test/gapi_desc_tests.cpp b/modules/gapi/test/gapi_desc_tests.cpp index 26da1f7f71..a9d2e573f3 100644 --- a/modules/gapi/test/gapi_desc_tests.cpp +++ b/modules/gapi/test/gapi_desc_tests.cpp @@ -46,19 +46,13 @@ TEST(GAPI_MetaDesc, VecMatDesc) cv::Mat(240, 320, CV_8U)}; const auto desc1 = cv::descr_of(vec1); - EXPECT_EQ(CV_8U, desc1[0].depth); - EXPECT_EQ(1, desc1[0].chan); - EXPECT_EQ(320, desc1[0].size.width); - EXPECT_EQ(240, desc1[0].size.height); + EXPECT_EQ((GMatDesc{CV_8U, 1, {320, 240}}), get(desc1[0])); std::vector vec2 = { cv::UMat(480, 640, CV_8UC3)}; const auto desc2 = cv::descr_of(vec2); - EXPECT_EQ(CV_8U, desc2[0].depth); - EXPECT_EQ(3, desc2[0].chan); - EXPECT_EQ(640, desc2[0].size.width); - EXPECT_EQ(480, desc2[0].size.height); + EXPECT_EQ((GMatDesc{CV_8U, 3, {640, 480}}), get(desc2[0])); } TEST(GAPI_MetaDesc, VecOwnMatDesc) @@ -68,15 +62,19 @@ TEST(GAPI_MetaDesc, VecOwnMatDesc) cv::gapi::own::Mat(480, 640, CV_8UC3, nullptr)}; const auto desc = cv::gapi::own::descr_of(vec); - EXPECT_EQ(CV_8U, desc[0].depth); - EXPECT_EQ(1, desc[0].chan); - EXPECT_EQ(320, desc[0].size.width); - EXPECT_EQ(240, desc[0].size.height); - - EXPECT_EQ(CV_8U, desc[1].depth); - EXPECT_EQ(3, desc[1].chan); - EXPECT_EQ(640, desc[1].size.width); - EXPECT_EQ(480, desc[1].size.height); + EXPECT_EQ((GMatDesc{CV_8U, 1, {320, 240}}), get(desc[0])); + EXPECT_EQ((GMatDesc{CV_8U, 3, {640, 480}}), get(desc[1])); +} + +TEST(GAPI_MetaDesc, AdlVecOwnMatDesc) +{ + std::vector vec = { + cv::gapi::own::Mat(240, 320, CV_8U, nullptr), + cv::gapi::own::Mat(480, 640, CV_8UC3, nullptr)}; + + const auto desc = descr_of(vec); + EXPECT_EQ((GMatDesc{CV_8U, 1, {320, 240}}), get(desc[0])); + EXPECT_EQ((GMatDesc{CV_8U, 3, {640, 480}}), get(desc[1])); } TEST(GAPI_MetaDesc, Compare_Equal_MatDesc)