Browse Source

16.12.24 22:39 Graphic manschma noch überforderet

master
David Moeckel 6 days ago
parent
commit
ada8284535

+ 39
- 49
.idea/workspace.xml View File

@@ -4,11 +4,15 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<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$/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/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/Player.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Player.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -29,38 +33,41 @@
&quot;associatedIndex&quot;: 8
}</component>
<component name="ProjectId" id="2p7Eq8ZJM8BEjLybOnAdhzZ82uv" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Application.GTCar.executor&quot;: &quot;Run&quot;,
&quot;Application.GraphicsProgram.executor&quot;: &quot;Run&quot;,
&quot;Application.Main.executor&quot;: &quot;Run&quot;,
&quot;Application.Tracker.executor&quot;: &quot;Run&quot;,
&quot;Downloaded.Files.Path.Enabled&quot;: &quot;false&quot;,
&quot;Repository.Attach.Annotations&quot;: &quot;false&quot;,
&quot;Repository.Attach.JavaDocs&quot;: &quot;false&quot;,
&quot;Repository.Attach.Sources&quot;: &quot;false&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;com.codeium.enabled&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/david/Documents/Uni/GTCar/opencv/build/java/opencv-4100.jar&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;project.structure.last.edited&quot;: &quot;Libraries&quot;,
&quot;project.structure.proportion&quot;: &quot;0.15&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.24022989&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_ADD_EXTERNAL_FILES": "true",
"Application.GTCar.executor": "Run",
"Application.GraphicsProgram.executor": "Run",
"Application.Main.executor": "Run",
"Application.Tracker.executor": "Run",
"Downloaded.Files.Path.Enabled": "false",
"Repository.Attach.Annotations": "false",
"Repository.Attach.JavaDocs": "false",
"Repository.Attach.Sources": "false",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"com.codeium.enabled": "true",
"git-widget-placeholder": "master",
"kotlin-language-version-configured": "true",
"last_opened_file_path": "C:/Users/david/Documents/Uni/GTCar/opencv/build/java/opencv-4100.jar",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"project.structure.last.edited": "Libraries",
"project.structure.proportion": "0.15",
"project.structure.side.proportion": "0.24022989",
"vue.rearranger.settings.migration": "true"
}
}</component>
}]]></component>
<component name="RunManager" selected="Application.Main">
<configuration name="GTCar" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="Tracker" />
@@ -80,7 +87,7 @@
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Main" />
<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">
<option name="Make" enabled="true" />
</method>
@@ -97,14 +104,6 @@
</list>
</recent_temporary>
</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="TaskManager">
<task active="true" id="Default" summary="Default task">
@@ -117,7 +116,6 @@
<workItem from="1732113837570" duration="20534000" />
<workItem from="1733327375447" duration="951000" />
<workItem from="1734091457440" duration="10746000" />
<workItem from="1734364915397" duration="9202000" />
</task>
<task id="LOCAL-00001" summary="First Commit Test">
<option name="closed" value="true" />
@@ -167,15 +165,7 @@
<option name="project" value="LOCAL" />
<updated>1734358037207</updated>
</task>
<task id="LOCAL-00007" summary="Funktionierender Puffer&#10;Bild wird nicht korrekt gespeichert&#10;16.12.2024 16:48">
<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" />
<option name="localTasksCounter" value="7" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -193,13 +183,13 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="First Commit Test" />
<MESSAGE value="Version 20.11" />
<MESSAGE value="Version 23.11 (Grafics update)" />
<MESSAGE value="Version 27.11" />
<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;Bild wird nicht korrekt gespeichert&#10;16.12.2024 16:48" />
<option name="LAST_COMMIT_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" />
</component>
</project>

BIN
Background.png View File


+ 5
- 3
src/main/java/CamPuffer.java View File

@@ -11,7 +11,7 @@ public class CamPuffer implements Runnable {

static {
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!");
} catch (UnsatisfiedLinkError e) {
System.err.println("Fehler beim Laden der OpenCV-Bibliothek: " + e.getMessage());
@@ -98,7 +98,9 @@ public class CamPuffer implements Runnable {
public Mat getCurrentMat() {
synchronized (frameBuffer) {
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
@@ -124,4 +126,4 @@ public class CamPuffer implements Runnable {
System.out.println("Kamera geöffnet und eingerichtet");
return capture;
}
}
}

+ 15
- 8
src/main/java/GameLogic.java View File

@@ -9,6 +9,7 @@ public class GameLogic extends PApplet {
PApplet.main("GameLogic");
}

private static final int MAX_TRAIL_SIZE = 100; // Maximale Größe des Trails
private Queue<int[]> trail = new LinkedList<>();
private Point testPoint = new Point(200, 200);

@@ -17,29 +18,35 @@ public class GameLogic extends PApplet {
}

public void setup() {
noLoop(); // Zeichnen nur bei Bedarf
fillTrail(); // Beispielpfad erstellen
//boolean collision = doCheck(trail, testPoint);
System.out.println("Collision detected: ");
noLoop(); // Zeichnen nur bei Bedarf
}

private void fillTrail() {
// Beispielhafte Füllung der Spur
for (int i = 0; i < 100; i++) {
// Beispielhafte Füllung der Spur (maximale Größe beachten)
for (int i = 0; i < MAX_TRAIL_SIZE; i++) {
trail.add(new int[]{50 + i * 5, 300}); // Punkte entlang der x-Achse
}
}

public boolean doCheckExtern(Queue<int[]> trail, Point point){
// 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) {
return doCheck(trail, point);
}

public boolean doCheck(Queue<int[]> trail, Point point) {
int particleSize = 10;

// Zeichne den Pfad auf das Canvas
// Zeichne den Pfad auf das Canvas nur, wenn nötig
background(255); // Weißer Hintergrund
for (int[] coordinates : new LinkedList<>(trail)) {
for (int[] coordinates : trail) {
int x = coordinates[0];
int y = coordinates[1];
fill(0); // Schwarz

+ 7
- 2
src/main/java/GameLoop.java View File

@@ -68,6 +68,12 @@ public class GameLoop {
} */

//draw();

try{
wait(50);
}
catch (Exception e){
}
}
}

@@ -90,6 +96,5 @@ public class GameLoop {
}*/

private void draw(){

}
}
}

+ 33
- 45
src/main/java/GraphicsProgram.java View File

@@ -6,18 +6,11 @@ import java.util.Queue;

public class GraphicsProgram extends PApplet {

PImage imgBlue;
PImage imgRed;
private Queue<int[]> playerTrails = new LinkedList<>();

Player player1;
Player player2;

private final int TRAIL_LENGTH = 30;

public GraphicsProgram(Player player1, Player player2) {
this.player1 = player1; // Beispiel: Initialgröße setzen
this.player2 = player2;
}
PImage img1;
PImage img2;
PImage backgroundImage;

public static void main(String[] args) {
PApplet.main("GraphicsProgram");
@@ -27,49 +20,44 @@ public class GraphicsProgram extends PApplet {
fullScreen();
}

public void setup(){
imgBlue = loadImage("TrailBlue.png");
imgRed = loadImage("TrailRed.png");
background(0);
}
public void setup() {
backgroundImage = loadImage("Background.png");
backgroundImage.resize(1792, 1024);

public void draw(){
drawPlayer(0);
drawPlayer(1);
img1 = loadImage("TrailBlue.png");
img2 = loadImage("TrailRed.png");
}
public void drawPlayer(int playerID){

int particleSize = 5;
public void draw() {
image(backgroundImage, 0, 0); // Hintergrund zeichnen

Queue<int[]> trail;

if(playerID == 0){
trail = player1.getTrail();
} else{
trail = player2.getTrail();
}
int particleSizeP1 = 30;
int particleSizeP2 = 30;



// 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);


while(!trail.isEmpty()) {
int[] koordinaten = trail.poll();
int x = koordinaten[0];
int y = koordinaten[1];

System.out.println();

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;
}
}

+ 40
- 22
src/main/java/ImgAnalyzer.java View File

@@ -4,10 +4,13 @@ import org.opencv.highgui.HighGui;
import org.opencv.imgproc.Imgproc;
import org.opencv.imgproc.Moments;
import org.opencv.videoio.Videoio;
import processing.core.PApplet;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.awt.Point;
import java.util.Queue;

public class ImgAnalyzer {

@@ -15,13 +18,20 @@ public class ImgAnalyzer {

private Point currentPositionP1 = 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 GraphicsProgram playerGraphics;

public ImgAnalyzer(CamPuffer cP, int threshold) {
THV = threshold;
camPuffer = cP;
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

playerGraphics = new GraphicsProgram();
String[] args ={"GraphicsProgram"};
PApplet.runSketch(args, playerGraphics);
}

public static void main(String[] args) {
@@ -44,37 +54,45 @@ public class ImgAnalyzer {
Mat thresholdFrame = new Mat();

while (true) {
try {
currentImg = camPuffer.getCurrentMat();
try {
currentImg = camPuffer.getCurrentMat();

if(currentImg.elemSize() != 0) {
if(currentImg.elemSize() != 0) {

// In Graustufen konvertieren
Imgproc.cvtColor(currentImg, grayFrame, Imgproc.COLOR_BGR2GRAY);
// In Graustufen konvertieren
Imgproc.cvtColor(currentImg, grayFrame, Imgproc.COLOR_BGR2GRAY);

// Threshold anwenden
Imgproc.threshold(grayFrame, thresholdFrame, THV, 255, Imgproc.THRESH_BINARY);
// Threshold anwenden
Imgproc.threshold(grayFrame, thresholdFrame, THV, 255, Imgproc.THRESH_BINARY);

//Ausgabe des Bildes zum Prüfen
HighGui.imshow("ThunfischHighGui", thresholdFrame);
HighGui.waitKey(1);
//Ende Bildausgabe */
}
//Ausgabe des Bildes zum Prüfen
HighGui.imshow("ThunfischHighGui", thresholdFrame);
HighGui.waitKey(1);
//Ende Bildausgabe */
}

} catch (Exception e) {
} catch (Exception e) {

}
}

if (currentImg != null) {
List<Point> positions = trackPositions(thresholdFrame);
if (currentImg != null) {
List<Point> positions = trackPositions(thresholdFrame);

if (positions.size() >= 2) {
currentPositionP1 = positions.get(0);
currentPositionP2 = positions.get(1);
System.out.println("currentPositionP1: " + currentPositionP1 + " currentPositionP2: " + currentPositionP2);
}
if (positions.size() >= 2) {
currentPositionP1 = positions.get(0);
currentPositionP2 = positions.get(1);
//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();

}
}
}

@@ -111,4 +129,4 @@ public class ImgAnalyzer {
return currentPositionP2;
}

}
}

+ 6
- 4
src/main/java/Player.java View File

@@ -1,3 +1,4 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

@@ -20,6 +21,7 @@ public class Player {
public Player(int id, String finalIpAddress, int finalPortNr) {
this.ID = id;
arduinoCommunicator = new ArduinoCommunication(finalIpAddress, finalPortNr);
trail.add(new int[]{0,0});
}

public int getX(){
@@ -38,14 +40,14 @@ public class Player {
this.y = y;
}

private void addToTrail(int x, int y) {
private void addToTrail(int x, int y) {
trail.add(new int[]{x, y});
if(trail.size() > TRAIL_LENGTH){
trail.poll();
if (trail.size() > TRAIL_LENGTH) {
trail.poll(); // Entfernt das älteste Element
}

}


public Queue<int[]> getTrail(){
return trail;
}

Loading…
Cancel
Save