Skip to content

Commit

Permalink
Fix Driver Mode Rotation (PhotonVision#1097)
Browse files Browse the repository at this point in the history
Demoves duplicate image rotation. Frames are rotated from the frame source provided. Then were rotated again in the driver mode pipeline.
  • Loading branch information
BytingBulldogs3539 authored Jan 1, 2024
1 parent 2ecd988 commit a9f1e50
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@
import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
import org.photonvision.common.util.math.MathUtils;
import org.photonvision.raspi.LibCameraJNI;
import org.photonvision.vision.camera.CameraQuirk;
import org.photonvision.vision.frame.Frame;
import org.photonvision.vision.frame.FrameThresholdType;
import org.photonvision.vision.pipe.impl.CalculateFPSPipe;
import org.photonvision.vision.pipe.impl.Draw2dCrosshairPipe;
import org.photonvision.vision.pipe.impl.ResizeImagePipe;
import org.photonvision.vision.pipe.impl.RotateImagePipe;
import org.photonvision.vision.pipeline.result.DriverModePipelineResult;

public class DriverModePipeline
extends CVPipeline<DriverModePipelineResult, DriverModePipelineSettings> {
private final RotateImagePipe rotateImagePipe = new RotateImagePipe();
private final Draw2dCrosshairPipe draw2dCrosshairPipe = new Draw2dCrosshairPipe();
private final CalculateFPSPipe calculateFPSPipe = new CalculateFPSPipe();
private final ResizeImagePipe resizeImagePipe = new ResizeImagePipe();
Expand All @@ -51,10 +47,6 @@ public DriverModePipeline(DriverModePipelineSettings settings) {

@Override
protected void setPipeParamsImpl() {
RotateImagePipe.RotateImageParams rotateImageParams =
new RotateImagePipe.RotateImageParams(settings.inputImageRotationMode);
rotateImagePipe.setParams(rotateImageParams);

Draw2dCrosshairPipe.Draw2dCrosshairParams draw2dCrosshairParams =
new Draw2dCrosshairPipe.Draw2dCrosshairParams(
frameStaticProperties, settings.streamingFrameDivisor, settings.inputImageRotationMode);
Expand All @@ -72,19 +64,13 @@ protected void setPipeParamsImpl() {
@Override
public DriverModePipelineResult process(Frame frame, DriverModePipelineSettings settings) {
long totalNanos = 0;
boolean accelerated = LibCameraJNI.isSupported() && cameraQuirks.hasQuirk(CameraQuirk.PiCam);

// apply pipes
var inputMat = frame.colorImage.getMat();

boolean emptyIn = inputMat.empty();

if (!emptyIn) {
if (!accelerated) {
var rotateImageResult = rotateImagePipe.run(inputMat);
totalNanos += rotateImageResult.nanosElapsed;
}

totalNanos += resizeImagePipe.run(inputMat).nanosElapsed;

var draw2dCrosshairResult = draw2dCrosshairPipe.run(Pair.of(inputMat, List.of()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private void update() {
// (pipeline-dependent). I kinda hate how much leak this has...
// TODO would a callback object be a better fit?
var wantedProcessType = pipeline.getThresholdType();

frameSupplier.requestFrameThresholdType(wantedProcessType);
var settings = pipeline.getSettings();
if (settings instanceof AdvancedPipelineSettings) {
Expand Down

0 comments on commit a9f1e50

Please sign in to comment.