mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-29 02:21:41 +00:00
Cleanup photonlib deps (#243)
Removes unnecessary photonlib dependencies and removes commons-math.
This commit is contained in:
@@ -18,13 +18,12 @@
|
||||
package org.photonvision.common.util.math;
|
||||
|
||||
import edu.wpi.first.wpiutil.WPIUtilJNI;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
public class MathUtils {
|
||||
MathUtils() {}
|
||||
|
||||
public static double toSlope(Number angle) {
|
||||
return FastMath.atan(FastMath.toRadians(angle.doubleValue() - 90));
|
||||
return Math.atan(Math.toRadians(angle.doubleValue() - 90));
|
||||
}
|
||||
|
||||
public static int safeDivide(int quotient, int divisor) {
|
||||
|
||||
@@ -19,8 +19,6 @@ package org.photonvision.vision.frame;
|
||||
|
||||
import edu.wpi.cscore.VideoMode;
|
||||
import edu.wpi.first.wpilibj.geometry.Rotation2d;
|
||||
import org.apache.commons.math3.fraction.Fraction;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.opencv.core.Point;
|
||||
import org.photonvision.common.util.numbers.DoubleCouple;
|
||||
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
|
||||
@@ -79,23 +77,20 @@ public class FrameStaticProperties {
|
||||
DoubleCouple horizVertViews =
|
||||
calculateHorizontalVerticalFoV(this.fov, this.imageWidth, this.imageHeight);
|
||||
|
||||
horizontalFocalLength = this.imageWidth / (2 * FastMath.tan(horizVertViews.getFirst() / 2));
|
||||
verticalFocalLength = this.imageHeight / (2 * FastMath.tan(horizVertViews.getSecond() / 2));
|
||||
horizontalFocalLength = this.imageWidth / (2 * Math.tan(horizVertViews.getFirst() / 2));
|
||||
verticalFocalLength = this.imageHeight / (2 * Math.tan(horizVertViews.getSecond() / 2));
|
||||
}
|
||||
|
||||
public static DoubleCouple calculateHorizontalVerticalFoV(
|
||||
double diagonalFoV, int imageWidth, int imageHeight) {
|
||||
double diagonalView = FastMath.toRadians(diagonalFoV);
|
||||
Fraction aspectFraction = new Fraction(imageWidth, imageHeight);
|
||||
|
||||
int horizontalRatio = aspectFraction.getNumerator();
|
||||
int verticalRatio = aspectFraction.getDenominator();
|
||||
double diagonalView = Math.toRadians(diagonalFoV);
|
||||
double diagonalAspect = Math.hypot(imageWidth, imageHeight);
|
||||
|
||||
double diagonalAspect = FastMath.hypot(horizontalRatio, verticalRatio);
|
||||
double horizontalView =
|
||||
FastMath.atan(FastMath.tan(diagonalView / 2) * (horizontalRatio / diagonalAspect)) * 2;
|
||||
Math.atan(Math.tan(diagonalView / 2) * (imageWidth / diagonalAspect)) * 2;
|
||||
double verticalView =
|
||||
FastMath.atan(FastMath.tan(diagonalView / 2) * (verticalRatio / diagonalAspect)) * 2;
|
||||
Math.atan(Math.tan(diagonalView / 2) * (imageHeight / diagonalAspect)) * 2;
|
||||
|
||||
return new DoubleCouple(horizontalView, verticalView);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package org.photonvision.vision.opencv;
|
||||
|
||||
import java.util.Comparator;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.photonvision.vision.target.PotentialTarget;
|
||||
|
||||
public enum ContourSortMode {
|
||||
@@ -33,8 +32,8 @@ public enum ContourSortMode {
|
||||
Centermost(
|
||||
Comparator.comparingDouble(
|
||||
rect ->
|
||||
(FastMath.pow(rect.getMinAreaRect().center.y, 2)
|
||||
+ FastMath.pow(rect.getMinAreaRect().center.x, 2))));
|
||||
(Math.pow(rect.getMinAreaRect().center.y, 2)
|
||||
+ Math.pow(rect.getMinAreaRect().center.x, 2))));
|
||||
|
||||
private Comparator<PotentialTarget> m_comparator;
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.opencv.core.MatOfPoint2f;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
@@ -96,7 +95,7 @@ public class CornerDetectionPipe
|
||||
* @return The straight line distance between them.
|
||||
*/
|
||||
private static double distanceBetween(Point a, Point b) {
|
||||
return FastMath.sqrt(FastMath.pow(a.x - b.x, 2) + FastMath.pow(a.y - b.y, 2));
|
||||
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,8 +104,7 @@ public class CornerDetectionPipe
|
||||
* @return The straight line distance between them.
|
||||
*/
|
||||
private static double distanceBetween(Translation2d a, Translation2d b) {
|
||||
return FastMath.sqrt(
|
||||
FastMath.pow(a.getX() - b.getX(), 2) + FastMath.pow(a.getY() - b.getY(), 2));
|
||||
return Math.sqrt(Math.pow(a.getX() - b.getX(), 2) + Math.pow(a.getY() - b.getY(), 2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,8 +119,7 @@ public class CornerDetectionPipe
|
||||
Comparator<Point> distanceProvider =
|
||||
Comparator.comparingDouble(
|
||||
(Point point) ->
|
||||
FastMath.sqrt(
|
||||
FastMath.pow(centroid.x - point.x, 2) + FastMath.pow(centroid.y - point.y, 2)));
|
||||
Math.sqrt(Math.pow(centroid.x - point.x, 2) + Math.pow(centroid.y - point.y, 2)));
|
||||
|
||||
MatOfPoint2f targetContour;
|
||||
if (convexHull) {
|
||||
|
||||
@@ -21,7 +21,6 @@ import edu.wpi.first.wpilibj.geometry.Rotation2d;
|
||||
import edu.wpi.first.wpilibj.geometry.Transform2d;
|
||||
import edu.wpi.first.wpilibj.geometry.Translation2d;
|
||||
import java.util.List;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.opencv.calib3d.Calib3d;
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.Mat;
|
||||
@@ -117,8 +116,7 @@ public class SolvePNPPipe
|
||||
// Z distance in the flat plane is given by
|
||||
// Z_field = z cos theta + y sin theta.
|
||||
// Z is the distance "out" of the camera (straight forward).
|
||||
var zField =
|
||||
tVec.get(2, 0)[0] * FastMath.cos(tiltAngle) + tVec.get(1, 0)[0] * FastMath.sin(tiltAngle);
|
||||
var zField = tVec.get(2, 0)[0] * Math.cos(tiltAngle) + tVec.get(1, 0)[0] * Math.sin(tiltAngle);
|
||||
|
||||
Calib3d.Rodrigues(rVec, rotationMatrix);
|
||||
Core.transpose(rotationMatrix, inverseRotationMatrix);
|
||||
@@ -128,7 +126,7 @@ public class SolvePNPPipe
|
||||
Core.gemm(inverseRotationMatrix, scaledTvec, 1, kMat, 0, pzeroWorld);
|
||||
scaledTvec.release();
|
||||
|
||||
var angle2 = FastMath.atan2(pzeroWorld.get(0, 0)[0], pzeroWorld.get(2, 0)[0]);
|
||||
var angle2 = Math.atan2(pzeroWorld.get(0, 0)[0], pzeroWorld.get(2, 0)[0]);
|
||||
|
||||
// target rotation is the rotation of the target relative to straight ahead. this number
|
||||
// should be unchanged if the robot purely translated left/right.
|
||||
|
||||
@@ -20,7 +20,6 @@ package org.photonvision.vision.pipe.impl;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.photonvision.vision.frame.FrameStaticProperties;
|
||||
import org.photonvision.vision.opencv.ContourSortMode;
|
||||
import org.photonvision.vision.pipe.CVPipe;
|
||||
@@ -53,9 +52,9 @@ public class SortContoursPipe
|
||||
}
|
||||
|
||||
private double calcSquareCenterDistance(PotentialTarget rect) {
|
||||
return FastMath.sqrt(
|
||||
FastMath.pow(params.getCamProperties().centerX - rect.getMinAreaRect().center.x, 2)
|
||||
+ FastMath.pow(params.getCamProperties().centerY - rect.getMinAreaRect().center.y, 2));
|
||||
return Math.sqrt(
|
||||
Math.pow(params.getCamProperties().centerX - rect.getMinAreaRect().center.x, 2)
|
||||
+ Math.pow(params.getCamProperties().centerY - rect.getMinAreaRect().center.y, 2));
|
||||
}
|
||||
|
||||
public static class SortContoursParams {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
package org.photonvision.vision.target;
|
||||
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.RotatedRect;
|
||||
import org.photonvision.common.util.math.MathUtils;
|
||||
@@ -27,14 +26,12 @@ import org.photonvision.vision.opencv.DualOffsetValues;
|
||||
public class TargetCalculations {
|
||||
public static double calculateYaw(
|
||||
double offsetCenterX, double targetCenterX, double horizontalFocalLength) {
|
||||
return FastMath.toDegrees(
|
||||
FastMath.atan((offsetCenterX - targetCenterX) / horizontalFocalLength));
|
||||
return Math.toDegrees(Math.atan((offsetCenterX - targetCenterX) / horizontalFocalLength));
|
||||
}
|
||||
|
||||
public static double calculatePitch(
|
||||
double offsetCenterY, double targetCenterY, double verticalFocalLength) {
|
||||
return -FastMath.toDegrees(
|
||||
FastMath.atan((offsetCenterY - targetCenterY) / verticalFocalLength));
|
||||
return -Math.toDegrees(Math.atan((offsetCenterY - targetCenterY) / verticalFocalLength));
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
|
||||
@@ -20,7 +20,6 @@ package org.photonvision.vision.target;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import edu.wpi.first.wpilibj.geometry.Rotation2d;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -70,7 +69,7 @@ public class TargetCalculationsTest {
|
||||
TargetCalculations.calculateYaw(
|
||||
imageCenterPoint.x, targetCenterPoint.x, params.horizontalFocalLength);
|
||||
|
||||
assertEquals(FastMath.toDegrees(trueYaw), yaw, 0.025, "Yaw not as expected");
|
||||
assertEquals(Math.toDegrees(trueYaw), yaw, 0.025, "Yaw not as expected");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +84,7 @@ public class TargetCalculationsTest {
|
||||
TargetCalculations.calculatePitch(
|
||||
imageCenterPoint.y, targetCenterPoint.y, params.verticalFocalLength);
|
||||
|
||||
assertEquals(FastMath.toDegrees(truePitch) * -1, pitch, 0.025, "Pitch not as expected");
|
||||
assertEquals(Math.toDegrees(truePitch) * -1, pitch, 0.025, "Pitch not as expected");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,8 +180,8 @@ public class TargetCalculationsTest {
|
||||
public void testCameraFOVCalculation() {
|
||||
final DoubleCouple glowormHorizVert =
|
||||
FrameStaticProperties.calculateHorizontalVerticalFoV(74.8, 640, 480);
|
||||
var gwHorizDeg = FastMath.toDegrees(glowormHorizVert.getFirst());
|
||||
var gwVertDeg = FastMath.toDegrees(glowormHorizVert.getSecond());
|
||||
var gwHorizDeg = Math.toDegrees(glowormHorizVert.getFirst());
|
||||
var gwVertDeg = Math.toDegrees(glowormHorizVert.getSecond());
|
||||
assertEquals(62.7, gwHorizDeg, .3);
|
||||
assertEquals(49, gwVertDeg, .3);
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ test {
|
||||
|
||||
// Apply Java configuration
|
||||
dependencies {
|
||||
compile project(":photon-core")
|
||||
compile project(":photon-targeting")
|
||||
|
||||
// WPILib non-JNI dependencies
|
||||
implementation "edu.wpi.first.cscore:cscore-java:$wpilibVersion"
|
||||
implementation "edu.wpi.first.cameraserver:cameraserver-java:$wpilibVersion"
|
||||
implementation "edu.wpi.first.wpilibj:wpilibj-java:$wpilibVersion"
|
||||
@@ -21,8 +21,16 @@ dependencies {
|
||||
implementation "edu.wpi.first.wpimath:wpimath-java:$wpilibVersion"
|
||||
implementation "edu.wpi.first.hal:hal-java:$wpilibVersion"
|
||||
implementation "edu.wpi.first.thirdparty.frc2020.opencv:opencv-java:3.4.7-2"
|
||||
implementation "edu.wpi.first.ntcore:ntcore-java:$wpilibVersion"
|
||||
|
||||
// NTCore
|
||||
implementation "edu.wpi.first.ntcore:ntcore-java:$wpilibVersion"
|
||||
compile "edu.wpi.first.ntcore:ntcore-jni:$wpilibVersion:linuxaarch64bionic"
|
||||
compile "edu.wpi.first.ntcore:ntcore-jni:$wpilibVersion:linuxraspbian"
|
||||
compile "edu.wpi.first.ntcore:ntcore-jni:$wpilibVersion:linuxx86-64"
|
||||
compile "edu.wpi.first.ntcore:ntcore-jni:$wpilibVersion:osxx86-64"
|
||||
compile "edu.wpi.first.ntcore:ntcore-jni:$wpilibVersion:windowsx86-64"
|
||||
|
||||
// Junit
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.2")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-params:5.6.2")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.2")
|
||||
|
||||
@@ -2,9 +2,6 @@ apply plugin: "java"
|
||||
|
||||
dependencies {
|
||||
implementation "edu.wpi.first.wpimath:wpimath-java:$wpilibVersion"
|
||||
implementation "com.fasterxml.jackson.core:jackson-core:2.10.0"
|
||||
implementation "com.fasterxml.jackson.core:jackson-annotations:2.10.0"
|
||||
implementation "org.apache.commons:commons-math3:3.6.1"
|
||||
}
|
||||
|
||||
java {
|
||||
|
||||
@@ -12,7 +12,6 @@ dependencies {
|
||||
|
||||
// Apache commons
|
||||
implementation group: "org.apache.commons", name: "commons-lang3", version: "3.9"
|
||||
implementation "org.apache.commons:commons-math3:3.6.1"
|
||||
implementation group: "commons-io", name: "commons-io", version: "2.6"
|
||||
implementation group: "commons-cli", name: "commons-cli", version: "1.4"
|
||||
implementation "org.apache.commons:commons-collections4:4.4"
|
||||
|
||||
Reference in New Issue
Block a user