Package org.hyperonline.hyperlib.vision
Class ClosestPairTargetProcessor
- java.lang.Object
-
- org.hyperonline.hyperlib.vision.AbstractTargetProcessor<TargetWithHeightResult>
-
- org.hyperonline.hyperlib.vision.ClosestPairTargetProcessor
-
- All Implemented Interfaces:
TargetProcessor
public class ClosestPairTargetProcessor extends AbstractTargetProcessor<TargetWithHeightResult>
Target processor which finds the closest two targets to the crosshairs, and averages their position. This is the algorithm that was used to track the boiler in the 2017 steamworks game. It can more generally be applied to anything that's two pieces of tape. This processor uses the height of the targets to measure distance. However, it computes x, y, and height all as simple averages, rather than weighting by depth. This is a good approximation as long as one target is not significantly closer than the other, meaning the camera is not viewing the target from a steep angle.
-
-
Constructor Summary
Constructors Constructor Description ClosestPairTargetProcessor(int xCrosshairs, int yCrosshairs)
Construct a new target processor with the given fixed crosshairs position.ClosestPairTargetProcessor(java.util.function.IntSupplier xCrosshairs, java.util.function.IntSupplier yCrosshairs)
Construct a new target processor which reads crosshairs position from the given functions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TargetWithHeightResult
computeResult(java.util.List<org.opencv.core.Rect> targets)
TargetWithHeightResult
getDefaultValue()
edu.wpi.first.wpilibj.PIDSource
heightPID()
Get a PID source that returns the height of the target.void
writeOutput(org.opencv.core.Mat mat)
Draw overlays on the image.-
Methods inherited from class org.hyperonline.hyperlib.vision.AbstractTargetProcessor
getLastResult, process, xPID, yPID
-
-
-
-
Constructor Detail
-
ClosestPairTargetProcessor
public ClosestPairTargetProcessor(int xCrosshairs, int yCrosshairs)
Construct a new target processor with the given fixed crosshairs position.- Parameters:
xCrosshairs
- X coordinate for the crosshairsyCrosshairs
- Y coordinate for the crosshairs
-
ClosestPairTargetProcessor
public ClosestPairTargetProcessor(java.util.function.IntSupplier xCrosshairs, java.util.function.IntSupplier yCrosshairs)
Construct a new target processor which reads crosshairs position from the given functions. The most common use case would be to passIntPreference.get()
. Whatever you pass must be safe to call from the vision thread, so it should not reference the internals of commands, subsystems, or other robot code. Note that preferences are safe to access from any thread.- Parameters:
xCrosshairs
- X coordinate for the crosshairsyCrosshairs
- Y coordinate for the crosshairs
-
-
Method Detail
-
computeResult
public TargetWithHeightResult computeResult(java.util.List<org.opencv.core.Rect> targets)
- Specified by:
computeResult
in classAbstractTargetProcessor<TargetWithHeightResult>
- Parameters:
targets
- list of targets to compute- Returns:
- {T}
-
heightPID
public edu.wpi.first.wpilibj.PIDSource heightPID()
Get a PID source that returns the height of the target.- Returns:
- A PID source returning the height of the target.
-
writeOutput
public void writeOutput(org.opencv.core.Mat mat)
Draw overlays on the image. This should give the user some indication of what the result ofTargetProcessor.process(List)
was.- Parameters:
mat
- The image to draw on.
-
getDefaultValue
public TargetWithHeightResult getDefaultValue()
- Specified by:
getDefaultValue
in classAbstractTargetProcessor<TargetWithHeightResult>
- Returns:
- {T}
-
-