commit 08/04/2025

This commit is contained in:
rdkartono
2025-04-08 15:27:12 +07:00
parent 6f3080293f
commit e72d25a213
8 changed files with 621 additions and 637 deletions

View File

@@ -3,8 +3,10 @@ package Config;
import com.google.gson.Gson;
import com.google.zxing.MultiFormatReader;
import javafx.application.Platform;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import org.bytedeco.javacv.Java2DFrameConverter;
import org.bytedeco.javacv.OpenCVFrameConverter;
@@ -15,9 +17,9 @@ import org.bytedeco.opencv.opencv_core.Mat;
import org.bytedeco.opencv.opencv_core.Rect;
import org.bytedeco.opencv.opencv_core.Size;
import org.bytedeco.opencv.opencv_core.UMat;
import org.opencv.core.MatOfDouble;
import org.tinylog.Logger;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStream;
@@ -32,7 +34,6 @@ import java.util.ArrayList;
import java.util.List;
import static org.bytedeco.opencv.global.opencv_core.CV_64F;
import static org.bytedeco.opencv.global.opencv_core.CV_64FC3;
@SuppressWarnings("unused")
public class SomeCodes {
@@ -603,6 +604,52 @@ public class SomeCodes {
}
}
public static void SetText(Object obj, String text){
if (obj!=null && text!=null){
if (Platform.isFxApplicationThread()){
if (obj instanceof Label){
((Label) obj).setText(text);
} else if (obj instanceof TextArea){
((TextArea) obj).setText(text);
} else if (obj instanceof TextField){
((TextField) obj).setText(text);
}
} else{
Platform.runLater(()->{
if (obj instanceof Label){
((Label) obj).setText(text);
} else if (obj instanceof TextArea){
((TextArea) obj).setText(text);
} else if (obj instanceof TextField){
((TextField) obj).setText(text);
}
});
}
}
}
public static void LabelVisible(Label label, boolean visible){
if (label!=null){
if (visible){
if (Platform.isFxApplicationThread()){
label.setVisible(true);
} else{
Platform.runLater(()->{
label.setVisible(true);
});
}
} else {
if (Platform.isFxApplicationThread()){
label.setVisible(false);
} else{
Platform.runLater(()->{
label.setVisible(false);
});
}
}
}
}
public static void ShowAlert(Alert.AlertType type, String title, String header, String content){
Alert alert = new Alert(type);
alert.setTitle(title);
@@ -647,15 +694,25 @@ public class SomeCodes {
return false;
}
/**
* Calculate sharpness of image
* @param mat image in UMat format, expected in gray scale
* @return sharpness value
*/
public static double CalculateSharpness(UMat mat){
if (mat!=null && !mat.empty()){
UMat gray = new UMat();
opencv_imgproc.cvtColor(mat, gray, opencv_imgproc.COLOR_BGR2GRAY);
opencv_imgproc.equalizeHist(gray, gray);
if (mat.channels()!=1){
UMat grey = new UMat();
opencv_imgproc.cvtColor(mat, grey, opencv_imgproc.COLOR_BGR2GRAY);
mat = grey;
}
opencv_imgproc.equalizeHist(mat, mat);
UMat laplacian = new UMat();
opencv_imgproc.Laplacian(gray, laplacian, CV_64F);
opencv_imgproc.Laplacian(mat, laplacian, CV_64F);
UMat mean = new UMat(1,1, CV_64F);
UMat stddev = new UMat(1,1, CV_64F);

View File

@@ -111,11 +111,11 @@ public class Cameradetail {
@FXML
private Label sharpness_indicator;
private Double sharpness_value = 0.0;
private @Getter final UMat BestMat = new UMat();
private @Getter final UMat LiveMat = new UMat();
private @Getter final UMat ReducedMat = new UMat();
private @Getter final UMat GrayMat = new UMat();
private @Getter Rect BestMatROI;
private @Getter Rect ReducedMatROI;
@@ -237,6 +237,7 @@ public class Cameradetail {
* @param title Title of the Camera
*/
public void setCameraTitle(String title){
if (ValidString(title)){
if (cameratitle!=null){
cameratitle.setText(title);
@@ -790,33 +791,33 @@ public class Cameradetail {
IsGrabbingLiveView.set(false);
}
public Rect GetFace(UMat mat, boolean isfrontal){
if (!mat.empty()){
Mat originalmat = new Mat();
mat.copyTo(originalmat);
Mat graymat = new Mat();
opencv_imgproc.cvtColor(originalmat,graymat, COLOR_BGR2GRAY); // convert to grayscale
int size = Math.min(graymat.cols(), graymat.rows());
int minsize = (int) (size * 0.4);
int maxsize = (int) (size * 0.9);
System.out.println("GetFace size = "+size+" minsize = "+minsize+" maxsize = "+maxsize);
RectVector faces = isfrontal ? Detectors.DetectFrontalFace(graymat, minsize, maxsize) : Detectors.DetectProfileFace(graymat, minsize, maxsize);
if (faces.size()>0){
Rect result = null;
for(Rect xx : faces.get()){
if (result==null){
result = xx;
} else {
if (xx.area()>result.area()){
result = xx;
}
}
}
return result;
}
} else raise_log("GetFace failed, Mat is empty");
return null;
}
// public Rect GetFace(UMat mat, boolean isfrontal){
// if (!mat.empty()){
// Mat originalmat = new Mat();
// mat.copyTo(originalmat);
// Mat graymat = new Mat();
// opencv_imgproc.cvtColor(originalmat,graymat, COLOR_BGR2GRAY); // convert to grayscale
// int size = Math.min(graymat.cols(), graymat.rows());
// int minsize = (int) (size * 0.4);
// int maxsize = (int) (size * 0.9);
// System.out.println("GetFace size = "+size+" minsize = "+minsize+" maxsize = "+maxsize);
// RectVector faces = isfrontal ? Detectors.DetectFrontalFace(graymat, minsize, maxsize) : Detectors.DetectProfileFace(graymat, minsize, maxsize);
// if (faces.size()>0){
// Rect result = null;
// for(Rect xx : faces.get()){
// if (result==null){
// result = xx;
// } else {
// if (xx.area()>result.area()){
// result = xx;
// }
// }
// }
// return result;
// }
// } else raise_log("GetFace failed, Mat is empty");
// return null;
// }
public boolean StartLiveView(LiveCamEvent event, String cameratitle, final boolean use_qr , final boolean use_face) {
this.event = event;
@@ -880,8 +881,8 @@ public class Cameradetail {
boolean have_fist = false;
int no_face_counter = 0;
int face_counter = 0;
int open_eye_counter = 0;
int close_eye_counter = 0;
//int open_eye_counter = 0;
//int close_eye_counter = 0;
while (Capturing.get()) {
try {
@@ -898,7 +899,7 @@ public class Cameradetail {
} catch (Exception e){
frame = null;
if (e.getMessage()!=null && e.getMessage().length()>0){
if (e.getMessage()!=null && !e.getMessage().isEmpty()){
String msg = e.getMessage();
if (msg.contains("start() been called")){
if (Capturing.get()){
@@ -941,11 +942,10 @@ public class Cameradetail {
if (!BestMat.empty()) {
opencv_imgproc.resize(BestMat, LiveMat, LiveSize); // resize to LiveSize
UMat graymat = new UMat(); // use OpenCL for grayscale
opencv_imgproc.cvtColor(LiveMat,graymat, COLOR_BGR2GRAY); // convert to grayscale
opencv_imgproc.cvtColor(LiveMat,GrayMat, COLOR_BGR2GRAY); // convert to grayscale
if (use_qr){
String qr = DetectQRFromMat(graymat);
String qr = DetectQRFromMat(GrayMat);
if (ValidBarCode(qr)){
qrtext = qr;
if (event!=null) event.onDetectedQRCode(qrtext);
@@ -958,7 +958,7 @@ public class Cameradetail {
_face_width = 0;
_face_height = 0;
List<DetectorResult> frontalfaces = HaveFrontalFace(graymat);
List<DetectorResult> frontalfaces = HaveFrontalFace(GrayMat);
if (!frontalfaces.isEmpty()){
for(DetectorResult rect : frontalfaces){
@@ -974,7 +974,7 @@ public class Cameradetail {
} else {
// gak punya frontal face
// coba cek punya profile left face 45 gak
List<DetectorResult> Left45Faces = HaveLeft45Face(graymat);
List<DetectorResult> Left45Faces = HaveLeft45Face(GrayMat);
if (!Left45Faces.isEmpty()){
for(DetectorResult rect : Left45Faces){
if (rect.haveFace()){
@@ -999,7 +999,7 @@ public class Cameradetail {
no_face_counter = 0;
if (event!=null) event.onFrontalFaceDetector(true, _face_width, _face_height);
face_indicator.setVisible(true);
LabelVisible(face_indicator,true);
if (theface.getFace()!=null){
LiveMatROI = new Rect(theface.getFace().x(), theface.getFace().y(), theface.getFace().width(), theface.getFace().height());
@@ -1008,32 +1008,36 @@ public class Cameradetail {
if (theface.haveEyes()){
// ada mata (buka mata)
close_eye_counter=0;
if (open_eye_counter<1){
open_eye_counter++;
continue;
}
// close_eye_counter=0;
// if (open_eye_counter<1){
// open_eye_counter++;
// continue;
// }
//System.out.println("Valid Open Eyes");
if (eye_state!=1){
// transisi dari tutup mata ke buka mata
if (eye_state==-1) {
System.out.println("First Eye Detected from camera "+cameratitle);
eye_state=1;
continue;
}
System.out.println("Transition from close to open eyes");
eye_state = 1;
if (event!=null) event.onEyeDetector(true);
eye_indicator.setVisible(true);
LabelVisible(eye_indicator,true);
long now = System.currentTimeMillis();
if (waiting_for_second_blink){
long diff = now - last_blink;
// kalau beda waktu antara blink 1 dan blink 2 kurang dari 10 detik
if (diff<=10000){
waiting_for_second_blink = false;
// kalau beda waktu antara blink 1 dan blink 2 kurang dari 2 detik
if (diff<=2000){
System.out.println("Double Blink Detected from camera "+cameratitle);
if (event!=null) event.onBlink((int)diff);
}
waiting_for_second_blink = false;
} else {
waiting_for_second_blink = true;
System.out.println("First Blink Detected from camera "+cameratitle);
@@ -1043,23 +1047,23 @@ public class Cameradetail {
} else {
// ada muka, tidak ada mata
// transisi dari buka mata ke tutup mata
open_eye_counter=0;
if (close_eye_counter<1){
close_eye_counter++;
continue;
}
// open_eye_counter=0;
// if (close_eye_counter<1){
// close_eye_counter++;
// continue;
// }
//System.out.println("Valid Closed Eyes");
if (eye_state!=0){
System.out.println("Transition from open to close eyes");
eye_state = 0;
if (event!=null) event.onEyeDetector(false);
eye_indicator.setVisible(false);
LabelVisible(eye_indicator,false);
}
}
} else if (have_left_45_face ){
no_face_counter = 0;
if (event!=null) event.onProfileFaceDetector(true, _face_width, _face_height);
face_indicator.setVisible(true);
LabelVisible(face_indicator,true);
} else {
// no face detected, but let's not cancel the previous state immediately
@@ -1071,17 +1075,17 @@ public class Cameradetail {
last_blink = 0;
waiting_for_second_blink = false;
face_counter = 0;
if (close_eye_counter!=0 || open_eye_counter!=0){
close_eye_counter=0;
open_eye_counter=0;
System.out.println("Reset Open and Close Eyes");
}
// if (close_eye_counter!=0 || open_eye_counter!=0){
// close_eye_counter=0;
// open_eye_counter=0;
// System.out.println("Reset Open and Close Eyes");
// }
if (event!=null) {
event.onFrontalFaceDetector(false, _face_width, _face_height);
event.onProfileFaceDetector(false, _face_width, _face_height);
face_indicator.setVisible(false);
eye_indicator.setVisible(false);
LabelVisible(face_indicator,false);
LabelVisible(eye_indicator,false);
}
} else no_face_counter++;
@@ -1089,21 +1093,6 @@ public class Cameradetail {
}
// if (HavePalm(graymat)) {
// if (!have_palm){
// have_fist = false;
// have_palm = true;
// System.out.println("Palm Detected from camera " + cameratitle);
// }
// }
// if (HaveFist(graymat)) {
// if (!have_fist) {
// have_palm = false;
// have_fist = true;
// System.out.println("Fist Detected from camera "+cameratitle);
// }
// }
UMat rgbmat = new UMat(LiveMat.size(), CV_8UC3);
cvtColor(LiveMat, rgbmat, COLOR_BGR2RGB);

File diff suppressed because it is too large Load Diff

View File

@@ -34,7 +34,7 @@ public class MainApplication extends Application {
Screen screen = Screen.getPrimary();
Rectangle2D screenbound = screen.getVisualBounds();
Scene scene = new Scene(fxmlLoader.load(), screenbound.getWidth(), screenbound.getHeight());
stage.setTitle("MultiCam Capture App for ERHA 27032025-001");
stage.setTitle("MultiCam Capture App for ERHA 08042025-003");
stage.setScene(scene);
stage.setResizable(true);
stage.setMaximized(true);

View File

@@ -5,7 +5,7 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane fx:id="CaptureViewAnchor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="768.0" prefWidth="1024.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="id.co.gtc.erhacam.CaptureView">
<AnchorPane fx:id="CaptureViewAnchor" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="768.0" prefWidth="1024.0" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="id.co.gtc.erhacam.CaptureView">
<children>
<GridPane layoutX="147.0" layoutY="239.0" AnchorPane.bottomAnchor="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
@@ -38,7 +38,14 @@
<AnchorPane fx:id="controlpane" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">
<padding>
<Insets top="5.0" />
</padding></AnchorPane>
</padding>
<children>
<Button fx:id="TakePhotoButton" disable="true" mnemonicParsing="false" onAction="#TakePhotos" prefHeight="175.0" prefWidth="512.0" text="Take Photo" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0">
<font>
<Font size="48.0" />
</font>
</Button>
</children></AnchorPane>
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<GridPane layoutX="68.0" layoutY="14.0" prefHeight="175.2" prefWidth="512.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">