mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-22 01:11:40 +00:00
Robot offset point (#98)
* Add offset point calculation in backend * Add pipeline result caching * Add dual offset unit test
This commit is contained in:
@@ -21,13 +21,15 @@ 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;
|
||||
import org.opencv.core.*;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.photonvision.common.util.TestUtils;
|
||||
import org.photonvision.common.util.numbers.DoubleCouple;
|
||||
import org.photonvision.vision.frame.FrameStaticProperties;
|
||||
import org.photonvision.vision.opencv.DualOffsetValues;
|
||||
|
||||
public class TargetCalculationsTest {
|
||||
|
||||
@@ -42,10 +44,10 @@ public class TargetCalculationsTest {
|
||||
new TrackedTarget.TargetCalculationParameters(
|
||||
true,
|
||||
TargetOffsetPointEdge.Center,
|
||||
new Point(),
|
||||
imageCenterPoint,
|
||||
new DoubleCouple(1.0, 0.0),
|
||||
RobotOffsetPointMode.None,
|
||||
new Point(),
|
||||
new DualOffsetValues(),
|
||||
imageCenterPoint,
|
||||
props.horizontalFocalLength,
|
||||
props.verticalFocalLength,
|
||||
imageSize.width * imageSize.height);
|
||||
@@ -173,4 +175,25 @@ public class TargetCalculationsTest {
|
||||
result = TargetCalculations.calculateSkew(isLandscape, minAreaRect);
|
||||
assertEquals(-70, result, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void robotOffsetDualTest() {
|
||||
final DualOffsetValues dualOffsetValues =
|
||||
new DualOffsetValues(
|
||||
new Point(400, 150), 10,
|
||||
new Point(390, 260), 2);
|
||||
|
||||
final Point expectedHalfway = new Point(393.75, 218.75);
|
||||
final Point expectedOutside = new Point(388.75, 273.75);
|
||||
|
||||
Point crosshairPointHalfway =
|
||||
TargetCalculations.calculateDualOffsetCrosshair(dualOffsetValues, 5);
|
||||
Point crosshairPointOutside =
|
||||
TargetCalculations.calculateDualOffsetCrosshair(dualOffsetValues, 1);
|
||||
|
||||
Assertions.assertEquals(expectedHalfway.x, crosshairPointHalfway.x);
|
||||
Assertions.assertEquals(expectedHalfway.y, crosshairPointHalfway.y);
|
||||
Assertions.assertEquals(expectedOutside.x, crosshairPointOutside.x);
|
||||
Assertions.assertEquals(expectedOutside.y, crosshairPointOutside.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfPoint;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Size;
|
||||
import org.photonvision.common.util.TestUtils;
|
||||
import org.photonvision.common.util.numbers.DoubleCouple;
|
||||
import org.photonvision.vision.opencv.Contour;
|
||||
import org.photonvision.vision.opencv.DualOffsetValues;
|
||||
|
||||
public class TrackedTargetTest {
|
||||
@BeforeEach
|
||||
@@ -38,8 +37,6 @@ public class TrackedTargetTest {
|
||||
|
||||
@Test
|
||||
void axisTest() {
|
||||
Mat background = new Mat();
|
||||
|
||||
MatOfPoint mat = new MatOfPoint();
|
||||
mat.fromList(
|
||||
List.of(
|
||||
@@ -56,10 +53,10 @@ public class TrackedTargetTest {
|
||||
new TrackedTarget.TargetCalculationParameters(
|
||||
false,
|
||||
TargetOffsetPointEdge.Center,
|
||||
new Point(0, 0),
|
||||
new Point(imageSize.width / 2, imageSize.height / 2),
|
||||
new DoubleCouple(0.0, 0.0),
|
||||
RobotOffsetPointMode.None,
|
||||
new Point(0, 0),
|
||||
new DualOffsetValues(),
|
||||
new Point(imageSize.width / 2, imageSize.height / 2),
|
||||
61,
|
||||
34.3,
|
||||
imageSize.area());
|
||||
|
||||
Reference in New Issue
Block a user