Funktionierender Puffer
Bild wird nicht korrekt gespeichert 16.12.2024 16:48
This commit is contained in:
parent
736154abf4
commit
789f9e56f1
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -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>
|
82
.idea/workspace.xml
generated
82
.idea/workspace.xml
generated
@ -4,13 +4,13 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<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 16.12.2024 15.06 Siuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu">
|
||||
<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$/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/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>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -38,6 +38,7 @@
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"Application.GTCar.executor": "Run",
|
||||
"Application.GraphicsProgram.executor": "Run",
|
||||
"Application.Main.executor": "Run",
|
||||
"Application.Tracker.executor": "Run",
|
||||
@ -50,7 +51,7 @@
|
||||
"com.codeium.enabled": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Users/paul3/OneDrive/Dokumente/Studium BME/Semester 3/Interaktion/opencv/build/java/opencv-4100.jar",
|
||||
"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)",
|
||||
@ -63,10 +64,17 @@
|
||||
}
|
||||
}</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="C:\Users\paul3\OneDrive\Dokumente\Studium BME\Semester 3\Interaktion\opencv\build\java\x64"" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
@ -74,30 +82,23 @@
|
||||
<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="C:\Users\paul3\OneDrive\Dokumente\Studium BME\Semester 3\Interaktion\opencv\build\java\x64"" />
|
||||
<option name="VM_PARAMETERS" value="-Djava.library.path="C:\Users\paul3\OneDrive\Dokumente\Studium BME\Semester 3\Interaktion\opencv\build\java\x64"" />
|
||||
<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" />
|
||||
</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">
|
||||
@ -107,8 +108,9 @@
|
||||
<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="1732113837570" duration="20534000" />
|
||||
<workItem from="1733327375447" duration="951000" />
|
||||
<workItem from="1734091457440" duration="10746000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="First Commit Test">
|
||||
<option name="closed" value="true" />
|
||||
@ -126,7 +128,39 @@
|
||||
<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 ("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 />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@ -146,6 +180,10 @@
|
||||
<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 ("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>
|
||||
</project>
|
@ -56,7 +56,7 @@ public class CamPuffer implements Runnable {
|
||||
|
||||
try {
|
||||
while (running) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
//long startTime = System.currentTimeMillis();
|
||||
capture.read(frame); // Bild einlesen
|
||||
|
||||
if (frame.empty()) {
|
||||
@ -65,10 +65,11 @@ public class CamPuffer implements Runnable {
|
||||
}
|
||||
|
||||
// Bildverarbeitung hier
|
||||
updateCurrentMat(frame);
|
||||
|
||||
// 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)
|
||||
if (System.currentTimeMillis() - lastGcTime > 1000) {
|
||||
@ -84,35 +85,24 @@ public class CamPuffer implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean isHasStartedCapturing() {
|
||||
return hasStartedCapturing;
|
||||
}
|
||||
|
||||
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
|
||||
frameBuffer.add(img.clone());
|
||||
currentMat = img;
|
||||
}
|
||||
}
|
||||
|
||||
public Mat getCurrentMat() {
|
||||
synchronized (lock) {
|
||||
return currentMat.clone(); // Rückgabe einer Kopie, um Speicherprobleme zu vermeiden
|
||||
}
|
||||
return currentMat;
|
||||
}
|
||||
|
||||
|
||||
public void stop() {
|
||||
running = false;
|
||||
}
|
||||
@ -127,7 +117,6 @@ public class CamPuffer implements Runnable {
|
||||
}
|
||||
|
||||
capture.set(Videoio.CAP_PROP_BUFFERSIZE, 3);
|
||||
|
||||
capture.set(Videoio.CAP_PROP_EXPOSURE, EXP);
|
||||
capture.set(Videoio.CAP_PROP_FPS, FPS);
|
||||
System.out.println("Kamera geöffnet und eingerichtet");
|
||||
|
@ -1,7 +1,10 @@
|
||||
import processing.core.PApplet;
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GameLoop {
|
||||
int activePlayer = 0;
|
||||
|
||||
ImgAnalyzer tracker;
|
||||
|
||||
@ -21,14 +24,14 @@ public class GameLoop {
|
||||
Thread trackerThread = new Thread(tracker::run);
|
||||
trackerThread.start();
|
||||
|
||||
graphics = new GraphicsProgram(player1, player2);
|
||||
/*graphics = new GraphicsProgram(player1, player2);
|
||||
String[] args = {"GraphicsProgram"};
|
||||
PApplet.runSketch(args, graphics);
|
||||
|
||||
|
||||
gl = new GameLogic();
|
||||
String[] args_ = {"GameLogic"};
|
||||
PApplet.runSketch(args_, gl);
|
||||
PApplet.runSketch(args_, gl); */
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
}catch (Exception e){
|
||||
@ -39,7 +42,7 @@ public class GameLoop {
|
||||
}
|
||||
|
||||
private void run(){
|
||||
while(true){
|
||||
/*while(true){
|
||||
//communicate();
|
||||
|
||||
Point p1 = tracker.getP1();
|
||||
@ -47,10 +50,10 @@ public class GameLoop {
|
||||
Point p2 = tracker.getP2();
|
||||
//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");
|
||||
break;
|
||||
}
|
||||
@ -58,10 +61,10 @@ public class GameLoop {
|
||||
if(gl.doCheckExtern(player1.getTrail(), p2)){ //Check Position von P2 mit Spur von P1
|
||||
System.out.println("Spieler 2 hat verloren");
|
||||
break;
|
||||
} */
|
||||
}
|
||||
|
||||
//draw();
|
||||
}
|
||||
draw();
|
||||
} */
|
||||
}
|
||||
|
||||
private void communicate() {
|
||||
|
@ -24,7 +24,7 @@ public class GraphicsProgram extends PApplet {
|
||||
}
|
||||
|
||||
public void settings() {
|
||||
//fullScreen();
|
||||
fullScreen();
|
||||
}
|
||||
|
||||
public void setup(){
|
||||
@ -51,8 +51,10 @@ public class GraphicsProgram extends PApplet {
|
||||
|
||||
while(!trail.isEmpty()) {
|
||||
int[] koordinaten = trail.poll();
|
||||
int x = 1;
|
||||
int y = 1;
|
||||
int x = koordinaten[0];
|
||||
int y = koordinaten[1];
|
||||
|
||||
System.out.println();
|
||||
|
||||
if(playerID == 0){
|
||||
image(imgBlue, x, y, particleSize, particleSize);
|
||||
|
@ -11,18 +11,17 @@ import java.awt.Point;
|
||||
|
||||
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 FPS = 20; // FPS
|
||||
private final int THV = 252; // Threshold
|
||||
private final int THV = 245; // Threshold
|
||||
|
||||
private Point currentPositionP1 = 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() {
|
||||
camPuffer = new CamPuffer(CAM, EXP, FPS, THV);
|
||||
Thread pufferThread = new Thread(camPuffer);
|
||||
pufferThread.start();
|
||||
}
|
||||
@ -41,20 +40,15 @@ public class ImgAnalyzer {
|
||||
}
|
||||
|
||||
Mat currentImg = null;
|
||||
|
||||
|
||||
Mat grayFrame = new Mat();
|
||||
Mat thresholdFrame = new Mat();
|
||||
|
||||
int debug = 0;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
currentImg = camPuffer.getCurrentMat();
|
||||
|
||||
//HighGui.imshow("Threshold Image", currentImg);
|
||||
|
||||
// ROI anwenden
|
||||
//Mat roiFrame = new Mat(downsizedFrame, roi);
|
||||
|
||||
// In Graustufen konvertieren
|
||||
Imgproc.cvtColor(currentImg, grayFrame, Imgproc.COLOR_BGR2GRAY);
|
||||
|
||||
@ -71,7 +65,7 @@ public class ImgAnalyzer {
|
||||
if (positions.size() >= 2) {
|
||||
currentPositionP1 = positions.get(0);
|
||||
currentPositionP2 = positions.get(1);
|
||||
//System.out.println("currentPositionP1: " + currentPositionP1 + " currentPositionP2: " + currentPositionP2);
|
||||
System.out.println("currentPositionP1: " + currentPositionP1 + " currentPositionP2: " + currentPositionP2);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user