Merge pull request #16745 from Volskig:mp/ocv-gapi-standalone-size

G-API: Unification of own:: structures with cv:: (Size, Point, Rect)

* deowned Size Rect Point

* Deownded Size Rect Point

* With Scalar
This commit is contained in:
Maxim Pashchenkov
2020-04-02 21:19:45 +03:00
committed by GitHub
parent 557ac3dbaf
commit 277f0d270f
21 changed files with 88 additions and 114 deletions
@@ -353,7 +353,7 @@ G_TYPED_KERNEL(GYUV2Gray, <cv::GMat(cv::GMat)>, "yuvtogray") {
* U V U V U V U V
*/
return {CV_8U, 1, cv::gapi::own::Size{in.size.width, in.size.height - (in.size.height / 3)}, false};
return {CV_8U, 1, cv::Size{in.size.width, in.size.height - (in.size.height / 3)}, false};
}
};
@@ -367,7 +367,7 @@ GAPI_OCV_KERNEL(GCPUYUV2Gray, GYUV2Gray)
G_TYPED_KERNEL(GConcatYUVPlanes, <cv::GMat(cv::GMat, cv::GMat)>, "concatyuvplanes") {
static cv::GMatDesc outMeta(cv::GMatDesc y, cv::GMatDesc uv) {
return {CV_8U, 1, cv::gapi::own::Size{y.size.width, y.size.height + uv.size.height}, false};
return {CV_8U, 1, cv::Size{y.size.width, y.size.height + uv.size.height}, false};
}
};
@@ -554,8 +554,8 @@ void cv::gimpl::FluidAgent::debug(std::ostream &os)
// GCPUExcecutable implementation //////////////////////////////////////////////
void cv::gimpl::GFluidExecutable::initBufferRois(std::vector<int>& readStarts,
std::vector<cv::gapi::own::Rect>& rois,
const std::vector<cv::gapi::own::Rect>& out_rois)
std::vector<cv::Rect>& rois,
const std::vector<cv::Rect>& out_rois)
{
GConstFluidModel fg(m_g);
auto proto = m_gm.metadata().get<Protocol>();
@@ -592,9 +592,9 @@ void cv::gimpl::GFluidExecutable::initBufferRois(std::vector<int>& readStarts,
readStarts[id] = 0;
const auto& out_roi = out_rois[idx];
if (out_roi == gapi::own::Rect{})
if (out_roi == cv::Rect{})
{
rois[id] = gapi::own::Rect{ 0, 0, desc.size.width, desc.size.height };
rois[id] = cv::Rect{ 0, 0, desc.size.width, desc.size.height };
}
else
{
@@ -639,14 +639,14 @@ void cv::gimpl::GFluidExecutable::initBufferRois(std::vector<int>& readStarts,
const auto& in_meta = util::get<GMatDesc>(in_data.meta);
const auto& fd = fg.metadata(in_node).get<FluidData>();
auto adjFilterRoi = [](cv::gapi::own::Rect produced, int b, int max_height) {
auto adjFilterRoi = [](cv::Rect produced, int b, int max_height) {
// Extend with border roi which should be produced, crop to logical image size
cv::gapi::own::Rect roi = {produced.x, produced.y - b, produced.width, produced.height + 2*b};
cv::gapi::own::Rect fullImg{ 0, 0, produced.width, max_height };
cv::Rect roi = {produced.x, produced.y - b, produced.width, produced.height + 2*b};
cv::Rect fullImg{ 0, 0, produced.width, max_height };
return roi & fullImg;
};
auto adjResizeRoi = [](cv::gapi::own::Rect produced, cv::gapi::own::Size inSz, cv::gapi::own::Size outSz) {
auto adjResizeRoi = [](cv::Rect produced, cv::Size inSz, cv::Size outSz) {
auto map = [](int outCoord, int producedSz, int inSize, int outSize) {
double ratio = (double)inSize / outSize;
int w0 = 0, w1 = 0;
@@ -671,30 +671,30 @@ void cv::gimpl::GFluidExecutable::initBufferRois(std::vector<int>& readStarts,
auto x0 = mapX.first;
auto x1 = mapX.second;
cv::gapi::own::Rect roi = {x0, y0, x1 - x0, y1 - y0};
cv::Rect roi = {x0, y0, x1 - x0, y1 - y0};
return roi;
};
auto adj420Roi = [&](cv::gapi::own::Rect produced, std::size_t port) {
auto adj420Roi = [&](cv::Rect produced, std::size_t port) {
GAPI_Assert(produced.x % 2 == 0);
GAPI_Assert(produced.y % 2 == 0);
GAPI_Assert(produced.width % 2 == 0);
GAPI_Assert(produced.height % 2 == 0);
cv::gapi::own::Rect roi;
cv::Rect roi;
switch (port) {
case 0: roi = produced; break;
case 1:
case 2: roi = cv::gapi::own::Rect{ produced.x/2, produced.y/2, produced.width/2, produced.height/2 }; break;
case 2: roi = cv::Rect{ produced.x/2, produced.y/2, produced.width/2, produced.height/2 }; break;
default: GAPI_Assert(false);
}
return roi;
};
cv::gapi::own::Rect produced = rois[m_id_map.at(data.rc)];
cv::Rect produced = rois[m_id_map.at(data.rc)];
// Apply resize-specific roi transformations
cv::gapi::own::Rect resized;
cv::Rect resized;
switch (fg.metadata(oh).get<FluidUnit>().k.m_kind)
{
case GFluidKernel::Kind::Filter: resized = produced; break;
@@ -727,7 +727,7 @@ void cv::gimpl::GFluidExecutable::initBufferRois(std::vector<int>& readStarts,
auto roi = adjFilterRoi(resized, fd.border_size, in_meta.size.height);
auto in_id = m_id_map.at(in_data.rc);
if (rois[in_id] == cv::gapi::own::Rect{})
if (rois[in_id] == cv::Rect{})
{
readStarts[in_id] = readStart;
rois[in_id] = roi;
@@ -828,7 +828,7 @@ cv::gimpl::FluidGraphInputData cv::gimpl::fluidExtractInputDataFromGraph(const a
cv::gimpl::GFluidExecutable::GFluidExecutable(const ade::Graph &g,
const cv::gimpl::FluidGraphInputData &traverse_res,
const std::vector<cv::gapi::own::Rect> &outputRois)
const std::vector<cv::Rect> &outputRois)
: m_g(g), m_gm(m_g),
m_num_int_buffers (traverse_res.m_mat_count),
m_scratch_users (traverse_res.m_scratch_users),
@@ -1146,13 +1146,13 @@ namespace
}
}
void cv::gimpl::GFluidExecutable::makeReshape(const std::vector<gapi::own::Rect> &out_rois)
void cv::gimpl::GFluidExecutable::makeReshape(const std::vector<cv::Rect> &out_rois)
{
GConstFluidModel fg(m_g);
// Calculate rois for each fluid buffer
std::vector<int> readStarts(m_num_int_buffers);
std::vector<cv::gapi::own::Rect> rois(m_num_int_buffers);
std::vector<cv::Rect> rois(m_num_int_buffers);
initBufferRois(readStarts, rois, out_rois);
// NB: Allocate ALL buffer object at once, and avoid any further reallocations
@@ -142,8 +142,8 @@ class GFluidExecutable final: public GIslandExecutable
void bindOutArg(const RcDesc &rc, const GRunArgP &arg);
void packArg (GArg &in_arg, const GArg &op_arg);
void initBufferRois(std::vector<int>& readStarts, std::vector<cv::gapi::own::Rect>& rois, const std::vector<gapi::own::Rect> &out_rois);
void makeReshape(const std::vector<cv::gapi::own::Rect>& out_rois);
void initBufferRois(std::vector<int>& readStarts, std::vector<cv::Rect>& rois, const std::vector<cv::Rect> &out_rois);
void makeReshape(const std::vector<cv::Rect>& out_rois);
std::size_t total_buffers_size() const;
public:
@@ -159,7 +159,7 @@ public:
GFluidExecutable(const ade::Graph &g,
const FluidGraphInputData &graph_data,
const std::vector<cv::gapi::own::Rect> &outputRois);
const std::vector<cv::Rect> &outputRois);
};
@@ -9,9 +9,6 @@
#include <iomanip> // 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"
#include <opencv2/gapi/opencv_includes.hpp>
@@ -271,8 +268,8 @@ const uint8_t* fluid::BufferStorageWithBorder::inLineB(int log_idx, int desc_hei
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)
{
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});
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});
subSrc.copyTo(subDst);
}
@@ -365,8 +362,8 @@ std::unique_ptr<fluid::BufferStorage> createStorage(int capacity, int desc_width
#endif
}
std::unique_ptr<BufferStorage> createStorage(const cv::gapi::own::Mat& data, cv::gapi::own::Rect roi);
std::unique_ptr<BufferStorage> createStorage(const cv::gapi::own::Mat& data, cv::gapi::own::Rect roi)
std::unique_ptr<BufferStorage> createStorage(const cv::gapi::own::Mat& data, cv::Rect roi);
std::unique_ptr<BufferStorage> createStorage(const cv::gapi::own::Mat& data, cv::Rect roi)
{
std::unique_ptr<BufferStorageWithoutBorder> storage(new BufferStorageWithoutBorder);
storage->attach(data, roi);
@@ -504,7 +501,7 @@ void fluid::View::Priv::initCache(int lineConsumption)
// Fluid Buffer implementation /////////////////////////////////////////////////
fluid::Buffer::Priv::Priv(int read_start, cv::gapi::own::Rect roi)
fluid::Buffer::Priv::Priv(int read_start, cv::Rect roi)
: m_readStart(read_start)
, m_roi(roi)
{}
@@ -512,12 +509,12 @@ fluid::Buffer::Priv::Priv(int read_start, cv::gapi::own::Rect roi)
void fluid::Buffer::Priv::init(const cv::GMatDesc &desc,
int writer_lpi,
int readStartPos,
cv::gapi::own::Rect roi)
cv::Rect roi)
{
m_writer_lpi = writer_lpi;
m_desc = desc;
m_readStart = readStartPos;
m_roi = roi == own::Rect{} ? own::Rect{ 0, 0, desc.size.width, desc.size.height }
m_roi = roi == cv::Rect{} ? cv::Rect{ 0, 0, desc.size.width, desc.size.height }
: roi;
m_cache.m_linePtrs.resize(writer_lpi);
m_cache.m_desc = desc;
@@ -652,7 +649,7 @@ fluid::Buffer::Buffer(const cv::GMatDesc &desc)
{
int lineConsumption = 1;
int border = 0, skew = 0, wlpi = 1, readStart = 0;
cv::gapi::own::Rect roi = {0, 0, desc.size.width, desc.size.height};
cv::Rect roi = {0, 0, desc.size.width, desc.size.height};
m_priv->init(desc, wlpi, readStart, roi);
m_priv->allocate({}, border, lineConsumption, skew);
}
@@ -667,7 +664,7 @@ fluid::Buffer::Buffer(const cv::GMatDesc &desc,
, m_cache(&m_priv->cache())
{
int readStart = 0;
cv::gapi::own::Rect roi = {0, 0, desc.size.width, desc.size.height};
cv::Rect roi = {0, 0, desc.size.width, desc.size.height};
m_priv->init(desc, wlpi, readStart, roi);
m_priv->allocate(border, border_size, max_line_consumption, skew);
}
@@ -677,7 +674,7 @@ fluid::Buffer::Buffer(const cv::gapi::own::Mat &data, bool is_input)
, m_cache(&m_priv->cache())
{
int wlpi = 1, readStart = 0;
cv::gapi::own::Rect roi{0, 0, data.cols, data.rows};
cv::Rect roi{0, 0, data.cols, data.rows};
m_priv->init(descr_of(data), wlpi, readStart, roi);
m_priv->bindTo(data, is_input);
}
@@ -101,23 +101,23 @@ public:
class BufferStorageWithoutBorder final : public BufferStorage
{
bool m_is_virtual = true;
cv::gapi::own::Rect m_roi;
cv::Rect m_roi;
public:
virtual void copyTo(BufferStorageWithBorder &dst, int startLine, int nLines) const override;
inline virtual const uint8_t* ptr(int idx) const override
{
GAPI_DbgAssert((m_is_virtual && m_roi == cv::gapi::own::Rect{}) || (!m_is_virtual && m_roi != cv::gapi::own::Rect{}));
GAPI_DbgAssert((m_is_virtual && m_roi == cv::Rect{}) || (!m_is_virtual && m_roi != cv::Rect{}));
return m_data.ptr(physIdx(idx), 0);
}
inline virtual uint8_t* ptr(int idx) override
{
GAPI_DbgAssert((m_is_virtual && m_roi == cv::gapi::own::Rect{}) || (!m_is_virtual && m_roi != cv::gapi::own::Rect{}));
GAPI_DbgAssert((m_is_virtual && m_roi == cv::Rect{}) || (!m_is_virtual && m_roi != cv::Rect{}));
return m_data.ptr(physIdx(idx), 0);
}
inline void attach(const cv::gapi::own::Mat& _data, cv::gapi::own::Rect _roi)
inline void attach(const cv::gapi::own::Mat& _data, cv::Rect _roi)
{
m_data = _data(_roi);
m_roi = _roi;
@@ -246,13 +246,13 @@ class GAPI_EXPORTS Buffer::Priv
// Coordinate starting from which this buffer is assumed
// to be read (with border not being taken into account)
int m_readStart;
cv::gapi::own::Rect m_roi;
cv::Rect m_roi;
friend void debugBufferPriv(const Buffer& p, std::ostream &os);
public:
Priv() = default;
Priv(int read_start, cv::gapi::own::Rect roi);
Priv(int read_start, cv::Rect roi);
inline const BufferStorage& storage() const { return *m_storage.get(); }
@@ -260,7 +260,7 @@ public:
void init(const cv::GMatDesc &desc,
int writer_lpi,
int readStart,
cv::gapi::own::Rect roi);
cv::Rect roi);
void allocate(BorderOpt border, int border_size, int line_consumption, int skew);
void bindTo(const cv::gapi::own::Mat &data, bool is_input);
@@ -2040,7 +2040,7 @@ GAPI_FLUID_KERNEL(GFluidResize, cv::gapi::core::GResize, true)
cv::GMatDesc desc;
desc.chan = 1;
desc.depth = CV_8UC1;
desc.size = to_own(scratch_size);
desc.size = scratch_size;
cv::gapi::fluid::Buffer buffer(desc);
scratch = std::move(buffer);
@@ -15,8 +15,6 @@
#include <opencv2/gapi/core.hpp>
#include <opencv2/gapi/imgproc.hpp>
#include <opencv2/gapi/own/types.hpp>
#include <opencv2/gapi/fluid/gfluidbuffer.hpp>
#include <opencv2/gapi/fluid/gfluidkernel.hpp>
#include <opencv2/gapi/fluid/imgproc.hpp>
@@ -451,7 +449,7 @@ GAPI_FLUID_KERNEL(GFluidBlur, cv::gapi::imgproc::GBlur, true)
int buflen = width * chan * Window; // work buffers
cv::gapi::own::Size bufsize(buflen, 1);
cv::Size bufsize(buflen, 1);
GMatDesc bufdesc = {CV_32F, 1, bufsize};
Buffer buffer(bufdesc);
scratch = std::move(buffer);
@@ -526,7 +524,7 @@ GAPI_FLUID_KERNEL(GFluidBoxFilter, cv::gapi::imgproc::GBoxFilter, true)
int buflen = width * chan * Window; // work buffers
cv::gapi::own::Size bufsize(buflen, 1);
cv::Size bufsize(buflen, 1);
GMatDesc bufdesc = {CV_32F, 1, bufsize};
Buffer buffer(bufdesc);
scratch = std::move(buffer);
@@ -748,7 +746,7 @@ GAPI_FLUID_KERNEL(GFluidSepFilter, cv::gapi::imgproc::GSepFilter, true)
int buflen = kxLen + kyLen + // x, y kernels
width * chan * Window; // work buffers
cv::gapi::own::Size bufsize(buflen, 1);
cv::Size bufsize(buflen, 1);
GMatDesc bufdesc = {CV_32F, 1, bufsize};
Buffer buffer(bufdesc);
scratch = std::move(buffer);
@@ -851,7 +849,7 @@ GAPI_FLUID_KERNEL(GFluidGaussBlur, cv::gapi::imgproc::GGaussBlur, true)
int buflen = kxsize + kysize + // x, y kernels
width * chan * ksize.height; // work buffers
cv::gapi::own::Size bufsize(buflen, 1);
cv::Size bufsize(buflen, 1);
GMatDesc bufdesc = {CV_32F, 1, bufsize};
Buffer buffer(bufdesc);
scratch = std::move(buffer);
@@ -1016,7 +1014,7 @@ GAPI_FLUID_KERNEL(GFluidSobel, cv::gapi::imgproc::GSobel, true)
int buflen = ksz + ksz // kernels: kx, ky
+ ksz * width * chan; // working buffers
cv::gapi::own::Size bufsize(buflen, 1);
cv::Size bufsize(buflen, 1);
GMatDesc bufdesc = {CV_32F, 1, bufsize};
Buffer buffer(bufdesc);
scratch = std::move(buffer);
@@ -1171,7 +1169,7 @@ GAPI_FLUID_KERNEL(GFluidSobelXY, cv::gapi::imgproc::GSobelXY, true)
int chan = in.chan;
int buflen = BufHelper::length(ksz, width, chan);
cv::gapi::own::Size bufsize(buflen, 1);
cv::Size bufsize(buflen, 1);
GMatDesc bufdesc = {CV_32F, 1, bufsize};
Buffer buffer(bufdesc);
scratch = std::move(buffer);
@@ -1319,7 +1317,7 @@ GAPI_FLUID_KERNEL(GFluidFilter2D, cv::gapi::imgproc::GFilter2D, true)
int buflen = krows * kcols; // kernel size
cv::gapi::own::Size bufsize(buflen, 1);
cv::Size bufsize(buflen, 1);
GMatDesc bufdesc = {CV_32F, 1, bufsize};
Buffer buffer(bufdesc);
scratch = std::move(buffer);
@@ -1496,7 +1494,7 @@ GAPI_FLUID_KERNEL(GFluidErode, cv::gapi::imgproc::GErode, true)
int k_cols = kernel.cols;
int k_size = k_rows * k_cols;
cv::gapi::own::Size bufsize(k_size + 1, 1);
cv::Size bufsize(k_size + 1, 1);
GMatDesc bufdesc = {CV_8U, 1, bufsize};
Buffer buffer(bufdesc);
scratch = std::move(buffer);
@@ -1582,7 +1580,7 @@ GAPI_FLUID_KERNEL(GFluidDilate, cv::gapi::imgproc::GDilate, true)
int k_cols = kernel.cols;
int k_size = k_rows * k_cols;
cv::gapi::own::Size bufsize(k_size + 1, 1);
cv::Size bufsize(k_size + 1, 1);
GMatDesc bufdesc = {CV_8U, 1, bufsize};
Buffer buffer(bufdesc);
scratch = std::move(buffer);
@@ -1749,7 +1747,7 @@ GAPI_FLUID_KERNEL(GFluidRGB2HSV, cv::gapi::imgproc::GRGB2HSV, true)
cv::GMatDesc desc;
desc.chan = 1;
desc.depth = CV_32S;
desc.size = cv::gapi::own::Size(512, 1);
desc.size = cv::Size(512, 1);
cv::gapi::fluid::Buffer buffer(desc);
scratch = std::move(buffer);