From d0c888dbc69e4092b372fdd679c47790301b0db8 Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Thu, 7 Sep 2023 16:21:37 -0400 Subject: [PATCH] Fix spotless divergence for FilterContoursPipe --- .../vision/pipe/impl/FilterContoursPipe.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/photon-core/src/main/java/org/photonvision/vision/pipe/impl/FilterContoursPipe.java b/photon-core/src/main/java/org/photonvision/vision/pipe/impl/FilterContoursPipe.java index 336dfef7a6..4c68c8e4f8 100644 --- a/photon-core/src/main/java/org/photonvision/vision/pipe/impl/FilterContoursPipe.java +++ b/photon-core/src/main/java/org/photonvision/vision/pipe/impl/FilterContoursPipe.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; - import org.opencv.core.RotatedRect; import org.photonvision.common.util.numbers.DoubleCouple; import org.photonvision.vision.frame.FrameStaticProperties; @@ -47,14 +46,15 @@ protected List process(List in) { private void rejectOutliers(List list, double xTol, double yTol) { if (list.size() < 2) return; // Must have at least 2 points to reject outliers -/* + /* spotless:off // Sort by X and find median list.sort(Comparator.comparingDouble(c -> c.getCenterPoint().x)); double medianX = list.get(list.size() / 2).getCenterPoint().x; if (list.size() % 2 == 0) medianX = (medianX + list.get(list.size() / 2 - 1).getCenterPoint().x) / 2; -*/ + */ + // spotless:on double meanX = list.stream().mapToDouble(it -> it.getCenterPoint().x).sum() / list.size(); @@ -63,14 +63,15 @@ private void rejectOutliers(List list, double xTol, double yTol) { stdDevX /= (list.size() - 1); stdDevX = Math.sqrt(stdDevX); -/* + /* spotless:off // Sort by Y and find median list.sort(Comparator.comparingDouble(c -> c.getCenterPoint().y)); double medianY = list.get(list.size() / 2).getCenterPoint().y; if (list.size() % 2 == 0) medianY = (medianY + list.get(list.size() / 2 - 1).getCenterPoint().y) / 2; -*/ + */ + // spotless:on double meanY = list.stream().mapToDouble(it -> it.getCenterPoint().y).sum() / list.size(); @@ -112,7 +113,8 @@ private void filterContour(Contour contour) { if (contourArea <= minFullness || contourArea >= maxFullness) return; // Aspect Ratio Filtering. - double aspectRatio = TargetCalculations.getAspectRatio(contour.getMinAreaRect(), params.isLandscape); + double aspectRatio = + TargetCalculations.getAspectRatio(contour.getMinAreaRect(), params.isLandscape); if (aspectRatio < params.getRatio().getFirst() || aspectRatio > params.getRatio().getSecond()) return; @@ -134,7 +136,8 @@ public FilterContoursParams( DoubleCouple extent, FrameStaticProperties camProperties, double xTol, - double yTol, boolean isLandscape) { + double yTol, + boolean isLandscape) { this.m_area = area; this.m_ratio = ratio; this.m_fullness = extent;