Files
ErhaCam/src/main/java/id/co/gtc/erhacam/DetectorResult.java
rdkartono d0fe8123e9 commit 27/2025
Tambah Crop Setting
2025-05-27 11:26:29 +07:00

85 lines
2.3 KiB
Java

package id.co.gtc.erhacam;
import lombok.Getter;
import lombok.Setter;
import org.bytedeco.opencv.opencv_core.Rect;
import org.bytedeco.opencv.opencv_core.Scalar;
import org.bytedeco.opencv.opencv_core.UMat;
import org.opencv.imgproc.Imgproc;
import java.util.List;
import static org.bytedeco.opencv.global.opencv_imgproc.rectangle;
@Getter
public class DetectorResult {
private @Setter Rect Face;
private List<Rect> Eyes;
private final int linethickness = 3;
private final int linetype = Imgproc.LINE_8;
private final int lineshift = 0;
public void AddEye(Rect eye){
if (Eyes == null) Eyes = new java.util.ArrayList<>();
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);
} catch (Exception ignored){}
}
}
// 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);
} catch (Exception ignored){}
}
}
}
public boolean haveFace(){
return Face != null && Face.width() > 0 && Face.height() > 0;
}
public int getFaceWidth(){
if (!haveFace()) return 0;
return Face.width();
}
public int getFaceHeight(){
if (!haveFace()) return 0;
return Face.height();
}
public boolean haveEyes(){
return Eyes != null && !Eyes.isEmpty();
}
public int getEyesCount(){
if (!haveEyes()) return 0;
return Eyes.size();
}
}