diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index f2b90e6..f952330 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -1,9 +1,10 @@ \ No newline at end of file diff --git a/config.properties b/config.properties index da28bc8..2dbd09a 100644 --- a/config.properties +++ b/config.properties @@ -1,12 +1,12 @@ -#Mon May 26 14:20:06 WIB 2025 +#Tue May 27 10:31:40 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 AudioPhase4=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam\\audio\\phase4.mp3 AudioPhase5=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam\\audio\\phase5.mp3 -Cam1BottomCrop=10.0 -Cam1LeftCrop=10.0 -Cam1RightCrop=10.0 +Cam1BottomCrop=20.0 +Cam1LeftCrop=8.0 +Cam1RightCrop=8.0 Cam1TopCrop=10.0 Cam2BottomCrop=10.0 Cam2LeftCrop=10.0 @@ -31,7 +31,7 @@ CameraConfigLeft90={"Brightness"\:0.0,"Contrast"\:0.0,"Saturation"\:0.0,"Hue"\:0 CameraConfigRight45={"Brightness"\:0.0,"Contrast"\:0.0,"Saturation"\:0.0,"Hue"\:0.0,"Gain"\:1.0,"Exposure"\:1.0,"Sharpness"\:0.0,"Gamma"\:0.0,"AutoExposure"\:true,"AutoFocus"\:true,"AutoWhiteBalance"\:true} CameraConfigRight90={"Brightness"\:0.0,"Contrast"\:0.0,"Saturation"\:0.0,"Hue"\:0.0,"Gain"\:1.0,"Exposure"\:1.0,"Sharpness"\:0.0,"Gamma"\:0.0,"AutoExposure"\:true,"AutoFocus"\:true,"AutoWhiteBalance"\:true} CameraLeft45= -CameraLeft90= +CameraLeft90=OBSBOT Meet 2 StreamCamera CameraRight45= CameraRight90= FTPHost=192.168.10.2 @@ -41,9 +41,9 @@ FTPPort=21 FTPUser=user FlipCamera=false MirrorCamera=false -PhotoDirectory=C\:\\Users\\rdkar\\OneDrive\\Documents\\IntelliJ Project\\ErhaCam +PhotoDirectory=C\:\\Users\\rdkar\\OneDrive\\Desktop\\Erha Capture SharpnessThreshold=300.0 -cascadeMaxSize=500 +cascadeMaxSize=360 cascadeMinNeighbors=3 cascadeMinSize=250 -cascadeScaleFactor=1.1 +cascadeScaleFactor=1.05 diff --git a/src/main/java/Config/ConfigFile.java b/src/main/java/Config/ConfigFile.java index bbcf4f8..3b41d61 100644 --- a/src/main/java/Config/ConfigFile.java +++ b/src/main/java/Config/ConfigFile.java @@ -55,23 +55,23 @@ public class ConfigFile { private @Getter final double leftcropmax = 30.0; private @Getter final double rightcropmax = 30.0; private @Getter double Cam1TopCrop = 10.0; - private @Getter double Cam1BottomCrop = 10.0; - private @Getter double Cam1LeftCrop = 10.0; - private @Getter double Cam1RightCrop = 10.0; + private @Getter double Cam1BottomCrop = 20.0; + private @Getter double Cam1LeftCrop = 8.0; + private @Getter double Cam1RightCrop = 8.0; private @Getter double Cam2TopCrop = 10.0; - private @Getter double Cam2BottomCrop = 10.0; - private @Getter double Cam2LeftCrop = 10.0; - private @Getter double Cam2RightCrop = 10.0; + private @Getter double Cam2BottomCrop = 20.0; + private @Getter double Cam2LeftCrop = 8.0; + private @Getter double Cam2RightCrop = 8.0; private @Getter double Cam3TopCrop = 10.0; - private @Getter double Cam3BottomCrop = 10.0; - private @Getter double Cam3LeftCrop = 10.0; - private @Getter double Cam3RightCrop = 10.0; + private @Getter double Cam3BottomCrop = 20.0; + private @Getter double Cam3LeftCrop = 8.0; + private @Getter double Cam3RightCrop = 8.0; private @Getter double Cam4TopCrop = 10.0; - private @Getter double Cam4BottomCrop = 10.0; - private @Getter double Cam4LeftCrop = 10.0; - private @Getter double Cam4RightCrop = 10.0; + private @Getter double Cam4BottomCrop = 20.0; + private @Getter double Cam4LeftCrop = 8.0; + private @Getter double Cam4RightCrop = 8.0; private @Getter double Cam5TopCrop = 10.0; - private @Getter double Cam5BottomCrop = 10.0; + private @Getter double Cam5BottomCrop = 20.0; private @Getter double Cam5LeftCrop = 10.0; private @Getter double Cam5RightCrop = 10.0; @@ -940,10 +940,10 @@ public class ConfigFile { SetDefaultCameraConfig(ConfigCenter); SetDefaultCameraConfig(ConfigRight45); SetDefaultCameraConfig(ConfigRight90); - cascadeScaleFactor = 1.1; + cascadeScaleFactor = 1.05; cascadeMinNeighbors = 3; cascadeMinSize = 250; - cascadeMaxSize = 500; + cascadeMaxSize = 360; Detectors.setFaceMaxSize(cascadeMaxSize); Detectors.setFaceMinSize(cascadeMinSize); Detectors.setScaleFactor(cascadeScaleFactor); @@ -952,29 +952,29 @@ public class ConfigFile { SharpnessThreshold = 300.0; Cam1TopCrop = 10.0; - Cam1BottomCrop = 10.0; - Cam1LeftCrop = 10.0; - Cam1RightCrop = 10.0; + Cam1BottomCrop = 20.0; + Cam1LeftCrop = 8.0; + Cam1RightCrop = 8.0; Cam2TopCrop = 10.0; - Cam2BottomCrop = 10.0; - Cam2LeftCrop = 10.0; - Cam2RightCrop = 10.0; + Cam2BottomCrop = 20.0; + Cam2LeftCrop = 8.0; + Cam2RightCrop = 8.0; Cam3TopCrop = 10.0; - Cam3BottomCrop = 10.0; - Cam3LeftCrop = 10.0; - Cam3RightCrop = 10.0; + Cam3BottomCrop = 20.0; + Cam3LeftCrop = 8.0; + Cam3RightCrop = 8.0; Cam4TopCrop = 10.0; - Cam4BottomCrop = 10.0; - Cam4LeftCrop = 10.0; - Cam4RightCrop = 10.0; + Cam4BottomCrop = 20.0; + Cam4LeftCrop = 8.0; + Cam4RightCrop = 8.0; Cam5TopCrop = 10.0; - Cam5BottomCrop = 10.0; - Cam5LeftCrop = 10.0; - Cam5RightCrop = 10.0; + Cam5BottomCrop = 20.0; + Cam5LeftCrop = 8.0; + Cam5RightCrop = 8.0; Logger.info("Default Config Created"); needsave = true; diff --git a/src/main/java/Config/SomeCodes.java b/src/main/java/Config/SomeCodes.java index 902f10e..5d12c16 100644 --- a/src/main/java/Config/SomeCodes.java +++ b/src/main/java/Config/SomeCodes.java @@ -643,7 +643,7 @@ public class SomeCodes { * Check if Region of Interest 1 is same with Region of Interest 2 * @param ROI1 Region of Interest 1 * @param ROI2 Region of Interest 2 - * @return true if same, false if not same + * @return true if same, false if different */ public static boolean IsSameROI(Rect ROI1, Rect ROI2){ if (ValidROI(ROI1) && ValidROI(ROI2)){ @@ -778,7 +778,7 @@ public class SomeCodes { public static double CalculateSharpness(String filename){ if (ValidFile(filename)){ try(Mat mat = opencv_imgcodecs.imread(filename)){ - return CalculateSharpness(new UMat(mat)); + return CalculateSharpness(mat); } catch (Exception e){ Logger.error("Error calculating sharpness: "+filename+", Msg : "+e.getMessage()); } @@ -816,23 +816,23 @@ public class SomeCodes { * @param mat image in UMat format, expected in gray scale * @return sharpness value */ - public static double CalculateSharpness(UMat mat){ + public static double CalculateSharpness(Mat mat){ if (mat!=null && !mat.empty()){ if (mat.channels()!=1){ - UMat grey = new UMat(); + Mat grey = new Mat(); opencv_imgproc.cvtColor(mat, grey, opencv_imgproc.COLOR_BGR2GRAY); mat = grey; } opencv_imgproc.equalizeHist(mat, mat); - UMat laplacian = new UMat(); + Mat laplacian = new Mat(); opencv_imgproc.Laplacian(mat, laplacian, CV_64F); - UMat mean = new UMat(1,1, CV_64F); - UMat stddev = new UMat(1,1, CV_64F); + Mat mean = new Mat(1,1, CV_64F); + Mat stddev = new Mat(1,1, CV_64F); opencv_core.meanStdDev(laplacian, mean, stddev); @@ -847,7 +847,7 @@ public class SomeCodes { return 0; } - public static boolean IsBlurred(UMat mat, double threshold){ + public static boolean IsBlurred(Mat mat, double threshold){ return CalculateSharpness(mat) frontalfaces = HaveFrontalFace(gray); + List frontalfaces = HaveFrontalFace(GrayMat.clone()); if (!frontalfaces.isEmpty()){ for(DetectorResult rect : frontalfaces){ if (rect.haveFace() ){ @@ -916,7 +916,7 @@ public class Cameradetail { } else { // gak punya frontal face // coba cek punya profile left face 45 gak - List Left45Faces = HaveLeft45Face(gray); + List Left45Faces = HaveLeft45Face(GrayMat.clone()); if (!Left45Faces.isEmpty()){ for(DetectorResult rect : Left45Faces){ if (rect.haveFace()){ @@ -938,9 +938,10 @@ public class Cameradetail { if (event!=null) event.onFrontalFaceDetector(true, _face_width, _face_height); LabelVisible(face_indicator,true); - if (theface.getFace()!=null){ - LiveMatROI = new Rect(theface.getFace().x(), theface.getFace().y(), theface.getFace().width(), theface.getFace().height()); - } + // Revisi 26/05/2025, LiveMatROI dihitung dari topcrop, bottomcrop, leftcrop dan rightcrop +// if (theface.getFace()!=null){ +// LiveMatROI = new Rect(theface.getFace().x(), theface.getFace().y(), theface.getFace().width(), theface.getFace().height()); +// } if (theface.getEyesCount()>=2){ // ada mata (buka mata) @@ -955,7 +956,7 @@ public class Cameradetail { if (eye_state.get()!=1){ // transisi dari tutup mata ke buka mata if (eye_state.get()==-1) { - System.out.println("First Eye Detected from camera "+cameratitle.getText()); + System.out.println("First Eye Detected from camera "+title); eye_state.set(1); } else { eye_state.set(1); @@ -969,13 +970,13 @@ public class Cameradetail { long diff = now - last_blink.get(); // kalau beda waktu antara blink 1 dan blink 2 kurang dari 3 detik if (diff<=3000){ - System.out.println("Double Blink Detected from camera "+cameratitle.getText()); + System.out.println("Double Blink Detected from camera "+title); if (event!=null) event.onDoubleBlink((int)diff); } waiting_for_second_blink.set(false); } else { waiting_for_second_blink.set(true); - System.out.println("First Blink Detected from camera "+cameratitle.getText()); + System.out.println("First Blink Detected from camera "+title); } last_blink.set(now); } @@ -1029,13 +1030,19 @@ public class Cameradetail { } - Mat imgmat = new Mat(); - LiveMat.copyTo(imgmat); - // copy back to CPU - setCameraStream(MatToImage(imgmat)); - imgmat.release(); + if (LiveMat != null && !LiveMat.empty()){ + Mat imgmat = new Mat(); + // copy back to CPU + LiveMat.copyTo(imgmat); + setCameraStream(MatToImage(imgmat)); + imgmat.release(); + } + + + + } catch (Exception e) { //System.out.println(Thread.currentThread().getName()+" interrupted"); } @@ -1055,7 +1062,7 @@ public class Cameradetail { Frame frame = mGrabber.grab(); // grab frame delta = System.currentTimeMillis() - now; now = System.currentTimeMillis(); - } catch (FrameGrabber.Exception ignored) { + } catch (Exception ignored) { } @@ -1081,11 +1088,9 @@ public class Cameradetail { if (Capturing.get()) { try{ - if (mGrabber!=null) - frame = mGrabber.grab(); - else throw new FrameGrabber.Exception("Grabber is null"); - - } catch (FrameGrabber.Exception e){ + if (mGrabber==null) continue; + frame = mGrabber.grab(); + } catch (Exception e){ if (Capturing.get()){ // kalau ada exception padahal masih capturing. Kalau sudah tidak capturing, tidak peduli if (ValidString(e.getMessage())){ @@ -1139,15 +1144,29 @@ public class Cameradetail { // rotate 90 degree counter clockwise karena kamera potrait opencv_core.rotate(originalmat, BestMat, opencv_core.ROTATE_90_COUNTERCLOCKWISE); - originalmat.release(); if (!BestMat.empty()) { // LiveMat and GrayMat are synchronized synchronized (lockObject){ - opencv_imgproc.resize(BestMat, LiveMat, LiveSize); // resize to LiveSize - opencv_imgproc.cvtColor(LiveMat,GrayMat, COLOR_BGR2GRAY); // convert to grayscale + // resize BestMat to LiveSize + UMat _liveMat = new UMat(); + opencv_imgproc.resize(BestMat, _liveMat, LiveSize); + // crop LiveMat + UMat croppedLiveMat = CropMat(_liveMat); + if (croppedLiveMat!=null && !croppedLiveMat.empty()){ + croppedLiveMat.copyTo(LiveMat); + croppedLiveMat.release(); + } else { + _liveMat.copyTo(LiveMat); + _liveMat.release(); + } + // convert to grayscale + + Mat xx = new Mat(); + LiveMat.copyTo(xx); + opencv_imgproc.cvtColor(xx,GrayMat, COLOR_BGR2GRAY); } if (use_qr){ @@ -1172,6 +1191,29 @@ public class Cameradetail { } }); + private UMat CropMat(UMat mat){ + if (mat != null && !mat.empty()){ + int width = mat.cols(); + int height = mat.rows(); + + int x = (int) (width * leftcrop / 100); + int y = (int) (height * topcrop / 100); + int w = (int) (width * (100 - leftcrop - rightcrop) / 100); + int h = (int) (height * (100 - topcrop - bottomcrop) / 100); + + // Ensure the crop dimensions are valid + if (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= width && y + h <= height) { + Rect roi = new Rect(x, y, w, h); + + UMat crop = new UMat(); + mat.apply(roi).copyTo(crop); + return crop; + } + } + return null; + + } + public void ChangeCropValue(){ if ("01".equals(title)){ topcrop = config.getCam1TopCrop(); @@ -1281,90 +1323,89 @@ public class Cameradetail { } - - /** - * Remap LiveMatROI to BestMatROI and ReducedMatROI Resolution - * @param scaleX scale factor for width - * @param scaleY scale factor for height - */ - public void RemapROI(double scaleX, double scaleY, boolean printdebug){ - BestMatROI = null; - ReducedMatROI = null; - if (ValidROI(LiveMatROI)){ - if (ROIInsideUMat(LiveMatROI, LiveMat)){ - if (printdebug) System.out.println("LiveMatROI camera "+cameratitle.getText()+" = "+RectToString(LiveMatROI)); - - double scaleXBest = 1.0*BestSize.width()/LiveSize.width(); - double scaleYBest = 1.0*BestSize.height()/LiveSize.height(); - int XBest = (int) (LiveMatROI.x()*scaleXBest); - int YBest = (int) (LiveMatROI.y()*scaleYBest); - int WBest = (int) (LiveMatROI.width()*scaleXBest); - int HBest = (int) (LiveMatROI.height()*scaleYBest); - int deltaWBest = (int) (BestSize.width() * scaleX); - int deltaHBest = (int) (BestSize.height() * scaleY); - XBest = XBest - deltaWBest/2; - if (XBest<0) XBest = 0; - YBest = YBest - deltaHBest/2; - if (YBest<0) YBest = 0; - WBest = WBest + deltaWBest; - if (WBest>BestSize.width()) WBest = BestSize.width(); - HBest = HBest + deltaHBest; - if (HBest>BestSize.height()) HBest = BestSize.height(); - BestMatROI = new Rect(XBest, YBest, WBest, HBest); - - if (printdebug){ - System.out.println("scaleXBest = "+scaleXBest+" scaleYBest = "+scaleYBest); - System.out.println("BestMatROI camera "+cameratitle.getText()+" = "+RectToString(BestMatROI)); - } - - double scaleXReduced = 1.0*ReducedSize.width()/LiveSize.width(); - double scaleYReduced = 1.0*ReducedSize.height()/LiveSize.height(); - int XReduced = (int) (LiveMatROI.x()*scaleXReduced); - int YReduced = (int) (LiveMatROI.y()*scaleYReduced); - int WReduced = (int) (LiveMatROI.width()*scaleXReduced); - int HReduced = (int) (LiveMatROI.height()*scaleYReduced); - int deltaWReduced = (int) (ReducedSize.width() * scaleX); - int deltaHReduced = (int) (ReducedSize.height() * scaleY); - XReduced = XReduced - deltaWReduced/2; - if (XReduced<0) XReduced = 0; - YReduced = YReduced - deltaHReduced/2; - if (YReduced<0) YReduced = 0; - WReduced = WReduced + deltaWReduced; - if (WReduced>ReducedSize.width()) WReduced = ReducedSize.width(); - HReduced = HReduced + deltaHReduced; - if (HReduced>ReducedSize.height()) HReduced = ReducedSize.height(); - ReducedMatROI = new Rect(XReduced, YReduced, WReduced, HReduced); - if (printdebug){ - System.out.println("scaleXReduced = "+scaleXReduced+" scaleYReduced = "+scaleYReduced); - System.out.println("ReducedMatROI camera "+cameratitle.getText()+" = "+RectToString(ReducedMatROI)); - } - } - } - - } +// /** +// * Remap LiveMatROI to BestMatROI and ReducedMatROI Resolution +// * @param scaleX scale factor for width +// * @param scaleY scale factor for height +// */ +// public void RemapROI(double scaleX, double scaleY, boolean printdebug){ +// BestMatROI = null; +// ReducedMatROI = null; +// if (ValidROI(LiveMatROI)){ +// if (ROIInsideUMat(LiveMatROI, LiveMat)){ +// if (printdebug) System.out.println("LiveMatROI camera "+cameratitle.getText()+" = "+RectToString(LiveMatROI)); +// +// double scaleXBest = 1.0*BestSize.width()/LiveSize.width(); +// double scaleYBest = 1.0*BestSize.height()/LiveSize.height(); +// int XBest = (int) (LiveMatROI.x()*scaleXBest); +// int YBest = (int) (LiveMatROI.y()*scaleYBest); +// int WBest = (int) (LiveMatROI.width()*scaleXBest); +// int HBest = (int) (LiveMatROI.height()*scaleYBest); +// int deltaWBest = (int) (BestSize.width() * scaleX); +// int deltaHBest = (int) (BestSize.height() * scaleY); +// XBest = XBest - deltaWBest/2; +// if (XBest<0) XBest = 0; +// YBest = YBest - deltaHBest/2; +// if (YBest<0) YBest = 0; +// WBest = WBest + deltaWBest; +// if (WBest>BestSize.width()) WBest = BestSize.width(); +// HBest = HBest + deltaHBest; +// if (HBest>BestSize.height()) HBest = BestSize.height(); +// BestMatROI = new Rect(XBest, YBest, WBest, HBest); +// +// if (printdebug){ +// System.out.println("scaleXBest = "+scaleXBest+" scaleYBest = "+scaleYBest); +// System.out.println("BestMatROI camera "+cameratitle.getText()+" = "+RectToString(BestMatROI)); +// } +// +// double scaleXReduced = 1.0*ReducedSize.width()/LiveSize.width(); +// double scaleYReduced = 1.0*ReducedSize.height()/LiveSize.height(); +// int XReduced = (int) (LiveMatROI.x()*scaleXReduced); +// int YReduced = (int) (LiveMatROI.y()*scaleYReduced); +// int WReduced = (int) (LiveMatROI.width()*scaleXReduced); +// int HReduced = (int) (LiveMatROI.height()*scaleYReduced); +// int deltaWReduced = (int) (ReducedSize.width() * scaleX); +// int deltaHReduced = (int) (ReducedSize.height() * scaleY); +// XReduced = XReduced - deltaWReduced/2; +// if (XReduced<0) XReduced = 0; +// YReduced = YReduced - deltaHReduced/2; +// if (YReduced<0) YReduced = 0; +// WReduced = WReduced + deltaWReduced; +// if (WReduced>ReducedSize.width()) WReduced = ReducedSize.width(); +// HReduced = HReduced + deltaHReduced; +// if (HReduced>ReducedSize.height()) HReduced = ReducedSize.height(); +// ReducedMatROI = new Rect(XReduced, YReduced, WReduced, HReduced); +// if (printdebug){ +// System.out.println("scaleXReduced = "+scaleXReduced+" scaleYReduced = "+scaleYReduced); +// System.out.println("ReducedMatROI camera "+cameratitle.getText()+" = "+RectToString(ReducedMatROI)); +// } +// } +// } +// +// } /** * Detect QR Code from Mat - * @param graymat Mat in Gray Scale + * @param mat Mat in Gray Scale * @return QR Code Text, or null if not detected */ - private String DetectQRFromMat(UMat graymat){ + private String DetectQRFromMat(Mat mat){ if (qrreader!=null){ - Mat mat = new Mat(); - graymat.copyTo(mat); // back to CPU, because zxing only accept BufferedImage - BufferedImage bufferedImage = matToBufferedImage(mat); - String title = cameratitle.getText(); - BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(bufferedImage))); - try{ - Result result = qrreader.decode(binaryBitmap); - if (result!=null){ - return result.getText(); + if (mat!=null && !mat.empty()){ + BufferedImage bufferedImage = matToBufferedImage(mat); + BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(bufferedImage))); + try{ + Result result = qrreader.decode(binaryBitmap); + if (result!=null){ + return result.getText(); + } + } catch (Exception ignored) { } - } catch (Exception ignored) { + mat.release(); } - mat.release(); + } return null; } diff --git a/src/main/java/id/co/gtc/erhacam/CaptureView.java b/src/main/java/id/co/gtc/erhacam/CaptureView.java index bfd3b93..9994996 100644 --- a/src/main/java/id/co/gtc/erhacam/CaptureView.java +++ b/src/main/java/id/co/gtc/erhacam/CaptureView.java @@ -220,7 +220,7 @@ public class CaptureView { @Override public PhotoResult call() { if (image!=null){ - image.RemapROI(0.1, 0.3, false); + //image.RemapROI(0.1, 0.3, false); double sharpness = CalculateSharpness(image.getGrayMat()); image.setSharpness_indicator(sharpness); PhotoResult p = image.TakePhoto(directory, prefix); @@ -477,7 +477,7 @@ public class CaptureView { String[] files = prc.compressed(); if (files.length>0){ - AutoCloseAlert.showpictures(prc.compressed(),3, (s)->{ + AutoCloseAlert.showpictures(prc.compressedcrop(),3, (s)->{ if (AutoCloseAlert.banner_02!=null) { AutoCloseAlert.showbanner(AutoCloseAlert.banner_02, 0, null); @@ -510,7 +510,7 @@ public class CaptureView { } private void UploadFiles(PhotoReviewClass prc, String prefix){ - String[] files = prc.compressed(); + String[] files = prc.compressedcrop(); if (files.length>0){ InsertSQL(prc); @@ -1096,7 +1096,7 @@ public class CaptureView { }; image.setCameraStatus("Camera Starting"); if (image.StartLiveView(lce, title, use_qr_detector, use_face_detector)){ - Runtime.getRuntime().addShutdownHook(new Thread(image::Release)); + //Runtime.getRuntime().addShutdownHook(new Thread(image::Release)); } else image.setCameraStatus("Unable to Set Grabber"); } else image.setCameraStatus("Camera not found, please check setting"); } diff --git a/src/main/java/id/co/gtc/erhacam/DetectorResult.java b/src/main/java/id/co/gtc/erhacam/DetectorResult.java index 725bc38..51ce476 100644 --- a/src/main/java/id/co/gtc/erhacam/DetectorResult.java +++ b/src/main/java/id/co/gtc/erhacam/DetectorResult.java @@ -24,8 +24,14 @@ public class DetectorResult { Eyes.add(eye); } + // trouble di sini public void FaceRectangle(UMat mat){ + if (mat == null || mat.empty()) return; + if (Face == null || Face.width() <= 0 || Face.height() <= 0) return; + if (Face.x() < 0 || Face.y() < 0) return; // ignore negative coordinates + if (Face.x() + Face.width() > mat.cols() || Face.y() + Face.height() > mat.rows()) return; // ignore out of bounds if (haveFace()){ + try{ rectangle(mat, Face, Scalar.GREEN, linethickness, linetype, lineshift); @@ -33,9 +39,17 @@ public class DetectorResult { } } + // trouble di sini public void EyesRectangle(UMat mat){ + if (mat == null || mat.empty()) return; + if (haveEyes()){ + for(Rect eye : Eyes){ + if (eye == null || eye.width() <= 0 || eye.height() <= 0) continue; + if (eye.x() < 0 || eye.y() < 0) continue; // ignore negative coordinates + if (eye.x() + eye.width() > mat.cols() || eye.y() + eye.height() > mat.rows()) continue; // ignore out of bounds + try{ rectangle(mat, eye, Scalar.BLUE); diff --git a/src/main/java/id/co/gtc/erhacam/Detectors.java b/src/main/java/id/co/gtc/erhacam/Detectors.java index 37d492c..b62165b 100644 --- a/src/main/java/id/co/gtc/erhacam/Detectors.java +++ b/src/main/java/id/co/gtc/erhacam/Detectors.java @@ -84,7 +84,7 @@ public class Detectors { * @param graymat Mat in Gray Scale * @return List of Rect if face detected, otherwise empty list */ - public static @NonNull List HaveFrontalFace(UMat graymat){ + public static @NonNull List HaveFrontalFace(Mat graymat){ List result = new ArrayList<>(); RectVector faces = DetectFrontalFace(graymat); if (faces!=null && faces.size()>0){ @@ -106,7 +106,7 @@ public class Detectors { return result; } - public static @NonNull List HaveLeft45Face(UMat graymat){ + public static @NonNull List HaveLeft45Face(Mat graymat){ List result = new ArrayList<>(); RectVector faces = DetectProfileFace(graymat); if (faces!=null && faces.size()>0){ @@ -160,7 +160,7 @@ public class Detectors { } - public static RectVector DetectProfileFace(UMat graymat){ + public static RectVector DetectProfileFace(Mat graymat){ return Detect(graymat, profilefaceDetector, scaleFactor, minNeighbors, flags, FaceminSize, FacemaxSize); } @@ -169,7 +169,7 @@ public class Detectors { * @param graymat Mat in Gray Scale * @return RectVector if face detected, otherwise null */ - public static RectVector DetectFrontalFace(UMat graymat){ + public static RectVector DetectFrontalFace(Mat graymat){ return Detect(graymat, frontalfaceDetector, scaleFactor, minNeighbors, flags, FaceminSize, FacemaxSize); } @@ -179,7 +179,7 @@ public class Detectors { * @param graymat Mat in Gray Scale * @return RectVector if eye detected, otherwise null */ - public static RectVector DetectEye(UMat graymat, int facewidth){ + public static RectVector DetectEye(Mat graymat, int facewidth){ //return Detect(graymat, eyeDetector); int minwidth = (int)(facewidth*0.2); int maxwidth = (int)(facewidth*0.4); @@ -189,24 +189,24 @@ public class Detectors { } @SuppressWarnings("SameParameterValue") - private static RectVector Detect(UMat graymat, CascadeClassifier detector, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize){ - if (detector!=null){ - if (graymat!=null && graymat.channels()==1){ - if (!graymat.empty()){ - if (minSize!=null){ - if (maxSize!=null){ - try{ + private static RectVector Detect(Mat graymat, CascadeClassifier detector, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize){ + if (detector!=null && !detector.empty()){ + if (graymat!=null && graymat.channels()==1 && !graymat.empty()){ + if (minSize!=null && maxSize!=null){ + if (minSize.width()<= maxSize.width() && minSize.height() <= maxSize.height()){ + if (graymat.cols()> minSize.width() && graymat.rows() > minSize.height()) { + try { RectVector detected = new RectVector(); + // try defaulting minSize and maxSize detector.detectMultiScale(graymat, detected, scaleFactor, minNeighbors, flags, minSize, maxSize); return detected; - } catch (Exception e){ - System.out.println("Detectors Detect Error, Message : "+e.getMessage()); + } catch (Exception e) { + System.out.println("Detectors Detect Error, Message : " + e.getMessage()); } - } - } + } } } diff --git a/src/main/java/id/co/gtc/erhacam/MainApplication.java b/src/main/java/id/co/gtc/erhacam/MainApplication.java index 318d6b1..0e44482 100644 --- a/src/main/java/id/co/gtc/erhacam/MainApplication.java +++ b/src/main/java/id/co/gtc/erhacam/MainApplication.java @@ -15,7 +15,6 @@ import javafx.stage.Stage; import org.tinylog.Logger; import java.io.IOException; -import java.util.Map; import static Config.SomeCodes.ShowAlert; import static Config.SomeCodes.config; @@ -50,7 +49,7 @@ public class MainApplication extends Application { Screen screen = Screen.getPrimary(); Rectangle2D screenbound = screen.getBounds(); Scene scene = new Scene(fxmlLoader.load(), screenbound.getWidth(), screenbound.getHeight()); - stage.setTitle("MultiCam Capture App for ERHA 26052025-001"); + stage.setTitle("MultiCam Capture App for ERHA 27052025-005"); stage.setScene(scene); stage.setResizable(true); stage.setMaximized(true);