Skip to content

Commit

Permalink
Add OpenCV DNN test pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Oct 8, 2023
1 parent 2881741 commit b244310
Show file tree
Hide file tree
Showing 18 changed files with 350 additions and 33 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ plugins {
id "com.diffplug.spotless" version "6.19.0"
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.github.node-gradle.node" version "3.1.1" apply false
id "edu.wpi.first.GradleJni" version "1.0.0"
id "edu.wpi.first.GradleVsCode" version "1.1.0"
id "edu.wpi.first.GradleJni" version "1.1.0"
id "edu.wpi.first.GradleVsCode" version "1.3.0"
id "edu.wpi.first.NativeUtils" version "2023.11.1" apply false
id "edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin" version "2020.2"
id "org.hidetake.ssh" version "2.10.1"
id 'edu.wpi.first.WpilibTools' version '1.0.0'
id 'edu.wpi.first.WpilibTools' version '1.1.0'
}

import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency;
Expand All @@ -27,7 +27,7 @@ apply from: "versioningHelper.gradle"

ext {
wpilibVersion = "2023.4.2"
opencvVersion = "4.6.0-4"
opencvVersion = "4.8.0-1"
joglVersion = "2.4.0-rc-20200307"
pubVersion = versionString
isDev = pubVersion.startsWith("dev")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const changeCurrentCameraIndex = (index: number) => {
case PipelineType.Aruco:
pipelineType.value = WebsocketPipelineType.Aruco;
break;
case PipelineType.Dnn:
pipelineType.value = WebsocketPipelineType.Dnn;
break;
}
};
Expand Down Expand Up @@ -151,8 +154,9 @@ const pipelineTypesWrapper = computed<{ name: string; value: number }[]>(() => {
const pipelineTypes = [
{ name: "Reflective", value: WebsocketPipelineType.Reflective },
{ name: "Colored Shape", value: WebsocketPipelineType.ColoredShape },
{ name: "AprilTag", value: WebsocketPipelineType.AprilTag }
{ name: "AprilTag", value: WebsocketPipelineType.AprilTag },
// { name: "Aruco", value: WebsocketPipelineType.Aruco }
{ name: "DNN", value: WebsocketPipelineType.Dnn }
];
if (useCameraSettingsStore().isDriverMode) {
Expand Down Expand Up @@ -203,6 +207,9 @@ useCameraSettingsStore().$subscribe((mutation, state) => {
case PipelineType.Aruco:
pipelineType.value = WebsocketPipelineType.Aruco;
break;
case PipelineType.Dnn:
pipelineType.value = WebsocketPipelineType.Dnn;
break;
}
});
</script>
Expand Down Expand Up @@ -322,8 +329,9 @@ useCameraSettingsStore().$subscribe((mutation, state) => {
:items="[
{ name: 'Reflective', value: WebsocketPipelineType.Reflective },
{ name: 'Colored Shape', value: WebsocketPipelineType.ColoredShape },
{ name: 'AprilTag', value: WebsocketPipelineType.AprilTag }
{ name: 'AprilTag', value: WebsocketPipelineType.AprilTag },
// { name: 'Aruco', value: WebsocketPipelineType.Aruco }
{ name: 'Dnn', value: WebsocketPipelineType.Dnn }
]"
/>
</v-card-text>
Expand Down
20 changes: 17 additions & 3 deletions photon-client/src/types/PipelineTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export enum PipelineType {
Reflective = 2,
ColoredShape = 3,
AprilTag = 4,
Aruco = 5
Aruco = 5,
Dnn = 6,
}

export enum AprilTagFamily {
Expand Down Expand Up @@ -239,6 +240,17 @@ export const DefaultAprilTagPipelineSettings: AprilTagPipelineSettings = {
tagFamily: AprilTagFamily.Family16h5
};

export interface DnnPipelineSettings extends PipelineSettings {
pipelineType: PipelineType.Dnn;
}
export type ConfigurableDnnPipelineSettings = Partial<Omit<DnnPipelineSettings, "pipelineType">> &
ConfigurablePipelineSettings;
export const DefaultDnnPipelineSettings: DnnPipelineSettings = {
...DefaultPipelineSettings,
pipelineType: PipelineType.Dnn
};


export interface ArucoPipelineSettings extends PipelineSettings {
pipelineType: PipelineType.Aruco;
decimate: number;
Expand Down Expand Up @@ -269,9 +281,11 @@ export type ActivePipelineSettings =
| ReflectivePipelineSettings
| ColoredShapePipelineSettings
| AprilTagPipelineSettings
| ArucoPipelineSettings;
| ArucoPipelineSettings
| DnnPipelineSettings;
export type ActiveConfigurablePipelineSettings =
| ConfigurableReflectivePipelineSettings
| ConfigurableColoredShapePipelineSettings
| ConfigurableAprilTagPipelineSettings
| ConfigurableArucoPipelineSettings;
| ConfigurableArucoPipelineSettings
| ConfigurableDnnPipelineSettings;
3 changes: 2 additions & 1 deletion photon-client/src/types/WebsocketDataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,6 @@ export enum WebsocketPipelineType {
Reflective = 0,
ColoredShape = 1,
AprilTag = 2,
Aruco = 3
Aruco = 3,
Dnn = 4
}
2 changes: 1 addition & 1 deletion photon-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'edu.wpi.first.WpilibTools' version '1.0.0'
id 'edu.wpi.first.WpilibTools' version '1.1.0'
}

import java.nio.file.Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

package org.photonvision.vision.aruco;

import org.opencv.aruco.Aruco;
import org.opencv.aruco.ArucoDetector;
import org.opencv.aruco.DetectorParameters;
import org.opencv.aruco.Dictionary;
import org.opencv.objdetect.ArucoDetector;
import org.opencv.objdetect.DetectorParameters;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;

Expand All @@ -31,15 +29,16 @@ public class ArucoDetectorParams {
private int m_iterations = -1;
private double m_accuracy = -1;

DetectorParameters parameters = DetectorParameters.create();
DetectorParameters parameters = new DetectorParameters();
ArucoDetector detector;

public ArucoDetectorParams() {
setDecimation(1);
setCornerAccuracy(25);
setCornerRefinementMaxIterations(100);

detector = new ArucoDetector(Dictionary.get(Aruco.DICT_APRILTAG_16h5), parameters);
// TODO
// detector = new ArucoDetector(Dictionary.get(Aruco.DICT_APRILTAG_16h5), parameters);
}

public void setDecimation(float decimate) {
Expand All @@ -56,7 +55,8 @@ public void setDecimation(float decimate) {
public void setCornerRefinementMaxIterations(int iters) {
if (iters == m_iterations || iters <= 0) return;

parameters.set_cornerRefinementMethod(Aruco.CORNER_REFINE_SUBPIX);
// TODO
// parameters.set_cornerRefinementMethod(Aruco.CORNER_REFINE_SUBPIX);
parameters.set_cornerRefinementMaxIterations(iters); // 200

m_iterations = iters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import edu.wpi.first.math.util.Units;
import java.util.ArrayList;
import org.opencv.aruco.Aruco;
import org.opencv.aruco.ArucoDetector;
import org.opencv.core.Mat;
import org.opencv.objdetect.ArucoDetector;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import edu.wpi.first.math.util.Units;
import java.util.List;
import org.opencv.aruco.DetectorParameters;
import org.opencv.core.Mat;
import org.opencv.objdetect.DetectorParameters;
import org.photonvision.vision.aruco.ArucoDetectionResult;
import org.photonvision.vision.aruco.PhotonArucoDetector;
import org.photonvision.vision.pipe.CVPipe;
Expand All @@ -45,6 +45,6 @@ public void setParams(ArucoDetectionPipeParams params) {
}

public DetectorParameters getParameters() {
return params == null ? null : params.detectorParams.get_params();
return params == null ? null : params.detectorParams.getDetectorParameters();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.photonvision.vision.pipe.impl;

import java.util.Objects;
import org.opencv.aruco.ArucoDetector;
import org.opencv.objdetect.ArucoDetector;
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;

public class ArucoDetectionPipeParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
@JsonSubTypes.Type(value = ReflectivePipelineSettings.class),
@JsonSubTypes.Type(value = DriverModePipelineSettings.class),
@JsonSubTypes.Type(value = AprilTagPipelineSettings.class),
@JsonSubTypes.Type(value = ArucoPipelineSettings.class)
@JsonSubTypes.Type(value = ArucoPipelineSettings.class),
@JsonSubTypes.Type(value = DnnPipelineSettings.class)
})
public class CVPipelineSettings implements Cloneable {
public int pipelineIndex = 0;
Expand Down
Loading

0 comments on commit b244310

Please sign in to comment.