From 5e2985c4f5827597f5850b1d33918f03569dd737 Mon Sep 17 00:00:00 2001 From: doppelgrau Date: Fri, 15 May 2020 05:27:08 +0200 Subject: [PATCH] Fix/release all mat (#1007) * Made sure all Mat are released * removed a bit too much, reverted that change but made sure the Mat is released if not returned. * Typo Co-authored-by: Johannes Formann --- .../org/openpnp/vision/pipeline/stages/MaskHsv.java | 13 ++++++++++--- .../openpnp/vision/pipeline/stages/Normalize.java | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openpnp/vision/pipeline/stages/MaskHsv.java b/src/main/java/org/openpnp/vision/pipeline/stages/MaskHsv.java index 9c45d4036e7..6bf3419f448 100644 --- a/src/main/java/org/openpnp/vision/pipeline/stages/MaskHsv.java +++ b/src/main/java/org/openpnp/vision/pipeline/stages/MaskHsv.java @@ -391,6 +391,12 @@ public Result process(CvPipeline pipeline) throws Exception { endIdx = -1; startIdx = -1; } + workingMat.release(); + mv.release(); + hist.release(); + ranges.release(); + channels.release(); + histSize.release(); setValueMax( endIdx ); Logger.trace( "valueMax = " + valueMax ); setValueMin( startIdx ); @@ -420,6 +426,7 @@ public Result process(CvPipeline pipeline) throws Exception { Core.inRange(mat, min, max, mask2); Core.bitwise_or(mask, mask2, mask); + mask2.release(); } //The mask is normally inverted because it is used to copy the unmasked portions of the @@ -430,12 +437,12 @@ public Result process(CvPipeline pipeline) throws Exception { double fractionActuallyMasked = 1.0 - Core.countNonZero(mask) / (double) ( mat.rows() * mat.cols() ) ; Logger.trace( "Fraction actually masked = " + fractionActuallyMasked ); - if (binaryMask) { + masked.release(); return new Result(mask); - } - else { + } else { mat.copyTo(masked, mask); + mask.release(); return new Result(masked); } } diff --git a/src/main/java/org/openpnp/vision/pipeline/stages/Normalize.java b/src/main/java/org/openpnp/vision/pipeline/stages/Normalize.java index 4063eb34da5..5fc1b669b17 100644 --- a/src/main/java/org/openpnp/vision/pipeline/stages/Normalize.java +++ b/src/main/java/org/openpnp/vision/pipeline/stages/Normalize.java @@ -26,6 +26,7 @@ private void filter(Mat src){ } } src.put(0, 0, pixel); + dst.release(); } @Override