gapi_kernel_tests.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2018-2021 Intel Corporation
  6. #include <algorithm>
  7. #include "test_precomp.hpp"
  8. #include "gapi_mock_kernels.hpp"
  9. #include <opencv2/gapi/cpu/gcpukernel.hpp> // cpu::backend
  10. #include <opencv2/gapi/fluid/gfluidkernel.hpp> // fluid::backend
  11. namespace opencv_test
  12. {
  13. namespace
  14. {
  15. namespace I
  16. {
  17. G_TYPED_KERNEL(GClone, <GMat(GMat)>, "org.opencv.test.clone")
  18. {
  19. static GMatDesc outMeta(GMatDesc in) { return in; }
  20. };
  21. }
  22. enum class KernelTags
  23. {
  24. CPU_CUSTOM_BGR2GRAY,
  25. CPU_CUSTOM_CLONE,
  26. CPU_CUSTOM_ADD,
  27. FLUID_CUSTOM_BGR2GRAY,
  28. FLUID_CUSTOM_CLONE,
  29. FLUID_CUSTOM_ADD
  30. };
  31. class HeteroGraph: public ::testing::Test
  32. {
  33. public:
  34. HeteroGraph()
  35. {
  36. auto tmp = I::GClone::on(cv::gapi::add(in[0], in[1]));
  37. out = cv::gapi::imgproc::GBGR2Gray::on(tmp);
  38. }
  39. static void registerCallKernel(KernelTags kernel_tag) {
  40. kernel_calls.insert(kernel_tag);
  41. }
  42. bool checkCallKernel(KernelTags kernel_tag) {
  43. return ade::util::contains(kernel_calls, kernel_tag);
  44. }
  45. protected:
  46. void SetUp() override
  47. {
  48. if (!kernel_calls.empty())
  49. cv::util::throw_error(std::logic_error("Kernel call log has not been cleared!!!"));
  50. }
  51. void TearDown() override
  52. {
  53. kernel_calls.clear();
  54. }
  55. protected:
  56. cv::GMat in[2], out;
  57. static std::set<KernelTags> kernel_calls;
  58. };
  59. namespace cpu
  60. {
  61. GAPI_OCV_KERNEL(GClone, I::GClone)
  62. {
  63. static void run(const cv::Mat&, cv::Mat)
  64. {
  65. HeteroGraph::registerCallKernel(KernelTags::CPU_CUSTOM_CLONE);
  66. }
  67. };
  68. GAPI_OCV_KERNEL(BGR2Gray, cv::gapi::imgproc::GBGR2Gray)
  69. {
  70. static void run(const cv::Mat&, cv::Mat&)
  71. {
  72. HeteroGraph::registerCallKernel(KernelTags::CPU_CUSTOM_BGR2GRAY);
  73. }
  74. };
  75. GAPI_OCV_KERNEL(GAdd, cv::gapi::core::GAdd)
  76. {
  77. static void run(const cv::Mat&, const cv::Mat&, int, cv::Mat&)
  78. {
  79. HeteroGraph::registerCallKernel(KernelTags::CPU_CUSTOM_ADD);
  80. }
  81. };
  82. }
  83. namespace fluid
  84. {
  85. GAPI_FLUID_KERNEL(GClone, I::GClone, false)
  86. {
  87. static const int Window = 1;
  88. static void run(const cv::gapi::fluid::View&, cv::gapi::fluid::Buffer&)
  89. {
  90. HeteroGraph::registerCallKernel(KernelTags::FLUID_CUSTOM_CLONE);
  91. }
  92. };
  93. GAPI_FLUID_KERNEL(BGR2Gray, cv::gapi::imgproc::GBGR2Gray, false)
  94. {
  95. static const int Window = 1;
  96. static void run(const cv::gapi::fluid::View&, cv::gapi::fluid::Buffer&)
  97. {
  98. HeteroGraph::registerCallKernel(KernelTags::FLUID_CUSTOM_BGR2GRAY);
  99. }
  100. };
  101. GAPI_FLUID_KERNEL(GAdd, cv::gapi::core::GAdd, false)
  102. {
  103. static const int Window = 1;
  104. static void run(const cv::gapi::fluid::View&, const cv::gapi::fluid::View&,
  105. int, cv::gapi::fluid::Buffer&)
  106. {
  107. HeteroGraph::registerCallKernel(KernelTags::FLUID_CUSTOM_ADD);
  108. }
  109. };
  110. }
  111. std::set<KernelTags> HeteroGraph::kernel_calls;
  112. } // anonymous namespace
  113. TEST(KernelPackage, Create)
  114. {
  115. namespace J = Jupiter;
  116. auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
  117. EXPECT_EQ(3u, pkg.size());
  118. }
  119. TEST(KernelPackage, Includes)
  120. {
  121. namespace J = Jupiter;
  122. auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
  123. EXPECT_TRUE (pkg.includes<J::Foo>());
  124. EXPECT_TRUE (pkg.includes<J::Bar>());
  125. EXPECT_TRUE (pkg.includes<J::Baz>());
  126. EXPECT_FALSE(pkg.includes<J::Qux>());
  127. }
  128. TEST(KernelPackage, Include)
  129. {
  130. namespace J = Jupiter;
  131. auto pkg = cv::gapi::kernels();
  132. pkg.include(J::backend(), "test.kernels.foo");
  133. pkg.include(J::backend(), "test.kernels.bar");
  134. EXPECT_TRUE (pkg.includes<J::Foo>());
  135. EXPECT_TRUE (pkg.includes<J::Bar>());
  136. }
  137. TEST(KernelPackage, GetIds)
  138. {
  139. namespace J = Jupiter;
  140. auto pkg = cv::gapi::kernels();
  141. pkg.include(J::backend(), "test.kernels.foo");
  142. pkg.include(J::backend(), "test.kernels.bar");
  143. pkg.include<J::Baz>();
  144. auto ids = pkg.get_kernel_ids();
  145. EXPECT_NE(ids.end(), std::find(ids.begin(), ids.end(), "test.kernels.foo"));
  146. EXPECT_NE(ids.end(), std::find(ids.begin(), ids.end(), "test.kernels.bar"));
  147. EXPECT_NE(ids.end(), std::find(ids.begin(), ids.end(), "test.kernels.baz"));
  148. }
  149. TEST(KernelPackage, IncludesAPI)
  150. {
  151. namespace J = Jupiter;
  152. namespace S = Saturn;
  153. auto pkg = cv::gapi::kernels<J::Foo, S::Bar>();
  154. EXPECT_TRUE (pkg.includesAPI<I::Foo>());
  155. EXPECT_TRUE (pkg.includesAPI<I::Bar>());
  156. EXPECT_FALSE(pkg.includesAPI<I::Baz>());
  157. EXPECT_FALSE(pkg.includesAPI<I::Qux>());
  158. }
  159. TEST(KernelPackage, Include_Add)
  160. {
  161. namespace J = Jupiter;
  162. auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
  163. EXPECT_FALSE(pkg.includes<J::Qux>());
  164. pkg.include<J::Qux>();
  165. EXPECT_TRUE(pkg.includes<J::Qux>());
  166. }
  167. TEST(KernelPackage, Include_REPLACE)
  168. {
  169. namespace J = Jupiter;
  170. namespace S = Saturn;
  171. auto pkg = cv::gapi::kernels<J::Foo, J::Bar>();
  172. EXPECT_FALSE(pkg.includes<S::Bar>());
  173. pkg.include<S::Bar>();
  174. EXPECT_FALSE(pkg.includes<J::Bar>());
  175. EXPECT_TRUE(pkg.includes<S::Bar>());
  176. }
  177. TEST(KernelPackage, RemoveBackend)
  178. {
  179. namespace J = Jupiter;
  180. namespace S = Saturn;
  181. auto pkg = cv::gapi::kernels<J::Foo, J::Bar, S::Baz>();
  182. EXPECT_TRUE(pkg.includes<J::Foo>());
  183. EXPECT_TRUE(pkg.includes<J::Bar>());
  184. pkg.remove(J::backend());
  185. EXPECT_FALSE(pkg.includes<J::Foo>());
  186. EXPECT_FALSE(pkg.includes<J::Bar>());
  187. EXPECT_TRUE(pkg.includes<S::Baz>());
  188. };
  189. TEST(KernelPackage, RemoveAPI)
  190. {
  191. namespace J = Jupiter;
  192. namespace S = Saturn;
  193. auto pkg = cv::gapi::kernels<J::Foo, J::Bar>();
  194. EXPECT_TRUE(pkg.includes<J::Foo>());
  195. EXPECT_TRUE(pkg.includes<J::Bar>());
  196. pkg.remove<I::Foo>();
  197. EXPECT_TRUE(pkg.includes<J::Bar>());
  198. EXPECT_FALSE(pkg.includes<J::Foo>());
  199. };
  200. TEST(KernelPackage, CreateHetero)
  201. {
  202. namespace J = Jupiter;
  203. namespace S = Saturn;
  204. auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz, S::Qux>();
  205. EXPECT_EQ(4u, pkg.size());
  206. }
  207. TEST(KernelPackage, IncludesHetero)
  208. {
  209. namespace J = Jupiter;
  210. namespace S = Saturn;
  211. auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz, S::Qux>();
  212. EXPECT_TRUE (pkg.includes<J::Foo>());
  213. EXPECT_TRUE (pkg.includes<J::Bar>());
  214. EXPECT_TRUE (pkg.includes<J::Baz>());
  215. EXPECT_FALSE(pkg.includes<J::Qux>());
  216. EXPECT_TRUE (pkg.includes<S::Qux>());
  217. }
  218. TEST(KernelPackage, IncludeHetero)
  219. {
  220. namespace J = Jupiter;
  221. namespace S = Saturn;
  222. auto pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
  223. EXPECT_FALSE(pkg.includes<J::Qux>());
  224. EXPECT_FALSE(pkg.includes<S::Qux>());
  225. pkg.include<S::Qux>();
  226. EXPECT_FALSE(pkg.includes<J::Qux>());
  227. EXPECT_TRUE (pkg.includes<S::Qux>());
  228. }
  229. TEST(KernelPackage, Combine_REPLACE_Full)
  230. {
  231. namespace J = Jupiter;
  232. namespace S = Saturn;
  233. auto j_pkg = cv::gapi::kernels<J::Foo, J::Bar, J::Baz>();
  234. auto s_pkg = cv::gapi::kernels<S::Foo, S::Bar, S::Baz>();
  235. auto u_pkg = cv::gapi::combine(j_pkg, s_pkg);
  236. EXPECT_EQ(3u, u_pkg.size());
  237. EXPECT_FALSE(u_pkg.includes<J::Foo>());
  238. EXPECT_FALSE(u_pkg.includes<J::Bar>());
  239. EXPECT_FALSE(u_pkg.includes<J::Baz>());
  240. EXPECT_TRUE (u_pkg.includes<S::Foo>());
  241. EXPECT_TRUE (u_pkg.includes<S::Bar>());
  242. EXPECT_TRUE (u_pkg.includes<S::Baz>());
  243. }
  244. TEST(KernelPackage, Combine_REPLACE_Partial)
  245. {
  246. namespace J = Jupiter;
  247. namespace S = Saturn;
  248. auto j_pkg = cv::gapi::kernels<J::Foo, J::Bar>();
  249. auto s_pkg = cv::gapi::kernels<S::Bar>();
  250. auto u_pkg = cv::gapi::combine(j_pkg, s_pkg);
  251. EXPECT_EQ(2u, u_pkg.size());
  252. EXPECT_TRUE (u_pkg.includes<J::Foo>());
  253. EXPECT_FALSE(u_pkg.includes<J::Bar>());
  254. EXPECT_TRUE (u_pkg.includes<S::Bar>());
  255. }
  256. TEST(KernelPackage, Combine_REPLACE_Append)
  257. {
  258. namespace J = Jupiter;
  259. namespace S = Saturn;
  260. auto j_pkg = cv::gapi::kernels<J::Foo, J::Bar>();
  261. auto s_pkg = cv::gapi::kernels<S::Qux>();
  262. auto u_pkg = cv::gapi::combine(j_pkg, s_pkg);
  263. EXPECT_EQ(3u, u_pkg.size());
  264. EXPECT_TRUE(u_pkg.includes<J::Foo>());
  265. EXPECT_TRUE(u_pkg.includes<J::Bar>());
  266. EXPECT_TRUE(u_pkg.includes<S::Qux>());
  267. }
  268. TEST(KernelPackage, TestWithEmptyLHS)
  269. {
  270. namespace J = Jupiter;
  271. auto lhs = cv::gapi::kernels<>();
  272. auto rhs = cv::gapi::kernels<J::Foo>();
  273. auto pkg = cv::gapi::combine(lhs, rhs);
  274. EXPECT_EQ(1u, pkg.size());
  275. EXPECT_TRUE(pkg.includes<J::Foo>());
  276. }
  277. TEST(KernelPackage, TestWithEmptyRHS)
  278. {
  279. namespace J = Jupiter;
  280. auto lhs = cv::gapi::kernels<J::Foo>();
  281. auto rhs = cv::gapi::kernels<>();
  282. auto pkg = cv::gapi::combine(lhs, rhs);
  283. EXPECT_EQ(1u, pkg.size());
  284. EXPECT_TRUE(pkg.includes<J::Foo>());
  285. }
  286. TEST(KernelPackage, Return_Unique_Backends)
  287. {
  288. auto pkg = cv::gapi::kernels<cpu::GClone, fluid::BGR2Gray, fluid::GAdd>();
  289. EXPECT_EQ(2u, pkg.backends().size());
  290. }
  291. TEST(KernelPackage, Can_Use_Custom_Kernel)
  292. {
  293. cv::GMat in[2];
  294. auto out = I::GClone::on(cv::gapi::add(in[0], in[1]));
  295. const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::Size(32,32)});
  296. auto pkg = cv::gapi::kernels<cpu::GClone>();
  297. EXPECT_NO_THROW(cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
  298. compile({in_meta, in_meta}, cv::compile_args(pkg)));
  299. }
  300. TEST(KernelPackage, CombineMultiple)
  301. {
  302. namespace J = Jupiter;
  303. namespace S = Saturn;
  304. auto a = cv::gapi::kernels<J::Foo>();
  305. auto b = cv::gapi::kernels<J::Bar>();
  306. auto c = cv::gapi::kernels<S::Qux>();
  307. auto pkg = cv::gapi::combine(a, b, c);
  308. EXPECT_EQ(3u, pkg.size());
  309. EXPECT_TRUE(pkg.includes<J::Foo>());
  310. EXPECT_TRUE(pkg.includes<J::Bar>());
  311. EXPECT_TRUE(pkg.includes<S::Qux>());
  312. }
  313. TEST_F(HeteroGraph, Call_Custom_Kernel_Default_Backend)
  314. {
  315. // in0 -> GCPUAdd -> tmp -> cpu::GClone -> GCPUBGR2Gray -> out
  316. // ^
  317. // |
  318. // in1 -------`
  319. cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC3),
  320. in_mat2 = cv::Mat::eye(3, 3, CV_8UC3),
  321. out_mat;
  322. auto pkg = cv::gapi::kernels<cpu::GClone>();
  323. cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
  324. apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat), cv::compile_args(pkg));
  325. EXPECT_TRUE(checkCallKernel(KernelTags::CPU_CUSTOM_CLONE));
  326. }
  327. TEST_F(HeteroGraph, Call_Custom_Kernel_Not_Default_Backend)
  328. {
  329. // in0 -> GCPUAdd -> tmp -> fluid::GClone -> GCPUBGR2Gray -> out
  330. // ^
  331. // |
  332. // in1 -------`
  333. cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC3),
  334. in_mat2 = cv::Mat::eye(3, 3, CV_8UC3),
  335. out_mat;
  336. auto pkg = cv::gapi::kernels<fluid::GClone>();
  337. cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
  338. apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat), cv::compile_args(pkg));
  339. EXPECT_TRUE(checkCallKernel(KernelTags::FLUID_CUSTOM_CLONE));
  340. }
  341. TEST_F(HeteroGraph, Replace_Default_To_Same_Backend)
  342. {
  343. // in0 -> GCPUAdd -> tmp -> cpu::GClone -> cpu::BGR2Gray -> out
  344. // ^
  345. // |
  346. // in1 -------`
  347. cv::Mat in_mat1 = cv::Mat::eye(3, 3, CV_8UC3),
  348. in_mat2 = cv::Mat::eye(3, 3, CV_8UC3),
  349. out_mat;
  350. auto pkg = cv::gapi::kernels<cpu::GClone, cpu::BGR2Gray>();
  351. cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
  352. apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat), cv::compile_args(pkg));
  353. EXPECT_TRUE(checkCallKernel(KernelTags::CPU_CUSTOM_BGR2GRAY));
  354. }
  355. TEST_F(HeteroGraph, Replace_Default_To_Another_Backend)
  356. {
  357. //in0 -> GCPUAdd -> tmp -> cpu::GClone -> fluid::BGR2Gray -> out
  358. // ^
  359. // |
  360. //in1 --------`
  361. cv::Mat in_mat1(300, 300, CV_8UC3),
  362. in_mat2(300, 300, CV_8UC3),
  363. out_mat;
  364. auto pkg = cv::gapi::kernels<cpu::GClone, fluid::BGR2Gray>();
  365. cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
  366. apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat), cv::compile_args(pkg));
  367. EXPECT_TRUE(checkCallKernel(KernelTags::FLUID_CUSTOM_BGR2GRAY));
  368. }
  369. TEST_F(HeteroGraph, Use_Only_Same_Backend)
  370. {
  371. //in0 -> cpu::GAdd -> tmp -> cpu::GClone -> cpu::BGR2Gray -> out
  372. // ^
  373. // |
  374. //in1 --------`
  375. cv::Mat in_mat1(300, 300, CV_8UC3),
  376. in_mat2(300, 300, CV_8UC3),
  377. out_mat;
  378. auto pkg = cv::gapi::kernels<cpu::GAdd, cpu::GClone, cpu::BGR2Gray>();
  379. cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
  380. apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat), cv::compile_args(cv::gapi::use_only{pkg}));
  381. EXPECT_TRUE(checkCallKernel(KernelTags::CPU_CUSTOM_ADD));
  382. EXPECT_TRUE(checkCallKernel(KernelTags::CPU_CUSTOM_CLONE));
  383. EXPECT_TRUE(checkCallKernel(KernelTags::CPU_CUSTOM_BGR2GRAY));
  384. }
  385. TEST_F(HeteroGraph, Use_Only_Another_Backend)
  386. {
  387. //in0 -> fluid::GAdd -> tmp -> fluid::GClone -> fluid::BGR2Gray -> out
  388. // ^
  389. // |
  390. //in1 --------`
  391. cv::Mat in_mat1(300, 300, CV_8UC3),
  392. in_mat2(300, 300, CV_8UC3),
  393. out_mat;
  394. auto pkg = cv::gapi::kernels<fluid::GAdd, fluid::GClone, fluid::BGR2Gray>();
  395. cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
  396. apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat), cv::compile_args(cv::gapi::use_only{pkg}));
  397. EXPECT_TRUE(checkCallKernel(KernelTags::FLUID_CUSTOM_ADD));
  398. EXPECT_TRUE(checkCallKernel(KernelTags::FLUID_CUSTOM_CLONE));
  399. EXPECT_TRUE(checkCallKernel(KernelTags::FLUID_CUSTOM_BGR2GRAY));
  400. }
  401. TEST_F(HeteroGraph, Use_Only_Hetero_Backend)
  402. {
  403. //in0 -> cpu::GAdd -> tmp -> fluid::GClone -> fluid::BGR2Gray -> out
  404. // ^
  405. // |
  406. //in1 --------`
  407. cv::Mat in_mat1(300, 300, CV_8UC3),
  408. in_mat2(300, 300, CV_8UC3),
  409. out_mat;
  410. auto pkg = cv::gapi::kernels<cpu::GAdd, fluid::GClone, fluid::BGR2Gray>();
  411. cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
  412. apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat), cv::compile_args(cv::gapi::use_only{pkg}));
  413. EXPECT_TRUE(checkCallKernel(KernelTags::CPU_CUSTOM_ADD));
  414. EXPECT_TRUE(checkCallKernel(KernelTags::FLUID_CUSTOM_CLONE));
  415. EXPECT_TRUE(checkCallKernel(KernelTags::FLUID_CUSTOM_BGR2GRAY));
  416. }
  417. TEST_F(HeteroGraph, Use_Only_Not_Found_Default)
  418. {
  419. //in0 -> GCPUAdd -> tmp -> fluid::GClone -> fluid::BGR2Gray -> out
  420. // ^
  421. // |
  422. //in1 --------`
  423. cv::Mat in_mat1(300, 300, CV_8UC3),
  424. in_mat2(300, 300, CV_8UC3),
  425. out_mat;
  426. auto pkg = cv::gapi::kernels<fluid::GClone, fluid::BGR2Gray>();
  427. EXPECT_ANY_THROW(cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
  428. apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat), cv::compile_args(cv::gapi::use_only{pkg})));
  429. }
  430. TEST_F(HeteroGraph, Use_Only_Not_Found_Custom)
  431. {
  432. //in0 -> cpu::GAdd -> tmp -> fluid::GClone -> fluid::BGR2Gray -> out
  433. // ^
  434. // |
  435. //in1 --------`
  436. cv::Mat in_mat1(300, 300, CV_8UC3),
  437. in_mat2(300, 300, CV_8UC3),
  438. out_mat;
  439. auto pkg = cv::gapi::kernels<cpu::GAdd, fluid::BGR2Gray>();
  440. EXPECT_ANY_THROW(cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
  441. apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat), cv::compile_args(cv::gapi::use_only{pkg})));
  442. }
  443. TEST_F(HeteroGraph, Use_Only_Other_Package_Ignored)
  444. {
  445. //in0 -> cpu::GAdd -> tmp -> fluid::GClone -> fluid::BGR2Gray -> out
  446. // ^
  447. // |
  448. //in1 --------`
  449. cv::Mat in_mat1(300, 300, CV_8UC3),
  450. in_mat2(300, 300, CV_8UC3),
  451. out_mat;
  452. auto pkg = cv::gapi::kernels<cpu::GAdd, fluid::BGR2Gray>();
  453. auto clone_pkg = cv::gapi::kernels<cpu::GClone>();
  454. EXPECT_ANY_THROW(cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)).
  455. apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat),
  456. cv::compile_args(clone_pkg, cv::gapi::use_only{pkg})));
  457. }
  458. } // namespace opencv_test