Skip to content

Commit

Permalink
Add MorphologyExWithParams
Browse files Browse the repository at this point in the history
  • Loading branch information
acharyab15 authored and deadprogram committed Aug 11, 2019
1 parent ad1f714 commit 0a03de5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions imgproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions imgproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions imgproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions imgproc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 0a03de5

Please sign in to comment.