commit 09/04/2025
This commit is contained in:
@@ -108,6 +108,9 @@ public class Cameradetail {
|
||||
@FXML
|
||||
private Label eye_indicator;
|
||||
|
||||
@FXML
|
||||
private Label BlinkCounterLabel;
|
||||
|
||||
@FXML
|
||||
private Label sharpness_indicator;
|
||||
|
||||
@@ -604,7 +607,7 @@ public class Cameradetail {
|
||||
|
||||
public boolean PutText(UMat Mat, String text, double fontScale, Scalar textColor, int thickness){
|
||||
if (!Mat.empty()){
|
||||
if (text!=null && !text.isEmpty()){
|
||||
if (text!=null && !text.isBlank()){
|
||||
//String timestamp = prefix+" "+SomeCodes.GetDateTimeString();
|
||||
int fontFace = FONT_HERSHEY_SIMPLEX;
|
||||
//double fontScale = 4.0;
|
||||
@@ -625,7 +628,7 @@ public class Cameradetail {
|
||||
|
||||
public boolean PutText(Mat Mat, String text, double fontScale, Scalar textColor, int thickness){
|
||||
if (!Mat.empty()){
|
||||
if (text!=null && !text.isEmpty()){
|
||||
if (text!=null && !text.isBlank()){
|
||||
//String timestamp = prefix+" "+SomeCodes.GetDateTimeString();
|
||||
int fontFace = FONT_HERSHEY_SIMPLEX;
|
||||
//double fontScale = 4.0;
|
||||
@@ -791,34 +794,6 @@ 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 boolean StartLiveView(LiveCamEvent event, String cameratitle, final boolean use_qr , final boolean use_face) {
|
||||
this.event = event;
|
||||
if (mGrabber != null) {
|
||||
@@ -861,7 +836,16 @@ public class Cameradetail {
|
||||
if (fpsval!=LiveFPS){
|
||||
LiveFPS = fpsval;
|
||||
if (event!=null) event.onIntervalUpdate();
|
||||
AutoCloseAlert.ChangeCamStatus(switch (cameratitle){
|
||||
case "01" -> 1;
|
||||
case "02" -> 2;
|
||||
case "03" -> 3;
|
||||
case "04" -> 4;
|
||||
case "05" -> 5;
|
||||
default -> 0;
|
||||
}, LiveFPS>0 );
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -881,8 +865,9 @@ 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 blink_counter = 0;
|
||||
int have_eye_counter = 0;
|
||||
int no_eye_counter = 0;
|
||||
|
||||
while (Capturing.get()) {
|
||||
try {
|
||||
@@ -899,7 +884,7 @@ public class Cameradetail {
|
||||
} catch (Exception e){
|
||||
frame = null;
|
||||
|
||||
if (e.getMessage()!=null && !e.getMessage().isEmpty()){
|
||||
if (e.getMessage()!=null && !e.getMessage().isBlank()){
|
||||
String msg = e.getMessage();
|
||||
if (msg.contains("start() been called")){
|
||||
if (Capturing.get()){
|
||||
@@ -1008,13 +993,15 @@ public class Cameradetail {
|
||||
|
||||
if (theface.haveEyes()){
|
||||
// ada mata (buka mata)
|
||||
// close_eye_counter=0;
|
||||
// if (open_eye_counter<1){
|
||||
// open_eye_counter++;
|
||||
// if (have_eye_counter<1){
|
||||
// have_eye_counter++;
|
||||
// continue;
|
||||
// }
|
||||
//System.out.println("Valid Open Eyes");
|
||||
|
||||
// no_eye_counter = 0;
|
||||
//System.out.println("Valid Eye Detected from camera "+cameratitle);
|
||||
if (event!=null) event.onEyeDetector(true);
|
||||
LabelVisible(eye_indicator,true);
|
||||
// Valid eye condition
|
||||
|
||||
if (eye_state!=1){
|
||||
// transisi dari tutup mata ke buka mata
|
||||
@@ -1025,17 +1012,20 @@ public class Cameradetail {
|
||||
}
|
||||
System.out.println("Transition from close to open eyes");
|
||||
eye_state = 1;
|
||||
if (event!=null) event.onEyeDetector(true);
|
||||
|
||||
LabelVisible(eye_indicator,true);
|
||||
blink_counter++;
|
||||
if (event!=null) event.onBlink(blink_counter);
|
||||
SetText(BlinkCounterLabel, String.valueOf(blink_counter));
|
||||
|
||||
|
||||
|
||||
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 2 detik
|
||||
if (diff<=2000){
|
||||
// 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);
|
||||
if (event!=null) event.onBlink((int)diff);
|
||||
if (event!=null) event.onDoubleBlink((int)diff);
|
||||
}
|
||||
waiting_for_second_blink = false;
|
||||
} else {
|
||||
@@ -1047,17 +1037,20 @@ 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++;
|
||||
// if (no_eye_counter<1){
|
||||
// no_eye_counter++;
|
||||
// continue;
|
||||
// }
|
||||
//System.out.println("Valid Closed Eyes");
|
||||
// have_eye_counter = 0;
|
||||
//System.out.println("Valid No Eye Detected from camera "+cameratitle);
|
||||
if (event!=null) event.onEyeDetector(false);
|
||||
LabelVisible(eye_indicator,false);
|
||||
// Valid no eye condition
|
||||
|
||||
if (eye_state!=0){
|
||||
System.out.println("Transition from open to close eyes");
|
||||
eye_state = 0;
|
||||
if (event!=null) event.onEyeDetector(false);
|
||||
LabelVisible(eye_indicator,false);
|
||||
|
||||
}
|
||||
}
|
||||
} else if (have_left_45_face ){
|
||||
@@ -1065,29 +1058,35 @@ public class Cameradetail {
|
||||
if (event!=null) event.onProfileFaceDetector(true, _face_width, _face_height);
|
||||
LabelVisible(face_indicator,true);
|
||||
|
||||
|
||||
} else {
|
||||
// no face detected, but let's not cancel the previous state immediately
|
||||
|
||||
if (no_face_counter>90){
|
||||
// kalau tidak ada face selama 30 frame, reset state
|
||||
// 30 frame approximately 2 second
|
||||
if (no_face_counter<60){
|
||||
// toleransi no face selama 60 frame
|
||||
no_face_counter++;
|
||||
continue;
|
||||
} else {
|
||||
// beneran dianggap no face detected
|
||||
eye_state = -1;
|
||||
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");
|
||||
// }
|
||||
blink_counter = 0;
|
||||
no_eye_counter=0;
|
||||
have_eye_counter=0;
|
||||
|
||||
|
||||
if (event!=null) {
|
||||
event.onFrontalFaceDetector(false, _face_width, _face_height);
|
||||
event.onProfileFaceDetector(false, _face_width, _face_height);
|
||||
event.onEyeDetector(false);
|
||||
event.onBlink(blink_counter);
|
||||
SetText(BlinkCounterLabel, "");
|
||||
LabelVisible(face_indicator,false);
|
||||
LabelVisible(eye_indicator,false);
|
||||
}
|
||||
} else no_face_counter++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user