Compare commits

..

1 Commits

Author SHA1 Message Date
Paul-1108
545e803554 Luppt
Fehlt noch:
Transformation und Collision
2024-12-17 19:56:53 +01:00
11 changed files with 169 additions and 148 deletions

2
.idea/misc.xml generated
View File

@ -8,7 +8,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

96
.idea/workspace.xml generated
View File

@ -4,18 +4,12 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="4d75e996-cee4-4ec6-b802-5b56d0c0eac4" name="Changes" comment="Puffer Versuch&#10;Speicher läuft voll&#10;16.12.2024 03:30">
<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" />
<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">
<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/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" />
@ -43,6 +37,7 @@
</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;,
@ -55,7 +50,7 @@
&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/paul3/OneDrive/Dokumente/Studium BME/Semester 3/Interaktion/opencv/build/java/opencv-4100.jar&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;,
@ -67,16 +62,18 @@
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}</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">
<configuration name="ImgAnalyzer" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="ImgAnalyzer" />
<configuration name="GTCar" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="Tracker" />
<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" />
<option name="PROGRAM_PARAMETERS" value="-Djava.library.path=&quot;C:\Users\paul3\OneDrive\Dokumente\Studium BME\Semester 3\Interaktion\opencv\build\java\x64&quot;" />
<method v="2">
<option name="Make" enabled="true" />
</method>
@ -84,27 +81,28 @@
<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="PROGRAM_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=&quot;C:\Users\paul3\OneDrive\Dokumente\Studium BME\Semester 3\Interaktion\opencv\build\java\x64&quot;" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<list>
<item itemvalue="Application.GTCar" />
<item itemvalue="Application.GraphicsProgram" />
<item itemvalue="Application.Main" />
<item itemvalue="Application.ImgAnalyzer" />
</list>
<recent_temporary>
<list>
<item itemvalue="Application.Main" />
<item itemvalue="Application.ImgAnalyzer" />
<item itemvalue="Application.GraphicsProgram" />
</list>
</recent_temporary>
</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" />
<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>
@ -117,9 +115,10 @@
<option name="presentableId" value="Default" />
<updated>1732108904989</updated>
<workItem from="1732108906083" duration="758000" />
<workItem from="1732113837570" duration="5187000" />
<workItem from="1734302243298" duration="10745000" />
<workItem from="1734469984979" duration="8232000" />
<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" />
@ -137,7 +136,47 @@
<option name="project" value="LOCAL" />
<updated>1732118799936</updated>
</task>
<option name="localTasksCounter" value="3" />
<task id="LOCAL-00003" summary="Version 23.11 (Grafics update)">
<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 (&quot;fertiger&quot; 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&#10;16.12.2024 15.06&#10;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>
<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" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -157,6 +196,11 @@
<component name="VcsManagerConfiguration">
<MESSAGE value="First Commit Test" />
<MESSAGE value="Version 20.11" />
<option name="LAST_COMMIT_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" />
</component>
</project>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

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\\paul3\\OneDrive\\Dokumente\\Studium BME\\Semester 3\\Interaktion\\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());
@ -74,7 +74,7 @@ public class CamPuffer implements Runnable {
if (System.currentTimeMillis() - lastGcTime > 1000) {
System.gc(); // Triggern des Garbage Collectors
lastGcTime = System.currentTimeMillis();
//System.out.println("Garbage Collection durchgeführt.");
System.out.println("Garbage Collection durchgeführt.");
}
}
} finally {
@ -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

View File

@ -1,21 +1,15 @@
import org.opencv.highgui.HighGui;
import processing.core.PApplet;
import java.awt.*;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import static java.lang.Thread.sleep;
public class GameLoop {
int activePlayer = 0;
private final int CAM = 0; // Kamera-ID (0 für Webcam, 1 für andere Cams)
private final int EXP = -8; // Belichtungszeit (idealerweise: 0)
private final int EXP = -9; // Belichtungszeit (idealerweise: 0)
private final int FPS = 20; // FPS
private final int THV = 240;
private final int TRAIL_LENGTH = 50;
private final int THV = 245; // Threshold
ImgAnalyzer tracker;
CamPuffer camPuffer;
@ -28,23 +22,22 @@ public class GameLoop {
Player player2;
public GameLoop(){
player1 = new Player(0, TRAIL_LENGTH);
player2 = new Player(1, TRAIL_LENGTH);
player1 = new Player(0, "192.168.1.1", 9000);
player2 = new Player(1, "192.168.1.2", 9000);
camPuffer = new CamPuffer(CAM, EXP, FPS, THV);
Thread pufferThread = new Thread(camPuffer);
pufferThread.start();
graphics = new GraphicsProgram();
String[] args = {"GraphicsProgram"};
PApplet.runSketch(args, graphics);
tracker = new ImgAnalyzer(camPuffer, THV, graphics);
tracker = new ImgAnalyzer(camPuffer, THV);
Thread trackerThread = new Thread(tracker::run);
trackerThread.start();
/*graphics = new GraphicsProgram(player1, player2);
String[] args = {"GraphicsProgram"};
PApplet.runSketch(args, graphics);
/*
gl = new GameLogic();
String[] args_ = {"GameLogic"};
PApplet.runSketch(args_, gl); */
@ -53,23 +46,55 @@ public class GameLoop {
}
private void run(){
while(camPuffer.getCurrentMat().elemSize() == 0){
System.out.println("Camera booting up");
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
graphics.nextGameState();
//Hier kommt Morphing rein
graphics.nextGameState();
while(true){
//communicate();
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{
wait(50);
}
catch (Exception e){
}
}
}
private void communicate() {
//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(){
}
}

View File

@ -2,28 +2,22 @@ import processing.core.PApplet;
import processing.core.PImage;
import java.util.LinkedList;
import java.util.List;
public class GraphicsProgram extends PApplet {
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 final int TRAIL_LENGTH = 15;
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 img2;
PImage backgroundImage;
LinkedList<PImage> cameraLoadingImages = new LinkedList<>();
public static void main(String[] args) {
PApplet.main("GraphicsProgram");
}
@ -38,91 +32,29 @@ public class GraphicsProgram extends PApplet {
img1 = loadImage("TrailBlue.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() {
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
strokeWeight(20); // Linienstärke festlegen
// Linien für Spieler 1 zeichnen
stroke(0, 0, 255); // Blau
drawTrail(player1Trail, 1);
drawTrail(player1Trail);
// Linien für Spieler 2 zeichnen
stroke(255, 0, 0); // Rot
drawTrail(player2Trail, 2);
}
private void gameOverScreen() {
}
public void nextGameState() {
gameState++;
drawTrail(player2Trail);
}
// 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
private void drawTrail(LinkedList<int[]> trail) {
if (trail.size() < 2) 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;
}
int[] current = trail.get(i);
int[] next = trail.get(i + 1);
// Null-Check für die Punkte
if (current != null && next != null) {
@ -146,7 +78,7 @@ public class GraphicsProgram extends PApplet {
// 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) {
if (trailCounter % 7 == 0) {
if(trailCounter % 21 == 0) {
if (x >= 0 && y >= 0) {
trail.add(new int[]{x, y});
if (trail.size() > TRAIL_LENGTH) {
@ -157,5 +89,4 @@ public class GraphicsProgram extends PApplet {
trailCounter++;
}
}

View File

@ -16,17 +16,19 @@ 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 = 90;
private final int TRAIL_LENGTH = 20;
private final CamPuffer camPuffer;
private GraphicsProgram playerGraphics;
public ImgAnalyzer(CamPuffer cP, int threshold, GraphicsProgram graphicsProgram) {
public ImgAnalyzer(CamPuffer cP, int threshold) {
THV = threshold;
camPuffer = cP;
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
playerGraphics = graphicsProgram;
playerGraphics = new GraphicsProgram();
String[] args ={"GraphicsProgram"};
PApplet.runSketch(args, playerGraphics);
}
public static void main(String[] args) {
@ -34,7 +36,6 @@ public class ImgAnalyzer {
}
public void run() {
/*
while (camPuffer.getCurrentMat().elemSize() == 0) {
System.out.println("Warten auf das erste Bild...");
try {
@ -44,7 +45,6 @@ public class ImgAnalyzer {
return;
}
}
*/
Mat currentImg = new Mat();
Mat grayFrame = new Mat();

View File

@ -7,13 +7,20 @@ public class Player {
private final int ID;
private int x;
private int y;
private final int TRAIL_LENGTH;
private String name = "Thunfisch";
Queue<int[]> trail = new LinkedList<>();
ArduinoCommunication arduinoCommunicator;
private final int TRAIL_LENGTH = 30;
// Konstruktor
public Player(int id, int trailLength) {
public Player(int id, String finalIpAddress, int finalPortNr) {
this.ID = id;
this.TRAIL_LENGTH = trailLength;
arduinoCommunicator = new ArduinoCommunication(finalIpAddress, finalPortNr);
trail.add(new int[]{0,0});
}
@ -25,7 +32,8 @@ public class Player {
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){
addToTrail(x,y);
this.x = x;
@ -39,9 +47,20 @@ public class Player {
}
}
public Queue<int[]> getTrail(){
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);
}
}