opencv/modules/gapi/src/api/gmat.cpp
Ruslan Garnov 3df83dce7e Merge pull request #14741 from rgarnov:gapi_fix_includes
Changed quotes to brackets when including public includes (#14741)
2019-06-14 19:27:19 +03:00

131 lines
2.9 KiB
C++

// 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
#include "precomp.hpp"
#include <opencv2/gapi/opencv_includes.hpp>
#include <opencv2/gapi/own/mat.hpp> //gapi::own::Mat
#include <opencv2/gapi/gmat.hpp>
#include "api/gorigin.hpp"
// cv::GMat public implementation //////////////////////////////////////////////
cv::GMat::GMat()
: m_priv(new GOrigin(GShape::GMAT, GNode::Param()))
{
}
cv::GMat::GMat(const GNode &n, std::size_t out)
: m_priv(new GOrigin(GShape::GMAT, n, out))
{
}
cv::GOrigin& cv::GMat::priv()
{
return *m_priv;
}
const cv::GOrigin& cv::GMat::priv() const
{
return *m_priv;
}
namespace{
template <typename T> cv::GMetaArgs vec_descr_of(const std::vector<T> &vec)
{
cv::GMetaArgs vec_descr;
vec_descr.reserve(vec.size());
for(auto& mat : vec){
vec_descr.emplace_back(descr_of(mat));
}
return vec_descr;
}
}
#if !defined(GAPI_STANDALONE)
cv::GMatDesc cv::descr_of(const cv::Mat &mat)
{
return GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}};
}
cv::GMatDesc cv::descr_of(const cv::UMat &mat)
{
return GMatDesc{ mat.depth(), mat.channels(),{ mat.cols, mat.rows } };
}
cv::GMetaArgs cv::descr_of(const std::vector<cv::Mat> &vec)
{
return vec_descr_of(vec);
}
cv::GMetaArgs cv::descr_of(const std::vector<cv::UMat> &vec)
{
return vec_descr_of(vec);
}
#endif
cv::GMatDesc cv::gapi::own::descr_of(const cv::gapi::own::Mat &mat)
{
return GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}};
}
cv::GMetaArgs cv::gapi::own::descr_of(const std::vector<cv::gapi::own::Mat> &vec)
{
return vec_descr_of(vec);
}
namespace cv {
std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc)
{
switch (desc.depth)
{
#define TT(X) case CV_##X: os << #X; break;
TT(8U);
TT(8S);
TT(16U);
TT(16S);
TT(32S);
TT(32F);
TT(64F);
#undef TT
default:
os << "(user type "
<< std::hex << desc.depth << std::dec
<< ")";
break;
}
os << "C" << desc.chan;
if (desc.planar) os << "p";
os << " ";
os << desc.size.width << "x" << desc.size.height;
return os;
}
namespace {
template<typename M> inline bool canDescribeHelper(const GMatDesc& desc, const M& mat)
{
const auto mat_desc = desc.planar ? descr_of(mat).asPlanar(desc.chan) : descr_of(mat);
return desc == mat_desc;
}
} // anonymous namespace
bool GMatDesc::canDescribe(const cv::gapi::own::Mat& mat) const
{
return canDescribeHelper(*this, mat);
}
#if !defined(GAPI_STANDALONE)
bool GMatDesc::canDescribe(const cv::Mat& mat) const
{
return canDescribeHelper(*this, mat);
}
#endif
}// namespace cv