commit 22/07/2025
This commit is contained in:
@@ -20,16 +20,23 @@ public class Detectors {
|
||||
private static Size FaceminSize;
|
||||
private static Size FacemaxSize;
|
||||
|
||||
public static void LoadAllDetectors(){
|
||||
|
||||
public Detectors(){
|
||||
LoadFrontalFaceDetector();
|
||||
LoadEyeDetector();
|
||||
|
||||
LoadProfileFaceDetector();
|
||||
|
||||
}
|
||||
|
||||
private static void LoadFrontalFaceDetector(){
|
||||
// public static void LoadAllDetectors(){
|
||||
//
|
||||
// LoadFrontalFaceDetector();
|
||||
// LoadEyeDetector();
|
||||
//
|
||||
// LoadProfileFaceDetector();
|
||||
//
|
||||
// }
|
||||
|
||||
private void LoadFrontalFaceDetector(){
|
||||
// revisi 09/05/2025, dari filename = SomeCodes.ExtractResource("/haarcascade_frontalface_default.xml");
|
||||
String filename = SomeCodes.ExtractResource("/haarcascade_frontalface_alt.xml");
|
||||
if (filename!=null) {
|
||||
@@ -46,7 +53,7 @@ public class Detectors {
|
||||
} else Logger.error("Unable to extract face detector file");
|
||||
}
|
||||
|
||||
private static void LoadProfileFaceDetector(){
|
||||
private void LoadProfileFaceDetector(){
|
||||
String filename = SomeCodes.ExtractResource("/haarcascade_profileface.xml");
|
||||
if (filename!=null) {
|
||||
Logger.info("Profile Face Detector file : " + filename);
|
||||
@@ -62,7 +69,7 @@ public class Detectors {
|
||||
} else Logger.error("Unable to extract profile face detector file");
|
||||
}
|
||||
|
||||
private static void LoadEyeDetector(){
|
||||
private void LoadEyeDetector(){
|
||||
String filename = SomeCodes.ExtractResource("/haarcascade_eye.xml");
|
||||
if (filename!=null) {
|
||||
Logger.info("Eye Detector file : " + filename);
|
||||
@@ -84,7 +91,7 @@ public class Detectors {
|
||||
* @param graymat Mat in Gray Scale
|
||||
* @return List of Rect if face detected, otherwise empty list
|
||||
*/
|
||||
public static @NonNull List<DetectorResult> HaveFrontalFace(Mat graymat){
|
||||
public @NonNull List<DetectorResult> HaveFrontalFace(Mat graymat){
|
||||
List<DetectorResult> result = new ArrayList<>();
|
||||
RectVector faces = DetectFrontalFace(graymat);
|
||||
if (faces!=null && faces.size()>0){
|
||||
@@ -106,7 +113,7 @@ public class Detectors {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static @NonNull List<DetectorResult> HaveLeft45Face(Mat graymat){
|
||||
public @NonNull List<DetectorResult> HaveLeft45Face(Mat graymat){
|
||||
List<DetectorResult> result = new ArrayList<>();
|
||||
RectVector faces = DetectProfileFace(graymat);
|
||||
if (faces!=null && faces.size()>0){
|
||||
@@ -129,11 +136,11 @@ public class Detectors {
|
||||
|
||||
|
||||
|
||||
public static void setScaleFactor(double value){
|
||||
public void setScaleFactor(double value){
|
||||
if (scaleFactor!=value) scaleFactor = value;
|
||||
}
|
||||
|
||||
public static void setFaceMinSize(int value){
|
||||
public void setFaceMinSize(int value){
|
||||
if (FaceminSize!=null){
|
||||
if (FaceminSize.width()!=value || FaceminSize.height()!=value) {
|
||||
FaceminSize = new Size(value, value);
|
||||
@@ -146,7 +153,7 @@ public class Detectors {
|
||||
|
||||
}
|
||||
|
||||
public static void setFaceMaxSize(int value){
|
||||
public void setFaceMaxSize(int value){
|
||||
if (FacemaxSize!=null){
|
||||
if (FacemaxSize.width()!=value || FacemaxSize.height()!=value) {
|
||||
FacemaxSize = new Size(value, value);
|
||||
@@ -160,7 +167,7 @@ public class Detectors {
|
||||
}
|
||||
|
||||
|
||||
public static RectVector DetectProfileFace(Mat graymat){
|
||||
public RectVector DetectProfileFace(Mat graymat){
|
||||
return Detect(graymat, profilefaceDetector, scaleFactor, minNeighbors, flags, FaceminSize, FacemaxSize);
|
||||
}
|
||||
|
||||
@@ -169,7 +176,7 @@ public class Detectors {
|
||||
* @param graymat Mat in Gray Scale
|
||||
* @return RectVector if face detected, otherwise null
|
||||
*/
|
||||
public static RectVector DetectFrontalFace(Mat graymat){
|
||||
public RectVector DetectFrontalFace(Mat graymat){
|
||||
return Detect(graymat, frontalfaceDetector, scaleFactor, minNeighbors, flags, FaceminSize, FacemaxSize);
|
||||
}
|
||||
|
||||
@@ -179,7 +186,7 @@ public class Detectors {
|
||||
* @param graymat Mat in Gray Scale
|
||||
* @return RectVector if eye detected, otherwise null
|
||||
*/
|
||||
public static RectVector DetectEye(Mat graymat, int facewidth){
|
||||
public RectVector DetectEye(Mat graymat, int facewidth){
|
||||
//return Detect(graymat, eyeDetector);
|
||||
int minwidth = (int)(facewidth*0.2);
|
||||
int maxwidth = (int)(facewidth*0.4);
|
||||
@@ -189,7 +196,7 @@ public class Detectors {
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static RectVector Detect(Mat graymat, CascadeClassifier detector, double scaleFactor, int minNeighbors, int flags, Size minSize, Size maxSize){
|
||||
private 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){
|
||||
|
||||
Reference in New Issue
Block a user