gapi_operators_tests_inl.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 Intel Corporation
  6. #ifndef OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP
  7. #define OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP
  8. #include "gapi_operators_tests.hpp"
  9. namespace opencv_test
  10. {
  11. TEST_P(MathOperatorMatScalarTest, OperatorAccuracyTest )
  12. {
  13. g_api_ocv_pair_mat_scalar funcs(op);
  14. auto fun_gapi = funcs.g_api_function;
  15. auto fun_ocv = funcs.ocv_function;
  16. if (op == DIVR)
  17. in_mat1.setTo(1, in_mat1 == 0); // avoiding zeros in divide input data
  18. if (op == DIV)
  19. sc += Scalar(sc[0] == 0, sc[1] == 0, sc[2] == 0, sc[3] == 0); // avoiding zeros in divide input data
  20. // G-API code & corresponding OpenCV code ////////////////////////////////
  21. cv::GMat in1;
  22. cv::GScalar in2;
  23. auto out = fun_gapi(in1, in2);
  24. cv::GComputation c(GIn(in1, in2), GOut(out));
  25. c.apply(gin(in_mat1, sc), gout(out_mat_gapi), getCompileArgs());
  26. fun_ocv(in_mat1, sc, out_mat_ocv);
  27. // Comparison //////////////////////////////////////////////////////////////
  28. {
  29. ASSERT_EQ(sz, out_mat_gapi.size());
  30. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  31. }
  32. }
  33. TEST_P(MathOperatorMatMatTest, OperatorAccuracyTest )
  34. {
  35. g_api_ocv_pair_mat_mat funcs(op);
  36. auto fun_gapi = funcs.g_api_function;
  37. auto fun_ocv = funcs.ocv_function;
  38. if (op == DIV)
  39. in_mat2.setTo(1, in_mat2 == 0); // avoiding zeros in divide input data
  40. // G-API code & corresponding OpenCV code ////////////////////////////////
  41. cv::GMat in1;
  42. cv::GMat in2;
  43. auto out = fun_gapi(in1, in2);
  44. cv::GComputation c(GIn(in1, in2), GOut(out));
  45. c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), getCompileArgs());
  46. fun_ocv(in_mat1, in_mat2, out_mat_ocv);
  47. // Comparison //////////////////////////////////////////////////////////////
  48. {
  49. ASSERT_EQ(sz, out_mat_gapi.size());
  50. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  51. }
  52. }
  53. TEST_P(NotOperatorTest, OperatorAccuracyTest)
  54. {
  55. // G-API code //////////////////////////////////////////////////////////////
  56. cv::GMat in;
  57. auto out = ~in;
  58. cv::GComputation c(in, out);
  59. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  60. // OpenCV code /////////////////////////////////////////////////////////////
  61. {
  62. out_mat_ocv =~in_mat1;
  63. }
  64. // Comparison //////////////////////////////////////////////////////////////
  65. {
  66. ASSERT_EQ(sz, out_mat_gapi.size());
  67. EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
  68. }
  69. }
  70. namespace for_test
  71. {
  72. class Foo {};
  73. inline int operator&(Foo, int) { return 1; }
  74. inline int operator|(Foo, int) { return 1; }
  75. inline int operator^(Foo, int) { return 1; }
  76. inline int operator~(Foo) { return 1; }
  77. inline int operator+(Foo, int) { return 1; }
  78. inline int operator-(Foo, int) { return 1; }
  79. inline int operator*(Foo, int) { return 1; }
  80. inline int operator/(Foo, int) { return 1; }
  81. inline int operator> (Foo, int) { return 1; }
  82. inline int operator>=(Foo, int) { return 1; }
  83. inline int operator< (Foo, int) { return 1; }
  84. inline int operator<=(Foo, int) { return 1; }
  85. inline int operator==(Foo, int) { return 1; }
  86. inline int operator!=(Foo, int) { return 1; }
  87. TEST(CVNamespaceOperatorsTest, OperatorCompilationTest)
  88. {
  89. cv::GScalar sc;
  90. cv::GMat mat_in1, mat_in2;
  91. cv::GMat op_not = ~ mat_in1;
  92. cv::GMat op_mat_mat1 = mat_in1 & mat_in2;
  93. cv::GMat op_mat_mat2 = mat_in1 | mat_in2;
  94. cv::GMat op_mat_mat3 = mat_in1 ^ mat_in2;
  95. cv::GMat op_mat_mat4 = mat_in1 + mat_in2;
  96. cv::GMat op_mat_mat5 = mat_in1 - mat_in2;
  97. cv::GMat op_mat_mat6 = mat_in1 / mat_in2;
  98. cv::GMat op_mat_mat7 = mat_in1 > mat_in2;
  99. cv::GMat op_mat_mat8 = mat_in1 >= mat_in2;
  100. cv::GMat op_mat_mat9 = mat_in1 < mat_in2;
  101. cv::GMat op_mat_mat10 = mat_in1 <= mat_in2;
  102. cv::GMat op_mat_mat11 = mat_in1 == mat_in2;
  103. cv::GMat op_mat_mat12 = mat_in1 != mat_in2;
  104. cv::GMat op_mat_sc1 = mat_in1 & sc;
  105. cv::GMat op_mat_sc2 = mat_in1 | sc;
  106. cv::GMat op_mat_sc3 = mat_in1 ^ sc;
  107. cv::GMat op_mat_sc4 = mat_in1 + sc;
  108. cv::GMat op_mat_sc5 = mat_in1 - sc;
  109. cv::GMat op_mat_sc6 = mat_in1 * sc;
  110. cv::GMat op_mat_sc7 = mat_in1 / sc;
  111. cv::GMat op_mat_sc8 = mat_in1 > sc;
  112. cv::GMat op_mat_sc9 = mat_in1 >= sc;
  113. cv::GMat op_mat_sc10 = mat_in1 < sc;
  114. cv::GMat op_mat_sc11 = mat_in1 <= sc;
  115. cv::GMat op_mat_sc12 = mat_in1 == sc;
  116. cv::GMat op_mat_sc13 = mat_in1 != sc;
  117. cv::GMat op_sc_mat1 = sc & mat_in2;
  118. cv::GMat op_sc_mat2 = sc | mat_in2;
  119. cv::GMat op_sc_mat3 = sc ^ mat_in2;
  120. cv::GMat op_sc_mat4 = sc + mat_in2;
  121. cv::GMat op_sc_mat5 = sc - mat_in2;
  122. cv::GMat op_sc_mat6 = sc * mat_in2;
  123. cv::GMat op_sc_mat7 = sc / mat_in2;
  124. cv::GMat op_sc_mat8 = sc > mat_in2;
  125. cv::GMat op_sc_mat9 = sc >= mat_in2;
  126. cv::GMat op_sc_mat10 = sc < mat_in2;
  127. cv::GMat op_sc_mat11 = sc <= mat_in2;
  128. cv::GMat op_sc_mat12 = sc == mat_in2;
  129. cv::GMat op_sc_mat13 = sc != mat_in2;
  130. cv::GMat mul_mat_float1 = mat_in1 * 1.0f;
  131. cv::GMat mul_mat_float2 = 1.0f * mat_in2;
  132. // No compilation errors expected
  133. }
  134. } // for_test
  135. } // opencv_test
  136. #endif // OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP