Example usage for org.opencv.core Size area

List of usage examples for org.opencv.core Size area

Introduction

In this page you can find the example usage for org.opencv.core Size area.

Prototype

public double area() 

Source Link

Usage

From source file:org.lasarobotics.vision.ftc.resq.BeaconScoringCOMPLEX.java

License:Open Source License

List<ScoredContour> scoreContours(List<Contour> contours, Point estimateLocation, Double estimateDistance,
        Mat rgba, Mat gray) {/* w  ww  . ja  v a2  s  .  c  om*/
    List<ScoredContour> scores = new ArrayList<>();

    for (Contour contour : contours) {
        double score = 1;

        //Find ratio - the closer it is to the actual ratio of the beacon, the better
        Size size = contour.size();
        double ratio = size.width / size.height;
        double ratioSubscore = createSubscore(ratio, Constants.CONTOUR_RATIO_BEST, Constants.CONTOUR_RATIO_NORM,
                Constants.CONTOUR_RATIO_BIAS, true);
        score *= ratioSubscore;

        //Find the area - the closer to a certain range, the better
        //We also take the log for better area comparisons
        double area = Math.log10(size.area() / imgSize.area());
        //Best value is the root mean squared of the min and max areas
        final double areaBestValue = Math.signum(Constants.CONTOUR_AREA_MIN)
                * Math.sqrt(Constants.CONTOUR_AREA_MIN * Constants.CONTOUR_AREA_MIN
                        + Constants.CONTOUR_AREA_MAX * Constants.CONTOUR_AREA_MAX)
                / 2;
        double areaSubscore = createSubscore(area, areaBestValue, Constants.CONTOUR_AREA_NORM,
                Constants.CONTOUR_AREA_BIAS, true);
        score *= areaSubscore;

        //TODO take color estimations into account

        //If score is above a value, keep the contour
        if (score >= Constants.CONTOUR_SCORE_MIN)
            scores.add(new ScoredContour(contour, score));
    }
    return scores;
}

From source file:org.lasarobotics.vision.image.Transform.java

License:Open Source License

private static void resize(Mat img, Size size) {
    int interpolation;
    if (MathUtil.equal(size.area(), img.size().area()))
        return;//  www . j ava  2s.  c  om
    else if (size.width > img.size().width && size.height > img.size().height)
        interpolation = Imgproc.CV_INTER_CUBIC; //enlarge image
    else if (size.width < img.size().width && size.height < img.size().height)
        interpolation = Imgproc.CV_INTER_AREA; //shrink image
    else
        interpolation = Imgproc.CV_INTER_LINEAR; //not entirely sure, so use safe option
    Imgproc.resize(img, img, size, 0, 0, interpolation);
}