1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge pull request #18652 from OrestChura:oc/morphologyEx

[G-API]: morphologyEx() Standard Kernel Implementation

* cv::gapi::morphologyEx() kernel
 - implemented (without separate 3x3 version)
 - tests added: check only different operations, not kernels/borders

* Address comments: add `const` where needed

* Replaced fundamental tyeps -> enums where needed
 - added operator<< overload for cv::MorphTypes for tests output
This commit is contained in:
Orest Chura
2020-11-10 21:57:52 +03:00
committed by GitHub
parent e12adcdf08
commit 5f1ca33c6f
7 changed files with 126 additions and 1 deletions
@@ -46,6 +46,8 @@ GAPI_TEST_FIXTURE(Erode3x3Test, initMatrixRandN, FIXTURE_API(CompareMats,int), 2
GAPI_TEST_FIXTURE(DilateTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int), 3,
cmpF, kernSize, kernType)
GAPI_TEST_FIXTURE(Dilate3x3Test, initMatrixRandN, FIXTURE_API(CompareMats,int), 2, cmpF, numIters)
GAPI_TEST_FIXTURE(MorphologyExTest, initMatrixRandN, FIXTURE_API(CompareMats,MorphTypes),
2, cmpF, op)
GAPI_TEST_FIXTURE(SobelTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int,int), 4,
cmpF, kernSize, dx, dy)
GAPI_TEST_FIXTURE(SobelXYTest, initMatrixRandN, FIXTURE_API(CompareMats,int,int,int,int), 5,
@@ -290,6 +290,29 @@ TEST_P(Dilate3x3Test, AccuracyTest)
}
}
TEST_P(MorphologyExTest, AccuracyTest)
{
MorphShapes defShape = cv::MORPH_RECT;
int defKernSize = 3;
cv::Mat kernel = cv::getStructuringElement(defShape, cv::Size(defKernSize, defKernSize));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::morphologyEx(in, op, kernel);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, getCompileArgs());
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::morphologyEx(in_mat1, out_mat_ocv, op, kernel);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), sz);
}
}
TEST_P(SobelTest, AccuracyTest)
{
// G-API code //////////////////////////////////////////////////////////////
@@ -848,6 +848,25 @@ inline std::ostream& operator<<(std::ostream& os, NormTypes op)
#undef CASE
return os;
}
inline std::ostream& operator<<(std::ostream& os, MorphTypes op)
{
#define CASE(v) case MorphTypes::v: os << #v; break
switch (op)
{
CASE(MORPH_ERODE);
CASE(MORPH_DILATE);
CASE(MORPH_OPEN);
CASE(MORPH_CLOSE);
CASE(MORPH_GRADIENT);
CASE(MORPH_TOPHAT);
CASE(MORPH_BLACKHAT);
CASE(MORPH_HITMISS);
default: GAPI_Assert(false && "unknown MorphTypes value");
}
#undef CASE
return os;
}
} // namespace cv
#endif //OPENCV_GAPI_TESTS_COMMON_HPP