mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-24 01:31:44 +00:00
Use WPILib Pair and drop dependency on Apache Commons Pair
This allowed us to drop a few Apache Commons dependencies, which is good for reducing JAR size and the number of things we need to pull in.
This commit is contained in:
@@ -17,14 +17,13 @@
|
||||
|
||||
package org.photonvision.common.logging;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
// import org.photonvision.common.configuration.ConfigManager;
|
||||
import org.photonvision.common.configuration.PathManager;
|
||||
import org.photonvision.common.dataflow.DataChangeService;
|
||||
import org.photonvision.common.dataflow.events.OutgoingUIEvent;
|
||||
@@ -194,7 +193,7 @@ public class Logger {
|
||||
connected = true;
|
||||
synchronized (uiBacklog) {
|
||||
for (var message : uiBacklog) {
|
||||
uiLogAppender.log(message.getLeft(), message.getRight());
|
||||
uiLogAppender.log(message.getFirst(), message.getSecond());
|
||||
}
|
||||
uiBacklog.clear();
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
package org.photonvision.vision.pipe.impl;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
@@ -40,7 +40,7 @@ public class Draw2dCrosshairPipe
|
||||
protected Void process(Pair<Mat, List<TrackedTarget>> in) {
|
||||
if (!params.shouldDraw()) return null;
|
||||
|
||||
var image = in.getLeft();
|
||||
var image = in.getFirst();
|
||||
|
||||
if (params.showCrosshair()) {
|
||||
double x = params.frameStaticProperties().centerX;
|
||||
@@ -57,8 +57,8 @@ public class Draw2dCrosshairPipe
|
||||
}
|
||||
}
|
||||
case Dual -> {
|
||||
if (!in.getRight().isEmpty()) {
|
||||
var target = in.getRight().get(0);
|
||||
if (!in.getSecond().isEmpty()) {
|
||||
var target = in.getSecond().get(0);
|
||||
if (target != null) {
|
||||
var area = target.getArea();
|
||||
var offsetCrosshair =
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
package org.photonvision.vision.pipe.impl;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.opencv.core.*;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
@@ -39,15 +39,15 @@ public class Draw2dTargetsPipe
|
||||
|
||||
@Override
|
||||
protected Void process(Pair<Mat, List<TrackedTarget>> in) {
|
||||
var imRows = in.getLeft().rows();
|
||||
var imCols = in.getLeft().cols();
|
||||
var imRows = in.getFirst().rows();
|
||||
var imCols = in.getFirst().cols();
|
||||
var imageSize = Math.sqrt(imRows * imCols);
|
||||
var textSize = params.kPixelsToText * imageSize;
|
||||
var thickness = params.kPixelsToThickness * imageSize;
|
||||
|
||||
if (!params.shouldDraw) return null;
|
||||
|
||||
if (!in.getRight().isEmpty()
|
||||
if (!in.getSecond().isEmpty()
|
||||
&& (params.showCentroid
|
||||
|| params.showMaximumBox
|
||||
|| params.showRotatedBox
|
||||
@@ -58,7 +58,7 @@ public class Draw2dTargetsPipe
|
||||
var circleColor = ColorHelper.colorToScalar(params.circleColor);
|
||||
var shapeColour = ColorHelper.colorToScalar(params.shapeOutlineColour);
|
||||
|
||||
for (int i = 0; i < (params.showMultipleTargets ? in.getRight().size() : 1); i++) {
|
||||
for (int i = 0; i < (params.showMultipleTargets ? in.getSecond().size() : 1); i++) {
|
||||
Point[] vertices = new Point[4];
|
||||
MatOfPoint contour = new MatOfPoint();
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Draw2dTargetsPipe
|
||||
break;
|
||||
}
|
||||
|
||||
TrackedTarget target = in.getRight().get(i);
|
||||
TrackedTarget target = in.getSecond().get(i);
|
||||
RotatedRect r = target.getMinAreaRect();
|
||||
|
||||
if (r == null) continue;
|
||||
@@ -77,14 +77,14 @@ public class Draw2dTargetsPipe
|
||||
|
||||
if (params.shouldShowRotatedBox(target.getShape())) {
|
||||
Imgproc.drawContours(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
List.of(contour),
|
||||
0,
|
||||
rotatedBoxColour,
|
||||
(int) Math.ceil(imageSize * params.kPixelsToBoxThickness));
|
||||
} else if (params.shouldShowCircle(target.getShape())) {
|
||||
Imgproc.circle(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
target.getShape().center,
|
||||
(int) target.getShape().radius,
|
||||
circleColor,
|
||||
@@ -101,7 +101,7 @@ public class Draw2dTargetsPipe
|
||||
mat.fromArray(poly.toArray());
|
||||
divideMat(mat, mat);
|
||||
Imgproc.drawContours(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
List.of(mat),
|
||||
-1,
|
||||
ColorHelper.colorToScalar(params.rotatedBoxColor),
|
||||
@@ -113,7 +113,7 @@ public class Draw2dTargetsPipe
|
||||
if (params.showMaximumBox) {
|
||||
Rect box = Imgproc.boundingRect(contour);
|
||||
Imgproc.rectangle(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
new Point(box.x, box.y),
|
||||
new Point(box.x + box.width, box.y + box.height),
|
||||
maximumBoxColour,
|
||||
@@ -123,7 +123,7 @@ public class Draw2dTargetsPipe
|
||||
if (params.showShape) {
|
||||
divideMat(target.m_mainContour.mat, tempMat);
|
||||
Imgproc.drawContours(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
List.of(tempMat),
|
||||
-1,
|
||||
shapeColour,
|
||||
@@ -142,7 +142,7 @@ public class Draw2dTargetsPipe
|
||||
var contourNumber = String.valueOf(id == -1 ? i : id);
|
||||
|
||||
Imgproc.putText(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
contourNumber,
|
||||
textPos,
|
||||
0,
|
||||
@@ -163,13 +163,13 @@ public class Draw2dTargetsPipe
|
||||
Point yMin = new Point(x, y - crosshairRadius);
|
||||
|
||||
Imgproc.line(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
xMax,
|
||||
xMin,
|
||||
centroidColour,
|
||||
(int) Math.ceil(imageSize * params.kPixelsToBoxThickness));
|
||||
Imgproc.line(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
yMax,
|
||||
yMin,
|
||||
centroidColour,
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
package org.photonvision.vision.pipe.impl;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.opencv.calib3d.Calib3d;
|
||||
import org.opencv.core.*;
|
||||
import org.opencv.core.Point;
|
||||
@@ -47,7 +47,7 @@ public class Draw3dTargetsPipe
|
||||
return null;
|
||||
}
|
||||
|
||||
for (var target : in.getRight()) {
|
||||
for (var target : in.getSecond()) {
|
||||
// draw convex hull
|
||||
if (params.shouldDrawHull(target)) {
|
||||
var pointMat = new MatOfPoint();
|
||||
@@ -59,14 +59,14 @@ public class Draw3dTargetsPipe
|
||||
continue;
|
||||
}
|
||||
Imgproc.drawContours(
|
||||
in.getLeft(), List.of(pointMat), -1, ColorHelper.colorToScalar(Color.green), 1);
|
||||
in.getFirst(), List.of(pointMat), -1, ColorHelper.colorToScalar(Color.green), 1);
|
||||
|
||||
// draw approximate polygon
|
||||
var poly = target.getApproximateBoundingPolygon();
|
||||
if (poly != null) {
|
||||
divideMat2f(poly, pointMat);
|
||||
Imgproc.drawContours(
|
||||
in.getLeft(), List.of(pointMat), -1, ColorHelper.colorToScalar(Color.blue), 2);
|
||||
in.getFirst(), List.of(pointMat), -1, ColorHelper.colorToScalar(Color.blue), 2);
|
||||
}
|
||||
pointMat.release();
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class Draw3dTargetsPipe
|
||||
// floor, then pillars, then top
|
||||
for (int i = 0; i < bottomPoints.size(); i++) {
|
||||
Imgproc.line(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
bottomPoints.get(i),
|
||||
bottomPoints.get((i + 1) % (bottomPoints.size())),
|
||||
ColorHelper.colorToScalar(Color.green),
|
||||
@@ -167,21 +167,21 @@ public class Draw3dTargetsPipe
|
||||
// XYZ is RGB
|
||||
// y-axis = green
|
||||
Imgproc.line(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
axisPoints.get(0),
|
||||
axisPoints.get(2),
|
||||
ColorHelper.colorToScalar(Color.GREEN),
|
||||
3);
|
||||
// z-axis = blue
|
||||
Imgproc.line(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
axisPoints.get(0),
|
||||
axisPoints.get(3),
|
||||
ColorHelper.colorToScalar(Color.BLUE),
|
||||
3);
|
||||
// x-axis = red
|
||||
Imgproc.line(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
axisPoints.get(0),
|
||||
axisPoints.get(1),
|
||||
ColorHelper.colorToScalar(Color.RED),
|
||||
@@ -190,7 +190,7 @@ public class Draw3dTargetsPipe
|
||||
// box edges perpendicular to tag
|
||||
for (int i = 0; i < bottomPoints.size(); i++) {
|
||||
Imgproc.line(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
bottomPoints.get(i),
|
||||
topPoints.get(i),
|
||||
ColorHelper.colorToScalar(Color.blue),
|
||||
@@ -199,7 +199,7 @@ public class Draw3dTargetsPipe
|
||||
// box edges parallel to tag
|
||||
for (int i = 0; i < topPoints.size(); i++) {
|
||||
Imgproc.line(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
topPoints.get(i),
|
||||
topPoints.get((i + 1) % (bottomPoints.size())),
|
||||
ColorHelper.colorToScalar(Color.orange),
|
||||
@@ -219,7 +219,7 @@ public class Draw3dTargetsPipe
|
||||
var y = corner.y / (double) params.divisor.value;
|
||||
|
||||
Imgproc.circle(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
new Point(x, y),
|
||||
params.radius,
|
||||
ColorHelper.colorToScalar(params.color),
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
package org.photonvision.vision.pipe.impl;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
@@ -44,7 +44,7 @@ public class DrawCalibrationPipe
|
||||
protected Void process(Pair<Mat, List<TrackedTarget>> in) {
|
||||
if (!params.drawAllSnapshots()) return null;
|
||||
|
||||
var image = in.getLeft();
|
||||
var image = in.getFirst();
|
||||
|
||||
var imgSz = image.size();
|
||||
var diag = Math.hypot(imgSz.width, imgSz.height);
|
||||
@@ -55,7 +55,7 @@ public class DrawCalibrationPipe
|
||||
int thickness = (int) Math.max(diag * 1.0 / 600.0, 1);
|
||||
|
||||
int i = 0;
|
||||
for (var target : in.getRight()) {
|
||||
for (var target : in.getSecond()) {
|
||||
for (var c : target.getTargetCorners()) {
|
||||
if (c.x < 0 || c.y < 0) {
|
||||
// Skip if the corner is less than zero
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
|
||||
package org.photonvision.vision.pipe.impl;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.opencv.calib3d.Calib3d;
|
||||
import org.opencv.core.*;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
@@ -244,8 +244,8 @@ public class FindBoardCornersPipe
|
||||
var objPts = new MatOfPoint3f();
|
||||
var outBoardCorners = new MatOfPoint2f();
|
||||
|
||||
var inFrame = in.getLeft();
|
||||
var outFrame = in.getRight();
|
||||
var inFrame = in.getFirst();
|
||||
var outFrame = in.getSecond();
|
||||
|
||||
// Convert the inFrame too grayscale to increase contrast
|
||||
Imgproc.cvtColor(inFrame, inFrame, Imgproc.COLOR_BGR2GRAY);
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
package org.photonvision.vision.pipe.impl;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
@@ -54,7 +54,7 @@ public class FindCirclesPipe
|
||||
var maxRadius = (int) (params.maxRadius() * diag / 100.0);
|
||||
|
||||
Imgproc.HoughCircles(
|
||||
in.getLeft(),
|
||||
in.getFirst(),
|
||||
circles,
|
||||
// Detection method, see #HoughModes. The available methods are #HOUGH_GRADIENT and
|
||||
// #HOUGH_GRADIENT_ALT.
|
||||
@@ -76,7 +76,7 @@ public class FindCirclesPipe
|
||||
// only match against them
|
||||
// This does mean that contours closer than allowableThreshold aren't matched to anything if
|
||||
// there's a 'better' option
|
||||
var unmatchedContours = in.getRight();
|
||||
var unmatchedContours = in.getSecond();
|
||||
for (int x = 0; x < circles.cols(); x++) {
|
||||
// Grab the current circle we are looking at
|
||||
double[] c = circles.get(0, x);
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
|
||||
package org.photonvision.vision.pipeline;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import edu.wpi.first.math.util.Units;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.photonvision.common.dataflow.DataChangeService;
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
|
||||
package org.photonvision.vision.pipeline;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.opencv.core.Point;
|
||||
import org.photonvision.vision.frame.Frame;
|
||||
import org.photonvision.vision.frame.FrameThresholdType;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package org.photonvision.vision.pipeline;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.photonvision.common.util.math.MathUtils;
|
||||
import org.photonvision.vision.frame.Frame;
|
||||
import org.photonvision.vision.frame.FrameThresholdType;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package org.photonvision.vision.pipeline;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.photonvision.vision.frame.Frame;
|
||||
import org.photonvision.vision.frame.FrameStaticProperties;
|
||||
import org.photonvision.vision.opencv.DualOffsetValues;
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
package org.photonvision.vision.processes;
|
||||
|
||||
import edu.wpi.first.math.Pair;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.opencv.core.Point;
|
||||
import org.photonvision.common.dataflow.DataChangeSubscriber;
|
||||
import org.photonvision.common.dataflow.events.DataChangeEvent;
|
||||
@@ -173,8 +173,8 @@ public class VisionModuleChangeSubscriber extends DataChangeSubscriber {
|
||||
}
|
||||
|
||||
public void newPipelineInfo(Pair<String, PipelineType> typeName) {
|
||||
var type = typeName.getRight();
|
||||
var name = typeName.getLeft();
|
||||
var type = typeName.getSecond();
|
||||
var name = typeName.getFirst();
|
||||
|
||||
logger.info("Adding a " + type + " pipeline with name " + name);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.photonvision.server;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import edu.wpi.first.math.Pair;
|
||||
import io.javalin.websocket.WsBinaryMessageContext;
|
||||
import io.javalin.websocket.WsCloseContext;
|
||||
import io.javalin.websocket.WsConnectContext;
|
||||
@@ -33,7 +34,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.msgpack.jackson.dataformat.MessagePackFactory;
|
||||
import org.photonvision.common.dataflow.DataChangeDestination;
|
||||
import org.photonvision.common.dataflow.DataChangeService;
|
||||
|
||||
@@ -44,8 +44,6 @@ dependencies {
|
||||
|
||||
implementation "commons-io:commons-io:2.11.0"
|
||||
implementation "commons-cli:commons-cli:1.5.0"
|
||||
implementation "org.apache.commons:commons-lang3:3.12.0"
|
||||
implementation "org.apache.commons:commons-collections4:4.4"
|
||||
implementation "org.apache.commons:commons-exec:1.3"
|
||||
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
|
||||
|
||||
Reference in New Issue
Block a user