added old tracking as test

This commit is contained in:
rgrebner 2023-11-20 14:52:25 +01:00
parent d227dfbc66
commit f152d34134

View File

@ -2,8 +2,9 @@ package com.cringe_studios.cristmastreescanning;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.awt.Color; import java.awt.Color;
import java.awt.Point; import java.awt.geom.Point2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -22,17 +23,17 @@ public class ExampleTest {
} }
@Test @Test
public void generateVisualTestImagees() { public void generateVisualTestImages() {
Path results; Path results;
try { try {
results = Files.createTempDirectory("testResult"); results = Files.createTempDirectory("testResult");
for(int i = 0; i < 100; i++) { for(int i = 0; i < 100; i++) {
try { try {
BufferedImage image = ImageIO.read(ExampleTest.class.getResourceAsStream("/0_" + i + ".png")); BufferedImage image = ImageIO.read(ExampleTest.class.getResourceAsStream("/0_" + i + ".png"));
Point p = ImageScanner.getBrightestSpot(image); Point2D p = ImageScanner.getBrightestSpot(image);
for(int j = -2; j < 2; j++) { for(int j = -2; j < 2; j++) {
for(int k = -2; k < 2; k++) { for(int k = -2; k < 2; k++) {
if(p.x + j > 0 && p.x + j < image.getWidth() && p.y + k > 0 && p.y + k < image.getHeight()) image.setRGB(p.x + j, p.y + k, Color.red.getRGB()); if((int) p.getX() + j > 0 && (int) p.getX() + j < image.getWidth() && (int) p.getY() + k > 0 && (int) p.getY() + k < image.getHeight()) image.setRGB((int) p.getX() + j, (int) p.getY() + k, Color.red.getRGB());
} }
} }
ImageIO.write(image, "png", Files.newOutputStream(results.resolve(String.valueOf(i) + ".png"))); ImageIO.write(image, "png", Files.newOutputStream(results.resolve(String.valueOf(i) + ".png")));
@ -44,5 +45,78 @@ public class ExampleTest {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Test
public void generateVisualTestImagesWithOldMethod() {
Path results;
try {
results = Files.createTempDirectory("testResultOldWay");
for(int i = 0; i < 100; i++) {
try {
BufferedImage image = ImageIO.read(ExampleTest.class.getResourceAsStream("/0_" + i + ".png"));
BufferedImage bi2 = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
bi2.createGraphics().drawImage(image, 0, 0, null);
int[] colors = ((DataBufferInt) bi2.getRaster().getDataBuffer()).getData();
int x = -1, y = -1, brightness = 0;
boolean multipleBright = true;
int boxLeangth = 3;
while (multipleBright) {
if(boxLeangth > 1000) {
System.out.println("alles gleich hell");
return;
}
for (int ä = 0; ä < colors.length; ä++) {
int b = 0;
x: for (int k = 0; k < boxLeangth; k++) {
y: for (int j = 0; j < boxLeangth; j++) {
int c = ä;
if (c + j - boxLeangth / 2 > 0 && c + j - boxLeangth / 2 < colors.length) {
c += j - boxLeangth / 2;
} else {
continue y;
}
if (c + (k - boxLeangth / 2) * bi2.getWidth() > 0 && c + (k - boxLeangth / 2) * bi2.getWidth() < colors.length) {
c += (k - boxLeangth / 2) * bi2.getWidth();
} else {
continue x;
}
b += colors[c] & 255 + ((colors[c] >> 8) & 255) + ((colors[c] >> 8) & 255);
}
}
if (b > brightness) {
brightness = b;
x = ä % bi2.getWidth();
y = ä / bi2.getWidth();
multipleBright = false;
} else if (b == brightness) {
multipleBright = true;
}
}
if(multipleBright) {
boxLeangth += 2;
}
}
for(int j = -2; j < 2; j++) {
for(int k = -2; k < 2; k++) {
if(x + j > 0 && x + j < image.getWidth() && y + k > 0 && y + k < image.getHeight()) image.setRGB(x + j, y + k, Color.red.getRGB());
}
}
ImageIO.write(image, "png", Files.newOutputStream(results.resolve(String.valueOf(i) + ".png")));
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} }