Skip to content

Commit

Permalink
Run spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroglyph committed Jul 14, 2020
1 parent 8591dc1 commit 59630a0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import java.util.List;
import java.util.Objects;
import org.photonvision.vision.frame.FrameDivisor;
import org.photonvision.vision.opencv.ImageFlipMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
package org.photonvision.vision.pipeline;

import java.util.List;

import org.apache.commons.lang3.tuple.Pair;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.photonvision.common.util.math.MathUtils;
import org.photonvision.vision.frame.Frame;
Expand Down Expand Up @@ -49,9 +47,7 @@
import org.photonvision.vision.target.PotentialTarget;
import org.photonvision.vision.target.TrackedTarget;

/**
* Represents a pipeline for tracking retro-reflective targets.
*/
/** Represents a pipeline for tracking retro-reflective targets. */
public class ReflectivePipeline extends CVPipeline<CVPipelineResult, ReflectivePipelineSettings> {

private final RotateImagePipe rotateImagePipe = new RotateImagePipe();
Expand Down Expand Up @@ -83,82 +79,82 @@ public ReflectivePipeline(ReflectivePipelineSettings settings) {

@Override
protected void setPipeParams(
FrameStaticProperties frameStaticProperties, ReflectivePipelineSettings settings) {
FrameStaticProperties frameStaticProperties, ReflectivePipelineSettings settings) {
RotateImagePipe.RotateImageParams rotateImageParams =
new RotateImagePipe.RotateImageParams(settings.inputImageRotationMode);
new RotateImagePipe.RotateImageParams(settings.inputImageRotationMode);
rotateImagePipe.setParams(rotateImageParams);

ErodeDilatePipe.ErodeDilateParams erodeDilateParams =
new ErodeDilatePipe.ErodeDilateParams(settings.erode, settings.dilate, 5);
new ErodeDilatePipe.ErodeDilateParams(settings.erode, settings.dilate, 5);
// TODO: add kernel size to pipeline settings
erodeDilatePipe.setParams(erodeDilateParams);

HSVPipe.HSVParams hsvParams =
new HSVPipe.HSVParams(settings.hsvHue, settings.hsvSaturation, settings.hsvValue);
new HSVPipe.HSVParams(settings.hsvHue, settings.hsvSaturation, settings.hsvValue);
hsvPipe.setParams(hsvParams);

FindContoursPipe.FindContoursParams findContoursParams =
new FindContoursPipe.FindContoursParams();
new FindContoursPipe.FindContoursParams();
findContoursPipe.setParams(findContoursParams);

SpeckleRejectPipe.SpeckleRejectParams speckleRejectParams =
new SpeckleRejectPipe.SpeckleRejectParams(settings.contourSpecklePercentage);
new SpeckleRejectPipe.SpeckleRejectParams(settings.contourSpecklePercentage);
speckleRejectPipe.setParams(speckleRejectParams);

FilterContoursPipe.FilterContoursParams filterContoursParams =
new FilterContoursPipe.FilterContoursParams(
settings.contourArea,
settings.contourRatio,
settings.contourExtent,
frameStaticProperties);
new FilterContoursPipe.FilterContoursParams(
settings.contourArea,
settings.contourRatio,
settings.contourExtent,
frameStaticProperties);
filterContoursPipe.setParams(filterContoursParams);

GroupContoursPipe.GroupContoursParams groupContoursParams =
new GroupContoursPipe.GroupContoursParams(
settings.contourGroupingMode, settings.contourIntersection);
new GroupContoursPipe.GroupContoursParams(
settings.contourGroupingMode, settings.contourIntersection);
groupContoursPipe.setParams(groupContoursParams);

SortContoursPipe.SortContoursParams sortContoursParams =
new SortContoursPipe.SortContoursParams(settings.contourSortMode, frameStaticProperties, 5);
new SortContoursPipe.SortContoursParams(settings.contourSortMode, frameStaticProperties, 5);
sortContoursPipe.setParams(sortContoursParams);

Collect2dTargetsPipe.Collect2dTargetsParams collect2dTargetsParams =
new Collect2dTargetsPipe.Collect2dTargetsParams(
frameStaticProperties,
settings.offsetRobotOffsetMode,
settings.offsetDualLineM,
settings.offsetDualLineB,
settings.offsetCalibrationPoint.toPoint(),
settings.contourTargetOffsetPointEdge,
settings.contourTargetOrientation);
new Collect2dTargetsPipe.Collect2dTargetsParams(
frameStaticProperties,
settings.offsetRobotOffsetMode,
settings.offsetDualLineM,
settings.offsetDualLineB,
settings.offsetCalibrationPoint.toPoint(),
settings.contourTargetOffsetPointEdge,
settings.contourTargetOrientation);
collect2dTargetsPipe.setParams(collect2dTargetsParams);

var params =
new CornerDetectionPipe.CornerDetectionPipeParameters(
settings.cornerDetectionStrategy,
settings.cornerDetectionUseConvexHulls,
settings.cornerDetectionExactSideCount,
settings.cornerDetectionSideCount,
settings.cornerDetectionAccuracyPercentage);
new CornerDetectionPipe.CornerDetectionPipeParameters(
settings.cornerDetectionStrategy,
settings.cornerDetectionUseConvexHulls,
settings.cornerDetectionExactSideCount,
settings.cornerDetectionSideCount,
settings.cornerDetectionAccuracyPercentage);
cornerDetectionPipe.setParams(params);

Draw2dTargetsPipe.Draw2dContoursParams draw2dContoursParams =
new Draw2dTargetsPipe.Draw2dContoursParams(settings.outputShowMultipleTargets);
new Draw2dTargetsPipe.Draw2dContoursParams(settings.outputShowMultipleTargets);
draw2DTargetsPipe.setParams(draw2dContoursParams);

Draw2dCrosshairPipe.Draw2dCrosshairParams draw2dCrosshairParams =
new Draw2dCrosshairPipe.Draw2dCrosshairParams(
settings.offsetRobotOffsetMode, settings.offsetCalibrationPoint);
new Draw2dCrosshairPipe.Draw2dCrosshairParams(
settings.offsetRobotOffsetMode, settings.offsetCalibrationPoint);
draw2dCrosshairPipe.setParams(draw2dCrosshairParams);

var draw3dContoursParams =
new Draw3dTargetsPipe.Draw3dContoursParams(
settings.cameraCalibration, settings.targetModel);
new Draw3dTargetsPipe.Draw3dContoursParams(
settings.cameraCalibration, settings.targetModel);
draw3dTargetsPipe.setParams(draw3dContoursParams);

var solvePNPParams =
new SolvePNPPipe.SolvePNPPipeParams(
settings.cameraCalibration, settings.cameraPitch, settings.targetModel);
new SolvePNPPipe.SolvePNPPipeParams(
settings.cameraCalibration, settings.cameraPitch, settings.targetModel);
solvePNPPipe.setParams(solvePNPParams);
}

Expand Down Expand Up @@ -190,23 +186,23 @@ public CVPipelineResult process(Frame frame, ReflectivePipelineSettings settings
sumPipeNanosElapsed += findContoursResult.nanosElapsed;

CVPipeResult<List<Contour>> speckleRejectResult =
speckleRejectPipe.apply(findContoursResult.result);
speckleRejectPipe.apply(findContoursResult.result);
sumPipeNanosElapsed += speckleRejectResult.nanosElapsed;

CVPipeResult<List<Contour>> filterContoursResult =
filterContoursPipe.apply(speckleRejectResult.result);
filterContoursPipe.apply(speckleRejectResult.result);
sumPipeNanosElapsed += filterContoursResult.nanosElapsed;

CVPipeResult<List<PotentialTarget>> groupContoursResult =
groupContoursPipe.apply(filterContoursResult.result);
groupContoursPipe.apply(filterContoursResult.result);
sumPipeNanosElapsed += groupContoursResult.nanosElapsed;

CVPipeResult<List<PotentialTarget>> sortContoursResult =
sortContoursPipe.apply(groupContoursResult.result);
sortContoursPipe.apply(groupContoursResult.result);
sumPipeNanosElapsed += sortContoursResult.nanosElapsed;

CVPipeResult<List<TrackedTarget>> collect2dTargetsResult =
collect2dTargetsPipe.apply(sortContoursResult.result);
collect2dTargetsPipe.apply(sortContoursResult.result);
sumPipeNanosElapsed += collect2dTargetsResult.nanosElapsed;

CVPipeResult<List<TrackedTarget>> targetList;
Expand All @@ -230,18 +226,18 @@ public CVPipelineResult process(Frame frame, ReflectivePipelineSettings settings
// Draw on input

CVPipeResult<Mat> draw2dCrosshairResultOnInput =
draw2dCrosshairPipe.apply(Pair.of(outputMats.first, targetList.result));
draw2dCrosshairPipe.apply(Pair.of(outputMats.first, targetList.result));
sumPipeNanosElapsed += draw2dCrosshairResultOnInput.nanosElapsed;

CVPipeResult<Mat> draw2dContoursResultOnInput =
draw2DTargetsPipe.apply(
Pair.of(draw2dCrosshairResultOnInput.result, collect2dTargetsResult.result));
draw2DTargetsPipe.apply(
Pair.of(draw2dCrosshairResultOnInput.result, collect2dTargetsResult.result));
sumPipeNanosElapsed += draw2dCrosshairResultOnInput.nanosElapsed;

if (settings.solvePNPEnabled) {
drawOnInputResult =
draw3dTargetsPipe.apply(
Pair.of(draw2dContoursResultOnInput.result, collect2dTargetsResult.result));
draw3dTargetsPipe.apply(
Pair.of(draw2dContoursResultOnInput.result, collect2dTargetsResult.result));
sumPipeNanosElapsed += drawOnInputResult.nanosElapsed;
} else {
drawOnInputResult = draw2dContoursResultOnInput;
Expand All @@ -251,27 +247,27 @@ public CVPipelineResult process(Frame frame, ReflectivePipelineSettings settings

Imgproc.cvtColor(outputMats.second, outputMats.second, Imgproc.COLOR_GRAY2BGR, 3);
CVPipeResult<Mat> draw2dCrosshairResultOnOutput =
draw2dCrosshairPipe.apply(Pair.of(outputMats.second, targetList.result));
draw2dCrosshairPipe.apply(Pair.of(outputMats.second, targetList.result));
sumPipeNanosElapsed += draw2dCrosshairResultOnOutput.nanosElapsed;

CVPipeResult<Mat> draw2dContoursResultOnOutput =
draw2DTargetsPipe.apply(
Pair.of(draw2dCrosshairResultOnOutput.result, collect2dTargetsResult.result));
draw2DTargetsPipe.apply(
Pair.of(draw2dCrosshairResultOnOutput.result, collect2dTargetsResult.result));
sumPipeNanosElapsed += draw2dContoursResultOnOutput.nanosElapsed;

if (settings.solvePNPEnabled) {
drawOnOutputResult =
draw3dTargetsPipe.apply(
Pair.of(draw2dContoursResultOnOutput.result, collect2dTargetsResult.result));
draw3dTargetsPipe.apply(
Pair.of(draw2dContoursResultOnOutput.result, collect2dTargetsResult.result));
sumPipeNanosElapsed += drawOnOutputResult.nanosElapsed;
} else {
drawOnOutputResult = draw2dContoursResultOnOutput;
}

return new CVPipelineResult(
MathUtils.nanosToMillis(sumPipeNanosElapsed),
collect2dTargetsResult.result,
new Frame(new CVMat(outputMats.second), frame.frameStaticProperties),
new Frame(new CVMat(outputMats.first), frame.frameStaticProperties));
MathUtils.nanosToMillis(sumPipeNanosElapsed),
collect2dTargetsResult.result,
new Frame(new CVMat(outputMats.second), frame.frameStaticProperties),
new Frame(new CVMat(outputMats.first), frame.frameStaticProperties));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.photonvision.vision.pipeline.result;

import java.util.List;

import org.photonvision.vision.frame.Frame;
import org.photonvision.vision.opencv.Releasable;
import org.photonvision.vision.target.TrackedTarget;
Expand All @@ -30,7 +29,8 @@ public class CVPipelineResult implements Releasable {
public final Frame outputFrame;
public final Frame inputFrame;

public CVPipelineResult(double processingMillis, List<TrackedTarget> targets, Frame outputFrame, Frame inputFrame) {
public CVPipelineResult(
double processingMillis, List<TrackedTarget> targets, Frame outputFrame, Frame inputFrame) {
this.processingMillis = processingMillis;
this.targets = targets;

Expand All @@ -51,7 +51,7 @@ public void release() {
tt.release();
}
outputFrame.release();
if(inputFrame != null) inputFrame.release();
if (inputFrame != null) inputFrame.release();
}

public double getLatencyMillis() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import edu.wpi.first.wpilibj.MedianFilter;
import java.util.*;
import org.apache.commons.lang3.tuple.Pair;
import org.opencv.imgcodecs.Imgcodecs;
import org.photonvision.common.configuration.CameraConfiguration;
import org.photonvision.common.configuration.ConfigManager;
import org.photonvision.common.configuration.PhotonConfiguration;
Expand Down Expand Up @@ -92,12 +91,14 @@ public VisionModule(PipelineManager pipelineManager, VisionSource visionSource,
dashboardInputStreamer =
new MJPGFrameConsumer(visionSource.getSettables().getConfiguration().uniqueName + "-input");

addResultConsumer(result -> {
dashboardInputStreamer.accept(result.inputFrame);
});
addResultConsumer(result -> {
dashboardOutputStreamer.accept(result.outputFrame);
});
addResultConsumer(
result -> {
dashboardInputStreamer.accept(result.inputFrame);
});
addResultConsumer(
result -> {
dashboardOutputStreamer.accept(result.outputFrame);
});

ntConsumer =
new NTDataPublisher(
Expand Down

0 comments on commit 59630a0

Please sign in to comment.