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 java.util.List;

import static org.bytedeco.opencv.global.opencv_imgproc.rectangle;

@Getter
public class DetectorResult {
    private @Setter Rect Face;
    private List<Rect> Eyes;

    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);
        }
    }

    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();
    }
}
