This commit is contained in:
Scott Barnes 2024-02-19 17:58:55 -06:00
parent 2775d950a8
commit 3ed9e95ee9
42 changed files with 53 additions and 321 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
/build
/.idea/
/.gradle/

Binary file not shown.

View File

@ -1,2 +0,0 @@
#Mon Feb 19 16:57:38 CST 2024
gradle.version=7.3.3

Binary file not shown.

View File

@ -1,2 +0,0 @@
#Mon Feb 19 16:32:55 CST 2024
java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home

Binary file not shown.

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="17" />
</component>
</project>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/ftctearabits" />
</set>
</option>
<option name="resolveExternalAnnotations" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectMigrations">
<option name="MigrateToGradleLocalJavaHome">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</component>
</project>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -1,258 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="ALL" />
</component>
<component name="ChangeListManager">
<list default="true" id="a9bdfa99-931b-4792-b678-e88cbbd6ab17" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.2/dependencies-accessors/gc.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.2/fileChanges/last-build.bin" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.2/fileHashes/fileHashes.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.2/gc.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.3.3/checksums/checksums.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.3.3/checksums/md5-checksums.bin" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.3.3/checksums/sha1-checksums.bin" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.3.3/dependencies-accessors/dependencies-accessors.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.3.3/dependencies-accessors/gc.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.3.3/executionHistory/executionHistory.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.3.3/fileChanges/last-build.bin" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.3.3/fileHashes/fileHashes.bin" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.3.3/fileHashes/fileHashes.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/7.3.3/gc.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/8.0/checksums/checksums.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/8.0/dependencies-accessors/dependencies-accessors.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/8.0/dependencies-accessors/gc.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/8.0/executionHistory/executionHistory.bin" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/8.0/executionHistory/executionHistory.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/8.0/fileChanges/last-build.bin" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/8.0/fileHashes/fileHashes.bin" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/8.0/fileHashes/fileHashes.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/8.0/gc.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/buildOutputCleanup/buildOutputCleanup.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/buildOutputCleanup/cache.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/buildOutputCleanup/outputFiles.bin" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/checksums/checksums.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/config.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.gradle/vcs-1/gc.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/gradle.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/migrations.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gradle.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gradlew" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gradlew.bat" afterDir="false" />
<change afterPath="$PROJECT_DIR$/local.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/settings.gradle" afterDir="false" />
<change beforePath="$PROJECT_DIR$/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/build.gradle" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tearabite/ftctearabits/vision/Detection.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tearabite/ftctearabits/vision/Detection.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ClangdSettings">
<option name="formatViaClangd" value="false" />
</component>
<component name="ExternalProjectsData">
<projectState path="$PROJECT_DIR$">
<ProjectState />
</projectState>
</component>
<component name="ExternalProjectsManager">
<system id="GRADLE">
<state>
<task path="$PROJECT_DIR$">
<activation />
</task>
<projects_view>
<tree_state>
<expand>
<path>
<item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" />
<item name="ftctearabits" type="f1a62948:ProjectNode" />
</path>
<path>
<item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" />
<item name="ftctearabits" type="f1a62948:ProjectNode" />
<item name="Tasks" type="e4a08cd1:TasksNode" />
</path>
<path>
<item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" />
<item name="ftctearabits" type="f1a62948:ProjectNode" />
<item name="Tasks" type="e4a08cd1:TasksNode" />
<item name="build" type="c8890929:TasksNode$1" />
</path>
<path>
<item name="" type="6a2764b6:ExternalProjectsStructure$RootNode" />
<item name="ftctearabits" type="f1a62948:ProjectNode" />
<item name="Run Configurations" type="7b0102dc:RunConfigurationsNode" />
</path>
</expand>
<select />
</tree_state>
</projects_view>
</state>
</system>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectId" id="2cbRiWI1WCq8tegqaIFeJ639wNy" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.cidr.known.project.marker": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"cf.first.check.clang-format": "false",
"cidr.known.project.marker": "true",
"git-widget-placeholder": "master",
"last_opened_file_path": "/Users/scott/Developer/FtcRobotController/libs/ftctearabits",
"project.structure.last.edited": "Dependencies",
"project.structure.proportion": "0.17",
"project.structure.side.proportion": "0.2",
"run.code.analysis.last.selected.profile": "pProject Default",
"settings.build.tools.auto.reload": "ALL",
"settings.editor.selected.configurable": "build.tools"
}
}]]></component>
<component name="RunManager" selected="Gradle.ftctearabits [wrapper]">
<configuration name="ftctearabits [assemble]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="assemble" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<ForceTestExec>false</ForceTestExec>
<method v="2" />
</configuration>
<configuration name="ftctearabits [buildDependents]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="buildDependents" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<ForceTestExec>false</ForceTestExec>
<method v="2" />
</configuration>
<configuration name="ftctearabits [buildNeeded]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="buildNeeded" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<ForceTestExec>false</ForceTestExec>
<method v="2" />
</configuration>
<configuration name="ftctearabits [build]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="build" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<ForceTestExec>false</ForceTestExec>
<method v="2" />
</configuration>
<configuration name="ftctearabits [wrapper]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="wrapper" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<ForceTestExec>false</ForceTestExec>
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Gradle.ftctearabits [wrapper]" />
<item itemvalue="Gradle.ftctearabits [build]" />
<item itemvalue="Gradle.ftctearabits [assemble]" />
<item itemvalue="Gradle.ftctearabits [buildNeeded]" />
<item itemvalue="Gradle.ftctearabits [buildDependents]" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="a9bdfa99-931b-4792-b678-e88cbbd6ab17" name="Changes" comment="" />
<created>1708378418555</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1708378418555</updated>
</task>
<servers />
</component>
</project>

View File

@ -1,5 +1,8 @@
package com.tearabite.ftctearabits.vision;
import static com.tearabite.ftctearabits.vision.Colors.FTC_BLUE_RANGE;
import static com.tearabite.ftctearabits.vision.Colors.FTC_RED_RANGE_1;
import static com.tearabite.ftctearabits.vision.Colors.FTC_RED_RANGE_2;
import static com.tearabite.ftctearabits.vision.Colors.WHITE;
import static com.tearabite.ftctearabits.vision.OpenCVUtil.getLargestContour;
@ -17,6 +20,7 @@ import org.opencv.imgproc.Imgproc;
import java.util.ArrayList;
import lombok.Getter;
import lombok.Setter;
public class BasicColorDetectionVisionProcessor implements VisionProcessor {
public static final Size BLUR_SIZE = new Size(7, 7);
@ -25,24 +29,29 @@ public class BasicColorDetectionVisionProcessor implements VisionProcessor {
public static final Point ANCHOR = new Point((STRUCTURING_ELEMENT.cols() / 2f), STRUCTURING_ELEMENT.rows() / 2f);
private final Mat blurred = new Mat();
private final ScalarRange[] colorRanges;
@Getter @Setter private ScalarRange[] colorRanges;
@Getter private Detection detection;
private final Mat hsv = new Mat();
private final double ignoreSmallerThan;
private final double ignoreLargerThan;
private final Mat mask = new Mat();
private final Mat tmpMask = new Mat();
public BasicColorDetectionVisionProcessor(double ignoreSmallerThan, double ignoreLargerThan, ScalarRange... colorRanges) {
this.ignoreSmallerThan = ignoreSmallerThan;
this.ignoreLargerThan = ignoreLargerThan;
public BasicColorDetectionVisionProcessor(ScalarRange... colorRanges) {
this.colorRanges = colorRanges;
}
public static BasicColorDetectionVisionProcessor Blue() {
return new BasicColorDetectionVisionProcessor(FTC_BLUE_RANGE);
}
public static BasicColorDetectionVisionProcessor Red() {
return new BasicColorDetectionVisionProcessor(FTC_RED_RANGE_1, FTC_RED_RANGE_2);
}
@Override
public void init(int width, int height, CameraCalibration calibration) {
this.detection = new Detection(new Size(width, height), ignoreSmallerThan, ignoreLargerThan);
this.detection = new Detection(new Size(width, height), 0, 0);
}
@Override
@ -76,4 +85,20 @@ public class BasicColorDetectionVisionProcessor implements VisionProcessor {
canvas.drawCircle((float) center.x, (float) center.y, 10, WHITE);
}
}
public double getIgnoreSmallerThan() {
return this.detection.getIgnoreSmallerThan();
}
public void setIgnoreSmallerThan(double ignoreSmallerThan) {
this.detection.setIgnoreSmallerThan(ignoreSmallerThan);
}
public double getIgnoreLargerThan() {
return this.detection.getIgnoreLargerThan();
}
public void setIgnoreLargerThan(double ignoreLargerThan) {
this.detection.setIgnoreLargerThan(ignoreLargerThan);
}
}

View File

@ -8,6 +8,8 @@ import static com.tearabite.ftctearabits.vision.OpenCVUtil.getBottomLeftOfContou
import static com.tearabite.ftctearabits.vision.OpenCVUtil.getBottomRightOfContour;
import static com.tearabite.ftctearabits.vision.OpenCVUtil.getCenterOfContour;
import android.graphics.drawable.Icon;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Point;
@ -130,4 +132,20 @@ public class Detection {
public Point getBottomRightCornerPx() {
return bottomRightPx;
}
public void setIgnoreSmallerThan(double ignoreSmallerThan) {
this.minAreaPx = maxSizePx.area() * ignoreSmallerThan;
}
public void setIgnoreLargerThan(double ignoreLargerThan) {
this.minAreaPx = maxSizePx.area() * ignoreLargerThan;
}
public double getIgnoreSmallerThan() {
return this.minAreaPx / this.maxSizePx.area();
}
public double getIgnoreLargerThan() {
return this.maxAreaPx / this.maxSizePx.area();
}
}