From 0a03de5aaba6c31058e14847bd1774859bbf150e Mon Sep 17 00:00:00 2001 From: Bipeen Acharya Date: Wed, 10 Jul 2019 12:51:37 -0700 Subject: [PATCH] Add MorphologyExWithParams --- imgproc.cpp | 5 +++++ imgproc.go | 13 +++++++++++++ imgproc.h | 1 + imgproc_test.go | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/imgproc.cpp b/imgproc.cpp index 17b2dc4c..ce1780b3 100644 --- a/imgproc.cpp +++ b/imgproc.cpp @@ -262,6 +262,11 @@ void MorphologyEx(Mat src, Mat dst, int op, Mat kernel) { cv::morphologyEx(*src, *dst, op, *kernel); } +void MorphologyExWithParams(Mat src, Mat dst, int op, Mat kernel, Point pt, int iterations, int borderType) { + cv::Point pt1(pt.x, pt.y); + cv::morphologyEx(*src, *dst, op, *kernel, pt1, iterations, borderType); +} + void GaussianBlur(Mat src, Mat dst, Size ps, double sX, double sY, int bt) { cv::Size sz(ps.width, ps.height); cv::GaussianBlur(*src, *dst, sz, sX, sY, bt); diff --git a/imgproc.go b/imgproc.go index 5bc660b5..f41c1e77 100644 --- a/imgproc.go +++ b/imgproc.go @@ -675,6 +675,19 @@ func MorphologyEx(src Mat, dst *Mat, op MorphType, kernel Mat) { C.MorphologyEx(src.p, dst.p, C.int(op), kernel.p) } +// MorphologyExWithParams performs advanced morphological transformations. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga67493776e3ad1a3df63883829375201f +// +func MorphologyExWithParams(src Mat, dst *Mat, op MorphType, kernel Mat, iterations int, borderType BorderType) { + pt := C.struct_Point{ + x: C.int(-1), + y: C.int(-1), + } + C.MorphologyExWithParams(src.p, dst.p, C.int(op), kernel.p, pt, C.int(iterations), C.int(borderType)) +} + // MorphShape is the shape of the structuring element used for Morphing operations. type MorphShape int diff --git a/imgproc.h b/imgproc.h index 41219fad..d2262e80 100644 --- a/imgproc.h +++ b/imgproc.h @@ -51,6 +51,7 @@ void Scharr(Mat src, Mat dst, int dDepth, int dx, int dy, double scale, double d Mat GetStructuringElement(int shape, Size ksize); Scalar MorphologyDefaultBorderValue(); void MorphologyEx(Mat src, Mat dst, int op, Mat kernel); +void MorphologyExWithParams(Mat src, Mat dst, int op, Mat kernel, Point pt, int iterations, int borderType); void MedianBlur(Mat src, Mat dst, int ksize); void Canny(Mat src, Mat edges, double t1, double t2); diff --git a/imgproc_test.go b/imgproc_test.go index f3ea2649..9b61aa80 100644 --- a/imgproc_test.go +++ b/imgproc_test.go @@ -529,6 +529,25 @@ func TestMorphologyEx(t *testing.T) { } } +func TestMorphologyExWithParams(t *testing.T) { + img := IMRead("images/face-detect.jpg", IMReadColor) + if img.Empty() { + t.Error("Invalid read of Mat in MorphologyEx test") + } + defer img.Close() + + dest := NewMat() + defer dest.Close() + + kernel := GetStructuringElement(MorphRect, image.Pt(1, 1)) + defer kernel.Close() + + MorphologyExWithParams(img, &dest, MorphOpen, kernel, 2, BorderConstant) + if dest.Empty() || img.Rows() != dest.Rows() || img.Cols() != dest.Cols() { + t.Error("Invalid MorphologyExWithParams test") + } +} + func TestGaussianBlur(t *testing.T) { img := IMRead("images/face-detect.jpg", IMReadColor) if img.Empty() {