Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / src / api / gmat.cpp
1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 //
5 // Copyright (C) 2018-2019 Intel Corporation
6
7
8 #include "precomp.hpp"
9 #include <opencv2/gapi/opencv_includes.hpp>
10 #include <opencv2/gapi/own/mat.hpp> //gapi::own::Mat
11
12 #include "opencv2/gapi/gmat.hpp"
13 #include "api/gapi_priv.hpp" // GOrigin
14
15 // cv::GMat public implementation //////////////////////////////////////////////
16 cv::GMat::GMat()
17     : m_priv(new GOrigin(GShape::GMAT, GNode::Param()))
18 {
19 }
20
21 cv::GMat::GMat(const GNode &n, std::size_t out)
22     : m_priv(new GOrigin(GShape::GMAT, n, out))
23 {
24 }
25
26 cv::GOrigin& cv::GMat::priv()
27 {
28     return *m_priv;
29 }
30
31 const cv::GOrigin& cv::GMat::priv() const
32 {
33     return *m_priv;
34 }
35
36 namespace{
37     template <typename T> cv::GMetaArgs vec_descr_of(const std::vector<T> &vec)
38         {
39         cv::GMetaArgs vec_descr;
40         vec_descr.reserve(vec.size());
41         for(auto& mat : vec){
42             vec_descr.emplace_back(descr_of(mat));
43         }
44         return vec_descr;
45     }
46 }
47
48
49 #if !defined(GAPI_STANDALONE)
50 cv::GMatDesc cv::descr_of(const cv::Mat &mat)
51 {
52     return GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}};
53 }
54
55 cv::GMatDesc cv::descr_of(const cv::UMat &mat)
56 {
57     return GMatDesc{ mat.depth(), mat.channels(),{ mat.cols, mat.rows } };
58 }
59
60 cv::GMetaArgs cv::descr_of(const std::vector<cv::Mat> &vec)
61 {
62     return vec_descr_of(vec);
63 }
64
65 cv::GMetaArgs cv::descr_of(const std::vector<cv::UMat> &vec)
66 {
67     return vec_descr_of(vec);
68 }
69 #endif
70
71 cv::GMatDesc cv::gapi::own::descr_of(const cv::gapi::own::Mat &mat)
72 {
73     return GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}};
74 }
75
76 cv::GMetaArgs cv::gapi::own::descr_of(const std::vector<cv::gapi::own::Mat> &vec)
77 {
78     return vec_descr_of(vec);
79 }
80
81 namespace cv {
82 std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc)
83 {
84     switch (desc.depth)
85     {
86 #define TT(X) case CV_##X: os << #X; break;
87         TT(8U);
88         TT(8S);
89         TT(16U);
90         TT(16S);
91         TT(32S);
92         TT(32F);
93         TT(64F);
94 #undef TT
95     default:
96         os << "(user type "
97            << std::hex << desc.depth << std::dec
98            << ")";
99         break;
100     }
101
102     os << "C" << desc.chan << " ";
103     os << desc.size.width << "x" << desc.size.height;
104
105     return os;
106 }
107 }