gapi_s11n_tests.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. #include "../test_precomp.hpp"
  2. #include "backends/common/serialization.hpp"
  3. #include <opencv2/gapi/rmat.hpp>
  4. #include <opencv2/gapi/media.hpp>
  5. #include <../src/backends/common/gbackend.hpp> // asView
  6. namespace {
  7. struct EmptyCustomType { };
  8. struct SimpleCustomType {
  9. bool val;
  10. bool operator==(const SimpleCustomType& other) const {
  11. return val == other.val;
  12. }
  13. };
  14. struct SimpleCustomType2 {
  15. int id;
  16. bool operator==(const SimpleCustomType2& other) const {
  17. return id == other.id;
  18. }
  19. };
  20. struct MyCustomType {
  21. int val;
  22. std::string name;
  23. std::vector<float> vec;
  24. std::map<int, uint64_t> mmap;
  25. bool operator==(const MyCustomType& other) const {
  26. return val == other.val && name == other.name &&
  27. vec == other.vec && mmap == other.mmap;
  28. }
  29. };
  30. struct MyCustomTypeNoS11N {
  31. char sym;
  32. int id;
  33. std::string name;
  34. bool operator==(const MyCustomTypeNoS11N& other) const {
  35. return sym == other.sym && id == other.id &&
  36. name == other.name;
  37. }
  38. };
  39. } // anonymous namespace
  40. namespace cv {
  41. namespace gapi {
  42. namespace s11n {
  43. namespace detail {
  44. template<> struct S11N<EmptyCustomType> {
  45. static void serialize(IOStream &, const EmptyCustomType &) { }
  46. static EmptyCustomType deserialize(IIStream &) { return EmptyCustomType { }; }
  47. };
  48. template<> struct S11N<SimpleCustomType> {
  49. static void serialize(IOStream &os, const SimpleCustomType &p) {
  50. os << p.val;
  51. }
  52. static SimpleCustomType deserialize(IIStream &is) {
  53. SimpleCustomType p;
  54. is >> p.val;
  55. return p;
  56. }
  57. };
  58. template<> struct S11N<SimpleCustomType2> {
  59. static void serialize(IOStream &os, const SimpleCustomType2 &p) {
  60. os << p.id;
  61. }
  62. static SimpleCustomType2 deserialize(IIStream &is) {
  63. SimpleCustomType2 p;
  64. is >> p.id;
  65. return p;
  66. }
  67. };
  68. template<> struct S11N<MyCustomType> {
  69. static void serialize(IOStream &os, const MyCustomType &p) {
  70. os << p.val << p.name << p.vec << p.mmap;
  71. }
  72. static MyCustomType deserialize(IIStream &is) {
  73. MyCustomType p;
  74. is >> p.val >> p.name >> p.vec >> p.mmap;
  75. return p;
  76. }
  77. };
  78. } // namespace detail
  79. } // namespace s11n
  80. } // namespace gapi
  81. } // namespace cv
  82. namespace cv {
  83. namespace detail {
  84. template<> struct CompileArgTag<EmptyCustomType> {
  85. static const char* tag() {
  86. return "org.opencv.test.empty_custom_type";
  87. }
  88. };
  89. template<> struct CompileArgTag<SimpleCustomType> {
  90. static const char* tag() {
  91. return "org.opencv.test.simple_custom_type";
  92. }
  93. };
  94. template<> struct CompileArgTag<SimpleCustomType2> {
  95. static const char* tag() {
  96. return "org.opencv.test.simple_custom_type_2";
  97. }
  98. };
  99. template<> struct CompileArgTag<MyCustomType> {
  100. static const char* tag() {
  101. return "org.opencv.test.my_custom_type";
  102. }
  103. };
  104. template<> struct CompileArgTag<MyCustomTypeNoS11N> {
  105. static const char* tag() {
  106. return "org.opencv.test.my_custom_type_no_s11n";
  107. }
  108. };
  109. } // namespace detail
  110. } // namespace cv
  111. namespace {
  112. class MyRMatAdapter : public cv::RMat::IAdapter {
  113. cv::Mat m_mat;
  114. int m_value;
  115. std::string m_str;
  116. public:
  117. MyRMatAdapter() = default;
  118. MyRMatAdapter(cv::Mat m, int value, const std::string& str)
  119. : m_mat(m), m_value(value), m_str(str)
  120. {}
  121. virtual cv::RMat::View access(cv::RMat::Access) override {
  122. return cv::gimpl::asView(m_mat);
  123. }
  124. virtual cv::GMatDesc desc() const override { return cv::descr_of(m_mat); }
  125. virtual void serialize(cv::gapi::s11n::IOStream& os) override {
  126. os << m_value << m_str;
  127. }
  128. virtual void deserialize(cv::gapi::s11n::IIStream& is) override {
  129. is >> m_value >> m_str;
  130. }
  131. int getVal() { return m_value; }
  132. std::string getStr() { return m_str; }
  133. };
  134. class MyMediaFrameAdapter : public cv::MediaFrame::IAdapter {
  135. cv::Mat m_mat;
  136. int m_value;
  137. std::string m_str;
  138. public:
  139. MyMediaFrameAdapter() = default;
  140. MyMediaFrameAdapter(cv::Mat m, int value, const std::string& str)
  141. : m_mat(m), m_value(value), m_str(str)
  142. {}
  143. virtual cv::MediaFrame::View access(cv::MediaFrame::Access) override {
  144. return cv::MediaFrame::View({m_mat.data}, {m_mat.step});
  145. }
  146. virtual cv::GFrameDesc meta() const override { return {cv::MediaFormat::BGR, m_mat.size()}; }
  147. virtual void serialize(cv::gapi::s11n::IOStream& os) override {
  148. os << m_value << m_str;
  149. }
  150. virtual void deserialize(cv::gapi::s11n::IIStream& is) override {
  151. is >> m_value >> m_str;
  152. }
  153. int getVal() { return m_value; }
  154. std::string getStr() { return m_str; }
  155. };
  156. }
  157. namespace opencv_test {
  158. struct S11N_Basic: public ::testing::Test {
  159. template<typename T> void put(T &&t) {
  160. cv::gapi::s11n::ByteMemoryOutStream os;
  161. os << t;
  162. m_buffer = os.data();
  163. }
  164. template<typename T> T get() {
  165. // FIXME: This stream API needs a fix-up
  166. cv::gapi::s11n::ByteMemoryInStream is(m_buffer);
  167. T t{};
  168. is >> t;
  169. return t;
  170. }
  171. private:
  172. std::vector<char> m_buffer;
  173. };
  174. namespace
  175. {
  176. template<typename T>
  177. bool operator==(const cv::detail::VectorRef& a, const cv::detail::VectorRef& b)
  178. {
  179. return a.rref<T>() == b.rref<T>();
  180. }
  181. template<typename T>
  182. bool operator==(const cv::detail::OpaqueRef& a, const cv::detail::OpaqueRef& b)
  183. {
  184. return a.rref<T>() == b.rref<T>();
  185. }
  186. }
  187. TEST_F(S11N_Basic, Test_int_pos) {
  188. int x = 42;
  189. put(x);
  190. EXPECT_EQ(x, get<int>());
  191. }
  192. TEST_F(S11N_Basic, Test_int_neg) {
  193. int x = -42;
  194. put(x);
  195. EXPECT_EQ(x, get<int>());
  196. }
  197. TEST_F(S11N_Basic, Test_fp32) {
  198. float x = 3.14f;
  199. put(x);
  200. EXPECT_EQ(x, get<float>());
  201. }
  202. TEST_F(S11N_Basic, Test_fp64) {
  203. double x = 3.14;
  204. put(x);
  205. EXPECT_EQ(x, get<double>());
  206. }
  207. TEST_F(S11N_Basic, Test_uint64) {
  208. uint64_t x = 2147483647374;
  209. put(x);
  210. EXPECT_EQ(x, get<uint64_t>());
  211. }
  212. TEST_F(S11N_Basic, Test_int32_pos) {
  213. int32_t x = 2147483647;
  214. put(x);
  215. EXPECT_EQ(x, get<int32_t>());
  216. }
  217. TEST_F(S11N_Basic, Test_int32_neg) {
  218. int32_t x = -2147483646;
  219. put(x);
  220. EXPECT_EQ(x, get<int32_t>());
  221. }
  222. TEST_F(S11N_Basic, Test_vector_bool) {
  223. std::vector<bool> v = {false, true, false};
  224. put(v);
  225. EXPECT_EQ(v, get<std::vector<bool>>());
  226. }
  227. TEST_F(S11N_Basic, Test_map_string2string) {
  228. using T = std::map<std::string, std::string>;
  229. T v;
  230. v["gapi"] = "cool";
  231. v["42"] = "answer";
  232. v["hi"] = "hello there";
  233. put(v);
  234. EXPECT_EQ(v, get<T>());
  235. }
  236. TEST_F(S11N_Basic, Test_map_int2int) {
  237. using T = std::map<int, int32_t>;
  238. T v;
  239. v[1] = 23;
  240. v[-100] = 0;
  241. v[435346] = -12346;
  242. put(v);
  243. EXPECT_EQ(v, get<T>());
  244. }
  245. TEST_F(S11N_Basic, Test_map_float2cvsize) {
  246. using T = std::map<float, cv::Size>;
  247. T v;
  248. v[0.4f] = cv::Size(4, 5);
  249. v[234.43f] = cv::Size(3421, 321);
  250. v[2223.f] = cv::Size(1920, 1080);
  251. put(v);
  252. EXPECT_EQ(v, get<T>());
  253. }
  254. TEST_F(S11N_Basic, Test_map_uint642cvmat) {
  255. using T = std::map<uint64_t, cv::Mat>;
  256. T v;
  257. v[21304805324] = cv::Mat(3, 3, CV_8UC1, cv::Scalar::all(3));
  258. v[4353245222] = cv::Mat(5, 5, CV_8UC3, cv::Scalar::all(7));
  259. v[0] = cv::Mat(10, 10, CV_32FC2, cv::Scalar::all(-128.f));
  260. put(v);
  261. auto out_v = get<T>();
  262. for (const auto& el : out_v) {
  263. EXPECT_NE(v.end(), v.find(el.first));
  264. EXPECT_EQ(0, cv::norm(el.second, v[el.first]));
  265. }
  266. }
  267. TEST_F(S11N_Basic, Test_vector_int) {
  268. std::vector<int> v = {1,2,3};
  269. put(v);
  270. EXPECT_EQ(v, get<std::vector<int>>());
  271. }
  272. TEST_F(S11N_Basic, Test_vector_cvSize) {
  273. std::vector<cv::Size> v = {
  274. cv::Size(640, 480),
  275. cv::Size(1280, 1024),
  276. };
  277. put(v);
  278. EXPECT_EQ(v, get<std::vector<cv::Size>>());
  279. }
  280. TEST_F(S11N_Basic, Test_vector_string) {
  281. std::vector<std::string> v = {
  282. "hello",
  283. "world",
  284. "ok!"
  285. };
  286. put(v);
  287. EXPECT_EQ(v, get<std::vector<std::string>>());
  288. }
  289. TEST_F(S11N_Basic, Test_vector_empty) {
  290. std::vector<char> v;
  291. put(v);
  292. EXPECT_EQ(v, get<std::vector<char>>());
  293. }
  294. TEST_F(S11N_Basic, Test_variant) {
  295. using S = std::string;
  296. using V = cv::util::variant<int,S>;
  297. V v1{42}, v2{S{"hey"}};
  298. put(v1);
  299. EXPECT_EQ(v1, get<V>());
  300. put(v2);
  301. EXPECT_EQ(v2, get<V>());
  302. }
  303. TEST_F(S11N_Basic, Test_GArg_int) {
  304. const int x = 42;
  305. cv::GArg gs(x);
  306. put(gs);
  307. cv::GArg gd = get<cv::GArg>();
  308. EXPECT_EQ(cv::detail::ArgKind::OPAQUE_VAL, gd.kind);
  309. EXPECT_EQ(cv::detail::OpaqueKind::CV_INT, gd.opaque_kind);
  310. EXPECT_EQ(x, gs.get<int>());
  311. }
  312. TEST_F(S11N_Basic, Test_GArg_Point) {
  313. const cv::Point pt{1,2};
  314. cv::GArg gs(pt);
  315. put(gs);
  316. cv::GArg gd = get<cv::GArg>();
  317. EXPECT_EQ(cv::detail::ArgKind::OPAQUE_VAL, gd.kind);
  318. EXPECT_EQ(cv::detail::OpaqueKind::CV_POINT, gd.opaque_kind);
  319. EXPECT_EQ(pt, gs.get<cv::Point>());
  320. }
  321. TEST_F(S11N_Basic, Test_Mat_full) {
  322. auto mat = cv::Mat::eye(cv::Size(64,64), CV_8UC3);
  323. put(mat);
  324. EXPECT_EQ(0, cv::norm(mat, get<cv::Mat>(), cv::NORM_INF));
  325. }
  326. TEST_F(S11N_Basic, Test_Mat_view) {
  327. auto mat = cv::Mat::eye(cv::Size(320,240), CV_8UC3);
  328. auto view = mat(cv::Rect(10,15,123,70));
  329. put(view);
  330. EXPECT_EQ(0, cv::norm(view, get<cv::Mat>(), cv::NORM_INF));
  331. }
  332. TEST_F(S11N_Basic, Test_MatDesc) {
  333. cv::GMatDesc v = { CV_8U, 1, {320,240} };
  334. put(v);
  335. EXPECT_EQ(v, get<cv::GMatDesc>());
  336. }
  337. TEST_F(S11N_Basic, Test_MatDescND) {
  338. cv::GMatDesc v = { CV_8U, {1,1,224,224} };
  339. put(v);
  340. EXPECT_EQ(v, get<cv::GMatDesc>());
  341. }
  342. TEST_F(S11N_Basic, Test_MetaArg_MatDesc) {
  343. cv::GMatDesc desc = { CV_8U, 1,{ 320,240 } };
  344. auto v = cv::GMetaArg{ desc };
  345. put(v);
  346. cv::GMetaArg out_v = get<cv::GMetaArg>();
  347. cv::GMatDesc out_desc = cv::util::get<cv::GMatDesc>(out_v);
  348. EXPECT_EQ(desc, out_desc);
  349. }
  350. TEST_F(S11N_Basic, Test_MetaArgs_MatDesc) {
  351. cv::GMatDesc desc1 = { CV_8U, 1,{ 320,240 } };
  352. cv::GMatDesc desc2 = { CV_8U, 1,{ 640,480 } };
  353. GMetaArgs v;
  354. v.resize(2);
  355. v[0] = cv::GMetaArg{ desc1 };
  356. v[1] = cv::GMetaArg{ desc2 };
  357. put(v);
  358. cv::GMetaArgs out_v = get<cv::GMetaArgs>();
  359. cv::GMatDesc out_desc1 = cv::util::get<cv::GMatDesc>(out_v[0]);
  360. cv::GMatDesc out_desc2 = cv::util::get<cv::GMatDesc>(out_v[1]);
  361. EXPECT_EQ(desc1, out_desc1);
  362. EXPECT_EQ(desc2, out_desc2);
  363. }
  364. TEST_F(S11N_Basic, Test_MetaArg_Monostate) {
  365. GMetaArg v;
  366. put(v);
  367. cv::GMetaArg out_v = get<cv::GMetaArg>();
  368. if (!util::holds_alternative<util::monostate>(out_v))
  369. {
  370. GTEST_FAIL();
  371. }
  372. }
  373. TEST_F(S11N_Basic, Test_RunArg_Mat) {
  374. cv::Mat mat = cv::Mat::eye(cv::Size(64, 64), CV_8UC3);
  375. auto v = cv::GRunArg{ mat };
  376. put(v);
  377. cv::GRunArg out_v = get<cv::GRunArg>();
  378. cv::Mat out_mat = cv::util::get<cv::Mat>(out_v);
  379. EXPECT_EQ(0, cv::norm(mat, out_mat, cv::NORM_INF));
  380. }
  381. TEST_F(S11N_Basic, Test_RunArgs_Mat) {
  382. cv::Mat mat1 = cv::Mat::eye(cv::Size(64, 64), CV_8UC3);
  383. cv::Mat mat2 = cv::Mat::eye(cv::Size(128, 128), CV_8UC3);
  384. GRunArgs v;
  385. v.resize(2);
  386. v[0] = cv::GRunArg{ mat1 };
  387. v[1] = cv::GRunArg{ mat2 };
  388. put(v);
  389. cv::GRunArgs out_v = get<cv::GRunArgs>();
  390. cv::Mat out_mat1 = cv::util::get<cv::Mat>(out_v[0]);
  391. cv::Mat out_mat2 = cv::util::get<cv::Mat>(out_v[1]);
  392. EXPECT_EQ(0, cv::norm(mat1, out_mat1, cv::NORM_INF));
  393. EXPECT_EQ(0, cv::norm(mat2, out_mat2, cv::NORM_INF));
  394. }
  395. TEST_F(S11N_Basic, Test_RunArg_Scalar) {
  396. cv::Scalar scalar = cv::Scalar(128, 33, 53);
  397. auto v = cv::GRunArg{ scalar };
  398. put(v);
  399. cv::GRunArg out_v = get<cv::GRunArg>();
  400. cv::Scalar out_scalar = cv::util::get<cv::Scalar>(out_v);
  401. EXPECT_EQ(scalar, out_scalar);
  402. }
  403. TEST_F(S11N_Basic, Test_RunArgs_Scalar) {
  404. cv::Scalar scalar1 = cv::Scalar(128, 33, 53);
  405. cv::Scalar scalar2 = cv::Scalar(64, 15, 23);
  406. GRunArgs v;
  407. v.resize(2);
  408. v[0] = cv::GRunArg{ scalar1 };
  409. v[1] = cv::GRunArg{ scalar2 };
  410. put(v);
  411. cv::GRunArgs out_v = get<cv::GRunArgs>();
  412. cv::Scalar out_scalar1 = cv::util::get<cv::Scalar>(out_v[0]);
  413. cv::Scalar out_scalar2 = cv::util::get<cv::Scalar>(out_v[1]);
  414. EXPECT_EQ(scalar1, out_scalar1);
  415. EXPECT_EQ(scalar2, out_scalar2);
  416. }
  417. TEST_F(S11N_Basic, Test_RunArg_Opaque) {
  418. auto op = cv::detail::OpaqueRef(42);
  419. auto v = cv::GRunArg{ op };
  420. put(v);
  421. cv::GRunArg out_v = get<cv::GRunArg>();
  422. cv::detail::OpaqueRef out_op = cv::util::get<cv::detail::OpaqueRef>(out_v);
  423. EXPECT_TRUE(operator==<int>(op, out_op));
  424. }
  425. TEST_F(S11N_Basic, Test_RunArgs_Opaque) {
  426. cv::detail::OpaqueRef op1 = cv::detail::OpaqueRef(cv::Point(1, 2));
  427. cv::detail::OpaqueRef op2 = cv::detail::OpaqueRef(cv::Size(12, 21));
  428. GRunArgs v;
  429. v.resize(2);
  430. v[0] = cv::GRunArg{ op1 };
  431. v[1] = cv::GRunArg{ op2 };
  432. put(v);
  433. cv::GRunArgs out_v = get<cv::GRunArgs>();
  434. cv::detail::OpaqueRef out_op1 = cv::util::get<cv::detail::OpaqueRef>(out_v[0]);
  435. cv::detail::OpaqueRef out_op2 = cv::util::get<cv::detail::OpaqueRef>(out_v[1]);
  436. EXPECT_TRUE(operator==<cv::Point>(op1, out_op1));
  437. EXPECT_TRUE(operator==<cv::Size>(op2, out_op2));
  438. }
  439. TEST_F(S11N_Basic, Test_RunArg_Array) {
  440. auto op = cv::detail::VectorRef(std::vector<cv::Mat>{cv::Mat::eye(3, 3, CV_8UC1), cv::Mat::zeros(5, 5, CV_8UC3)});
  441. auto v = cv::GRunArg{ op };
  442. put(v);
  443. cv::GRunArg out_v = get<cv::GRunArg>();
  444. cv::detail::VectorRef out_op = cv::util::get<cv::detail::VectorRef>(out_v);
  445. auto vec1 = op.rref<cv::Mat>();
  446. auto vec2 = out_op.rref<cv::Mat>();
  447. EXPECT_EQ(0, cv::norm(vec1[0], vec2[0], cv::NORM_INF));
  448. EXPECT_EQ(0, cv::norm(vec1[1], vec2[1], cv::NORM_INF));
  449. }
  450. TEST_F(S11N_Basic, Test_RunArgs_Array) {
  451. auto vec_sc = std::vector<cv::Scalar>{cv::Scalar(11), cv::Scalar(31)};
  452. auto vec_d = std::vector<double>{0.4, 1.0, 123.55, 22.08};
  453. cv::detail::VectorRef op1 = cv::detail::VectorRef(vec_sc);
  454. cv::detail::VectorRef op2 = cv::detail::VectorRef(vec_d);
  455. GRunArgs v;
  456. v.resize(2);
  457. v[0] = cv::GRunArg{ op1 };
  458. v[1] = cv::GRunArg{ op2 };
  459. put(v);
  460. cv::GRunArgs out_v = get<cv::GRunArgs>();
  461. cv::detail::VectorRef out_op1 = cv::util::get<cv::detail::VectorRef>(out_v[0]);
  462. cv::detail::VectorRef out_op2 = cv::util::get<cv::detail::VectorRef>(out_v[1]);
  463. EXPECT_TRUE(operator==<cv::Scalar>(op1, out_op1));
  464. EXPECT_TRUE(operator==<double>(op2, out_op2));
  465. }
  466. TEST_F(S11N_Basic, Test_RunArgs_MatScalar) {
  467. cv::Mat mat = cv::Mat::eye(cv::Size(64, 64), CV_8UC3);
  468. cv::Scalar scalar = cv::Scalar(128, 33, 53);
  469. GRunArgs v;
  470. v.resize(2);
  471. v[0] = cv::GRunArg{ mat };
  472. v[1] = cv::GRunArg{ scalar };
  473. put(v);
  474. cv::GRunArgs out_v = get<cv::GRunArgs>();
  475. unsigned int i = 0;
  476. for (auto it : out_v)
  477. {
  478. using T = cv::GRunArg;
  479. switch (it.index())
  480. {
  481. case T::index_of<cv::Mat>() :
  482. {
  483. cv::Mat out_mat = cv::util::get<cv::Mat>(out_v[i]);
  484. EXPECT_EQ(0, cv::norm(mat, out_mat, cv::NORM_INF));
  485. } break;
  486. case T::index_of<cv::Scalar>() :
  487. {
  488. cv::Scalar out_scalar = cv::util::get<cv::Scalar>(out_v[i]);
  489. EXPECT_EQ(scalar, out_scalar);
  490. } break;
  491. default:
  492. GAPI_Assert(false && "This value type is not supported!"); // ...maybe because of STANDALONE mode.
  493. break;
  494. }
  495. i++;
  496. }
  497. }
  498. TEST_F(S11N_Basic, Test_Bind_RunArgs_MatScalar) {
  499. cv::Mat mat = cv::Mat::eye(cv::Size(128, 64), CV_8UC3);
  500. cv::Scalar scalar = cv::Scalar(128, 33, 53);
  501. GRunArgs v;
  502. v.resize(2);
  503. v[0] = cv::GRunArg{ mat };
  504. v[1] = cv::GRunArg{ scalar };
  505. GRunArgsP output = cv::gapi::bind(v);
  506. unsigned int i = 0;
  507. for (auto it : output)
  508. {
  509. using T = cv::GRunArgP;
  510. switch (it.index())
  511. {
  512. case T::index_of<cv::Mat*>() :
  513. {
  514. cv::Mat* out_mat = cv::util::get<cv::Mat*>(it);
  515. EXPECT_EQ(mat.size(), out_mat->size());
  516. } break;
  517. case T::index_of<cv::Scalar*>() :
  518. {
  519. cv::Scalar* out_scalar = cv::util::get<cv::Scalar*>(it);
  520. EXPECT_EQ(out_scalar->val[0], scalar.val[0]);
  521. EXPECT_EQ(out_scalar->val[1], scalar.val[1]);
  522. EXPECT_EQ(out_scalar->val[2], scalar.val[2]);
  523. } break;
  524. default:
  525. GAPI_Assert(false && "This value type is not supported!"); // ...maybe because of STANDALONE mode.
  526. break;
  527. }
  528. i++;
  529. }
  530. }
  531. TEST_F(S11N_Basic, Test_Vector_Of_Strings) {
  532. std::vector<std::string> vs{"hello", "world", "42"};
  533. const std::vector<char> ser = cv::gapi::serialize(vs);
  534. auto des = cv::gapi::deserialize<std::vector<std::string>>(ser);
  535. EXPECT_EQ("hello", des[0]);
  536. EXPECT_EQ("world", des[1]);
  537. EXPECT_EQ("42", des[2]);
  538. }
  539. TEST_F(S11N_Basic, Test_RunArg) {
  540. cv::Mat mat = cv::Mat::eye(cv::Size(128, 64), CV_8UC3);
  541. auto v = cv::GRunArgs{ cv::GRunArg{ mat } };
  542. const std::vector<char> sargsin = cv::gapi::serialize(v);
  543. cv::GRunArgs out = cv::gapi::deserialize<cv::GRunArgs>(sargsin);
  544. cv::Mat out_mat = cv::util::get<cv::Mat>(out[0]);
  545. EXPECT_EQ(0, cv::norm(mat, out_mat));
  546. }
  547. TEST_F(S11N_Basic, Test_RunArg_RMat) {
  548. cv::Mat mat = cv::Mat::eye(cv::Size(128, 64), CV_8UC3);
  549. cv::RMat rmat = cv::make_rmat<MyRMatAdapter>(mat, 42, "It actually works");
  550. auto v = cv::GRunArgs{ cv::GRunArg{ rmat } };
  551. const std::vector<char> sargsin = cv::gapi::serialize(v);
  552. cv::GRunArgs out = cv::gapi::deserialize<cv::GRunArgs, MyRMatAdapter>(sargsin);
  553. cv::RMat out_mat = cv::util::get<cv::RMat>(out[0]);
  554. auto adapter = out_mat.get<MyRMatAdapter>();
  555. EXPECT_EQ(42, adapter->getVal());
  556. EXPECT_EQ("It actually works", adapter->getStr());
  557. }
  558. TEST_F(S11N_Basic, Test_RunArg_RMat_Scalar_Mat) {
  559. cv::Mat mat = cv::Mat::eye(cv::Size(128, 64), CV_8UC3);
  560. cv::RMat rmat = cv::make_rmat<MyRMatAdapter>(mat, 42, "It actually works");
  561. cv::Scalar sc(111);
  562. auto v = cv::GRunArgs{ cv::GRunArg{ rmat }, cv::GRunArg{ sc }, cv::GRunArg{ mat } };
  563. const std::vector<char> sargsin = cv::gapi::serialize(v);
  564. cv::GRunArgs out = cv::gapi::deserialize<cv::GRunArgs, MyRMatAdapter>(sargsin);
  565. cv::RMat out_rmat = cv::util::get<cv::RMat>(out[0]);
  566. auto adapter = out_rmat.get<MyRMatAdapter>();
  567. EXPECT_EQ(42, adapter->getVal());
  568. EXPECT_EQ("It actually works", adapter->getStr());
  569. cv::Scalar out_sc = cv::util::get<cv::Scalar>(out[1]);
  570. EXPECT_EQ(sc, out_sc);
  571. cv::Mat out_mat = cv::util::get<cv::Mat>(out[2]);
  572. EXPECT_EQ(0, cv::norm(mat, out_mat));
  573. }
  574. TEST_F(S11N_Basic, Test_RunArg_MediaFrame) {
  575. cv::Mat mat = cv::Mat::eye(cv::Size(128, 64), CV_8UC3);
  576. auto frame = cv::MediaFrame::Create<MyMediaFrameAdapter>(mat, 42, "It actually works");
  577. auto v = cv::GRunArgs{ cv::GRunArg{ frame } };
  578. const std::vector<char> sargsin = cv::gapi::serialize(v);
  579. cv::GRunArgs out = cv::gapi::deserialize<cv::GRunArgs, MyMediaFrameAdapter>(sargsin);
  580. cv::MediaFrame out_mat = cv::util::get<cv::MediaFrame>(out[0]);
  581. auto adapter = out_mat.get<MyMediaFrameAdapter>();
  582. EXPECT_EQ(42, adapter->getVal());
  583. EXPECT_EQ("It actually works", adapter->getStr());
  584. }
  585. TEST_F(S11N_Basic, Test_RunArg_MediaFrame_Scalar_Mat) {
  586. cv::Mat mat = cv::Mat::eye(cv::Size(128, 64), CV_8UC3);
  587. auto frame = cv::MediaFrame::Create<MyMediaFrameAdapter>(mat, 42, "It actually works");
  588. cv::Scalar sc(111);
  589. auto v = cv::GRunArgs{ cv::GRunArg{ frame }, cv::GRunArg{ sc }, cv::GRunArg{ mat } };
  590. const std::vector<char> sargsin = cv::gapi::serialize(v);
  591. cv::GRunArgs out = cv::gapi::deserialize<cv::GRunArgs, MyMediaFrameAdapter>(sargsin);
  592. cv::MediaFrame out_frame = cv::util::get<cv::MediaFrame>(out[0]);
  593. auto adapter = out_frame.get<MyMediaFrameAdapter>();
  594. EXPECT_EQ(42, adapter->getVal());
  595. EXPECT_EQ("It actually works", adapter->getStr());
  596. cv::Scalar out_sc = cv::util::get<cv::Scalar>(out[1]);
  597. EXPECT_EQ(sc, out_sc);
  598. cv::Mat out_mat = cv::util::get<cv::Mat>(out[2]);
  599. EXPECT_EQ(0, cv::norm(mat, out_mat));
  600. }
  601. TEST_F(S11N_Basic, Test_RunArg_MediaFrame_RMat) {
  602. cv::Mat mat = cv::Mat::eye(cv::Size(128, 64), CV_8UC3);
  603. cv::Mat mat2 = cv::Mat::eye(cv::Size(128, 64), CV_8UC3);
  604. auto frame = cv::MediaFrame::Create<MyMediaFrameAdapter>(mat, 42, "It actually works");
  605. auto rmat = cv::make_rmat<MyRMatAdapter>(mat2, 24, "Hello there");
  606. auto v = cv::GRunArgs{ cv::GRunArg{ frame }, cv::GRunArg{ rmat } };
  607. const std::vector<char> sargsin = cv::gapi::serialize(v);
  608. cv::GRunArgs out = cv::gapi::deserialize<cv::GRunArgs, MyMediaFrameAdapter, MyRMatAdapter>(sargsin);
  609. cv::MediaFrame out_frame = cv::util::get<cv::MediaFrame>(out[0]);
  610. cv::RMat out_rmat = cv::util::get<cv::RMat>(out[1]);
  611. auto adapter = out_frame.get<MyMediaFrameAdapter>();
  612. EXPECT_EQ(42, adapter->getVal());
  613. EXPECT_EQ("It actually works", adapter->getStr());
  614. auto adapter2 = out_rmat.get<MyRMatAdapter>();
  615. EXPECT_EQ(24, adapter2->getVal());
  616. EXPECT_EQ("Hello there", adapter2->getStr());
  617. }
  618. TEST_F(S11N_Basic, Test_RunArg_RMat_MediaFrame) {
  619. cv::Mat mat = cv::Mat::eye(cv::Size(128, 64), CV_8UC3);
  620. cv::Mat mat2 = cv::Mat::eye(cv::Size(128, 64), CV_8UC3);
  621. auto frame = cv::MediaFrame::Create<MyMediaFrameAdapter>(mat, 42, "It actually works");
  622. auto rmat = cv::make_rmat<MyRMatAdapter>(mat2, 24, "Hello there");
  623. auto v = cv::GRunArgs{ cv::GRunArg{ rmat }, cv::GRunArg{ frame } };
  624. const std::vector<char> sargsin = cv::gapi::serialize(v);
  625. cv::GRunArgs out = cv::gapi::deserialize<cv::GRunArgs, MyMediaFrameAdapter, MyRMatAdapter>(sargsin);
  626. cv::RMat out_rmat = cv::util::get<cv::RMat>(out[0]);
  627. cv::MediaFrame out_frame = cv::util::get<cv::MediaFrame>(out[1]);
  628. auto adapter = out_frame.get<MyMediaFrameAdapter>();
  629. EXPECT_EQ(42, adapter->getVal());
  630. EXPECT_EQ("It actually works", adapter->getStr());
  631. auto adapter2 = out_rmat.get<MyRMatAdapter>();
  632. EXPECT_EQ(24, adapter2->getVal());
  633. EXPECT_EQ("Hello there", adapter2->getStr());
  634. }
  635. namespace {
  636. template <cv::detail::OpaqueKind K, typename T>
  637. bool verifyOpaqueKind(T&& in) {
  638. auto inObjs = cv::gin(in);
  639. auto in_o_ref = cv::util::get<cv::detail::OpaqueRef>(inObjs[0]);
  640. return K == in_o_ref.getKind();
  641. }
  642. template <cv::detail::OpaqueKind K, typename T>
  643. bool verifyArrayKind(T&& in) {
  644. auto inObjs = cv::gin(in);
  645. auto in_o_ref = cv::util::get<cv::detail::VectorRef>(inObjs[0]);
  646. return K == in_o_ref.getKind();
  647. }
  648. }
  649. TEST_F(S11N_Basic, Test_Gin_GOpaque) {
  650. int i; float f; double d;
  651. std::uint64_t ui; bool b;
  652. std::string s;
  653. cv::Rect r; cv::Size sz;
  654. cv::Point p;
  655. EXPECT_TRUE(verifyOpaqueKind<cv::detail::OpaqueKind::CV_INT>(i));
  656. EXPECT_TRUE(verifyOpaqueKind<cv::detail::OpaqueKind::CV_FLOAT>(f));
  657. EXPECT_TRUE(verifyOpaqueKind<cv::detail::OpaqueKind::CV_DOUBLE>(d));
  658. EXPECT_TRUE(verifyOpaqueKind<cv::detail::OpaqueKind::CV_UINT64>(ui));
  659. EXPECT_TRUE(verifyOpaqueKind<cv::detail::OpaqueKind::CV_BOOL>(b));
  660. EXPECT_TRUE(verifyOpaqueKind<cv::detail::OpaqueKind::CV_STRING>(s));
  661. EXPECT_TRUE(verifyOpaqueKind<cv::detail::OpaqueKind::CV_RECT>(r));
  662. EXPECT_TRUE(verifyOpaqueKind<cv::detail::OpaqueKind::CV_SIZE>(sz));
  663. EXPECT_TRUE(verifyOpaqueKind<cv::detail::OpaqueKind::CV_POINT>(p));
  664. }
  665. TEST_F(S11N_Basic, Test_Gin_GArray) {
  666. std::vector<int> i; std::vector<float> f; std::vector<double> d;
  667. std::vector<std::uint64_t> ui; std::vector<bool> b;
  668. std::vector<std::string> s;
  669. std::vector<cv::Rect> r; std::vector<cv::Size> sz;
  670. std::vector<cv::Point> p;
  671. std::vector<cv::Mat> mat;
  672. std::vector<cv::Scalar> sc;
  673. EXPECT_TRUE(verifyArrayKind<cv::detail::OpaqueKind::CV_INT>(i));
  674. EXPECT_TRUE(verifyArrayKind<cv::detail::OpaqueKind::CV_FLOAT>(f));
  675. EXPECT_TRUE(verifyArrayKind<cv::detail::OpaqueKind::CV_DOUBLE>(d));
  676. EXPECT_TRUE(verifyArrayKind<cv::detail::OpaqueKind::CV_UINT64>(ui));
  677. EXPECT_TRUE(verifyArrayKind<cv::detail::OpaqueKind::CV_BOOL>(b));
  678. EXPECT_TRUE(verifyArrayKind<cv::detail::OpaqueKind::CV_STRING>(s));
  679. EXPECT_TRUE(verifyArrayKind<cv::detail::OpaqueKind::CV_RECT>(r));
  680. EXPECT_TRUE(verifyArrayKind<cv::detail::OpaqueKind::CV_SIZE>(sz));
  681. EXPECT_TRUE(verifyArrayKind<cv::detail::OpaqueKind::CV_POINT>(p));
  682. EXPECT_TRUE(verifyArrayKind<cv::detail::OpaqueKind::CV_MAT>(mat));
  683. EXPECT_TRUE(verifyArrayKind<cv::detail::OpaqueKind::CV_SCALAR>(sc));
  684. }
  685. TEST_F(S11N_Basic, Test_Custom_Type) {
  686. MyCustomType var{1324, "Hello", {1920, 1080, 720}, {{1, 2937459432}, {42, 253245432}}};
  687. cv::gapi::s11n::ByteMemoryOutStream os;
  688. cv::gapi::s11n::detail::S11N<MyCustomType>::serialize(os, var);
  689. cv::gapi::s11n::ByteMemoryInStream is(os.data());
  690. MyCustomType new_var = cv::gapi::s11n::detail::S11N<MyCustomType>::deserialize(is);
  691. EXPECT_EQ(var, new_var);
  692. }
  693. TEST_F(S11N_Basic, Test_CompileArg) {
  694. MyCustomType customVar{1248, "World", {1280, 720, 640, 480}, {{5, 32434142342}, {7, 34242432}}};
  695. std::vector<char> sArgs = cv::gapi::serialize(cv::compile_args(customVar));
  696. GCompileArgs dArgs = cv::gapi::deserialize<GCompileArgs, MyCustomType>(sArgs);
  697. MyCustomType dCustomVar = cv::gapi::getCompileArg<MyCustomType>(dArgs).value();
  698. EXPECT_EQ(customVar, dCustomVar);
  699. }
  700. TEST_F(S11N_Basic, Test_CompileArg_Without_UserCallback) {
  701. SimpleCustomType customVar1 { false };
  702. MyCustomTypeNoS11N customVar2 { 'z', 189, "Name" };
  703. MyCustomType customVar3 { 1248, "World", {1280, 720, 640, 480},
  704. {{5, 32434142342}, {7, 34242432}} };
  705. EXPECT_NO_THROW(cv::gapi::serialize(cv::compile_args(customVar1, customVar2, customVar3)));
  706. std::vector<char> sArgs = cv::gapi::serialize(
  707. cv::compile_args(customVar1, customVar2, customVar3));
  708. GCompileArgs dArgs = cv::gapi::deserialize<GCompileArgs,
  709. SimpleCustomType,
  710. MyCustomType>(sArgs);
  711. SimpleCustomType dCustomVar1 = cv::gapi::getCompileArg<SimpleCustomType>(dArgs).value();
  712. MyCustomType dCustomVar3 = cv::gapi::getCompileArg<MyCustomType>(dArgs).value();
  713. EXPECT_EQ(customVar1, dCustomVar1);
  714. EXPECT_EQ(customVar3, dCustomVar3);
  715. }
  716. TEST_F(S11N_Basic, Test_Deserialize_Only_Requested_CompileArgs) {
  717. MyCustomType myCustomVar { 1248, "World", {1280, 720, 640, 480},
  718. {{5, 32434142342}, {7, 34242432}} };
  719. SimpleCustomType simpleCustomVar { false };
  720. std::vector<char> sArgs = cv::gapi::serialize(cv::compile_args(myCustomVar, simpleCustomVar));
  721. GCompileArgs dArgs = cv::gapi::deserialize<GCompileArgs, MyCustomType>(sArgs);
  722. EXPECT_EQ(1u, dArgs.size());
  723. EXPECT_EQ(myCustomVar, cv::gapi::getCompileArg<MyCustomType>(dArgs).value());
  724. dArgs.clear();
  725. dArgs = cv::gapi::deserialize<GCompileArgs, SimpleCustomType>(sArgs);
  726. EXPECT_EQ(1u, dArgs.size());
  727. EXPECT_EQ(simpleCustomVar, cv::gapi::getCompileArg<SimpleCustomType>(dArgs).value());
  728. dArgs.clear();
  729. dArgs = cv::gapi::deserialize<GCompileArgs, SimpleCustomType2>(sArgs);
  730. EXPECT_EQ(0u, dArgs.size());
  731. dArgs.clear();
  732. dArgs = cv::gapi::deserialize<GCompileArgs, MyCustomType, SimpleCustomType>(sArgs);
  733. EXPECT_EQ(2u, dArgs.size());
  734. EXPECT_EQ(myCustomVar, cv::gapi::getCompileArg<MyCustomType>(dArgs).value());
  735. EXPECT_EQ(simpleCustomVar, cv::gapi::getCompileArg<SimpleCustomType>(dArgs).value());
  736. SimpleCustomType2 simpleCustomVar2 { 5 };
  737. std::vector<char> sArgs2 = cv::gapi::serialize(
  738. cv::compile_args(myCustomVar, simpleCustomVar, simpleCustomVar2));
  739. GCompileArgs dArgs2 = cv::gapi::deserialize<GCompileArgs,
  740. MyCustomType,
  741. SimpleCustomType2>(sArgs2);
  742. EXPECT_EQ(2u, dArgs2.size());
  743. EXPECT_EQ(myCustomVar, cv::gapi::getCompileArg<MyCustomType>(dArgs2).value());
  744. EXPECT_EQ(simpleCustomVar2, cv::gapi::getCompileArg<SimpleCustomType2>(dArgs2).value());
  745. }
  746. TEST_F(S11N_Basic, Test_Deserialize_CompileArgs_RandomOrder) {
  747. SimpleCustomType simpleCustomVar { false };
  748. SimpleCustomType2 simpleCustomVar2 { 5 };
  749. std::vector<char> sArgs = cv::gapi::serialize(
  750. cv::compile_args(simpleCustomVar, simpleCustomVar2));
  751. GCompileArgs dArgs = cv::gapi::deserialize<GCompileArgs,
  752. SimpleCustomType2,
  753. SimpleCustomType>(sArgs);
  754. EXPECT_EQ(simpleCustomVar, cv::gapi::getCompileArg<SimpleCustomType>(dArgs).value());
  755. EXPECT_EQ(simpleCustomVar2, cv::gapi::getCompileArg<SimpleCustomType2>(dArgs).value());
  756. }
  757. TEST_F(S11N_Basic, Test_CompileArgs_With_EmptyCompileArg) {
  758. MyCustomType myCustomVar { 1248, "World", {1280, 720, 640, 480},
  759. {{5, 32434142342}, {7, 34242432}} };
  760. SimpleCustomType simpleCustomVar { false };
  761. EmptyCustomType emptyCustomVar { };
  762. //----{ emptyCustomVar, myCustomVar }----
  763. std::vector<char> sArgs1 = cv::gapi::serialize(cv::compile_args(emptyCustomVar, myCustomVar));
  764. GCompileArgs dArgsEmptyVar1 = cv::gapi::deserialize<GCompileArgs, EmptyCustomType>(sArgs1);
  765. GCompileArgs dArgsMyVar1 = cv::gapi::deserialize<GCompileArgs, MyCustomType>(sArgs1);
  766. GCompileArgs dArgsEmptyAndMyVars1 = cv::gapi::deserialize<GCompileArgs,
  767. EmptyCustomType,
  768. MyCustomType>(sArgs1);
  769. EXPECT_EQ(1u, dArgsEmptyVar1.size());
  770. EXPECT_TRUE(cv::gapi::getCompileArg<EmptyCustomType>(dArgsEmptyVar1).has_value());
  771. EXPECT_EQ(1u, dArgsMyVar1.size());
  772. EXPECT_EQ(myCustomVar, cv::gapi::getCompileArg<MyCustomType>(dArgsMyVar1).value());
  773. EXPECT_EQ(2u, dArgsEmptyAndMyVars1.size());
  774. EXPECT_TRUE(cv::gapi::getCompileArg<EmptyCustomType>(dArgsEmptyAndMyVars1).has_value());
  775. EXPECT_EQ(myCustomVar, cv::gapi::getCompileArg<MyCustomType>(dArgsEmptyAndMyVars1).value());
  776. //----{ myCustomVar, emptyCustomVar }----
  777. std::vector<char> sArgs2 = cv::gapi::serialize(cv::compile_args(myCustomVar, emptyCustomVar));
  778. GCompileArgs dArgsMyVar2 = cv::gapi::deserialize<GCompileArgs, MyCustomType>(sArgs2);
  779. GCompileArgs dArgsEmptyVar2 = cv::gapi::deserialize<GCompileArgs, EmptyCustomType>(sArgs2);
  780. GCompileArgs dArgsMyAndEmptyVars2 = cv::gapi::deserialize<GCompileArgs,
  781. MyCustomType,
  782. EmptyCustomType>(sArgs2);
  783. EXPECT_EQ(1u, dArgsMyVar2.size());
  784. EXPECT_EQ(myCustomVar, cv::gapi::getCompileArg<MyCustomType>(dArgsMyVar2).value());
  785. EXPECT_EQ(1u, dArgsEmptyVar2.size());
  786. EXPECT_TRUE(cv::gapi::getCompileArg<EmptyCustomType>(dArgsEmptyVar2).has_value());
  787. EXPECT_EQ(2u, dArgsMyAndEmptyVars2.size());
  788. EXPECT_EQ(myCustomVar, cv::gapi::getCompileArg<MyCustomType>(dArgsMyAndEmptyVars2).value());
  789. EXPECT_TRUE(cv::gapi::getCompileArg<EmptyCustomType>(dArgsMyAndEmptyVars2).has_value());
  790. //----{ myCustomVar, emptyCustomVar, simpleCustomVar }----
  791. std::vector<char> sArgs3 = cv::gapi::serialize(
  792. cv::compile_args(myCustomVar, emptyCustomVar, simpleCustomVar));
  793. GCompileArgs dArgsMyVar3 = cv::gapi::deserialize<GCompileArgs, MyCustomType>(sArgs3);
  794. GCompileArgs dArgsEmptyVar3 = cv::gapi::deserialize<GCompileArgs, EmptyCustomType>(sArgs3);
  795. GCompileArgs dArgsSimpleVar3 = cv::gapi::deserialize<GCompileArgs, SimpleCustomType>(sArgs3);
  796. GCompileArgs dArgsMyAndSimpleVars3 = cv::gapi::deserialize<GCompileArgs,
  797. MyCustomType,
  798. SimpleCustomType>(sArgs3);
  799. GCompileArgs dArgs3 = cv::gapi::deserialize<GCompileArgs,
  800. MyCustomType,
  801. EmptyCustomType,
  802. SimpleCustomType>(sArgs3);
  803. EXPECT_EQ(1u, dArgsMyVar3.size());
  804. EXPECT_EQ(myCustomVar, cv::gapi::getCompileArg<MyCustomType>(dArgsMyVar3).value());
  805. EXPECT_EQ(1u, dArgsEmptyVar3.size());
  806. EXPECT_TRUE(cv::gapi::getCompileArg<EmptyCustomType>(dArgsEmptyVar3).has_value());
  807. EXPECT_EQ(1u, dArgsSimpleVar3.size());
  808. EXPECT_EQ(simpleCustomVar, cv::gapi::getCompileArg<SimpleCustomType>(dArgsSimpleVar3).value());
  809. EXPECT_EQ(2u, dArgsMyAndSimpleVars3.size());
  810. EXPECT_EQ(myCustomVar, cv::gapi::getCompileArg<MyCustomType>(dArgsMyAndSimpleVars3).value());
  811. EXPECT_EQ(simpleCustomVar,
  812. cv::gapi::getCompileArg<SimpleCustomType>(dArgsMyAndSimpleVars3).value());
  813. EXPECT_EQ(3u, dArgs3.size());
  814. EXPECT_EQ(myCustomVar, cv::gapi::getCompileArg<MyCustomType>(dArgs3).value());
  815. EXPECT_TRUE(cv::gapi::getCompileArg<EmptyCustomType>(dArgs3).has_value());
  816. EXPECT_EQ(simpleCustomVar, cv::gapi::getCompileArg<SimpleCustomType>(dArgs3).value());
  817. //----{ emptyCustomVar }----
  818. std::vector<char> sArgs4 = cv::gapi::serialize(cv::compile_args(emptyCustomVar));
  819. GCompileArgs dArgsEmptyVar4 = cv::gapi::deserialize<GCompileArgs, EmptyCustomType>(sArgs4);
  820. EXPECT_EQ(1u, dArgsEmptyVar4.size());
  821. EXPECT_TRUE(cv::gapi::getCompileArg<EmptyCustomType>(dArgsEmptyVar4).has_value());
  822. }
  823. } // namespace opencv_test