Files
ErhaCam/src/main/java/id/co/gtc/erhacam/DetectorResult.java
2025-04-10 16:21:56 +07:00

66 lines
1.5 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);
}
public void FaceRectangle(UMat mat){
if (haveFace()){
rectangle(mat, Face, Scalar.GREEN, linethickness, linetype, lineshift);
}
}
public void EyesRectangle(UMat mat){
if (haveEyes()){
for(Rect eye : Eyes){
rectangle(mat, eye, Scalar.BLUE);
}
}
}
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();
}
}