16.12.24 22:39 Graphic manschma noch überforderet

This commit is contained in:
David Moeckel 2024-12-16 22:40:09 +01:00
parent a7efee2023
commit ada8284535
8 changed files with 144 additions and 132 deletions

88
.idea/workspace.xml generated
View File

@ -4,11 +4,15 @@
<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&#10;Bild wird nicht korrekt gespeichert&#10;16.12.2024 16:48"> <list default="true" id="4d75e996-cee4-4ec6-b802-5b56d0c0eac4" name="Changes" comment="Funktionierender Puffer&#10;16.12.2024 15.06&#10;Siuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu">
<change afterPath="$PROJECT_DIR$/Background.png" 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/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" />
<change beforePath="$PROJECT_DIR$/src/main/java/Player.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Player.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -29,38 +33,41 @@
&quot;associatedIndex&quot;: 8 &quot;associatedIndex&quot;: 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">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;Application.GTCar.executor&quot;: &quot;Run&quot;, "ASKED_ADD_EXTERNAL_FILES": "true",
&quot;Application.GraphicsProgram.executor&quot;: &quot;Run&quot;, "Application.GTCar.executor": "Run",
&quot;Application.Main.executor&quot;: &quot;Run&quot;, "Application.GraphicsProgram.executor": "Run",
&quot;Application.Tracker.executor&quot;: &quot;Run&quot;, "Application.Main.executor": "Run",
&quot;Downloaded.Files.Path.Enabled&quot;: &quot;false&quot;, "Application.Tracker.executor": "Run",
&quot;Repository.Attach.Annotations&quot;: &quot;false&quot;, "Downloaded.Files.Path.Enabled": "false",
&quot;Repository.Attach.JavaDocs&quot;: &quot;false&quot;, "Repository.Attach.Annotations": "false",
&quot;Repository.Attach.Sources&quot;: &quot;false&quot;, "Repository.Attach.JavaDocs": "false",
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "Repository.Attach.Sources": "false",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;com.codeium.enabled&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;git-widget-placeholder&quot;: &quot;master&quot;, "com.codeium.enabled": "true",
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;, "git-widget-placeholder": "master",
&quot;last_opened_file_path&quot;: &quot;C:/Users/david/Documents/Uni/GTCar/opencv/build/java/opencv-4100.jar&quot;, "kotlin-language-version-configured": "true",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "last_opened_file_path": "C:/Users/david/Documents/Uni/GTCar/opencv/build/java/opencv-4100.jar",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;project.structure.last.edited&quot;: &quot;Libraries&quot;, "nodejs_package_manager_path": "npm",
&quot;project.structure.proportion&quot;: &quot;0.15&quot;, "project.structure.last.edited": "Libraries",
&quot;project.structure.side.proportion&quot;: &quot;0.24022989&quot;, "project.structure.proportion": "0.15",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "project.structure.side.proportion": "0.24022989",
"vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="RunManager" selected="Application.Main"> <component name="RunManager" selected="Application.Main">
<configuration name="GTCar" type="Application" factoryName="Application"> <configuration name="GTCar" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="Tracker" /> <option name="MAIN_CLASS_NAME" value="Tracker" />
@ -80,7 +87,7 @@
<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=&quot;C:\Users\paul3\OneDrive\Dokumente\Studium BME\Semester 3\Interaktion\opencv\build\java\x64&quot;" /> <option name="VM_PARAMETERS" value="-Djava.library.path=C:\Users\david\Documents\Uni\GTCar\opencv\build\java\x64" />
<method v="2"> <method v="2">
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
@ -97,14 +104,6 @@
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-jdk-9823dce3aa75-28b599e66164-intellij.indexing.shared.core-IU-242.23726.103" />
<option value="bundled-js-predefined-d6986cc7102b-5c90d61e3bab-JavaScript-IU-242.23726.103" />
</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">
@ -117,7 +116,6 @@
<workItem from="1732113837570" duration="20534000" /> <workItem from="1732113837570" duration="20534000" />
<workItem from="1733327375447" duration="951000" /> <workItem from="1733327375447" duration="951000" />
<workItem from="1734091457440" duration="10746000" /> <workItem from="1734091457440" duration="10746000" />
<workItem from="1734364915397" duration="9202000" />
</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" />
@ -167,15 +165,7 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1734358037207</updated> <updated>1734358037207</updated>
</task> </task>
<task id="LOCAL-00007" summary="Funktionierender Puffer&#10;Bild wird nicht korrekt gespeichert&#10;16.12.2024 16:48"> <option name="localTasksCounter" value="7" />
<option name="closed" value="true" />
<created>1734364131101</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1734364131101</updated>
</task>
<option name="localTasksCounter" value="8" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -193,13 +183,13 @@
</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)" /> <MESSAGE value="Version 23.11 (Grafics update)" />
<MESSAGE value="Version 27.11" /> <MESSAGE value="Version 27.11" />
<MESSAGE value="Version 27.11 (&quot;fertiger&quot; Tracker)" /> <MESSAGE value="Version 27.11 (&quot;fertiger&quot; Tracker)" />
<MESSAGE value="Funktionierender Puffer&#10;16.12.2024 15.06&#10;Siuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu" /> <MESSAGE value="Funktionierender Puffer&#10;16.12.2024 15.06&#10;Siuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu" />
<MESSAGE value="Funktionierender Puffer&#10;Bild wird nicht korrekt gespeichert&#10;16.12.2024 16:48" /> <option name="LAST_COMMIT_MESSAGE" value="Funktionierender Puffer&#10;16.12.2024 15.06&#10;Siuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu" />
<option name="LAST_COMMIT_MESSAGE" value="Funktionierender Puffer&#10;Bild wird nicht korrekt gespeichert&#10;16.12.2024 16:48" />
</component> </component>
</project> </project>

BIN
Background.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

View File

@ -11,7 +11,7 @@ public class CamPuffer implements Runnable {
static { static {
try { try {
System.load("C:\\Users\\paul3\\OneDrive\\Dokumente\\Studium BME\\Semester 3\\Interaktion\\GTCar V3\\opencv\\build\\java\\x64\\opencv_java4100.dll"); System.load("C:\\Users\\david\\Documents\\Uni\\GTCar\\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());
@ -98,7 +98,9 @@ public class CamPuffer implements Runnable {
public Mat getCurrentMat() { public Mat getCurrentMat() {
synchronized (frameBuffer) { synchronized (frameBuffer) {
if (!frameBuffer.isEmpty()) { if (!frameBuffer.isEmpty()) {
return frameBuffer.pollLast().clone(); // Rückgabe des neuesten Frames Mat resizedFrame = new Mat();
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

View File

@ -9,6 +9,7 @@ public class GameLogic extends PApplet {
PApplet.main("GameLogic"); PApplet.main("GameLogic");
} }
private static final int MAX_TRAIL_SIZE = 100; // Maximale Größe des Trails
private Queue<int[]> trail = new LinkedList<>(); private Queue<int[]> trail = new LinkedList<>();
private Point testPoint = new Point(200, 200); private Point testPoint = new Point(200, 200);
@ -17,19 +18,25 @@ public class GameLogic extends PApplet {
} }
public void setup() { public void setup() {
noLoop(); // Zeichnen nur bei Bedarf
fillTrail(); // Beispielpfad erstellen fillTrail(); // Beispielpfad erstellen
//boolean collision = doCheck(trail, testPoint); noLoop(); // Zeichnen nur bei Bedarf
System.out.println("Collision detected: ");
} }
private void fillTrail() { private void fillTrail() {
// Beispielhafte Füllung der Spur // Beispielhafte Füllung der Spur (maximale Größe beachten)
for (int i = 0; i < 100; i++) { for (int i = 0; i < MAX_TRAIL_SIZE; i++) {
trail.add(new int[]{50 + i * 5, 300}); // Punkte entlang der x-Achse trail.add(new int[]{50 + i * 5, 300}); // Punkte entlang der x-Achse
} }
} }
// Methode zum Hinzufügen eines neuen Punkts, begrenzt auf MAX_TRAIL_SIZE
public void addToTrail(int x, int y) {
if (trail.size() >= MAX_TRAIL_SIZE) {
trail.poll(); // Entferne das älteste Element, wenn die maximale Größe erreicht ist
}
trail.add(new int[]{x, y});
}
public boolean doCheckExtern(Queue<int[]> trail, Point point) { public boolean doCheckExtern(Queue<int[]> trail, Point point) {
return doCheck(trail, point); return doCheck(trail, point);
} }
@ -37,9 +44,9 @@ public class GameLogic extends PApplet {
public boolean doCheck(Queue<int[]> trail, Point point) { public boolean doCheck(Queue<int[]> trail, Point point) {
int particleSize = 10; int particleSize = 10;
// Zeichne den Pfad auf das Canvas // Zeichne den Pfad auf das Canvas nur, wenn nötig
background(255); // Weißer Hintergrund background(255); // Weißer Hintergrund
for (int[] coordinates : new LinkedList<>(trail)) { for (int[] coordinates : trail) {
int x = coordinates[0]; int x = coordinates[0];
int y = coordinates[1]; int y = coordinates[1];
fill(0); // Schwarz fill(0); // Schwarz

View File

@ -68,6 +68,12 @@ public class GameLoop {
} */ } */
//draw(); //draw();
try{
wait(50);
}
catch (Exception e){
}
} }
} }
@ -90,6 +96,5 @@ public class GameLoop {
}*/ }*/
private void draw(){ private void draw(){
} }
} }

View File

@ -6,18 +6,11 @@ import java.util.Queue;
public class GraphicsProgram extends PApplet { public class GraphicsProgram extends PApplet {
PImage imgBlue; private Queue<int[]> playerTrails = new LinkedList<>();
PImage imgRed;
Player player1; PImage img1;
Player player2; PImage img2;
PImage backgroundImage;
private final int TRAIL_LENGTH = 30;
public GraphicsProgram(Player player1, Player player2) {
this.player1 = player1; // Beispiel: Initialgröße setzen
this.player2 = player2;
}
public static void main(String[] args) { public static void main(String[] args) {
PApplet.main("GraphicsProgram"); PApplet.main("GraphicsProgram");
@ -28,48 +21,43 @@ public class GraphicsProgram extends PApplet {
} }
public void setup() { public void setup() {
imgBlue = loadImage("TrailBlue.png"); backgroundImage = loadImage("Background.png");
imgRed = loadImage("TrailRed.png"); backgroundImage.resize(1792, 1024);
background(0);
img1 = loadImage("TrailBlue.png");
img2 = loadImage("TrailRed.png");
} }
public void draw() { public void draw() {
drawPlayer(0); image(backgroundImage, 0, 0); // Hintergrund zeichnen
drawPlayer(1);
}
public void drawPlayer(int playerID){
int particleSize = 5;
Queue<int[]> trail; int particleSizeP1 = 30;
int particleSizeP2 = 30;
if(playerID == 0){
trail = player1.getTrail();
} else{
trail = player2.getTrail();
}
while(!trail.isEmpty()) {
int[] koordinaten = trail.poll();
int x = koordinaten[0];
int y = koordinaten[1];
System.out.println(); // Kopie von trailPlayer1 erstellen und durch die Kopie iterieren
for (int[] koordinates : new LinkedList<>(playerTrails)) {
int x1 = koordinates[0];
int y1 = koordinates[1];
int x2 = koordinates[2];
int y2 = koordinates[3];
fill(0, 0, 255);
rect(x1, y1, particleSizeP1, particleSizeP1);
//image(img1, x1, y1, particleSizeP1, particleSizeP1);
fill(255, 0, 0);
rect(x2, y2, particleSizeP2, particleSizeP2);
//image(img2, x2, y2, particleSizeP2, particleSizeP2);
if(playerID == 0){
image(imgBlue, x, y, particleSize, particleSize);
} else if (playerID == 1) {
image(imgRed, x, y, particleSize, particleSize);
}else{
fill(0, 255, 0);
rect(x, y, particleSize, particleSize);
}
particleSize ++;
} }
} }
public void drawEvent(){ public void updateTrail(Queue<int[]> trails){
this.playerTrails = trails;
} }
} }

View File

@ -4,10 +4,13 @@ import org.opencv.highgui.HighGui;
import org.opencv.imgproc.Imgproc; import org.opencv.imgproc.Imgproc;
import org.opencv.imgproc.Moments; import org.opencv.imgproc.Moments;
import org.opencv.videoio.Videoio; import org.opencv.videoio.Videoio;
import processing.core.PApplet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.awt.Point; import java.awt.Point;
import java.util.Queue;
public class ImgAnalyzer { public class ImgAnalyzer {
@ -15,13 +18,20 @@ 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<>();
private final int TRAIL_LENGTH = 200;
private final CamPuffer camPuffer; private final CamPuffer camPuffer;
private GraphicsProgram playerGraphics;
public ImgAnalyzer(CamPuffer cP, int threshold) { public ImgAnalyzer(CamPuffer cP, int threshold) {
THV = threshold; THV = threshold;
camPuffer = cP; camPuffer = cP;
System.loadLibrary(Core.NATIVE_LIBRARY_NAME); System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
playerGraphics = new GraphicsProgram();
String[] args ={"GraphicsProgram"};
PApplet.runSketch(args, playerGraphics);
} }
public static void main(String[] args) { public static void main(String[] args) {
@ -71,9 +81,17 @@ public class ImgAnalyzer {
if (positions.size() >= 2) { if (positions.size() >= 2) {
currentPositionP1 = positions.get(0); currentPositionP1 = positions.get(0);
currentPositionP2 = positions.get(1); currentPositionP2 = positions.get(1);
System.out.println("currentPositionP1: " + currentPositionP1 + " currentPositionP2: " + currentPositionP2); //System.out.println("currentPositionP1: " + currentPositionP1 + " currentPositionP2: " + currentPositionP2);
} }
trails.add(new int[]{currentPositionP1.x, currentPositionP1.y, currentPositionP2.x, currentPositionP2.y});
if(trails.size() > TRAIL_LENGTH){
trails.poll();
}
System.out.println(trails.size());
playerGraphics.updateTrail(trails);
playerGraphics.draw();
} }
} }
} }

View File

@ -1,3 +1,4 @@
import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
@ -20,6 +21,7 @@ public class Player {
public Player(int id, String finalIpAddress, int finalPortNr) { public Player(int id, String finalIpAddress, int finalPortNr) {
this.ID = id; this.ID = id;
arduinoCommunicator = new ArduinoCommunication(finalIpAddress, finalPortNr); arduinoCommunicator = new ArduinoCommunication(finalIpAddress, finalPortNr);
trail.add(new int[]{0,0});
} }
public int getX(){ public int getX(){
@ -41,10 +43,10 @@ public class Player {
private void addToTrail(int x, int y) { private void addToTrail(int x, int y) {
trail.add(new int[]{x, y}); trail.add(new int[]{x, y});
if (trail.size() > TRAIL_LENGTH) { if (trail.size() > TRAIL_LENGTH) {
trail.poll(); trail.poll(); // Entfernt das älteste Element
}
} }
}
public Queue<int[]> getTrail(){ public Queue<int[]> getTrail(){
return trail; return trail;