Skip to content

Commit 7a796b2

Browse files
authored
Merge pull request opencv#18182 from OrestChura:oc/operators_to_cv
[G-API]: Relocation of operators' overloads * Relocates overloaded operators for `cv::GMat` and `cv::GScalar` to `cv::` namespace - adds test to check usage of operators compilation * Add tests for all the operators * Address comments
1 parent 0428dce commit 7a796b2

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

modules/gapi/include/opencv2/gapi/operators.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <opencv2/gapi/gmat.hpp>
1212
#include <opencv2/gapi/gscalar.hpp>
1313

14+
namespace cv
15+
{
1416
GAPI_EXPORTS cv::GMat operator+(const cv::GMat& lhs, const cv::GMat& rhs);
1517

1618
GAPI_EXPORTS cv::GMat operator+(const cv::GMat& lhs, const cv::GScalar& rhs);
@@ -63,7 +65,6 @@ GAPI_EXPORTS cv::GMat operator<(const cv::GScalar& lhs, const cv::GMat& rhs);
6365
GAPI_EXPORTS cv::GMat operator<=(const cv::GScalar& lhs, const cv::GMat& rhs);
6466
GAPI_EXPORTS cv::GMat operator==(const cv::GScalar& lhs, const cv::GMat& rhs);
6567
GAPI_EXPORTS cv::GMat operator!=(const cv::GScalar& lhs, const cv::GMat& rhs);
66-
67-
68+
} // cv
6869

6970
#endif // OPENCV_GAPI_OPERATORS_HPP

modules/gapi/src/api/operators.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <opencv2/gapi/gscalar.hpp>
1313
#include <opencv2/gapi/operators.hpp>
1414

15+
namespace cv
16+
{
1517
cv::GMat operator+(const cv::GMat& lhs, const cv::GMat& rhs)
1618
{
1719
return cv::gapi::add(lhs, rhs);
@@ -211,3 +213,4 @@ cv::GMat operator!=(const cv::GScalar& lhs, const cv::GMat& rhs)
211213
{
212214
return cv::gapi::cmpNE(rhs, lhs);
213215
}
216+
} // cv

modules/gapi/test/common/gapi_operators_tests_inl.hpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,81 @@ TEST_P(NotOperatorTest, OperatorAccuracyTest)
7777
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
7878
}
7979
}
80+
81+
namespace for_test
82+
{
83+
class Foo {};
84+
85+
inline int operator&(Foo, int) { return 1; }
86+
inline int operator|(Foo, int) { return 1; }
87+
inline int operator^(Foo, int) { return 1; }
88+
inline int operator~(Foo) { return 1; }
89+
90+
inline int operator+(Foo, int) { return 1; }
91+
inline int operator-(Foo, int) { return 1; }
92+
inline int operator*(Foo, int) { return 1; }
93+
inline int operator/(Foo, int) { return 1; }
94+
95+
inline int operator> (Foo, int) { return 1; }
96+
inline int operator>=(Foo, int) { return 1; }
97+
inline int operator< (Foo, int) { return 1; }
98+
inline int operator<=(Foo, int) { return 1; }
99+
inline int operator==(Foo, int) { return 1; }
100+
inline int operator!=(Foo, int) { return 1; }
101+
102+
TEST(CVNamespaceOperatorsTest, OperatorCompilationTest)
103+
{
104+
cv::GScalar sc;
105+
cv::GMat mat_in1, mat_in2;
106+
107+
cv::GMat op_not = ~ mat_in1;
108+
109+
cv::GMat op_mat_mat1 = mat_in1 & mat_in2;
110+
cv::GMat op_mat_mat2 = mat_in1 | mat_in2;
111+
cv::GMat op_mat_mat3 = mat_in1 ^ mat_in2;
112+
cv::GMat op_mat_mat4 = mat_in1 + mat_in2;
113+
cv::GMat op_mat_mat5 = mat_in1 - mat_in2;
114+
cv::GMat op_mat_mat6 = mat_in1 / mat_in2;
115+
cv::GMat op_mat_mat7 = mat_in1 > mat_in2;
116+
cv::GMat op_mat_mat8 = mat_in1 >= mat_in2;
117+
cv::GMat op_mat_mat9 = mat_in1 < mat_in2;
118+
cv::GMat op_mat_mat10 = mat_in1 <= mat_in2;
119+
cv::GMat op_mat_mat11 = mat_in1 == mat_in2;
120+
cv::GMat op_mat_mat12 = mat_in1 != mat_in2;
121+
122+
cv::GMat op_mat_sc1 = mat_in1 & sc;
123+
cv::GMat op_mat_sc2 = mat_in1 | sc;
124+
cv::GMat op_mat_sc3 = mat_in1 ^ sc;
125+
cv::GMat op_mat_sc4 = mat_in1 + sc;
126+
cv::GMat op_mat_sc5 = mat_in1 - sc;
127+
cv::GMat op_mat_sc6 = mat_in1 * sc;
128+
cv::GMat op_mat_sc7 = mat_in1 / sc;
129+
cv::GMat op_mat_sc8 = mat_in1 > sc;
130+
cv::GMat op_mat_sc9 = mat_in1 >= sc;
131+
cv::GMat op_mat_sc10 = mat_in1 < sc;
132+
cv::GMat op_mat_sc11 = mat_in1 <= sc;
133+
cv::GMat op_mat_sc12 = mat_in1 == sc;
134+
cv::GMat op_mat_sc13 = mat_in1 != sc;
135+
136+
cv::GMat op_sc_mat1 = sc & mat_in2;
137+
cv::GMat op_sc_mat2 = sc | mat_in2;
138+
cv::GMat op_sc_mat3 = sc ^ mat_in2;
139+
cv::GMat op_sc_mat4 = sc + mat_in2;
140+
cv::GMat op_sc_mat5 = sc - mat_in2;
141+
cv::GMat op_sc_mat6 = sc * mat_in2;
142+
cv::GMat op_sc_mat7 = sc / mat_in2;
143+
cv::GMat op_sc_mat8 = sc > mat_in2;
144+
cv::GMat op_sc_mat9 = sc >= mat_in2;
145+
cv::GMat op_sc_mat10 = sc < mat_in2;
146+
cv::GMat op_sc_mat11 = sc <= mat_in2;
147+
cv::GMat op_sc_mat12 = sc == mat_in2;
148+
cv::GMat op_sc_mat13 = sc != mat_in2;
149+
150+
cv::GMat mul_mat_float1 = mat_in1 * 1.0f;
151+
cv::GMat mul_mat_float2 = 1.0f * mat_in2;
152+
// No compilation errors expected
153+
}
154+
} // for_test
80155
} // opencv_test
81156

82157
#endif // OPENCV_GAPI_OPERATOR_TESTS_INL_COMMON_HPP

0 commit comments

Comments
 (0)