1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge pull request #15090 from dmatveev:dm/ng-0001-g-api-inference-api

* G-API-NG/API: Introduced inference API and IE-based backend

- Very quick-n-dirty implementation
- OpenCV's own DNN module is not used
- No tests so far

* G-API-NG/IE: Refined IE backend, added more tests

* G-API-NG/IE: Fixed various CI warnings & build issues + tests

- Added tests on multi-dimensional own::Mat
- Added tests on GMatDesc with dimensions
- Documentation on infer.hpp
- Fixed more warnings + added a ROI list test
- Fix descr_of clash for vector<Mat> & standalone mode
- Fix build issue with gcc-4.8x
- Addressed review comments

* G-API-NG/IE: Addressed review comments

- Pass `false` to findDataFile()
- Add deprecation warning suppression macros for IE
This commit is contained in:
Dmitry Matveev
2019-08-05 17:56:34 +03:00
committed by Alexander Alekhin
parent 59b0314a0e
commit 0757a51e2b
32 changed files with 1974 additions and 85 deletions
+52 -4
View File
@@ -31,6 +31,7 @@ TEST(GAPI_MetaDesc, MatDesc)
EXPECT_EQ(1, desc1.chan);
EXPECT_EQ(320, desc1.size.width);
EXPECT_EQ(240, desc1.size.height);
EXPECT_FALSE(desc1.isND());
cv::Mat m2(480, 640, CV_8UC3);
const auto desc2 = cv::descr_of(m2);
@@ -38,6 +39,21 @@ TEST(GAPI_MetaDesc, MatDesc)
EXPECT_EQ(3, desc2.chan);
EXPECT_EQ(640, desc2.size.width);
EXPECT_EQ(480, desc2.size.height);
EXPECT_FALSE(desc2.isND());
}
TEST(GAPI_MetaDesc, MatDescND)
{
std::vector<int> dims = {1,3,299,299};
cv::Mat m(dims, CV_32F);
const auto desc = cv::descr_of(m);
EXPECT_EQ(CV_32F, desc.depth);
EXPECT_EQ(-1, desc.chan);
EXPECT_EQ(1, desc.dims[0]);
EXPECT_EQ(3, desc.dims[1]);
EXPECT_EQ(299, desc.dims[2]);
EXPECT_EQ(299, desc.dims[3]);
EXPECT_TRUE(desc.isND());
}
TEST(GAPI_MetaDesc, VecMatDesc)
@@ -45,13 +61,13 @@ TEST(GAPI_MetaDesc, VecMatDesc)
std::vector<cv::Mat> vec1 = {
cv::Mat(240, 320, CV_8U)};
const auto desc1 = cv::descr_of(vec1);
const auto desc1 = cv::descrs_of(vec1);
EXPECT_EQ((GMatDesc{CV_8U, 1, {320, 240}}), get<GMatDesc>(desc1[0]));
std::vector<cv::UMat> vec2 = {
cv::UMat(480, 640, CV_8UC3)};
const auto desc2 = cv::descr_of(vec2);
const auto desc2 = cv::descrs_of(vec2);
EXPECT_EQ((GMatDesc{CV_8U, 3, {640, 480}}), get<GMatDesc>(desc2[0]));
}
@@ -61,7 +77,7 @@ TEST(GAPI_MetaDesc, VecOwnMatDesc)
cv::gapi::own::Mat(240, 320, CV_8U, nullptr),
cv::gapi::own::Mat(480, 640, CV_8UC3, nullptr)};
const auto desc = cv::gapi::own::descr_of(vec);
const auto desc = cv::gapi::own::descrs_of(vec);
EXPECT_EQ((GMatDesc{CV_8U, 1, {320, 240}}), get<GMatDesc>(desc[0]));
EXPECT_EQ((GMatDesc{CV_8U, 3, {640, 480}}), get<GMatDesc>(desc[1]));
}
@@ -72,7 +88,7 @@ TEST(GAPI_MetaDesc, AdlVecOwnMatDesc)
cv::gapi::own::Mat(240, 320, CV_8U, nullptr),
cv::gapi::own::Mat(480, 640, CV_8UC3, nullptr)};
const auto desc = descr_of(vec);
const auto desc = descrs_of(vec);
EXPECT_EQ((GMatDesc{CV_8U, 1, {320, 240}}), get<GMatDesc>(desc[0]));
EXPECT_EQ((GMatDesc{CV_8U, 3, {640, 480}}), get<GMatDesc>(desc[1]));
}
@@ -93,6 +109,38 @@ TEST(GAPI_MetaDesc, Compare_Not_Equal_MatDesc)
EXPECT_TRUE(desc1 != desc2);
}
TEST(GAPI_MetaDesc, Compare_Equal_MatDesc_ND)
{
const auto desc1 = cv::GMatDesc{CV_8U, {1,3,224,224}};
const auto desc2 = cv::GMatDesc{CV_8U, {1,3,224,224}};
EXPECT_TRUE(desc1 == desc2);
}
TEST(GAPI_MetaDesc, Compare_Not_Equal_MatDesc_ND_1)
{
const auto desc1 = cv::GMatDesc{CV_8U, {1,1000}};
const auto desc2 = cv::GMatDesc{CV_32F, {1,1000}};
EXPECT_TRUE(desc1 != desc2);
}
TEST(GAPI_MetaDesc, Compare_Not_Equal_MatDesc_ND_2)
{
const auto desc1 = cv::GMatDesc{CV_8U, {1,1000}};
const auto desc2 = cv::GMatDesc{CV_8U, {1,1400}};
EXPECT_TRUE(desc1 != desc2);
}
TEST(GAPI_MetaDesc, Compare_Not_Equal_MatDesc_ND_3)
{
const auto desc1 = cv::GMatDesc{CV_8U, {1,1000}};
const auto desc2 = cv::GMatDesc{CV_8U, 1, {32,32}};
EXPECT_TRUE(desc1 != desc2);
}
TEST(GAPI_MetaDesc, Compile_MatchMetaNumber_1)
{
cv::GMat in;
@@ -0,0 +1,281 @@
// 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) 2019 Intel Corporation
#include "../test_precomp.hpp"
#ifdef HAVE_INF_ENGINE
#include <stdexcept>
////////////////////////////////////////////////////////////////////////////////
// FIXME: Suppress deprecation warnings for OpenVINO 2019R2+
// BEGIN {{{
#if defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#ifdef _MSC_VER
#pragma warning(disable: 4996) // was declared deprecated
#endif
#if defined(__GNUC__)
#pragma GCC visibility push(default)
#endif
#include <inference_engine.hpp>
#if defined(__GNUC__)
#pragma GCC visibility pop
#endif
// END }}}
////////////////////////////////////////////////////////////////////////////////
#include <ade/util/iota_range.hpp>
#include <opencv2/gapi/infer/ie.hpp>
#include <opencv2/gapi/infer/ie/util.hpp>
namespace opencv_test
{
namespace {
// FIXME: taken from DNN module
static void initDLDTDataPath()
{
#ifndef WINRT
static bool initialized = false;
if (!initialized)
{
const char* omzDataPath = getenv("OPENCV_OPEN_MODEL_ZOO_DATA_PATH");
if (omzDataPath)
cvtest::addDataSearchPath(omzDataPath);
const char* dnnDataPath = getenv("OPENCV_DNN_TEST_DATA_PATH");
if (dnnDataPath) {
// Add the dnnDataPath itself - G-API is using some images there directly
cvtest::addDataSearchPath(dnnDataPath);
cvtest::addDataSearchPath(dnnDataPath + std::string("/omz_intel_models"));
}
initialized = true;
}
#endif // WINRT
}
// FIXME: taken from the DNN module
void normAssert(cv::InputArray ref, cv::InputArray test,
const char *comment /*= ""*/,
double l1 = 0.00001, double lInf = 0.0001)
{
double normL1 = cvtest::norm(ref, test, cv::NORM_L1) / ref.getMat().total();
EXPECT_LE(normL1, l1) << comment;
double normInf = cvtest::norm(ref, test, cv::NORM_INF);
EXPECT_LE(normInf, lInf) << comment;
}
} // anonymous namespace
// TODO: Probably DNN/IE part can be further parametrized with a template
// NOTE: here ".." is used to leave the default "gapi/" search scope
TEST(TestAgeGenderIE, InferBasicTensor)
{
initDLDTDataPath();
const std::string path = "Retail/object_attributes/age_gender/dldt/age-gender-recognition-retail-0013";
const auto topology_path = findDataFile(path + ".xml", false);
const auto weights_path = findDataFile(path + ".bin", false);
// Load IE network, initialize input data using that.
namespace IE = InferenceEngine;
cv::Mat in_mat;
cv::Mat gapi_age, gapi_gender;
IE::Blob::Ptr ie_age, ie_gender;
{
IE::CNNNetReader reader;
reader.ReadNetwork(topology_path);
reader.ReadWeights(weights_path);
auto net = reader.getNetwork();
const auto &iedims = net.getInputsInfo().begin()->second->getDims();
auto cvdims = cv::gapi::ie::util::to_ocv(iedims);
std::reverse(cvdims.begin(), cvdims.end());
in_mat.create(cvdims, CV_32F);
cv::randu(in_mat, -1, 1);
auto plugin = IE::PluginDispatcher().getPluginByDevice("CPU");
auto plugin_net = plugin.LoadNetwork(net, {});
auto infer_request = plugin_net.CreateInferRequest();
infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in_mat));
infer_request.Infer();
ie_age = infer_request.GetBlob("age_conv3");
ie_gender = infer_request.GetBlob("prob");
}
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GMat in;
cv::GMat age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
topology_path, weights_path, "CPU"
}.cfgOutputLayers({ "age_conv3", "prob" });
comp.apply(cv::gin(in_mat), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
normAssert(cv::gapi::ie::util::to_ocv(ie_age), gapi_age, "Test age output" );
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
}
TEST(TestAgeGenderIE, InferBasicImage)
{
initDLDTDataPath();
const std::string path = "Retail/object_attributes/age_gender/dldt/age-gender-recognition-retail-0013";
const auto topology_path = findDataFile(path + ".xml", false);
const auto weights_path = findDataFile(path + ".bin", false);
// FIXME: Ideally it should be an image from disk
// cv::Mat in_mat = cv::imread(findDataFile("grace_hopper_227.png"));
cv::Mat in_mat(cv::Size(320, 240), CV_8UC3);
cv::randu(in_mat, 0, 255);
cv::Mat gapi_age, gapi_gender;
// Load & run IE network
namespace IE = InferenceEngine;
IE::Blob::Ptr ie_age, ie_gender;
{
IE::CNNNetReader reader;
reader.ReadNetwork(topology_path);
reader.ReadWeights(weights_path);
auto net = reader.getNetwork();
auto &ii = net.getInputsInfo().at("data");
ii->setPrecision(IE::Precision::U8);
ii->setLayout(IE::Layout::NHWC);
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
auto plugin = IE::PluginDispatcher().getPluginByDevice("CPU");
auto plugin_net = plugin.LoadNetwork(net, {});
auto infer_request = plugin_net.CreateInferRequest();
infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(in_mat));
infer_request.Infer();
ie_age = infer_request.GetBlob("age_conv3");
ie_gender = infer_request.GetBlob("prob");
}
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GMat in;
cv::GMat age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
topology_path, weights_path, "CPU"
}.cfgOutputLayers({ "age_conv3", "prob" });
comp.apply(cv::gin(in_mat), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
normAssert(cv::gapi::ie::util::to_ocv(ie_age), gapi_age, "Test age output" );
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
}
TEST(TestAgeGenderIE, InferROIList)
{
initDLDTDataPath();
const std::string path = "Retail/object_attributes/age_gender/dldt/age-gender-recognition-retail-0013";
const auto topology_path = findDataFile(path + ".xml", false);
const auto weights_path = findDataFile(path + ".bin", false);
// FIXME: Ideally it should be an image from disk
// cv::Mat in_mat = cv::imread(findDataFile("grace_hopper_227.png"));
cv::Mat in_mat(cv::Size(640, 480), CV_8UC3);
cv::randu(in_mat, 0, 255);
std::vector<cv::Rect> rois = {
cv::Rect(cv::Point{ 0, 0}, cv::Size{80, 120}),
cv::Rect(cv::Point{50, 100}, cv::Size{96, 160}),
};
std::vector<cv::Mat> gapi_age, gapi_gender;
// Load & run IE network
namespace IE = InferenceEngine;
std::vector<cv::Mat> ie_age, ie_gender;
{
IE::CNNNetReader reader;
reader.ReadNetwork(topology_path);
reader.ReadWeights(weights_path);
auto net = reader.getNetwork();
auto &ii = net.getInputsInfo().at("data");
ii->setPrecision(IE::Precision::U8);
ii->setLayout(IE::Layout::NHWC);
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
auto plugin = IE::PluginDispatcher().getPluginByDevice("CPU");
auto plugin_net = plugin.LoadNetwork(net, {});
auto infer_request = plugin_net.CreateInferRequest();
auto frame_blob = cv::gapi::ie::util::to_ie(in_mat);
for (auto &&rc : rois) {
const auto ie_rc = IE::ROI {
0u
, static_cast<std::size_t>(rc.x)
, static_cast<std::size_t>(rc.y)
, static_cast<std::size_t>(rc.width)
, static_cast<std::size_t>(rc.height)
};
infer_request.SetBlob("data", IE::make_shared_blob(frame_blob, ie_rc));
infer_request.Infer();
using namespace cv::gapi::ie::util;
ie_age.push_back(to_ocv(infer_request.GetBlob("age_conv3")).clone());
ie_gender.push_back(to_ocv(infer_request.GetBlob("prob")).clone());
}
}
// Configure & run G-API
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
cv::GArray<cv::Rect> rr;
cv::GMat in;
cv::GArray<cv::GMat> age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));
auto pp = cv::gapi::ie::Params<AgeGender> {
topology_path, weights_path, "CPU"
}.cfgOutputLayers({ "age_conv3", "prob" });
comp.apply(cv::gin(in_mat, rois), cv::gout(gapi_age, gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
// Validate with IE itself (avoid DNN module dependency here)
ASSERT_EQ(2u, ie_age.size() );
ASSERT_EQ(2u, ie_gender.size());
ASSERT_EQ(2u, gapi_age.size() );
ASSERT_EQ(2u, gapi_gender.size());
normAssert(ie_age [0], gapi_age [0], "0: Test age output");
normAssert(ie_gender[0], gapi_gender[0], "0: Test gender output");
normAssert(ie_age [1], gapi_age [1], "1: Test age output");
normAssert(ie_gender[1], gapi_gender[1], "1: Test gender output");
}
} // namespace opencv_test
#endif // HAVE_INF_ENGINE
@@ -23,12 +23,12 @@ namespace
{
cv::GMat unaryOp(cv::GMat m)
{
return cv::GCall(cv::GKernel{"gapi.test.unaryop", nullptr, { GShape::GMAT } }).pass(m).yield(0);
return cv::GCall(cv::GKernel{"gapi.test.unaryop", "", nullptr, { GShape::GMAT } }).pass(m).yield(0);
}
cv::GMat binaryOp(cv::GMat m1, cv::GMat m2)
{
return cv::GCall(cv::GKernel{"gapi.test.binaryOp", nullptr, { GShape::GMAT } }).pass(m1, m2).yield(0);
return cv::GCall(cv::GKernel{"gapi.test.binaryOp", "", nullptr, { GShape::GMAT } }).pass(m1, m2).yield(0);
}
std::vector<ade::NodeHandle> collectOperations(const cv::gimpl::GModel::Graph& gr)
+199 -1
View File
@@ -12,6 +12,7 @@
namespace opencv_test
{
using Mat = cv::gapi::own::Mat;
using Dims = std::vector<int>;
TEST(OwnMat, DefaultConstruction)
{
@@ -22,6 +23,7 @@ TEST(OwnMat, DefaultConstruction)
ASSERT_EQ(m.cols, 0);
ASSERT_EQ(m.type(), 0);
ASSERT_EQ(m.depth(), 0);
ASSERT_TRUE(m.dims.empty());
}
TEST(OwnMat, Create)
@@ -39,6 +41,25 @@ TEST(OwnMat, Create)
ASSERT_EQ(m.channels(), 1);
ASSERT_EQ(m.elemSize(), sizeof(uint8_t));
ASSERT_EQ(m.step, sizeof(uint8_t) * m.cols);
ASSERT_TRUE(m.dims.empty());
}
TEST(OwnMat, CreateND)
{
Dims dims = {1,1,32,32};
Mat m;
m.create(dims, CV_32F);
ASSERT_NE(nullptr , m.data );
ASSERT_EQ((cv::gapi::own::Size{0,0}), (cv::gapi::own::Size{m.cols, m.rows}));
ASSERT_EQ(static_cast<size_t>(dims[0]*dims[1]*dims[2]*dims[3]), m.total());
ASSERT_EQ(CV_32F , m.type() );
ASSERT_EQ(CV_32F , m.depth() );
ASSERT_EQ(-1 , m.channels());
ASSERT_EQ(sizeof(float) , m.elemSize());
ASSERT_EQ(0u , m.step );
ASSERT_EQ(dims , m.dims );
}
TEST(OwnMat, CreateOverload)
@@ -56,7 +77,9 @@ TEST(OwnMat, CreateOverload)
ASSERT_EQ(m.channels(), 1);
ASSERT_EQ(m.elemSize(), sizeof(uint8_t));
ASSERT_EQ(m.step, sizeof(uint8_t) * m.cols);
ASSERT_TRUE(m.dims.empty());
}
TEST(OwnMat, Create3chan)
{
auto size = cv::Size{32,16};
@@ -71,6 +94,7 @@ TEST(OwnMat, Create3chan)
ASSERT_EQ(m.channels(), 3);
ASSERT_EQ(m.elemSize(), 3 * sizeof(uint8_t));
ASSERT_EQ(m.step, 3* sizeof(uint8_t) * m.cols);
ASSERT_TRUE(m.dims.empty());
}
struct NonEmptyMat {
@@ -91,7 +115,8 @@ namespace {
cv::Size{mat.cols, mat.rows},
mat.type(),
mat.depth(),
mat.channels()
mat.channels(),
mat.dims
);
};
@@ -194,6 +219,23 @@ TEST(OwnMatConversion, WithStep)
<< (cvMat != cvMatFromOwn);
}
TEST(OwnMatConversion, WithND)
{
const Dims dims = {1,3,8,8};
std::vector<uint8_t> data(dims[0]*dims[1]*dims[2]*dims[3]);
for (size_t i = 0u; i < data.size(); i++)
{
data[i] = static_cast<uint8_t>(i);
}
cv::Mat cvMat(dims, CV_32S, data.data());
auto ownMat = to_own(cvMat);
auto cvMatFromOwn = cv::gapi::own::to_ocv(ownMat);
EXPECT_EQ(0, cv::countNonZero(cvMat != cvMatFromOwn))
<< cvMat << std::endl
<< (cvMat != cvMatFromOwn);
}
TEST(OwnMat, PtrWithStep)
{
constexpr int width = 8;
@@ -242,6 +284,149 @@ TEST(OwnMat, CopyToWithStep)
<< (to_ocv(mat) != to_ocv(dst));
}
TEST(OwnMat, AssignNDtoRegular)
{
const auto sz = cv::gapi::own::Size{32,32};
const auto dims = Dims{1,3,224,224};
Mat a;
a.create(sz, CV_8U);
const auto *old_ptr = a.data;
ASSERT_NE(nullptr , a.data);
ASSERT_EQ(sz , (cv::gapi::own::Size{a.cols, a.rows}));
ASSERT_EQ(static_cast<size_t>(sz.width*sz.height), a.total());
ASSERT_EQ(CV_8U , a.type());
ASSERT_EQ(CV_8U , a.depth());
ASSERT_EQ(1 , a.channels());
ASSERT_EQ(sizeof(uint8_t), a.elemSize());
ASSERT_EQ(static_cast<size_t>(sz.width), a.step);
ASSERT_TRUE(a.dims.empty());
Mat b;
b.create(dims, CV_32F);
a = b;
ASSERT_NE(nullptr , a.data);
ASSERT_NE(old_ptr , a.data);
ASSERT_EQ((cv::gapi::own::Size{0,0}), (cv::gapi::own::Size{a.cols, a.rows}));
ASSERT_EQ(static_cast<size_t>(dims[0]*dims[1]*dims[2]*dims[3]), a.total());
ASSERT_EQ(CV_32F , a.type());
ASSERT_EQ(CV_32F , a.depth());
ASSERT_EQ(-1 , a.channels());
ASSERT_EQ(sizeof(float), a.elemSize());
ASSERT_EQ(0u , a.step);
ASSERT_EQ(dims , a.dims);
}
TEST(OwnMat, AssignRegularToND)
{
const auto sz = cv::gapi::own::Size{32,32};
const auto dims = Dims{1,3,224,224};
Mat a;
a.create(dims, CV_32F);
const auto *old_ptr = a.data;
ASSERT_NE(nullptr , a.data);
ASSERT_EQ((cv::gapi::own::Size{0,0}), (cv::gapi::own::Size{a.cols, a.rows}));
ASSERT_EQ(static_cast<size_t>(dims[0]*dims[1]*dims[2]*dims[3]), a.total());
ASSERT_EQ(CV_32F , a.type());
ASSERT_EQ(CV_32F , a.depth());
ASSERT_EQ(-1 , a.channels());
ASSERT_EQ(sizeof(float), a.elemSize());
ASSERT_EQ(0u , a.step);
ASSERT_EQ(dims , a.dims);
Mat b;
b.create(sz, CV_8U);
a = b;
ASSERT_NE(nullptr , a.data);
ASSERT_NE(old_ptr , a.data);
ASSERT_EQ(sz , (cv::gapi::own::Size{a.cols, a.rows}));
ASSERT_EQ(static_cast<size_t>(sz.width*sz.height), a.total());
ASSERT_EQ(CV_8U , a.type());
ASSERT_EQ(CV_8U , a.depth());
ASSERT_EQ(1 , a.channels());
ASSERT_EQ(sizeof(uint8_t), a.elemSize());
ASSERT_EQ(static_cast<size_t>(sz.width), a.step);
ASSERT_TRUE(a.dims.empty());
}
TEST(OwnMat, CopyNDtoRegular)
{
const auto sz = cv::gapi::own::Size{32,32};
const auto dims = Dims{1,3,224,224};
Mat a;
a.create(sz, CV_8U);
const auto *old_ptr = a.data;
ASSERT_NE(nullptr , a.data);
ASSERT_EQ(sz , (cv::gapi::own::Size{a.cols, a.rows}));
ASSERT_EQ(static_cast<size_t>(sz.width*sz.height), a.total());
ASSERT_EQ(CV_8U , a.type());
ASSERT_EQ(CV_8U , a.depth());
ASSERT_EQ(1 , a.channels());
ASSERT_EQ(sizeof(uint8_t), a.elemSize());
ASSERT_EQ(static_cast<size_t>(sz.width), a.step);
ASSERT_TRUE(a.dims.empty());
Mat b;
b.create(dims, CV_32F);
b.copyTo(a);
ASSERT_NE(nullptr , a.data);
ASSERT_NE(old_ptr , a.data);
ASSERT_NE(b.data , a.data);
ASSERT_EQ((cv::gapi::own::Size{0,0}), (cv::gapi::own::Size{a.cols, a.rows}));
ASSERT_EQ(static_cast<size_t>(dims[0]*dims[1]*dims[2]*dims[3]), a.total());
ASSERT_EQ(CV_32F , a.type());
ASSERT_EQ(CV_32F , a.depth());
ASSERT_EQ(-1 , a.channels());
ASSERT_EQ(sizeof(float), a.elemSize());
ASSERT_EQ(0u , a.step);
ASSERT_EQ(dims , a.dims);
}
TEST(OwnMat, CopyRegularToND)
{
const auto sz = cv::gapi::own::Size{32,32};
const auto dims = Dims{1,3,224,224};
Mat a;
a.create(dims, CV_32F);
const auto *old_ptr = a.data;
ASSERT_NE(nullptr , a.data);
ASSERT_EQ((cv::gapi::own::Size{0,0}), (cv::gapi::own::Size{a.cols, a.rows}));
ASSERT_EQ(static_cast<size_t>(dims[0]*dims[1]*dims[2]*dims[3]), a.total());
ASSERT_EQ(CV_32F , a.type());
ASSERT_EQ(CV_32F , a.depth());
ASSERT_EQ(-1 , a.channels());
ASSERT_EQ(sizeof(float), a.elemSize());
ASSERT_EQ(0u , a.step);
ASSERT_EQ(dims , a.dims);
Mat b;
b.create(sz, CV_8U);
b.copyTo(a);
ASSERT_NE(nullptr , a.data);
ASSERT_NE(old_ptr , a.data);
ASSERT_NE(b.data , a.data);
ASSERT_EQ(sz , (cv::gapi::own::Size{a.cols, a.rows}));
ASSERT_EQ(static_cast<size_t>(sz.width*sz.height), a.total());
ASSERT_EQ(CV_8U , a.type());
ASSERT_EQ(CV_8U , a.depth());
ASSERT_EQ(1 , a.channels());
ASSERT_EQ(sizeof(uint8_t), a.elemSize());
ASSERT_EQ(static_cast<size_t>(sz.width), a.step);
ASSERT_TRUE(a.dims.empty());
}
TEST(OwnMat, ScalarAssign32SC1)
{
constexpr int width = 8;
@@ -304,6 +489,19 @@ TEST(OwnMat, ScalarAssign8UC1)
<< cmp_result_mat << std::endl;
}
TEST(OwnMat, ScalarAssignND)
{
std::vector<int> dims = {1,1000};
Mat m;
m.create(dims, CV_32F);
m = cv::gapi::own::Scalar{-1};
const float *ptr = reinterpret_cast<float*>(m.data);
for (auto i = 0u; i < m.total(); i++) {
EXPECT_EQ(-1.f, ptr[i]);
}
}
TEST(OwnMat, ScalarAssign8UC3)
{
constexpr auto cv_type = CV_8SC3;
+2
View File
@@ -14,6 +14,7 @@
#include <vector>
#include <opencv2/ts.hpp>
#include <opencv2/gapi.hpp>
#include <opencv2/gapi/imgproc.hpp>
#include <opencv2/gapi/core.hpp>
@@ -25,5 +26,6 @@
#include <opencv2/gapi/operators.hpp>
#include <opencv2/gapi/fluid/imgproc.hpp>
#include <opencv2/gapi/fluid/core.hpp>
#include <opencv2/gapi/infer.hpp>
#endif // __OPENCV_GAPI_TEST_PRECOMP_HPP__