From 2d28b9a0e740dc9d6c2258dbbe1579200f1f57f1 Mon Sep 17 00:00:00 2001 From: Michael Russo Date: Thu, 5 Oct 2023 17:13:00 +0000 Subject: [PATCH] Add additional signature for MinMaxLoc. --- core.cpp | 11 +++++++++++ core.go | 19 +++++++++++++++++++ core.h | 1 + 3 files changed, 31 insertions(+) diff --git a/core.cpp b/core.cpp index 64958414..fdff80a0 100644 --- a/core.cpp +++ b/core.cpp @@ -628,6 +628,17 @@ void Mat_MinMaxLoc(Mat m, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc->y = cMaxLoc.y; } +void Mat_MinMaxLocWithMask(Mat m, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc, Mat mask) { + cv::Point cMinLoc; + cv::Point cMaxLoc; + cv::minMaxLoc(*m, minVal, maxVal, &cMinLoc, &cMaxLoc, *mask); + + minLoc->x = cMinLoc.x; + minLoc->y = cMinLoc.y; + maxLoc->x = cMaxLoc.x; + maxLoc->y = cMaxLoc.y; +} + void Mat_MixChannels(struct Mats src, struct Mats dst, struct IntVector fromTo) { std::vector srcMats; diff --git a/core.go b/core.go index a95cdcb2..b359a4b9 100644 --- a/core.go +++ b/core.go @@ -1534,6 +1534,25 @@ func MinMaxLoc(input Mat) (minVal, maxVal float32, minLoc, maxLoc image.Point) { return float32(cMinVal), float32(cMaxVal), minLoc, maxLoc } +// MinMaxLocWithMask finds the global minimum and maximum in an array with a mask used to select a sub-array. +// +// For further details, please see: +// https://docs.opencv.org/trunk/d2/de8/group__core__array.html#gab473bf2eb6d14ff97e89b355dac20707 +// +func MinMaxLocWithMask(input Mat, mask Mat) (minVal, maxVal float32, minLoc, maxLoc image.Point) { + var cMinVal C.double + var cMaxVal C.double + var cMinLoc C.struct_Point + var cMaxLoc C.struct_Point + + C.Mat_MinMaxLocWithMask(input.p, &cMinVal, &cMaxVal, &cMinLoc, &cMaxLoc, mask.p) + + minLoc = image.Pt(int(cMinLoc.x), int(cMinLoc.y)) + maxLoc = image.Pt(int(cMaxLoc.x), int(cMaxLoc.y)) + + return float32(cMinVal), float32(cMaxVal), minLoc, maxLoc +} + // Copies specified channels from input arrays to the specified channels of output arrays. // // For further details, please see: diff --git a/core.h b/core.h index 955c5ea1..e47a108f 100644 --- a/core.h +++ b/core.h @@ -405,6 +405,7 @@ void Mat_Merge(struct Mats mats, Mat dst); void Mat_Min(Mat src1, Mat src2, Mat dst); void Mat_MinMaxIdx(Mat m, double* minVal, double* maxVal, int* minIdx, int* maxIdx); void Mat_MinMaxLoc(Mat m, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc); +void Mat_MinMaxLocWithMask(Mat m, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc, Mat mask); void Mat_MixChannels(struct Mats src, struct Mats dst, struct IntVector fromTo); void Mat_MulSpectrums(Mat a, Mat b, Mat c, int flags); void Mat_Multiply(Mat src1, Mat src2, Mat dst);