Trial 04022025

This commit is contained in:
2025-02-04 08:48:28 +07:00
parent a60fe56510
commit 29884c03ed
24 changed files with 16423 additions and 158594 deletions

View File

@@ -38,13 +38,13 @@ import java.awt.image.DataBufferByte;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import static Config.SomeCodes.*;
import static id.co.gtc.erhacam.Detectors.*;
import static org.bytedeco.opencv.global.opencv_core.CV_8UC3;
import static org.bytedeco.opencv.global.opencv_core.mean;
import static org.bytedeco.opencv.global.opencv_imgcodecs.imwrite;
@@ -60,6 +60,7 @@ public class Cameradetail {
} else {
System.out.println("CUDA is not available");
}
}
private final AtomicBoolean Capturing = new AtomicBoolean(false);
private final AtomicBoolean TakingPhoto = new AtomicBoolean(false);
@@ -684,49 +685,116 @@ public class Cameradetail {
}
}
if (use_face){
RectVector face = DetectFace(graymat);
if (face!=null && face.size()>0){
// ada muka
if (event!=null) event.onFaceDetector(true, BestSize.width(), BestSize.height());
for(int i=0; i<face.size(); i++){
Rect rect = face.get(i);
List<Rect> frontalfaces = Detectors.HaveFrontalFace(graymat);
if (!frontalfaces.isEmpty()){
if (event!=null) event.onFrontalFaceDetector(true, BestSize.width(), BestSize.height());
for(Rect rect : frontalfaces){
rectangle(LiveMat, rect, Scalar.GREEN);
}
// kalau detect muka, baru coba detect mata
RectVector eye = DetectEye(graymat);
if (eye!=null && eye.size()>=2){
// ada mata
if (eye_was_closed.get()){
eye_was_closed.set(false);
if (blink_counter.get()>=2){
blink_counter.set(0);
if (event!=null) event.onBlink(blink_counter.get());
}
}
if (event!=null) event.onEyeDetector(true, BestSize.width(), BestSize.height());
for(int i=0; i<eye.size(); i++){
Rect rect = eye.get(i);
rectangle(LiveMat, rect, Scalar.RED);
}
} else {
// mata tidak ada
if (!eye_was_closed.get()){
eye_was_closed.set(true);
blink_counter.incrementAndGet();
}
if (event!=null) event.onEyeDetector(false, BestSize.width(), BestSize.height());
}
} else {
eye_was_closed.set(false);
blink_counter.set(0);
// tidak ada muka, tidak ada mata
if (event!=null) event.onFaceDetector(false, BestSize.width(), BestSize.height());
if (event!=null) event.onEyeDetector(false, BestSize.width(), BestSize.height());
if (event!=null) event.onFrontalFaceDetector(false, BestSize.width(), BestSize.height());
}
List<Rect> Left45Faces = Detectors.HaveLeft45Face(graymat);
if (!Left45Faces.isEmpty()){
if (event!=null){
event.onLeftEyeDetector(true, BestSize.width(), BestSize.height());
event.onProfileFaceDetector(true, BestSize.width(), BestSize.height());
}
for(Rect rect : Left45Faces){
rectangle(LiveMat, rect, Scalar.BLUE);
}
} else {
if (event!=null) {
event.onLeftEyeDetector(false, BestSize.width(), BestSize.height());
event.onProfileFaceDetector(false, BestSize.width(), BestSize.height());
}
}
List<Rect> Right45Faces = Detectors.HaveRight45Face(graymat);
if (!Right45Faces.isEmpty()){
if (event!=null){
event.onRightEyeDetector(true, BestSize.width(), BestSize.height());
event.onProfileFaceDetector(true, BestSize.width(), BestSize.height());
}
for(Rect rect : Right45Faces){
rectangle(LiveMat, rect, Scalar.BLUE);
}
} else {
if (event!=null) {
event.onRightEyeDetector(false, BestSize.width(), BestSize.height());
event.onProfileFaceDetector(false, BestSize.width(), BestSize.height());
}
}
// List<Rect> Left90Faces = Detectors.HaveLeft90Face(graymat);
// if (!Left90Faces.isEmpty()){
// if (event!=null){
// event.onLeftEyeDetector(true, BestSize.width(), BestSize.height());
// event.onLeftEarDetector(true, BestSize.width(), BestSize.height());
// }
// for(Rect rect : Left90Faces){
// rectangle(LiveMat, rect, Scalar.YELLOW);
// }
// } else {
// if (event!=null) {
// event.onLeftEyeDetector(false, BestSize.width(), BestSize.height());
// event.onLeftEarDetector(false, BestSize.width(), BestSize.height());
// }
// }
//
// List<Rect> Right90Faces = Detectors.HaveRight90Face(graymat);
// if (!Right90Faces.isEmpty()){
// if (event!=null){
// event.onRightEyeDetector(true, BestSize.width(), BestSize.height());
// event.onRightEarDetector(true, BestSize.width(), BestSize.height());
// }
// for(Rect rect : Right90Faces){
// rectangle(LiveMat, rect, Scalar.YELLOW);
// }
// } else {
// if (event!=null) {
// event.onRightEyeDetector(false, BestSize.width(), BestSize.height());
// event.onRightEarDetector(false, BestSize.width(), BestSize.height());
// }
// }
// if (have_face){
// // kalau detect muka, baru coba detect mata
// RectVector eye = DetectEye(graymat);
// if (eye!=null && eye.size()>=2){
// // ada mata
// if (eye_was_closed.get()){
// eye_was_closed.set(false);
// if (blink_counter.get()>=2){
// blink_counter.set(0);
// if (event!=null) event.onBlink(blink_counter.get());
// }
// }
//
// if (event!=null) event.onEyeDetector(true, BestSize.width(), BestSize.height());
// for(int i=0; i<eye.size(); i++){
// Rect rect = eye.get(i);
// rectangle(LiveMat, rect, Scalar.RED);
// }
// } else {
// // mata tidak ada
// if (!eye_was_closed.get()){
// eye_was_closed.set(true);
// blink_counter.incrementAndGet();
// }
// if (event!=null) event.onEyeDetector(false, BestSize.width(), BestSize.height());
// }
//
// } else {
// eye_was_closed.set(false);
// blink_counter.set(0);
// // tidak ada muka, tidak ada mata
//
// }
}