Browse Source

Funktionierender Puffer

Bild wird nicht korrekt gespeichert
16.12.2024 16:48
master
Paul-1108 6 days ago
parent
commit
789f9e56f1

+ 1
- 1
.idea/misc.xml View File

</list> </list>
</option> </option>
</component> </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" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

+ 60
- 22
.idea/workspace.xml View File

<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="Version 20.11">
<change afterPath="$PROJECT_DIR$/src/main/java/CamPuffer.java" afterDir="false" />
<list default="true" id="4d75e996-cee4-4ec6-b802-5b56d0c0eac4" name="Changes" comment="Funktionierender Puffer&#10;16.12.2024 15.06&#10;Siuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu">
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" 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/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/Tracker.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" />
</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" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent">{
&quot;keyToString&quot;: { &quot;keyToString&quot;: {
&quot;Application.GTCar.executor&quot;: &quot;Run&quot;,
&quot;Application.GraphicsProgram.executor&quot;: &quot;Run&quot;, &quot;Application.GraphicsProgram.executor&quot;: &quot;Run&quot;,
&quot;Application.Main.executor&quot;: &quot;Run&quot;, &quot;Application.Main.executor&quot;: &quot;Run&quot;,
&quot;Application.Tracker.executor&quot;: &quot;Run&quot;, &quot;Application.Tracker.executor&quot;: &quot;Run&quot;,
&quot;com.codeium.enabled&quot;: &quot;true&quot;, &quot;com.codeium.enabled&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;, &quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&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.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&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.eslint&quot;: &quot;(autodetect)&quot;,
} }
}</component> }</component>
<component name="RunManager" selected="Application.Main"> <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" /> <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"> <method v="2">
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
<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="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"> <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.ImgAnalyzer" />
<item itemvalue="Application.GraphicsProgram" />
</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">
<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="5187000" />
<workItem from="1734302243298" duration="10745000" />
<workItem from="1732113837570" duration="20534000" />
<workItem from="1733327375447" duration="951000" />
<workItem from="1734091457440" duration="10746000" />
</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" />
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1732118799936</updated> <updated>1732118799936</updated>
</task> </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>
<option name="localTasksCounter" value="7" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="First Commit Test" /> <MESSAGE value="First Commit Test" />
<MESSAGE value="Version 20.11" /> <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" />
<option name="LAST_COMMIT_MESSAGE" value="Funktionierender Puffer&#10;16.12.2024 15.06&#10;Siuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu" />
</component> </component>
</project> </project>

+ 12
- 23
src/main/java/CamPuffer.java View File



try { try {
while (running) { while (running) {
long startTime = System.currentTimeMillis();
//long startTime = System.currentTimeMillis();
capture.read(frame); // Bild einlesen capture.read(frame); // Bild einlesen


if (frame.empty()) { if (frame.empty()) {
} }


// Bildverarbeitung hier // Bildverarbeitung hier
updateCurrentMat(frame);


// Debug-Ausgabe // Debug-Ausgabe
long elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("Verarbeitungszeit für das Bild: " + elapsedTime + " ms");
//long elapsedTime = System.currentTimeMillis() - startTime;
//System.out.println("Verarbeitungszeit für das Bild: " + elapsedTime + " ms");


// Speicherbereinigung alle 1000 ms (1 Sekunde) // Speicherbereinigung alle 1000 ms (1 Sekunde)
if (System.currentTimeMillis() - lastGcTime > 1000) { if (System.currentTimeMillis() - lastGcTime > 1000) {
} }
} }






public boolean isHasStartedCapturing() {
return hasStartedCapturing;
}

private void updateCurrentMat(Mat img) { private void updateCurrentMat(Mat img) {
synchronized (lock) {
// Puffergröße überwachen
if (frameBuffer.size() >= MAX_BUFFER_SIZE) {
Mat oldFrame = frameBuffer.poll(); // Entfernt das älteste Bild im Puffer
if (oldFrame != null) {
oldFrame.release(); // Verhindert das Anhäufen von nicht freigegebenen Mat-Objekten
}
// Puffergröße überwachen
if (frameBuffer.size() >= MAX_BUFFER_SIZE) {
Mat oldFrame = frameBuffer.poll(); // Entfernt das älteste Bild im Puffer
if (oldFrame != null) {
oldFrame.release(); // Verhindert das Anhäufen von nicht freigegebenen Mat-Objekten
} }

// Neues Bild in den Puffer hinzufügen // Neues Bild in den Puffer hinzufügen
frameBuffer.add(img.clone()); frameBuffer.add(img.clone());
currentMat = img;
} }
} }


public Mat getCurrentMat() { public Mat getCurrentMat() {
synchronized (lock) {
return currentMat.clone(); // Rückgabe einer Kopie, um Speicherprobleme zu vermeiden
}
return currentMat;
} }



public void stop() { public void stop() {
running = false; running = false;
} }
} }


capture.set(Videoio.CAP_PROP_BUFFERSIZE, 3); capture.set(Videoio.CAP_PROP_BUFFERSIZE, 3);

capture.set(Videoio.CAP_PROP_EXPOSURE, EXP); capture.set(Videoio.CAP_PROP_EXPOSURE, EXP);
capture.set(Videoio.CAP_PROP_FPS, FPS); capture.set(Videoio.CAP_PROP_FPS, FPS);
System.out.println("Kamera geöffnet und eingerichtet"); System.out.println("Kamera geöffnet und eingerichtet");

+ 12
- 9
src/main/java/GameLoop.java View File

import processing.core.PApplet; import processing.core.PApplet;
import java.awt.Point; import java.awt.Point;
import java.util.ArrayList;
import java.util.List;


public class GameLoop { public class GameLoop {
int activePlayer = 0;


ImgAnalyzer tracker; ImgAnalyzer tracker;


Thread trackerThread = new Thread(tracker::run); Thread trackerThread = new Thread(tracker::run);
trackerThread.start(); trackerThread.start();


graphics = new GraphicsProgram(player1, player2);
/*graphics = new GraphicsProgram(player1, player2);
String[] args = {"GraphicsProgram"}; String[] args = {"GraphicsProgram"};
PApplet.runSketch(args, graphics); PApplet.runSketch(args, graphics);




gl = new GameLogic(); gl = new GameLogic();
String[] args_ = {"GameLogic"}; String[] args_ = {"GameLogic"};
PApplet.runSketch(args_, gl);
PApplet.runSketch(args_, gl); */
try { try {
Thread.sleep(5000); Thread.sleep(5000);
}catch (Exception e){ }catch (Exception e){
} }


private void run(){ private void run(){
while(true){
/*while(true){
//communicate(); //communicate();


Point p1 = tracker.getP1(); Point p1 = tracker.getP1();
Point p2 = tracker.getP2(); Point p2 = tracker.getP2();
//System.out.println("Player 2 is at " + p2.x + " and " + p2.y); //System.out.println("Player 2 is at " + p2.x + " and " + p2.y);


player1.setKoords((int)p1.x, (int)p1.y);
player2.setKoords((int)p2.x, (int)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
if(gl.doCheckExtern(player2.getTrail(), p1)){ //Check Position von P1 mit Spur von P2
System.out.println("Spieler 1 hat verloren"); System.out.println("Spieler 1 hat verloren");
break; break;
} }
if(gl.doCheckExtern(player1.getTrail(), p2)){ //Check Position von P2 mit Spur von P1 if(gl.doCheckExtern(player1.getTrail(), p2)){ //Check Position von P2 mit Spur von P1
System.out.println("Spieler 2 hat verloren"); System.out.println("Spieler 2 hat verloren");
break; break;
} */
}


//draw();
}
draw();
} */
} }


private void communicate() { private void communicate() {

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

} }


public void settings() { public void settings() {
//fullScreen();
fullScreen();
} }


public void setup(){ public void setup(){


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

System.out.println();


if(playerID == 0){ if(playerID == 0){
image(imgBlue, x, y, particleSize, particleSize); image(imgBlue, x, y, particleSize, particleSize);

+ 6
- 12
src/main/java/ImgAnalyzer.java View File



public class ImgAnalyzer { public class ImgAnalyzer {


private final int CAM = 0; // Kamera-ID (0 für Webcam, 1 für andere Cams)
private final int CAM = 1; // Kamera-ID (0 für Webcam, 1 für andere Cams)
private final int EXP = -9; // Belichtungszeit (idealerweise: 0) private final int EXP = -9; // Belichtungszeit (idealerweise: 0)
private final int FPS = 20; // FPS private final int FPS = 20; // FPS
private final int THV = 252; // Threshold
private final int THV = 245; // Threshold


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


private CamPuffer camPuffer;
private CamPuffer camPuffer = new CamPuffer(CAM, EXP, FPS, THV);;


public ImgAnalyzer() { public ImgAnalyzer() {
camPuffer = new CamPuffer(CAM, EXP, FPS, THV);
Thread pufferThread = new Thread(camPuffer); Thread pufferThread = new Thread(camPuffer);
pufferThread.start(); pufferThread.start();
} }
} }


Mat currentImg = null; Mat currentImg = null;


Mat grayFrame = new Mat(); Mat grayFrame = new Mat();
Mat thresholdFrame = new Mat(); Mat thresholdFrame = new Mat();


int debug = 0;

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


//HighGui.imshow("Threshold Image", currentImg);

// ROI anwenden
//Mat roiFrame = new Mat(downsizedFrame, roi);

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


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


} }

Loading…
Cancel
Save