From 933f00dba6e62d407a7c8627975e8dffc8122eb2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Nicolas <6371790+pynicolas@users.noreply.github.com> Date: Tue, 10 Feb 2026 21:42:49 +0100 Subject: [PATCH] Add missing calls to Mat.release() --- .../org/fairscan/imageprocessing/DocumentDetection.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/imageprocessing/src/main/java/org/fairscan/imageprocessing/DocumentDetection.kt b/imageprocessing/src/main/java/org/fairscan/imageprocessing/DocumentDetection.kt index b6ce6e3..44863e5 100644 --- a/imageprocessing/src/main/java/org/fairscan/imageprocessing/DocumentDetection.kt +++ b/imageprocessing/src/main/java/org/fairscan/imageprocessing/DocumentDetection.kt @@ -24,7 +24,6 @@ import org.opencv.core.MatOfPoint2f import org.opencv.core.Size import org.opencv.imgproc.Imgproc import kotlin.math.abs -import kotlin.math.max interface Mask { val width: Int @@ -141,14 +140,18 @@ fun extractDocument( ) val transform = Imgproc.getPerspectiveTransform(srcPoints, dstPoints) - val outputMat = Mat() + val warped = Mat() val outputSize = Size(targetWidth, targetHeight) - Imgproc.warpPerspective(inputMat, outputMat, transform, outputSize) + Imgproc.warpPerspective(inputMat, warped, transform, outputSize) - val resized = resizeForMaxPixels(outputMat, maxPixels.toDouble()) + val resized = resizeForMaxPixels(warped, maxPixels.toDouble()) val enhanced = enhanceCapturedImage(resized, isColored) val rotated = rotate(enhanced, rotationDegrees) + warped.release() + resized.release() + enhanced.release() + return rotated }