Created
January 10, 2020 15:18
-
-
Save aspose-com-gists/5dfadede6434f4d17847b621a18cbdee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String outputDirectory = "GenerationResult"; | |
String[] GenerationMarkups = new String[] { "Sheet.txt", "Grid.txt", "AsposeTest.txt" }; | |
String[] GenerationMarkupsNoExt = new String[] { "Sheet", "Grid", "AsposeTest" }; | |
OmrEngine engine = new OmrEngine(); | |
for (int i = 0; i < GenerationMarkups.length; i++) | |
{ | |
// call template generation providing path to the txt file with markup | |
GenerationResult res = engine.generateTemplate(GenerationMarkups[i]); | |
// check in case of errors | |
if (res.getErrorCode() != 0) | |
{ | |
System.out.println("ERROR CODE: " + res.getErrorCode()); | |
} | |
// save generation result: image and .omr template | |
res.save(outputDirectory, GenerationMarkupsNoExt[i]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String[] UserImages = new String[] { "Sheet1.jpg", "Sheet2.jpg" }; | |
String[] UserImagesNoExt = new String[] { "Sheet1", "Sheet2" }; | |
String outputDirectory = "Result"; | |
String templatePath = "Sheet.omr"; | |
// init engine and get template processor | |
OmrEngine engine = new OmrEngine(); | |
TemplateProcessor templateProcessor = engine.getTemplateProcessor(templatePath); | |
System.out.println("Template loaded."); | |
// Set custom threshold to use in recalculation | |
// this value is in range (0 to 100) | |
// represents the percentage of required black pixels on bubble image to be recognized | |
// i.e. the lower the value - the less black pixels required for bubble to be counted as filled and vice versa | |
int CustomThreshold = 40; | |
// images loop | |
for (int i = 0; i < UserImages.length; i++) | |
{ | |
String image = UserImages[i]; | |
String imagePath = image; | |
System.out.println("Processing image: " + imagePath); | |
// recognize image | |
RecognitionResult result = templateProcessor.recognizeImage(imagePath); | |
// get export csv string | |
String stringRes = result.getCsv(); | |
// save csv to output folder | |
String outputName = UserImagesNoExt[i] + ".csv"; | |
PrintWriter wr = new PrintWriter(new FileOutputStream(outputName), true); | |
wr.println(stringRes); | |
System.out.println("Export done. Path: " + outputName); | |
// recalculate recognition results with custom threshold | |
templateProcessor.recalculate(result, CustomThreshold); | |
// get export csv string | |
stringRes = result.getCsv(); | |
// save recalculated results | |
outputName = UserImagesNoExt[i] + "_recalculated.csv"; | |
wr = new PrintWriter(new FileOutputStream(outputName), true); | |
wr.println(stringRes); | |
System.out.println("Recalculated result export done. Path: " + outputName); | |
System.out.println(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String[] UserImages = new String[] { "Sheet1.jpg", "Sheet2.jpg" }; | |
String[] UserImagesNoExt = new String[] { "Sheet1", "Sheet2" }; | |
String outputDirectory = "Result"; | |
String templatePath = "Sheet.omr"; | |
int customThreshold = 40; | |
// initialize engine and get template processor providing path to the .omr file | |
OmrEngine engine = new OmrEngine(); | |
TemplateProcessor templateProcessor = engine.getTemplateProcessor(templatePath); | |
System.out.println("Template loaded."); | |
// images loop | |
for (int i = 0; i < UserImages.length; i++) { | |
// path to the image to be recognized | |
String imagePath = UserImages[i]; | |
System.out.println("Processing image: " + imagePath); | |
// recognize image and receive result | |
RecognitionResult result = templateProcessor.recognizeImage(imagePath, customThreshold); | |
// export results as csv string | |
String csvResult = result.getCsv(); | |
String json = result.getJson(); | |
// save csv to the output folder | |
PrintWriter wr = new PrintWriter(new FileOutputStream(UserImagesNoExt[i] + ".csv"), true); | |
wr.println(csvResult); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String[] UserImages = new String[] { "Sheet1.jpg", "Sheet2.jpg" }; | |
String[] UserImagesNoExt = new String[] { "Sheet1", "Sheet2" }; | |
String outputDirectory = "Result"; | |
String templatePath = "Sheet.omr"; | |
// initialize engine and get template processor providing path to the .omr file | |
OmrEngine engine = new OmrEngine(); | |
TemplateProcessor templateProcessor = engine.getTemplateProcessor(templatePath); | |
System.out.println("Template loaded."); | |
// images loop | |
for (int i = 0; i < UserImages.length; i++) { | |
// path to the image to be recognized | |
String imagePath = UserImages[i]; | |
System.out.println("Processing image: " + imagePath); | |
// recognize image and receive result | |
RecognitionResult result = templateProcessor.recognizeImage(imagePath); | |
// export results as csv string | |
String csvResult = result.getCsv(); | |
String json = result.getJson(); | |
// save csv to the output folder | |
PrintWriter wr = new PrintWriter(new FileOutputStream(UserImagesNoExt[i] + ".csv"), true); | |
wr.println(csvResult); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment