From 8a2c9f2ae052e43c04f31f2cc86b5b64aaccfaa8 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Thu, 20 Mar 2025 01:32:14 -0400 Subject: [PATCH] Refactor FileSaveFrameConsumer to close objects and let Java handle paths --- .../frame/consumer/FileSaveFrameConsumer.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/photon-core/src/main/java/org/photonvision/vision/frame/consumer/FileSaveFrameConsumer.java b/photon-core/src/main/java/org/photonvision/vision/frame/consumer/FileSaveFrameConsumer.java index d12f491fd..dce9366a5 100644 --- a/photon-core/src/main/java/org/photonvision/vision/frame/consumer/FileSaveFrameConsumer.java +++ b/photon-core/src/main/java/org/photonvision/vision/frame/consumer/FileSaveFrameConsumer.java @@ -103,19 +103,17 @@ public class FileSaveFrameConsumer implements Consumer { + matchData; // Check if the Unique Camera directory exists and create it if it doesn't - String cameraPath = FILE_PATH + File.separator + this.cameraUniqueName; - var cameraDir = new File(cameraPath); + var cameraDir = new File(FILE_PATH, this.cameraUniqueName); if (!cameraDir.exists()) { cameraDir.mkdir(); } - - String saveFilePath = cameraPath + File.separator + fileName + FILE_EXTENSION; + var saveFilePath = cameraDir.toPath().resolve(fileName + FILE_EXTENSION); logger.info("Saving image to: " + saveFilePath); if (image == null || image.getMat() == null || image.getMat().empty()) { - Imgcodecs.imwrite(saveFilePath, StaticFrames.LOST_MAT); + Imgcodecs.imwrite(saveFilePath.toString(), StaticFrames.LOST_MAT); } else { - Imgcodecs.imwrite(saveFilePath, image.getMat()); + Imgcodecs.imwrite(saveFilePath.toString(), image.getMat()); } savedImagesCount++; @@ -178,6 +176,9 @@ public class FileSaveFrameConsumer implements Consumer { } public void close() { - // troododfa;lkjadsf;lkfdsaj otgooadflsk;j + saveFrameEntry.close(); + ntEventName.close(); + ntMatchNum.close(); + ntMatchType.close(); } }