Skip to content

Commit

Permalink
Fix spotless divergence for FilterContoursPipe (#908)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt <[email protected]>
  • Loading branch information
rzblue and mcm001 committed Sep 12, 2023
1 parent 6e8e379 commit 9f3a735
Showing 1 changed file with 4 additions and 21 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,31 +46,13 @@ 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

/*
// 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;
*/

double meanX = list.stream().mapToDouble(it -> it.getCenterPoint().x).sum() / list.size();

double stdDevX =
list.stream().mapToDouble(it -> Math.pow(it.getCenterPoint().x - meanX, 2.0)).sum();
stdDevX /= (list.size() - 1);
stdDevX = Math.sqrt(stdDevX);

/*
// 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;
*/

double meanY = list.stream().mapToDouble(it -> it.getCenterPoint().y).sum() / list.size();

double stdDevY =
Expand Down Expand Up @@ -112,7 +93,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 +116,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 9f3a735

Please sign in to comment.