Mit Cosmetics
This commit is contained in:
parent
ada8284535
commit
f8977976b2
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -8,7 +8,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
145
.idea/workspace.xml
generated
145
.idea/workspace.xml
generated
@ -4,11 +4,14 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="4d75e996-cee4-4ec6-b802-5b56d0c0eac4" name="Changes" comment="Funktionierender Puffer 16.12.2024 15.06 Siuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu">
|
<list default="true" id="4d75e996-cee4-4ec6-b802-5b56d0c0eac4" name="Changes" comment="Puffer Versuch Speicher läuft voll 16.12.2024 03:30">
|
||||||
<change afterPath="$PROJECT_DIR$/Background.png" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/Welcome0.png" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/Welcome1.png" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/Welcome2.png" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/Welcome3.png" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/CamPuffer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/CamPuffer.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/CamPuffer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/CamPuffer.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/GameLogic.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/GameLogic.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/GameLoop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/GameLoop.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/GameLoop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/GameLoop.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/GraphicsProgram.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/GraphicsProgram.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/GraphicsProgram.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/GraphicsProgram.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/ImgAnalyzer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ImgAnalyzer.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/ImgAnalyzer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ImgAnalyzer.java" afterDir="false" />
|
||||||
@ -33,53 +36,47 @@
|
|||||||
"associatedIndex": 8
|
"associatedIndex": 8
|
||||||
}</component>
|
}</component>
|
||||||
<component name="ProjectId" id="2p7Eq8ZJM8BEjLybOnAdhzZ82uv" />
|
<component name="ProjectId" id="2p7Eq8ZJM8BEjLybOnAdhzZ82uv" />
|
||||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
|
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||||
<ConfirmationsSetting value="2" id="Add" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectViewState">
|
<component name="ProjectViewState">
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
"Application.GraphicsProgram.executor": "Run",
|
||||||
"Application.GTCar.executor": "Run",
|
"Application.Main.executor": "Run",
|
||||||
"Application.GraphicsProgram.executor": "Run",
|
"Application.Tracker.executor": "Run",
|
||||||
"Application.Main.executor": "Run",
|
"Downloaded.Files.Path.Enabled": "false",
|
||||||
"Application.Tracker.executor": "Run",
|
"Repository.Attach.Annotations": "false",
|
||||||
"Downloaded.Files.Path.Enabled": "false",
|
"Repository.Attach.JavaDocs": "false",
|
||||||
"Repository.Attach.Annotations": "false",
|
"Repository.Attach.Sources": "false",
|
||||||
"Repository.Attach.JavaDocs": "false",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"Repository.Attach.Sources": "false",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"com.codeium.enabled": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"git-widget-placeholder": "master",
|
||||||
"com.codeium.enabled": "true",
|
"kotlin-language-version-configured": "true",
|
||||||
"git-widget-placeholder": "master",
|
"last_opened_file_path": "C:/Users/paul3/OneDrive/Dokumente/Studium BME/Semester 3/Interaktion/opencv/build/java/opencv-4100.jar",
|
||||||
"kotlin-language-version-configured": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"last_opened_file_path": "C:/Users/david/Documents/Uni/GTCar/opencv/build/java/opencv-4100.jar",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"nodejs_package_manager_path": "npm",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"project.structure.last.edited": "Libraries",
|
||||||
"nodejs_package_manager_path": "npm",
|
"project.structure.proportion": "0.15",
|
||||||
"project.structure.last.edited": "Libraries",
|
"project.structure.side.proportion": "0.24022989",
|
||||||
"project.structure.proportion": "0.15",
|
"vue.rearranger.settings.migration": "true"
|
||||||
"project.structure.side.proportion": "0.24022989",
|
|
||||||
"vue.rearranger.settings.migration": "true"
|
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
|
<component name="RecentsManager">
|
||||||
|
<key name="MoveFile.RECENT_KEYS">
|
||||||
|
<recent name="C:\Users\paul3\OneDrive\Dokumente\Studium BME\Semester 2\Praktikum Programmieren 2 A\Interaktion_GTCaar" />
|
||||||
|
</key>
|
||||||
|
</component>
|
||||||
<component name="RunManager" selected="Application.Main">
|
<component name="RunManager" selected="Application.Main">
|
||||||
<configuration name="GTCar" type="Application" factoryName="Application">
|
<configuration name="ImgAnalyzer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||||
<option name="MAIN_CLASS_NAME" value="Tracker" />
|
<option name="MAIN_CLASS_NAME" value="ImgAnalyzer" />
|
||||||
<module name="GTCar_V2_maven" />
|
|
||||||
<option name="VM_PARAMETERS" value="-Djava.library.path=C:\Users\david\Documents\Uni\GTCar\opencv\build\java\x64" />
|
|
||||||
<method v="2">
|
|
||||||
<option name="Make" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
<configuration name="GraphicsProgram" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
|
||||||
<option name="MAIN_CLASS_NAME" value="GraphicsProgram" />
|
|
||||||
<module name="GTCar_V2_maven" />
|
<module name="GTCar_V2_maven" />
|
||||||
|
<option name="PROGRAM_PARAMETERS" value="-Djava.library.path="C:\Users\paul3\OneDrive\Dokumente\Studium BME\Semester 3\Interaktion\opencv\build\java\x64"" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
@ -87,23 +84,30 @@
|
|||||||
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||||
<option name="MAIN_CLASS_NAME" value="Main" />
|
<option name="MAIN_CLASS_NAME" value="Main" />
|
||||||
<module name="GTCar_V2_maven" />
|
<module name="GTCar_V2_maven" />
|
||||||
<option name="VM_PARAMETERS" value="-Djava.library.path=C:\Users\david\Documents\Uni\GTCar\opencv\build\java\x64" />
|
<option name="PROGRAM_PARAMETERS" value="-Djava.library.path="C:\Users\paul3\OneDrive\Dokumente\Studium BME\Semester 3\Interaktion\opencv\build\java\x64"" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
<list>
|
<list>
|
||||||
<item itemvalue="Application.GTCar" />
|
|
||||||
<item itemvalue="Application.GraphicsProgram" />
|
|
||||||
<item itemvalue="Application.Main" />
|
<item itemvalue="Application.Main" />
|
||||||
|
<item itemvalue="Application.ImgAnalyzer" />
|
||||||
</list>
|
</list>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
<item itemvalue="Application.Main" />
|
<item itemvalue="Application.Main" />
|
||||||
<item itemvalue="Application.GraphicsProgram" />
|
<item itemvalue="Application.ImgAnalyzer" />
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
|
<component name="SharedIndexes">
|
||||||
|
<attachedChunks>
|
||||||
|
<set>
|
||||||
|
<option value="bundled-jdk-9f38398b9061-39b83d9b5494-intellij.indexing.shared.core-IU-241.15989.150" />
|
||||||
|
<option value="bundled-js-predefined-1d06a55b98c1-91d5c284f522-JavaScript-IU-241.15989.150" />
|
||||||
|
</set>
|
||||||
|
</attachedChunks>
|
||||||
|
</component>
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
<component name="TaskManager">
|
<component name="TaskManager">
|
||||||
<task active="true" id="Default" summary="Default task">
|
<task active="true" id="Default" summary="Default task">
|
||||||
@ -113,9 +117,9 @@
|
|||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1732108904989</updated>
|
<updated>1732108904989</updated>
|
||||||
<workItem from="1732108906083" duration="758000" />
|
<workItem from="1732108906083" duration="758000" />
|
||||||
<workItem from="1732113837570" duration="20534000" />
|
<workItem from="1732113837570" duration="5187000" />
|
||||||
<workItem from="1733327375447" duration="951000" />
|
<workItem from="1734302243298" duration="10745000" />
|
||||||
<workItem from="1734091457440" duration="10746000" />
|
<workItem from="1734469984979" duration="8232000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="First Commit Test">
|
<task id="LOCAL-00001" summary="First Commit Test">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
@ -133,39 +137,7 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1732118799936</updated>
|
<updated>1732118799936</updated>
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00003" summary="Version 23.11 (Grafics update)">
|
<option name="localTasksCounter" value="3" />
|
||||||
<option name="closed" value="true" />
|
|
||||||
<created>1732368525825</created>
|
|
||||||
<option name="number" value="00003" />
|
|
||||||
<option name="presentableId" value="LOCAL-00003" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1732368525826</updated>
|
|
||||||
</task>
|
|
||||||
<task id="LOCAL-00004" summary="Version 27.11">
|
|
||||||
<option name="closed" value="true" />
|
|
||||||
<created>1732703104268</created>
|
|
||||||
<option name="number" value="00004" />
|
|
||||||
<option name="presentableId" value="LOCAL-00004" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1732703104268</updated>
|
|
||||||
</task>
|
|
||||||
<task id="LOCAL-00005" summary="Version 27.11 ("fertiger" Tracker)">
|
|
||||||
<option name="closed" value="true" />
|
|
||||||
<created>1732706211714</created>
|
|
||||||
<option name="number" value="00005" />
|
|
||||||
<option name="presentableId" value="LOCAL-00005" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1732706211714</updated>
|
|
||||||
</task>
|
|
||||||
<task id="LOCAL-00006" summary="Funktionierender Puffer 16.12.2024 15.06 Siuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu">
|
|
||||||
<option name="closed" value="true" />
|
|
||||||
<created>1734358037207</created>
|
|
||||||
<option name="number" value="00006" />
|
|
||||||
<option name="presentableId" value="LOCAL-00006" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1734358037207</updated>
|
|
||||||
</task>
|
|
||||||
<option name="localTasksCounter" value="7" />
|
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
@ -183,13 +155,8 @@
|
|||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
|
||||||
<MESSAGE value="First Commit Test" />
|
<MESSAGE value="First Commit Test" />
|
||||||
<MESSAGE value="Version 20.11" />
|
<MESSAGE value="Version 20.11" />
|
||||||
<MESSAGE value="Version 23.11 (Grafics update)" />
|
<option name="LAST_COMMIT_MESSAGE" value="Version 20.11" />
|
||||||
<MESSAGE value="Version 27.11" />
|
|
||||||
<MESSAGE value="Version 27.11 ("fertiger" Tracker)" />
|
|
||||||
<MESSAGE value="Funktionierender Puffer 16.12.2024 15.06 Siuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu" />
|
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Funktionierender Puffer 16.12.2024 15.06 Siuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu" />
|
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
BIN
Welcome0.png
Normal file
BIN
Welcome0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
BIN
Welcome1.png
Normal file
BIN
Welcome1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
BIN
Welcome2.png
Normal file
BIN
Welcome2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
BIN
Welcome3.png
Normal file
BIN
Welcome3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
@ -11,7 +11,7 @@ public class CamPuffer implements Runnable {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
System.load("C:\\Users\\david\\Documents\\Uni\\GTCar\\opencv\\build\\java\\x64\\opencv_java4100.dll");
|
System.load("C:\\Users\\paul3\\OneDrive\\Dokumente\\Studium BME\\Semester 3\\Interaktion\\GTCar V3\\opencv\\build\\java\\x64\\opencv_java4100.dll");
|
||||||
System.out.println("OpenCV manuell geladen!");
|
System.out.println("OpenCV manuell geladen!");
|
||||||
} catch (UnsatisfiedLinkError e) {
|
} catch (UnsatisfiedLinkError e) {
|
||||||
System.err.println("Fehler beim Laden der OpenCV-Bibliothek: " + e.getMessage());
|
System.err.println("Fehler beim Laden der OpenCV-Bibliothek: " + e.getMessage());
|
||||||
@ -74,7 +74,7 @@ public class CamPuffer implements Runnable {
|
|||||||
if (System.currentTimeMillis() - lastGcTime > 1000) {
|
if (System.currentTimeMillis() - lastGcTime > 1000) {
|
||||||
System.gc(); // Triggern des Garbage Collectors
|
System.gc(); // Triggern des Garbage Collectors
|
||||||
lastGcTime = System.currentTimeMillis();
|
lastGcTime = System.currentTimeMillis();
|
||||||
System.out.println("Garbage Collection durchgeführt.");
|
//System.out.println("Garbage Collection durchgeführt.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -98,9 +98,7 @@ public class CamPuffer implements Runnable {
|
|||||||
public Mat getCurrentMat() {
|
public Mat getCurrentMat() {
|
||||||
synchronized (frameBuffer) {
|
synchronized (frameBuffer) {
|
||||||
if (!frameBuffer.isEmpty()) {
|
if (!frameBuffer.isEmpty()) {
|
||||||
Mat resizedFrame = new Mat();
|
return frameBuffer.pollLast().clone(); // Rückgabe des neuesten Frames
|
||||||
Imgproc.resize(frameBuffer.pollLast().clone(), resizedFrame, new Size(1792, 1024));
|
|
||||||
return resizedFrame; // Rückgabe des neuesten Frames
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Mat(); // Rückgabe eines leeren Frames, falls der Puffer leer ist
|
return new Mat(); // Rückgabe eines leeren Frames, falls der Puffer leer ist
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
|
import org.opencv.highgui.HighGui;
|
||||||
import processing.core.PApplet;
|
import processing.core.PApplet;
|
||||||
import java.awt.Point;
|
|
||||||
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.lang.Thread.sleep;
|
||||||
|
|
||||||
public class GameLoop {
|
public class GameLoop {
|
||||||
int activePlayer = 0;
|
int activePlayer = 0;
|
||||||
|
|
||||||
private final int CAM = 1; // Kamera-ID (0 für Webcam, 1 für andere Cams)
|
private final int CAM = 0; // Kamera-ID (0 für Webcam, 1 für andere Cams)
|
||||||
private final int EXP = -9; // Belichtungszeit (idealerweise: 0)
|
private final int EXP = -8; // Belichtungszeit (idealerweise: 0)
|
||||||
private final int FPS = 20; // FPS
|
private final int FPS = 20; // FPS
|
||||||
private final int THV = 245; // Threshold
|
private final int THV = 240;
|
||||||
|
|
||||||
|
private final int TRAIL_LENGTH = 50;
|
||||||
|
|
||||||
ImgAnalyzer tracker;
|
ImgAnalyzer tracker;
|
||||||
CamPuffer camPuffer;
|
CamPuffer camPuffer;
|
||||||
@ -22,22 +28,23 @@ public class GameLoop {
|
|||||||
Player player2;
|
Player player2;
|
||||||
|
|
||||||
public GameLoop(){
|
public GameLoop(){
|
||||||
player1 = new Player(0, "192.168.1.1", 9000);
|
player1 = new Player(0, TRAIL_LENGTH);
|
||||||
player2 = new Player(1, "192.168.1.2", 9000);
|
player2 = new Player(1, TRAIL_LENGTH);
|
||||||
|
|
||||||
camPuffer = new CamPuffer(CAM, EXP, FPS, THV);
|
camPuffer = new CamPuffer(CAM, EXP, FPS, THV);
|
||||||
Thread pufferThread = new Thread(camPuffer);
|
Thread pufferThread = new Thread(camPuffer);
|
||||||
pufferThread.start();
|
pufferThread.start();
|
||||||
|
|
||||||
tracker = new ImgAnalyzer(camPuffer, THV);
|
graphics = new GraphicsProgram();
|
||||||
Thread trackerThread = new Thread(tracker::run);
|
|
||||||
trackerThread.start();
|
|
||||||
|
|
||||||
/*graphics = new GraphicsProgram(player1, player2);
|
|
||||||
String[] args = {"GraphicsProgram"};
|
String[] args = {"GraphicsProgram"};
|
||||||
PApplet.runSketch(args, graphics);
|
PApplet.runSketch(args, graphics);
|
||||||
|
|
||||||
|
tracker = new ImgAnalyzer(camPuffer, THV, graphics);
|
||||||
|
Thread trackerThread = new Thread(tracker::run);
|
||||||
|
trackerThread.start();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
gl = new GameLogic();
|
gl = new GameLogic();
|
||||||
String[] args_ = {"GameLogic"};
|
String[] args_ = {"GameLogic"};
|
||||||
PApplet.runSketch(args_, gl); */
|
PApplet.runSketch(args_, gl); */
|
||||||
@ -46,55 +53,23 @@ public class GameLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void run(){
|
private void run(){
|
||||||
while(true){
|
while(camPuffer.getCurrentMat().elemSize() == 0){
|
||||||
//communicate();
|
System.out.println("Camera booting up");
|
||||||
|
|
||||||
Point p1 = tracker.getP1();
|
|
||||||
//System.out.println("Player 1 is at " + p1.x + " and " + p1.y);
|
|
||||||
Point p2 = tracker.getP2();
|
|
||||||
//System.out.println("Player 2 is at " + p2.x + " and " + p2.y);
|
|
||||||
|
|
||||||
/*player1.setKoords(p1.x, p1.y);
|
|
||||||
player2.setKoords(p2.x, p2.y);
|
|
||||||
|
|
||||||
if(gl.doCheckExtern(player2.getTrail(), p1)){ //Check Position von P1 mit Spur von P2
|
|
||||||
System.out.println("Spieler 1 hat verloren");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(gl.doCheckExtern(player1.getTrail(), p2)){ //Check Position von P2 mit Spur von P1
|
|
||||||
System.out.println("Spieler 2 hat verloren");
|
|
||||||
break;
|
|
||||||
} */
|
|
||||||
|
|
||||||
//draw();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
wait(50);
|
sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
catch (Exception e){
|
|
||||||
}
|
}
|
||||||
|
graphics.nextGameState();
|
||||||
|
//Hier kommt Morphing rein
|
||||||
|
graphics.nextGameState();
|
||||||
|
while(true){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void communicate() {
|
private void communicate() {
|
||||||
//offen für Auto Kommunikation
|
//offen für Auto Kommunikation
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private List<Point> track(){
|
|
||||||
Point p1 = tracker.getP1();
|
|
||||||
Point p2 = tracker.getP2();
|
|
||||||
System.out.println(p1.x);
|
|
||||||
|
|
||||||
player1.setKoords(p1.x, p1.y);
|
|
||||||
player2.setKoords(p2.x, p2.y);
|
|
||||||
|
|
||||||
List<Point> output = new ArrayList<>();
|
|
||||||
output.add(0, p1);
|
|
||||||
output.add(1, p2);
|
|
||||||
return output;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private void draw(){
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -2,16 +2,28 @@ import processing.core.PApplet;
|
|||||||
import processing.core.PImage;
|
import processing.core.PImage;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.List;
|
||||||
|
|
||||||
public class GraphicsProgram extends PApplet {
|
public class GraphicsProgram extends PApplet {
|
||||||
|
|
||||||
private Queue<int[]> playerTrails = new LinkedList<>();
|
private LinkedList<int[]> player1Trail = new LinkedList<>(); // Liste für Spieler 1
|
||||||
|
private LinkedList<int[]> player2Trail = new LinkedList<>(); // Liste für Spieler 2
|
||||||
|
|
||||||
|
private final int TRAIL_LENGTH = 150;
|
||||||
|
private int trailCounter = 17;
|
||||||
|
|
||||||
|
private int distanceTh = 100;
|
||||||
|
|
||||||
|
private int gameState = 0; //0 für Welcome, 1 für Morphing, 2 für Game, 3 für Gameover
|
||||||
|
|
||||||
|
private float startingTime = System.currentTimeMillis();
|
||||||
|
|
||||||
PImage img1;
|
PImage img1;
|
||||||
PImage img2;
|
PImage img2;
|
||||||
PImage backgroundImage;
|
PImage backgroundImage;
|
||||||
|
|
||||||
|
LinkedList<PImage> cameraLoadingImages = new LinkedList<>();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
PApplet.main("GraphicsProgram");
|
PApplet.main("GraphicsProgram");
|
||||||
}
|
}
|
||||||
@ -26,38 +38,124 @@ public class GraphicsProgram extends PApplet {
|
|||||||
|
|
||||||
img1 = loadImage("TrailBlue.png");
|
img1 = loadImage("TrailBlue.png");
|
||||||
img2 = loadImage("TrailRed.png");
|
img2 = loadImage("TrailRed.png");
|
||||||
|
|
||||||
|
cameraLoadingImages.add(loadImage("Welcome0.png"));
|
||||||
|
cameraLoadingImages.add(loadImage("Welcome1.png"));
|
||||||
|
cameraLoadingImages.add(loadImage("Welcome2.png"));
|
||||||
|
cameraLoadingImages.add(loadImage("Welcome3.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw() {
|
public void draw() {
|
||||||
|
if (gameState == 0) {
|
||||||
|
drawWelcome();
|
||||||
|
}
|
||||||
|
if (gameState == 1) {
|
||||||
|
setUpMorphing();
|
||||||
|
}
|
||||||
|
if (gameState == 2) {
|
||||||
|
gameScreen();
|
||||||
|
}
|
||||||
|
if (gameState == 3) {
|
||||||
|
gameOverScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawWelcome() {
|
||||||
|
int waitingTime = (int) (System.currentTimeMillis() / 1000);
|
||||||
|
switch (waitingTime % 4) {
|
||||||
|
case 0:
|
||||||
|
image(cameraLoadingImages.get(0), 0, 0);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
image(cameraLoadingImages.get(1), 0, 0);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
image(cameraLoadingImages.get(2), 0, 0);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
image(cameraLoadingImages.get(3), 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpMorphing() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private void gameScreen() {
|
||||||
image(backgroundImage, 0, 0); // Hintergrund zeichnen
|
image(backgroundImage, 0, 0); // Hintergrund zeichnen
|
||||||
|
strokeWeight(20); // Linienstärke festlegen
|
||||||
|
// Linien für Spieler 1 zeichnen
|
||||||
|
stroke(0, 0, 255); // Blau
|
||||||
|
drawTrail(player1Trail, 1);
|
||||||
|
// Linien für Spieler 2 zeichnen
|
||||||
|
stroke(255, 0, 0); // Rot
|
||||||
|
drawTrail(player2Trail, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void gameOverScreen() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nextGameState() {
|
||||||
|
gameState++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methode, um Linien für eine gegebene Trail-Liste zu zeichnen
|
||||||
|
private void drawTrail(LinkedList<int[]> trail, int player) {
|
||||||
|
if (trail.size() < 4) return; // Mindestens 2 Punkte nötig, um Linien zu zeichnen
|
||||||
|
|
||||||
|
for (int i = 0; i < trail.size() - 1; i++) {
|
||||||
|
if (player == 1){
|
||||||
|
stroke(170-(255/trail.size() * i),0,255/2 + (255/trail.size() * i)/2);
|
||||||
|
} else if (player == 2){
|
||||||
|
stroke(255, 170-(255/trail.size() * i), 0);
|
||||||
|
}
|
||||||
|
int[] current = new int[2];
|
||||||
|
try {
|
||||||
|
current = trail.get(i);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
System.out.println("Index 1 out of bounds");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] next = new int[2];
|
||||||
|
try {
|
||||||
|
next = trail.get(i + 1);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
System.out.println("Index 2 out of bounds");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Null-Check für die Punkte
|
||||||
|
if (current != null && next != null) {
|
||||||
|
if (current[0] - next[0] > -distanceTh && current[0] - next[0] < distanceTh && current[1] - next[1] > -distanceTh && current[1] - next[1] < distanceTh) {
|
||||||
|
line(current[0], current[1], next[0], next[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int particleSizeP1 = 30;
|
// Methode zum Aktualisieren der Trails für beide Spieler
|
||||||
int particleSizeP2 = 30;
|
public void updateTrail(int x1, int y1, int x2, int y2) {
|
||||||
|
if (x1 >= 0 && y1 >= 0) {
|
||||||
|
addToTrail(player1Trail, x1, y1);
|
||||||
|
}
|
||||||
|
if (x2 >= 0 && y2 >= 0) {
|
||||||
|
addToTrail(player2Trail, x2, y2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methode zum Hinzufügen eines Punktes zur Trail-Liste und Begrenzung auf 20 Einträge
|
||||||
|
private void addToTrail(LinkedList<int[]> trail, int x, int y) {
|
||||||
// Kopie von trailPlayer1 erstellen und durch die Kopie iterieren
|
if (trailCounter % 7 == 0) {
|
||||||
for (int[] koordinates : new LinkedList<>(playerTrails)) {
|
if (x >= 0 && y >= 0) {
|
||||||
int x1 = koordinates[0];
|
trail.add(new int[]{x, y});
|
||||||
int y1 = koordinates[1];
|
if (trail.size() > TRAIL_LENGTH) {
|
||||||
int x2 = koordinates[2];
|
trail.removeFirst();
|
||||||
int y2 = koordinates[3];
|
}
|
||||||
|
}
|
||||||
fill(0, 0, 255);
|
}
|
||||||
rect(x1, y1, particleSizeP1, particleSizeP1);
|
trailCounter++;
|
||||||
//image(img1, x1, y1, particleSizeP1, particleSizeP1);
|
}
|
||||||
|
|
||||||
fill(255, 0, 0);
|
|
||||||
rect(x2, y2, particleSizeP2, particleSizeP2);
|
|
||||||
//image(img2, x2, y2, particleSizeP2, particleSizeP2);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateTrail(Queue<int[]> trails){
|
|
||||||
this.playerTrails = trails;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -6,11 +6,8 @@ import org.opencv.imgproc.Moments;
|
|||||||
import org.opencv.videoio.Videoio;
|
import org.opencv.videoio.Videoio;
|
||||||
import processing.core.PApplet;
|
import processing.core.PApplet;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.util.Queue;
|
|
||||||
|
|
||||||
public class ImgAnalyzer {
|
public class ImgAnalyzer {
|
||||||
|
|
||||||
@ -19,19 +16,17 @@ public class ImgAnalyzer {
|
|||||||
private Point currentPositionP1 = new Point(0, 0);
|
private Point currentPositionP1 = new Point(0, 0);
|
||||||
private Point currentPositionP2 = new Point(0, 0);
|
private Point currentPositionP2 = new Point(0, 0);
|
||||||
Queue<int[]> trails = new LinkedList<>();
|
Queue<int[]> trails = new LinkedList<>();
|
||||||
private final int TRAIL_LENGTH = 200;
|
private final int TRAIL_LENGTH = 90;
|
||||||
|
|
||||||
private final CamPuffer camPuffer;
|
private final CamPuffer camPuffer;
|
||||||
private GraphicsProgram playerGraphics;
|
private GraphicsProgram playerGraphics;
|
||||||
|
|
||||||
public ImgAnalyzer(CamPuffer cP, int threshold) {
|
public ImgAnalyzer(CamPuffer cP, int threshold, GraphicsProgram graphicsProgram) {
|
||||||
THV = threshold;
|
THV = threshold;
|
||||||
camPuffer = cP;
|
camPuffer = cP;
|
||||||
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
||||||
|
|
||||||
playerGraphics = new GraphicsProgram();
|
playerGraphics = graphicsProgram;
|
||||||
String[] args ={"GraphicsProgram"};
|
|
||||||
PApplet.runSketch(args, playerGraphics);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -39,6 +34,7 @@ public class ImgAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
/*
|
||||||
while (camPuffer.getCurrentMat().elemSize() == 0) {
|
while (camPuffer.getCurrentMat().elemSize() == 0) {
|
||||||
System.out.println("Warten auf das erste Bild...");
|
System.out.println("Warten auf das erste Bild...");
|
||||||
try {
|
try {
|
||||||
@ -48,6 +44,7 @@ public class ImgAnalyzer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
Mat currentImg = new Mat();
|
Mat currentImg = new Mat();
|
||||||
Mat grayFrame = new Mat();
|
Mat grayFrame = new Mat();
|
||||||
@ -88,11 +85,21 @@ public class ImgAnalyzer {
|
|||||||
if(trails.size() > TRAIL_LENGTH){
|
if(trails.size() > TRAIL_LENGTH){
|
||||||
trails.poll();
|
trails.poll();
|
||||||
}
|
}
|
||||||
System.out.println(trails.size());
|
playerGraphics.updateTrail(currentPositionP1.x, currentPositionP1.y, currentPositionP2.x, currentPositionP2.y);
|
||||||
playerGraphics.updateTrail(trails);
|
//playerGraphics.draw();
|
||||||
playerGraphics.draw();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*org.opencv.core.Point pp1 = new org.opencv.core.Point(currentPositionP1.x, currentPositionP1.y);
|
||||||
|
Imgproc.circle(currentImg, pp1, 10, new Scalar(255,0,0), -1);
|
||||||
|
|
||||||
|
org.opencv.core.Point pp2 = new org.opencv.core.Point(currentPositionP2.x, currentPositionP2.y);
|
||||||
|
Imgproc.circle(currentImg, pp2, 10, new Scalar(0,0,255), -1);
|
||||||
|
|
||||||
|
if(currentImg.elemSize() != 0) {
|
||||||
|
|
||||||
|
HighGui.imshow("el thunfisch", currentImg);
|
||||||
|
|
||||||
|
} */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,24 +110,42 @@ public class ImgAnalyzer {
|
|||||||
// Finde Konturen
|
// Finde Konturen
|
||||||
Imgproc.findContours(thresholdFrame, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
|
Imgproc.findContours(thresholdFrame, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
|
||||||
|
|
||||||
// Sortiere Konturen nach Fläche (absteigend)
|
// Liste für die Positionen und zugehörige Pixelanzahl
|
||||||
contours.sort((c1, c2) -> Double.compare(Imgproc.contourArea(c2), Imgproc.contourArea(c1)));
|
|
||||||
|
|
||||||
// Speichere die Positionen der zwei größten Konturen
|
|
||||||
List<Point> positions = new ArrayList<>();
|
List<Point> positions = new ArrayList<>();
|
||||||
|
List<Double> whitePixelCounts = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < Math.min(contours.size(), 2); i++) {
|
for (MatOfPoint contour : contours) {
|
||||||
Moments moments = Imgproc.moments(contours.get(i));
|
Moments moments = Imgproc.moments(contour);
|
||||||
if (moments.get_m00() != 0) {
|
if (moments.get_m00() != 0) {
|
||||||
|
// Berechne den Mittelpunkt der Kontur
|
||||||
int cx = (int) (moments.get_m10() / moments.get_m00());
|
int cx = (int) (moments.get_m10() / moments.get_m00());
|
||||||
int cy = (int) (moments.get_m01() / moments.get_m00());
|
int cy = (int) (moments.get_m01() / moments.get_m00());
|
||||||
|
|
||||||
|
// Berechne die Anzahl der weißen Pixel in der Kontur
|
||||||
|
Mat mask = Mat.zeros(thresholdFrame.size(), CvType.CV_8UC1);
|
||||||
|
Imgproc.drawContours(mask, List.of(contour), 0, new Scalar(255), -1); // Fülle die Kontur mit Weiß
|
||||||
|
double whitePixels = Core.sumElems(mask).val[0] / 255.0; // Summe der Pixelwerte durch 255 (1 Pixel = 255)
|
||||||
|
|
||||||
|
// Speichere Position und Pixelanzahl
|
||||||
positions.add(new Point(cx, cy));
|
positions.add(new Point(cx, cy));
|
||||||
|
whitePixelCounts.add(whitePixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Check
|
|
||||||
return positions;
|
// Sortiere die Positionen basierend auf der Anzahl weißer Pixel (absteigend)
|
||||||
|
List<Point> sortedPositions = new ArrayList<>();
|
||||||
|
while (!whitePixelCounts.isEmpty()) {
|
||||||
|
int maxIndex = whitePixelCounts.indexOf(Collections.max(whitePixelCounts));
|
||||||
|
sortedPositions.add(positions.get(maxIndex));
|
||||||
|
positions.remove(maxIndex);
|
||||||
|
whitePixelCounts.remove(maxIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gib die Positionen der zwei größten Konturen zurück
|
||||||
|
return sortedPositions.subList(0, Math.min(sortedPositions.size(), 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized Point getP1() {
|
public synchronized Point getP1() {
|
||||||
return currentPositionP1;
|
return currentPositionP1;
|
||||||
}
|
}
|
||||||
|
@ -7,20 +7,13 @@ public class Player {
|
|||||||
private final int ID;
|
private final int ID;
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
|
private final int TRAIL_LENGTH;
|
||||||
private String name = "Thunfisch";
|
|
||||||
Queue<int[]> trail = new LinkedList<>();
|
Queue<int[]> trail = new LinkedList<>();
|
||||||
|
|
||||||
ArduinoCommunication arduinoCommunicator;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private final int TRAIL_LENGTH = 30;
|
|
||||||
|
|
||||||
// Konstruktor
|
// Konstruktor
|
||||||
public Player(int id, String finalIpAddress, int finalPortNr) {
|
public Player(int id, int trailLength) {
|
||||||
this.ID = id;
|
this.ID = id;
|
||||||
arduinoCommunicator = new ArduinoCommunication(finalIpAddress, finalPortNr);
|
this.TRAIL_LENGTH = trailLength;
|
||||||
trail.add(new int[]{0,0});
|
trail.add(new int[]{0,0});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,8 +25,7 @@ public class Player {
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fügt 2 Koordinaten zum Trail hinzu und verhindert, dass dieser zu lang wird
|
||||||
//fügt 2 Koordinaten zum Trail hinzu nd verhindert, dass dieser zulang wird
|
|
||||||
public void setKoords(int x, int y){
|
public void setKoords(int x, int y){
|
||||||
addToTrail(x,y);
|
addToTrail(x,y);
|
||||||
this.x = x;
|
this.x = x;
|
||||||
@ -47,20 +39,9 @@ public class Player {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Queue<int[]> getTrail(){
|
public Queue<int[]> getTrail(){
|
||||||
return trail;
|
return trail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToCar(int light, double steer, double speed){
|
|
||||||
arduinoCommunicator.sendMessage(light, steer, speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//gibt aktuelle Position aus
|
|
||||||
public void printPosition() {
|
|
||||||
System.out.println(trail);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user