From 30660b9afba592c19e9f3c1d4a516dddd1bc0b7a Mon Sep 17 00:00:00 2001 From: rdkartono Date: Wed, 15 Jan 2025 10:23:18 +0700 Subject: [PATCH] * tambah timestamp * full resolution ganti ke PNG compression 0 * tambah reduced resolution di 1280x720 JPG quality 100 --- config.properties | 2 +- database.db | Bin 36864 -> 36864 bytes src/main/java/Config/SomeCodes.java | 7 +- .../java/id/co/gtc/erhacam/Cameradetail.java | 68 +++++++++++++----- .../java/id/co/gtc/erhacam/CaptureView.java | 6 +- 5 files changed, 63 insertions(+), 20 deletions(-) diff --git a/config.properties b/config.properties index 38356fd..6e8a6ea 100644 --- a/config.properties +++ b/config.properties @@ -1,4 +1,4 @@ -#Thu Dec 19 11:49:05 WIB 2024 +#Wed Jan 15 10:18:31 WIB 2025 AudioPhase1=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam\\audio\\phase1.mp3 AudioPhase2=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam\\audio\\phase2.mp3 AudioPhase3=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam\\audio\\phase3.mp3 diff --git a/database.db b/database.db index 54ecf6b3ace9f1733efed57d8059f236a35e7d16..0308505522fbc928ae6d44bb463d77a2416a9af9 100644 GIT binary patch delta 686 zcmZozz|^pSX@WGP)kGO*Myrhp^Ys}mHyN-5@Ub#JW#D(@5#dc#kUW8q~+y|yGv z2?k@?Mol<0Z-hc410z#i14CUyQw2i5(6kW>QG?LH+{(}p6oeuOgUo?}h#G;N&W B4S4_n diff --git a/src/main/java/Config/SomeCodes.java b/src/main/java/Config/SomeCodes.java index 2c26322..cf2a3bf 100644 --- a/src/main/java/Config/SomeCodes.java +++ b/src/main/java/Config/SomeCodes.java @@ -5,7 +5,6 @@ import com.google.gson.Gson; import com.google.zxing.MultiFormatReader; import javafx.embed.swing.SwingFXUtils; import javafx.scene.image.Image; -import lombok.val; import org.bytedeco.javacv.Java2DFrameConverter; import org.bytedeco.javacv.OpenCVFrameConverter; import org.bytedeco.opencv.global.opencv_imgcodecs; @@ -37,6 +36,10 @@ public class SomeCodes { public static final Gson gson = new Gson(); public static final ConfigFile config = new ConfigFile(); + public static String GetDateTimeString(){ + return LocalDateTime.now().format(dtf); + } + public static Path GetLogsPath(){ return Path.of(currentDirectory, "logs"); } @@ -288,7 +291,7 @@ public class SomeCodes { public static String[] MakeArray(String... args){ if (args!=null && args.length>0){ - List ll = new ArrayList(); + List ll = new ArrayList<>(); for(String x : args){ if (ValidString(x)) ll.add(x); } diff --git a/src/main/java/id/co/gtc/erhacam/Cameradetail.java b/src/main/java/id/co/gtc/erhacam/Cameradetail.java index e1697b4..e1dd8c7 100644 --- a/src/main/java/id/co/gtc/erhacam/Cameradetail.java +++ b/src/main/java/id/co/gtc/erhacam/Cameradetail.java @@ -4,6 +4,7 @@ import Camera.ArducamIMX477Preset; import Camera.CameraProperty; import Camera.LiveCamEvent; import Config.CameraConfigEnum; +import Config.SomeCodes; import com.google.zxing.BinaryBitmap; import com.google.zxing.NotFoundException; import com.google.zxing.Result; @@ -11,8 +12,6 @@ import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.common.HybridBinarizer; import javafx.application.Platform; -import javafx.beans.InvalidationListener; -import javafx.beans.Observable; import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.Slider; @@ -26,6 +25,7 @@ import lombok.Getter; import lombok.Setter; import org.bytedeco.javacv.Frame; import org.bytedeco.javacv.OpenCVFrameGrabber; +import org.bytedeco.opencv.global.opencv_imgcodecs; import org.bytedeco.opencv.global.opencv_imgproc; import org.bytedeco.opencv.opencv_core.*; import org.opencv.videoio.Videoio; @@ -90,8 +90,10 @@ public class Cameradetail { private final UMat BestMat = new UMat(); private final UMat LiveMat = new UMat(); + private final UMat ReducedMat = new UMat(); private Size LiveSize = new Size(640, 480); - private Size PhotoSize = new Size(1920, 1080); + private Size ReducedSize = new Size(1280, 720); + private Size BestSize = new Size(1920, 1080); private void setSliderValue(Slider sld, CameraProperty prop, double value){ if (sld!=null){ @@ -310,13 +312,16 @@ public class Cameradetail { * @param liveheight Height used on live view * @param photowidth Width used on photo capture * @param photoheight Height used on photo capture + * @param reducedwidth Width used on reduced resolution + * @param reducedheight Height used on reduced resolution */ - public void SetGrabber(OpenCVFrameGrabber grabber, int livewidth, int liveheight, int photowidth, int photoheight){ + public void SetGrabber(OpenCVFrameGrabber grabber, int livewidth, int liveheight, int photowidth, int photoheight, int reducedwidth, int reducedheight){ if (mGrabber!=null) { StopLiveView(); } LiveSize = new Size(livewidth, liveheight); - PhotoSize = new Size(photowidth, photoheight); + BestSize = new Size(photowidth, photoheight); + ReducedSize = new Size(reducedwidth, reducedheight); mGrabber = grabber; } @@ -519,11 +524,36 @@ public class Cameradetail { if (!BestMat.empty()){ Size sz = BestMat.size(); raise_log("TakePhoto got frame with width: " + sz.width() + " and height: " + sz.height()); - String filename = Path.of(directory, makeFileName(prefix)).toString(); - if (imwrite(filename, BestMat)){ + + String timestamp = prefix+" "+SomeCodes.GetDateTimeString(); + int fontFace = FONT_HERSHEY_SIMPLEX; + double fontScale = 4.0; + int thickness = 2; + Scalar textColor = new Scalar(255, 255, 255, 0); // white color in BGR format + int[] baseline = {0}; + Size textSize = getTextSize(timestamp, fontFace, fontScale, thickness, baseline); + // position of the text in the bottom right corner + int textX = BestMat.cols() - textSize.width() - 10; // 10 pixels from the right + int textY = BestMat.rows() - 10; // 10 pixels from the bottom + opencv_imgproc.putText(BestMat, timestamp, new Point(textX, textY), fontFace, fontScale, textColor, thickness, opencv_imgproc.LINE_AA, false); + + int[] paramjpeg = {opencv_imgcodecs.IMWRITE_JPEG_QUALITY, 100}; + int[] parampng = {opencv_imgcodecs.IMWRITE_PNG_COMPRESSION, 0}; + + // save BestMat at quality 9 PNG + String filename = Path.of(directory, makeFileName(prefix,".png")).toString(); + if (imwrite(filename, BestMat, parampng)){ raise_log("TakePhoto success, Photo saved to " + filename); result = filename; } else raise_log("TakePhoto failed, Unable to Save Photo"); + + // save ReducedMat at 100% JPEG + String reducedfilename = Path.of(directory, makeReducedFileName(prefix,".jpg")).toString(); + opencv_imgproc.resize(BestMat, ReducedMat, ReducedSize); + if (imwrite(reducedfilename, ReducedMat, paramjpeg)){ + raise_log("TakePhoto success, Reduced Photo saved to " + reducedfilename); + } else raise_log("TakePhoto failed, Unable to Save Reduced Photo"); + } else raise_log("TakePhoto failed, Live View is Empty"); } else raise_log("TakePhoto failed, Grabber is null"); TakingPhoto.set(false); @@ -531,14 +561,20 @@ public class Cameradetail { } - //TODO Revisi nama file - private String makeFileName(String prefix){ - //make filename with prefix_POSITION_YYYY-MM-DD_HH-MM-SS + + @SuppressWarnings("SameParameterValue") + private String makeFileName(String prefix, String extension){ LocalDateTime ldt = LocalDateTime.now(); String timetag = ldt.getYear() + "-" + ldt.getMonthValue() + "-" + ldt.getDayOfMonth() + "_" + ldt.getHour() + "-" + ldt.getMinute() + "-" + ldt.getSecond(); - return prefix+" "+timetag+" "+cameratitle.getText() + ".jpg"; + return prefix+" "+timetag+" "+cameratitle.getText() + extension; + } + @SuppressWarnings("SameParameterValue") + private String makeReducedFileName(String prefix, String extension){ + LocalDateTime ldt = LocalDateTime.now(); + String timetag = ldt.getYear() + "-" + ldt.getMonthValue() + "-" + ldt.getDayOfMonth() + "_" + ldt.getHour() + "-" + ldt.getMinute() + "-" + ldt.getSecond(); + return prefix+" "+timetag+" "+cameratitle.getText() + "_reduced" + extension; } public void StopLiveView(){ @@ -565,15 +601,15 @@ public class Cameradetail { if (use_qr) raise_log("QR Reader loaded"); if (use_face) raise_log("Face detector loaded"); // capture with best resolution - setFrameHeight(PhotoSize.height()); - setFrameWidth(PhotoSize.width()); + setFrameHeight(BestSize.height()); + setFrameWidth(BestSize.width()); LiveFPS = 0; mGrabber.start(); Capturing.set(true); // just information - String ss = String.format("Camera Started with resolution %dx%d@%d", PhotoSize.width(), PhotoSize.height(),LiveFPS); + String ss = String.format("Camera Started with resolution %dx%d@%d", BestSize.width(), BestSize.height(),LiveFPS); Platform.runLater(()->setCameraStatus(ss)); raise_log(ss); @@ -628,12 +664,12 @@ public class Cameradetail { if (use_face){ RectVector face = DetectFace(graymat); if (face!=null && face.size()>0){ - if (event!=null) event.onFaceDetector(true, PhotoSize.width(), PhotoSize.height()); + if (event!=null) event.onFaceDetector(true, BestSize.width(), BestSize.height()); for(int i=0; i