diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 6f54b49..6965a52 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -4,7 +4,7 @@ org.baxter.disco ocr Disco OCR Accuracy Over Life Testing - 4.3.2 + 4.3.3 Testing Discos for long-term accuracy, using automated optical character recognition. Baxter International diff --git a/pom.xml b/pom.xml index b8cc3c6..4059755 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.baxter.disco ocr - 4.3.2 + 4.3.3 jar Disco OCR Accuracy Over Life Testing Testing Discos for long-term accuracy, using automated optical character recognition. diff --git a/runScript.sh b/runScript.sh index bf30fd0..6729115 100644 --- a/runScript.sh +++ b/runScript.sh @@ -1,2 +1,2 @@ #! /usr/bin/env sh -sudo java -jar discoTesting-4.2.0.jar 2>/dev/null +sudo java -jar discoTesting-4.3.3.jar 2>/dev/null diff --git a/src/main/java/org/baxter/disco/ocr/Cli.java b/src/main/java/org/baxter/disco/ocr/Cli.java index aaeba77..755bb01 100644 --- a/src/main/java/org/baxter/disco/ocr/Cli.java +++ b/src/main/java/org/baxter/disco/ocr/Cli.java @@ -25,7 +25,7 @@ public class Cli /** * Complete build version number */ - private static final String version = "4.3.2"; + private static final String version = "4.3.3"; /** * Currently saved iteration count. @@ -687,19 +687,15 @@ public class Cli //useful for multithreading, which isn't necessary in CLI final int localIterations = iterationCount; - //TODO: Hard-coded value that needs fixing - boolean prime = false; + //Save whether to prime the devices; defaults to false + boolean prime = false; //Create a List of *active* cameras. List cameraList = new ArrayList<>(); for(String cameraName : OpenCVFacade.getCameraNames()) { - //if(cameraName != null) { /*println(cameraName);*/ } - //else ErrorLogging.logError("Null camera!"); - if(ConfigFacade.getValue(cameraName,ConfigProperties.PRIME) != 0) - { - prime = true; - } + prime = (ConfigFacade.getValue(cameraName,ConfigProperties.PRIME) != 0) || prime; + if(ConfigFacade.getValue(cameraName,ConfigProperties.ACTIVE) != 0) { cameraList.add(cameraName); @@ -709,11 +705,10 @@ public class Cli //Initialise the workbook, with the number of cameras and the final output location DataSaving.initWorkbook(ConfigFacade.getOutputSaveLocation(),cameraList.size()); - //Do 2 dummy passes, to make completely sure that the devices are awake + //Wake the device, then wait to ensure they're awake before continuing ErrorLogging.logError("DEBUG: Waking devices..."); - fixture.iterationMovement(prime); fixture.pressButton(); - fixture.iterationMovement(prime); + try{ Thread.sleep(2000); } catch(Exception e){ ErrorLogging.logError(e); } //Create final maps for result images, result values, and camera names Map resultMap = new HashMap<>(); @@ -779,22 +774,20 @@ public class Cli resultMap.put(file,result); ErrorLogging.logError("Tesseract final output: " + result); LOCK.unlock(); - } - - //LO detection and avoidance - for(Double result : resultMap.values()) - { - if(result <= 1.0 || result >= 117.0 || result == Double.NEGATIVE_INFINITY) + if(result <= 10 || + result >= 100 || + result == Double.NEGATIVE_INFINITY) { fixture.goUp(); - try{ Thread.sleep(20000); } catch(Exception e){ ErrorLogging.logError(e); } + try{ Thread.sleep(20000); } + catch(Exception e){ ErrorLogging.logError(e); } fixture.pressButton(); fail = true; break; } } } - while(fail == true); + while(fail); //Write all given values to the Excel file while(!LOCK.tryLock()) {} diff --git a/src/main/java/org/baxter/disco/ocr/DataSaving.java b/src/main/java/org/baxter/disco/ocr/DataSaving.java index dfe08c6..56aaadb 100644 --- a/src/main/java/org/baxter/disco/ocr/DataSaving.java +++ b/src/main/java/org/baxter/disco/ocr/DataSaving.java @@ -1,16 +1,19 @@ package org.baxter.disco.ocr; +import java.io.DataInputStream; //Standard imports import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.InputStream; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import java.util.Map; //Generic spreadsheet imports import org.apache.poi.ss.util.CellReference; +import org.apache.poi.util.IOUtils; import org.apache.poi.ss.usermodel.DataFormat; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.FormulaEvaluator; @@ -18,16 +21,18 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator; //Excel-specific imports import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; +import org.apache.poi.hssf.usermodel.HSSFClientAnchor; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFPatriarch; import static org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined; /** * Facade for saving data out to a file. * * @author Blizzard Finnegan - * @version 4.0.1, 13 Feb. 2023 + * @version 4.1.0, 24 Feb. 2023 */ public class DataSaving { @@ -222,7 +227,7 @@ public class DataSaving HSSFRow row = outputSheet.createRow(++startingRow); List cameraNames = new ArrayList<>(cameraToFile.keySet()); //ErrorLogging.logError("DEBUG: image locations: " + imageLocations.toString()); - List objectArray = new LinkedList<>(); + //List objectArray = new LinkedList<>(); cycle++; @@ -230,46 +235,91 @@ public class DataSaving indexCell.setCellValue(cycle); for(String cameraName : cameraNames) { + //put serial number into sheet + String serialNumber = ConfigFacade.getSerial(cameraName); + HSSFCell serialCell = row.createCell(cellnum++); + serialCell.setCellValue(serialNumber); + + //Put the generated image into the spreadsheet File file = cameraToFile.get(cameraName); + HSSFCell imageCell = row.createCell(cellnum++); + try + { + InputStream cameraImage = new DataInputStream(new FileInputStream(file)); + byte[] cameraImageRaw = IOUtils.toByteArray(cameraImage); + HSSFPatriarch patriarch = outputSheet.createDrawingPatriarch(); + int imageID = outputWorkbook.addPicture(cameraImageRaw,HSSFWorkbook.PICTURE_TYPE_PNG); + HSSFClientAnchor imageAnchor = new HSSFClientAnchor(); + imageAnchor.setCol1(cellnum-1); + imageAnchor.setCol2(cellnum); + imageAnchor.setRow1(startingRow); + imageAnchor.setRow2(startingRow+1); + patriarch.createPicture(imageAnchor, imageID); + } + //If the image fails for some reason, fallback to putting the image path into the cell + catch(Exception e) + { + String fileLocation = file.getPath(); + imageCell.setCellValue(fileLocation); + ErrorLogging.logError(e); + } + + //Put the OCR value into the sheet + HSSFCell ocrCell = row.createCell(cellnum++); + Double ocrRead = inputMap.get(file); + if(ocrRead.equals(Double.NEGATIVE_INFINITY)) + { + ocrCell.setCellValue("ERROR!"); + ocrCell.setCellStyle(errorStyle); + } + else + { + ocrCell.setCellValue(ocrRead); + if( ocrRead.doubleValue() > (targetTemp + failRange) || + ocrRead.doubleValue() < (targetTemp - failRange) ) + ocrCell.setCellStyle(failStyle); + } + + //Create a blank cell as a spacer + row.createCell(cellnum++); //ErrorLogging.logError("DEBUG: " + cameraName); - String serialNumber = ConfigFacade.getSerial(cameraName); - objectArray.add(serialNumber); - objectArray.add(file.getPath()); - objectArray.add(inputMap.get(file)); - objectArray.add(" "); + //objectArray.add(serialNumber); + //objectArray.add(file.getPath()); + //objectArray.add(inputMap.get(file)); + //objectArray.add(" "); } - for(Object cellObject : objectArray) - { - HSSFCell cell = row.createCell(cellnum++); - if(cellObject instanceof Double) - { - Double cellValue = (Double)cellObject; - ErrorLogging.logError("DEBUG: " + cellValue + " ?= " + targetTemp + " +- " + failRange); - if(cellValue.equals(Double.NEGATIVE_INFINITY)) - { - cell.setCellValue("ERROR!"); - cell.setCellStyle(errorStyle); - } - else - { - cell.setCellValue(cellValue); - if( cellValue.doubleValue() > (targetTemp + failRange) || - cellValue.doubleValue() < (targetTemp - failRange) ) - { - ErrorLogging.logError("DEBUG: Cell value " + cellValue.doubleValue() + " is outside the allowed range! (" + (targetTemp -failRange) + "-" + (targetTemp + failRange) + "). Setting cell to fail colouring."); - cell.setCellStyle(failStyle); - } - } - } - else if(cellObject instanceof String) cell.setCellValue((String) cellObject); - else - { - ErrorLogging.logError("XLSX Write Error!!! - Invalid input."); - ErrorLogging.logError("\t" + cellObject.toString()); - } + //for(Object cellObject : objectArray) + //{ + // HSSFCell cell = row.createCell(cellnum++); + // if(cellObject instanceof Double) + // { + // Double cellValue = (Double)cellObject; + // ErrorLogging.logError("DEBUG: " + cellValue + " ?= " + targetTemp + " +- " + failRange); + // if(cellValue.equals(Double.NEGATIVE_INFINITY)) + // { + // cell.setCellValue("ERROR!"); + // cell.setCellStyle(errorStyle); + // } + // else + // { + // cell.setCellValue(cellValue); + // if( cellValue.doubleValue() > (targetTemp + failRange) || + // cellValue.doubleValue() < (targetTemp - failRange) ) + // { + // ErrorLogging.logError("DEBUG: Cell value " + cellValue.doubleValue() + " is outside the allowed range! (" + (targetTemp -failRange) + "-" + (targetTemp + failRange) + "). Setting cell to fail colouring."); + // cell.setCellStyle(failStyle); + // } + // } + // } + // else if(cellObject instanceof String) cell.setCellValue((String) cellObject); + // else + // { + // ErrorLogging.logError("XLSX Write Error!!! - Invalid input."); + // ErrorLogging.logError("\t" + cellObject.toString()); + // } - } + //} try (FileOutputStream outputStream = new FileOutputStream(outputFile)) { outputWorkbook.write(outputStream); output = true; } catch(Exception e) {ErrorLogging.logError(e);} diff --git a/src/main/java/org/baxter/disco/ocr/OpenCVFacade.java b/src/main/java/org/baxter/disco/ocr/OpenCVFacade.java index 13c77bb..f485954 100644 --- a/src/main/java/org/baxter/disco/ocr/OpenCVFacade.java +++ b/src/main/java/org/baxter/disco/ocr/OpenCVFacade.java @@ -324,7 +324,7 @@ public class OpenCVFacade { File output = null; IplImage temp = MAT_CONVERTER.convertToIplImage(MAT_CONVERTER.convert(image)); - fileLocation = fileLocation + "/" + ErrorLogging.fileDatetime.format(LocalDateTime.now()) + "-" + cameraName + ".jpg"; + fileLocation = fileLocation + "/" + ErrorLogging.fileDatetime.format(LocalDateTime.now()) + "-" + cameraName + ".png"; cvSaveImage(fileLocation,temp); output = new File(fileLocation); return output;