}
public void testFindRelativePixel() throws Exception {
ScreenAnalyser analyser = new ScreenAnalyser();
RelativePixelAnalyser relativePixelAnalyser = new RelativePixelAnalyser();
File imageFolder = new File(IMAGE_PATH);
File[] imageArray = imageFolder.listFiles();
Assert.assertNotNull("No files found in " + IMAGE_PATH + ". Please make sure you've set the path to a folder that contains screenshots from Hearthstone", imageArray);
List<File> images = new ArrayList<>(imageArray.length);
for (File image : imageArray) {
if (image.getName().endsWith(".png")) {
// Determine if this is a match end image
BufferedImage bufferedImage = ImageIO.read(image);
Screen screen = analyser.identifyScreen(bufferedImage, null);
if (screen == Screen.MATCH_NAXXRAMAS_END || screen == Screen.MATCH_ORGRIMMAR_END || screen == Screen.MATCH_PANDARIA_END
|| screen == Screen.MATCH_STORMWIND_END || screen == Screen.MATCH_STRANGLETHORN_END) {
// This is a match end screen, so it is suitable for testing with the RelativePixelAnalyser
images.add(image);
}
bufferedImage.flush();
}
}
Assert.assertFalse("No match end images found in " + IMAGE_PATH + ". Please make sure you've set the path to a folder that contains screenshots from Hearthstone", images.size() == 0);
int page = 0;
int pageCount = (images.size() / PAGE_SIZE) + 1;
while (page < pageCount) {
page++;
String filename = IMAGE_PATH + "/relative-test-" + page + ".html";
try (BufferedWriter output = new BufferedWriter(new FileWriter(filename))) {
writeHtmlHeader(output, page, pageCount);
List<Coordinate> coordinates = new ArrayList<>();
for (int i = (page - 1) * PAGE_SIZE; i < images.size() && i < page * PAGE_SIZE; i++) {
File image = images.get(i);
output.write("<tr>" +
"<td colspan=\"3\" class=\"filename\"><h2>");
output.write(image.getName());
output.write("</h2></td>" +
"</tr>" +
"<tr>" +
"<td><div><img src=\"");
output.write(image.getName());
output.write("\" id=\"img_");
output.write(String.valueOf(i - ((page - 1) * PAGE_SIZE)));
output.write("\" alt=\"");
output.write(image.getName());
output.write("\" width=\"400\"></div></td>");
output.write("<td><canvas id=\"canvas_");
output.write(String.valueOf(i - ((page - 1) * PAGE_SIZE)));
output.write("\" width=\"300\" height=\"300\"></td>");
try {
log.debug("***** Testing Image {} *****", image.getName());
BufferedImage bufferedImage = ImageIO.read(image);
Coordinate coordinate = relativePixelAnalyser.findRelativePixel(bufferedImage, UniquePixel.VICTORY_DEFEAT_REFBOX_TL, UniquePixel.VICTORY_DEFEAT_REFBOX_BR, 8, 11);
coordinates.add(coordinate);
output.write("<td class=\"");
if (coordinate == null) {
output.write("matchzero");
} else {
output.write("matchone");
}
output.write("\">");
if (coordinate != null) {
output.write("<div>Reference Pixel = ");
output.write(String.valueOf(coordinate.x()));
output.write(", ");
output.write(String.valueOf(coordinate.y()));
output.write("</div>");
int victory1Matches = relativePixelAnalyser.countMatchingRelativePixels(bufferedImage, coordinate, new UniquePixel[] {
UniquePixel.VICTORY_REL_1A, UniquePixel.VICTORY_REL_1B
});
int victory2Matches = relativePixelAnalyser.countMatchingRelativePixels(bufferedImage, coordinate, new UniquePixel[] {
UniquePixel.VICTORY_REL_2A, UniquePixel.VICTORY_REL_2B, UniquePixel.VICTORY_REL_2C
});
int defeat1Matches = relativePixelAnalyser.countMatchingRelativePixels(bufferedImage, coordinate, new UniquePixel[] {
UniquePixel.DEFEAT_REL_1A, UniquePixel.DEFEAT_REL_1B, UniquePixel.DEFEAT_REL_1C, UniquePixel.DEFEAT_REL_1D, UniquePixel.DEFEAT_REL_1E
});
int defeat2Matches = relativePixelAnalyser.countMatchingRelativePixels(bufferedImage, coordinate, new UniquePixel[] {
UniquePixel.DEFEAT_REL_2A
});
output.write("<div>Count of V1 matches: ");
output.write(String.valueOf(victory1Matches));