Skip to content

Commit

Permalink
Fix spotless divergence for FilterContoursPipe
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Sep 7, 2023
1 parent 306677e commit d0c888d
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,14 +46,15 @@ protected List<Contour> process(List<Contour> in) {
private void rejectOutliers(List<Contour> 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();

Expand All @@ -63,14 +63,15 @@ private void rejectOutliers(List<Contour> 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();

Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit d0c888d

Please sign in to comment.