Merge pull request #21040 from alexgiving:atrutnev/rename_RMatAdapter

GAPI: Rename MatAdapter to RMatOnMat
pull/21048/head
Trutnev Aleksei 3 years ago committed by GitHub
parent da6344297a
commit 18ca998f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      modules/gapi/src/backends/common/gbackend.hpp
  2. 2
      modules/gapi/src/backends/python/gpythonbackend.cpp
  3. 6
      modules/gapi/src/backends/streaming/gstreamingbackend.cpp
  4. 11
      modules/gapi/src/executor/gexecutor.cpp
  5. 4
      modules/gapi/src/executor/gstreamingexecutor.cpp

@ -45,11 +45,11 @@ namespace gimpl {
#endif #endif
} }
class RMatAdapter : public RMat::IAdapter { class RMatOnMat : public RMat::IAdapter {
cv::Mat m_mat; cv::Mat m_mat;
public: public:
const void* data() const { return m_mat.data; } const void* data() const { return m_mat.data; }
RMatAdapter(cv::Mat m) : m_mat(m) {} RMatOnMat(cv::Mat m) : m_mat(m) {}
virtual RMat::View access(RMat::Access) override { return asView(m_mat); } virtual RMat::View access(RMat::Access) override { return asView(m_mat); }
virtual cv::GMatDesc desc() const override { return cv::descr_of(m_mat); } virtual cv::GMatDesc desc() const override { return cv::descr_of(m_mat); }
}; };

@ -128,7 +128,7 @@ static void writeBack(cv::GRunArg& arg, cv::GRunArgP& out)
case cv::GRunArg::index_of<cv::Mat>(): case cv::GRunArg::index_of<cv::Mat>():
{ {
auto& rmat = *cv::util::get<cv::RMat*>(out); auto& rmat = *cv::util::get<cv::RMat*>(out);
rmat = cv::make_rmat<cv::gimpl::RMatAdapter>(cv::util::get<cv::Mat>(arg)); rmat = cv::make_rmat<cv::gimpl::RMatOnMat>(cv::util::get<cv::Mat>(arg));
break; break;
} }
case cv::GRunArg::index_of<cv::Scalar>(): case cv::GRunArg::index_of<cv::Scalar>():

@ -279,7 +279,7 @@ void GOCVBGR::Actor::extractRMat(const cv::MediaFrame& frame, cv::RMat& rmat)
cv::Mat y_plane (desc.size, CV_8UC1, view.ptr[0], view.stride[0]); cv::Mat y_plane (desc.size, CV_8UC1, view.ptr[0], view.stride[0]);
cv::Mat uv_plane(desc.size / 2, CV_8UC2, view.ptr[1], view.stride[1]); cv::Mat uv_plane(desc.size / 2, CV_8UC2, view.ptr[1], view.stride[1]);
cv::cvtColorTwoPlane(y_plane, uv_plane, bgr, cv::COLOR_YUV2BGR_NV12); cv::cvtColorTwoPlane(y_plane, uv_plane, bgr, cv::COLOR_YUV2BGR_NV12);
rmat = cv::make_rmat<cv::gimpl::RMatAdapter>(bgr); rmat = cv::make_rmat<cv::gimpl::RMatOnMat>(bgr);
break; break;
} }
default: default:
@ -327,7 +327,7 @@ void GOCVY::Actor::extractRMat(const cv::MediaFrame& frame, cv::RMat& rmat)
cv::Mat tmp_bgr(desc.size, CV_8UC3, view.ptr[0], view.stride[0]); cv::Mat tmp_bgr(desc.size, CV_8UC3, view.ptr[0], view.stride[0]);
cv::Mat yuv; cv::Mat yuv;
cvtColor(tmp_bgr, yuv, cv::COLOR_BGR2YUV_I420); cvtColor(tmp_bgr, yuv, cv::COLOR_BGR2YUV_I420);
rmat = cv::make_rmat<cv::gimpl::RMatAdapter>(yuv.rowRange(0, desc.size.height)); rmat = cv::make_rmat<cv::gimpl::RMatOnMat>(yuv.rowRange(0, desc.size.height));
break; break;
} }
case cv::MediaFormat::NV12: case cv::MediaFormat::NV12:
@ -396,7 +396,7 @@ void GOCVUV::Actor::extractRMat(const cv::MediaFrame& frame, cv::RMat& rmat)
yuv.rowRange(start + range_h, start + range_h * 2).reshape(0, dims) yuv.rowRange(start + range_h, start + range_h * 2).reshape(0, dims)
}; };
cv::merge(uv_planes, uv); cv::merge(uv_planes, uv);
rmat = cv::make_rmat<cv::gimpl::RMatAdapter>(uv); rmat = cv::make_rmat<cv::gimpl::RMatOnMat>(uv);
break; break;
} }
case cv::MediaFormat::NV12: case cv::MediaFormat::NV12:

@ -100,7 +100,7 @@ void bindInArgExec(Mag& mag, const RcDesc &rc, const GRunArg &arg)
switch (arg.index()) switch (arg.index())
{ {
case GRunArg::index_of<Mat>() : case GRunArg::index_of<Mat>() :
mag_rmat = make_rmat<RMatAdapter>(util::get<Mat>(arg)); break; mag_rmat = make_rmat<RMatOnMat>(util::get<Mat>(arg)); break;
case GRunArg::index_of<cv::RMat>() : case GRunArg::index_of<cv::RMat>() :
mag_rmat = util::get<cv::RMat>(arg); break; mag_rmat = util::get<cv::RMat>(arg); break;
default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?")); default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?"));
@ -121,7 +121,7 @@ void bindOutArgExec(Mag& mag, const RcDesc &rc, const GRunArgP &arg)
switch (arg.index()) switch (arg.index())
{ {
case GRunArgP::index_of<Mat*>() : case GRunArgP::index_of<Mat*>() :
mag_rmat = make_rmat<RMatAdapter>(*util::get<Mat*>(arg)); break; mag_rmat = make_rmat<RMatOnMat>(*util::get<Mat*>(arg)); break;
case GRunArgP::index_of<cv::RMat*>() : case GRunArgP::index_of<cv::RMat*>() :
mag_rmat = *util::get<cv::RMat*>(arg); break; mag_rmat = *util::get<cv::RMat*>(arg); break;
default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?")); default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?"));
@ -155,12 +155,11 @@ void writeBackExec(const Mag& mag, const RcDesc &rc, GRunArgP &g_arg)
// FIXME: // FIXME:
// Rework, find a better way to check if there should be // Rework, find a better way to check if there should be
// a real copy (add a pass to StreamingBackend?) // a real copy (add a pass to StreamingBackend?)
// NB: In case RMat adapter not equal to "RMatAdapter" need to // NB: In case RMat adapter not equal to "RMatOnMat" need to
// copy data back to the host as well. // copy data back to the host as well.
// FIXME: Rename "RMatAdapter" to "OpenCVAdapter".
auto& out_mat = *util::get<cv::Mat*>(g_arg); auto& out_mat = *util::get<cv::Mat*>(g_arg);
const auto& rmat = mag.template slot<cv::RMat>().at(rc.id); const auto& rmat = mag.template slot<cv::RMat>().at(rc.id);
auto* adapter = rmat.get<RMatAdapter>(); auto* adapter = rmat.get<RMatOnMat>();
if ((adapter != nullptr && out_mat.data != adapter->data()) || if ((adapter != nullptr && out_mat.data != adapter->data()) ||
(adapter == nullptr)) { (adapter == nullptr)) {
auto view = rmat.access(RMat::Access::R); auto view = rmat.access(RMat::Access::R);
@ -221,7 +220,7 @@ void cv::gimpl::GExecutor::initResource(const ade::NodeHandle & nh, const ade::N
} else { } else {
Mat mat; Mat mat;
createMat(desc, mat); createMat(desc, mat);
rmat = make_rmat<RMatAdapter>(mat); rmat = make_rmat<RMatOnMat>(mat);
} }
} }
break; break;

@ -662,7 +662,7 @@ class StreamingInput final: public cv::gimpl::GIslandExecutable::IInput
// Wrap all input cv::Mats with RMats // Wrap all input cv::Mats with RMats
for (auto& arg : isl_input_args) { for (auto& arg : isl_input_args) {
if (arg.index() == cv::GRunArg::index_of<cv::Mat>()) { if (arg.index() == cv::GRunArg::index_of<cv::Mat>()) {
arg = cv::GRunArg{ cv::make_rmat<cv::gimpl::RMatAdapter>(cv::util::get<cv::Mat>(arg)) arg = cv::GRunArg{ cv::make_rmat<cv::gimpl::RMatOnMat>(cv::util::get<cv::Mat>(arg))
, arg.meta , arg.meta
}; };
} }
@ -745,7 +745,7 @@ class StreamingOutput final: public cv::gimpl::GIslandExecutable::IOutput
{ {
MatType newMat; MatType newMat;
cv::gimpl::createMat(desc, newMat); cv::gimpl::createMat(desc, newMat);
auto rmat = cv::make_rmat<cv::gimpl::RMatAdapter>(newMat); auto rmat = cv::make_rmat<cv::gimpl::RMatOnMat>(newMat);
out_arg = cv::GRunArg(std::move(rmat)); out_arg = cv::GRunArg(std::move(rmat));
} }
ret_val = cv::GRunArgP(&cv::util::get<cv::RMat>(out_arg)); ret_val = cv::GRunArgP(&cv::util::get<cv::RMat>(out_arg));

Loading…
Cancel
Save