Skip to content

Commit

Permalink
Run lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Nov 23, 2024
1 parent 73ad72c commit 0ee6405
Show file tree
Hide file tree
Showing 13 changed files with 1,296 additions and 1,286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,61 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.photonvision.vision.pipe.impl;
package org.photonvision.vision.pipe.impl;

import edu.wpi.first.apriltag.AprilTagDetection;
import edu.wpi.first.apriltag.AprilTagDetector;
import java.util.List;
import org.photonvision.vision.opencv.CVMat;
import org.photonvision.vision.opencv.Releasable;
import org.photonvision.vision.pipe.CVPipe;

public class AprilTagDetectionPipe
extends CVPipe<CVMat, List<AprilTagDetection>, AprilTagDetectionPipeParams>
implements Releasable {
private AprilTagDetector m_detector = new AprilTagDetector();

public AprilTagDetectionPipe() {
super();

m_detector.addFamily("tag16h5");
m_detector.addFamily("tag36h11");
}

@Override
protected List<AprilTagDetection> process(CVMat in) {
if (in.getMat().empty()) {
return List.of();
}

if (m_detector == null) {
throw new RuntimeException("Apriltag detector was released!");
}

var ret = m_detector.detect(in.getMat());

if (ret == null) {
return List.of();
}

return List.of(ret);
}

@Override
public void setParams(AprilTagDetectionPipeParams newParams) {
if (this.params == null || !this.params.equals(newParams)) {
m_detector.setConfig(newParams.detectorParams);

m_detector.clearFamilies();
m_detector.addFamily(newParams.family.getNativeName());
}

super.setParams(newParams);
}

@Override
public void release() {
m_detector.close();
m_detector = null;
}
}

import edu.wpi.first.apriltag.AprilTagDetection;
import edu.wpi.first.apriltag.AprilTagDetector;
import java.util.List;
import org.photonvision.vision.opencv.CVMat;
import org.photonvision.vision.opencv.Releasable;
import org.photonvision.vision.pipe.CVPipe;

public class AprilTagDetectionPipe
extends CVPipe<CVMat, List<AprilTagDetection>, AprilTagDetectionPipeParams>
implements Releasable {
private AprilTagDetector m_detector = new AprilTagDetector();

public AprilTagDetectionPipe() {
super();

m_detector.addFamily("tag16h5");
m_detector.addFamily("tag36h11");
}

@Override
protected List<AprilTagDetection> process(CVMat in) {
if (in.getMat().empty()) {
return List.of();
}

if (m_detector == null) {
throw new RuntimeException("Apriltag detector was released!");
}

var ret = m_detector.detect(in.getMat());

if (ret == null) {
return List.of();
}

return List.of(ret);
}

@Override
public void setParams(AprilTagDetectionPipeParams newParams) {
if (this.params == null || !this.params.equals(newParams)) {
m_detector.setConfig(newParams.detectorParams);

m_detector.clearFamilies();
m_detector.addFamily(newParams.family.getNativeName());
}

super.setParams(newParams);
}

@Override
public void release() {
m_detector.close();
m_detector = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,38 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.photonvision.vision.pipe.impl;
package org.photonvision.vision.pipe.impl;

import edu.wpi.first.apriltag.AprilTagDetector;
import org.photonvision.vision.apriltag.AprilTagFamily;

public class AprilTagDetectionPipeParams {
public final AprilTagFamily family;
public final AprilTagDetector.Config detectorParams;

public AprilTagDetectionPipeParams(AprilTagFamily tagFamily, AprilTagDetector.Config config) {
this.family = tagFamily;
this.detectorParams = config;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((family == null) ? 0 : family.hashCode());
result = prime * result + ((detectorParams == null) ? 0 : detectorParams.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
AprilTagDetectionPipeParams other = (AprilTagDetectionPipeParams) obj;
if (family != other.family) return false;
if (detectorParams == null) {
return other.detectorParams == null;
} else return detectorParams.equals(other.detectorParams);
}
}

import edu.wpi.first.apriltag.AprilTagDetector;
import org.photonvision.vision.apriltag.AprilTagFamily;

public class AprilTagDetectionPipeParams {
public final AprilTagFamily family;
public final AprilTagDetector.Config detectorParams;

public AprilTagDetectionPipeParams(AprilTagFamily tagFamily, AprilTagDetector.Config config) {
this.family = tagFamily;
this.detectorParams = config;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((family == null) ? 0 : family.hashCode());
result = prime * result + ((detectorParams == null) ? 0 : detectorParams.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
AprilTagDetectionPipeParams other = (AprilTagDetectionPipeParams) obj;
if (family != other.family) return false;
if (detectorParams == null) {
return other.detectorParams == null;
} else return detectorParams.equals(other.detectorParams);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/*
* Copyright (C) Photon Vision.
*
Expand Down Expand Up @@ -25,7 +42,7 @@

public class CropPipe extends CVPipe<CVMat, CVMat, Rect> {
public Rect dynamiRect;

public CropPipe() {
Rect full_screen = new Rect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);

Expand All @@ -48,9 +65,11 @@ protected CVMat process(CVMat in) {

return new CVMat(mat.submat(y, y + height, x, x + width));
}
public void setDynamicRect(Rect newDynamicCropp){

public void setDynamicRect(Rect newDynamicCropp) {
dynamiRect = newDynamicCropp;
}

/**
* Returns true if the given rectangle fully covers some given image.
*
Expand All @@ -62,7 +81,9 @@ public static boolean fullyCovers(Rect rect, Mat mat) {
return rect.x <= 0 && rect.y <= 0 && rect.width >= mat.width() && rect.height >= mat.height();
}

private boolean isDynamicInvalid(){
return !this.params.contains(new Point(dynamiRect.x,dynamiRect.y)) || this.params.height < dynamiRect.height || this.params.width < dynamiRect.width;
private boolean isDynamicInvalid() {
return !this.params.contains(new Point(dynamiRect.x, dynamiRect.y))
|| this.params.height < dynamiRect.height
|| this.params.width < dynamiRect.width;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public class DrawRectanglePipe
extends MutatingPipe<Mat, DrawRectanglePipe.DrawRectanglePipeParams> {
Scalar staticColor;
Scalar dynamicColor;
public DrawRectanglePipe(Scalar staticColor, Scalar dynamicColor) {
super();
this.params = new DrawRectanglePipeParams();
this.staticColor = staticColor;
this.dynamicColor = dynamicColor;

public DrawRectanglePipe(Scalar staticColor, Scalar dynamicColor) {
super();
this.params = new DrawRectanglePipeParams();
this.staticColor = staticColor;
this.dynamicColor = dynamicColor;
}

@Override
Expand Down Expand Up @@ -68,13 +68,14 @@ public static class DrawRectanglePipeParams {

public DrawRectanglePipeParams() {}

public DrawRectanglePipeParams(Rect static_rect,Rect dynamic_rect) {
public DrawRectanglePipeParams(Rect static_rect, Rect dynamic_rect) {
this.static_rect = static_rect;
this.dynamic_rect = dynamic_rect;
}

public DrawRectanglePipeParams(int x, int y, int width, int height, int x2, int y2, int width2, int height2) {
this(new Rect(x, y, width, height),new Rect(x2, y2, width2, height2));
public DrawRectanglePipeParams(
int x, int y, int width, int height, int x2, int y2, int width2, int height2) {
this(new Rect(x, y, width, height), new Rect(x2, y2, width2, height2));
}
}
}
Loading

0 comments on commit 0ee6405

Please sign in to comment.