4.3.3 patch #11

Merged
blizzardfinnegan merged 3 commits from devel into stable 2023-02-24 12:59:27 -05:00
6 changed files with 105 additions and 62 deletions

View file

@ -4,7 +4,7 @@
<groupId>org.baxter.disco</groupId> <groupId>org.baxter.disco</groupId>
<artifactId>ocr</artifactId> <artifactId>ocr</artifactId>
<name>Disco OCR Accuracy Over Life Testing</name> <name>Disco OCR Accuracy Over Life Testing</name>
<version>4.3.2</version> <version>4.3.3</version>
<description>Testing Discos for long-term accuracy, using automated optical character recognition.</description> <description>Testing Discos for long-term accuracy, using automated optical character recognition.</description>
<organization> <organization>
<name>Baxter International</name> <name>Baxter International</name>

View file

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.baxter.disco</groupId> <groupId>org.baxter.disco</groupId>
<artifactId>ocr</artifactId> <artifactId>ocr</artifactId>
<version>4.3.2</version> <version>4.3.3</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Disco OCR Accuracy Over Life Testing</name> <name>Disco OCR Accuracy Over Life Testing</name>
<description>Testing Discos for long-term accuracy, using automated optical character recognition.</description> <description>Testing Discos for long-term accuracy, using automated optical character recognition.</description>

View file

@ -1,2 +1,2 @@
#! /usr/bin/env sh #! /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

View file

@ -25,7 +25,7 @@ public class Cli
/** /**
* Complete build version number * Complete build version number
*/ */
private static final String version = "4.3.2"; private static final String version = "4.3.3";
/** /**
* Currently saved iteration count. * Currently saved iteration count.
@ -687,19 +687,15 @@ public class Cli
//useful for multithreading, which isn't necessary in CLI //useful for multithreading, which isn't necessary in CLI
final int localIterations = iterationCount; final int localIterations = iterationCount;
//TODO: Hard-coded value that needs fixing //Save whether to prime the devices; defaults to false
boolean prime = false; boolean prime = false;
//Create a List of *active* cameras. //Create a List of *active* cameras.
List<String> cameraList = new ArrayList<>(); List<String> cameraList = new ArrayList<>();
for(String cameraName : OpenCVFacade.getCameraNames()) for(String cameraName : OpenCVFacade.getCameraNames())
{ {
//if(cameraName != null) { /*println(cameraName);*/ } prime = (ConfigFacade.getValue(cameraName,ConfigProperties.PRIME) != 0) || prime;
//else ErrorLogging.logError("Null camera!");
if(ConfigFacade.getValue(cameraName,ConfigProperties.PRIME) != 0)
{
prime = true;
}
if(ConfigFacade.getValue(cameraName,ConfigProperties.ACTIVE) != 0) if(ConfigFacade.getValue(cameraName,ConfigProperties.ACTIVE) != 0)
{ {
cameraList.add(cameraName); cameraList.add(cameraName);
@ -709,11 +705,10 @@ public class Cli
//Initialise the workbook, with the number of cameras and the final output location //Initialise the workbook, with the number of cameras and the final output location
DataSaving.initWorkbook(ConfigFacade.getOutputSaveLocation(),cameraList.size()); 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..."); ErrorLogging.logError("DEBUG: Waking devices...");
fixture.iterationMovement(prime);
fixture.pressButton(); 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 //Create final maps for result images, result values, and camera names
Map<File,Double> resultMap = new HashMap<>(); Map<File,Double> resultMap = new HashMap<>();
@ -779,22 +774,20 @@ public class Cli
resultMap.put(file,result); resultMap.put(file,result);
ErrorLogging.logError("Tesseract final output: " + result); ErrorLogging.logError("Tesseract final output: " + result);
LOCK.unlock(); LOCK.unlock();
} if(result <= 10 ||
result >= 100 ||
//LO detection and avoidance result == Double.NEGATIVE_INFINITY)
for(Double result : resultMap.values())
{
if(result <= 1.0 || result >= 117.0 || result == Double.NEGATIVE_INFINITY)
{ {
fixture.goUp(); fixture.goUp();
try{ Thread.sleep(20000); } catch(Exception e){ ErrorLogging.logError(e); } try{ Thread.sleep(20000); }
catch(Exception e){ ErrorLogging.logError(e); }
fixture.pressButton(); fixture.pressButton();
fail = true; fail = true;
break; break;
} }
} }
} }
while(fail == true); while(fail);
//Write all given values to the Excel file //Write all given values to the Excel file
while(!LOCK.tryLock()) {} while(!LOCK.tryLock()) {}

View file

@ -1,16 +1,19 @@
package org.baxter.disco.ocr; package org.baxter.disco.ocr;
import java.io.DataInputStream;
//Standard imports //Standard imports
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
//Generic spreadsheet imports //Generic spreadsheet imports
import org.apache.poi.ss.util.CellReference; 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.DataFormat;
import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.FormulaEvaluator;
@ -18,16 +21,18 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator;
//Excel-specific imports //Excel-specific imports
import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle; 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.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import static org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined; import static org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
/** /**
* Facade for saving data out to a file. * Facade for saving data out to a file.
* *
* @author Blizzard Finnegan * @author Blizzard Finnegan
* @version 4.0.1, 13 Feb. 2023 * @version 4.1.0, 24 Feb. 2023
*/ */
public class DataSaving public class DataSaving
{ {
@ -222,7 +227,7 @@ public class DataSaving
HSSFRow row = outputSheet.createRow(++startingRow); HSSFRow row = outputSheet.createRow(++startingRow);
List<String> cameraNames = new ArrayList<>(cameraToFile.keySet()); List<String> cameraNames = new ArrayList<>(cameraToFile.keySet());
//ErrorLogging.logError("DEBUG: image locations: " + imageLocations.toString()); //ErrorLogging.logError("DEBUG: image locations: " + imageLocations.toString());
List<Object> objectArray = new LinkedList<>(); //List<Object> objectArray = new LinkedList<>();
cycle++; cycle++;
@ -230,46 +235,91 @@ public class DataSaving
indexCell.setCellValue(cycle); indexCell.setCellValue(cycle);
for(String cameraName : cameraNames) 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); 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); //ErrorLogging.logError("DEBUG: " + cameraName);
String serialNumber = ConfigFacade.getSerial(cameraName); //objectArray.add(serialNumber);
objectArray.add(serialNumber); //objectArray.add(file.getPath());
objectArray.add(file.getPath()); //objectArray.add(inputMap.get(file));
objectArray.add(inputMap.get(file)); //objectArray.add(" ");
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)) try (FileOutputStream outputStream = new FileOutputStream(outputFile))
{ outputWorkbook.write(outputStream); output = true; } { outputWorkbook.write(outputStream); output = true; }
catch(Exception e) {ErrorLogging.logError(e);} catch(Exception e) {ErrorLogging.logError(e);}

View file

@ -324,7 +324,7 @@ public class OpenCVFacade
{ {
File output = null; File output = null;
IplImage temp = MAT_CONVERTER.convertToIplImage(MAT_CONVERTER.convert(image)); 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); cvSaveImage(fileLocation,temp);
output = new File(fileLocation); output = new File(fileLocation);
return output; return output;