Fix endless loop, save image directly into excel
Images are now also PNG to reduce storage space
This commit is contained in:
parent
3c1260b648
commit
a965283b47
6 changed files with 99 additions and 51 deletions
|
@ -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>
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -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>
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#! /usr/bin/env sh
|
#! /usr/bin/env sh
|
||||||
sudo java -jar discoTesting-4.3.2.jar 2>/dev/null
|
sudo java -jar discoTesting-4.3.3.jar 2>/dev/null
|
||||||
|
|
|
@ -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.
|
||||||
|
@ -774,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()) {}
|
||||||
|
|
|
@ -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);}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue