翻譯|行業(yè)資訊|編輯:李顯亮|2020-01-14 11:34:44.843|閱讀 231 次
概述:Aspose一直致力于研究用于執(zhí)行文件間格式轉換,對文件進行操作(例如創(chuàng)建、版本、操作等)的文件格式API。好消息來啦!專門用于Java平臺識別光學標識并管理轉換的API控件Aspose.OMR for Java首次公開發(fā)行啦!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose一直致力于研究用于執(zhí)行文件間格式轉換,對文件進行操作(例如創(chuàng)建、版本、操作等)的文件格式API。好消息來啦!專門用于Java平臺識別光學標識并管理轉換的API控件Aspose.OMR for Java首次公開發(fā)行啦!
Aspose.OMR for Java是一種可從多種圖像格式識別光學標記,包括PNG,GIF,JPEG,TIFF,BMP的API。API將輸出保存為CSV和JSON格式,并且可以在執(zhí)行OMR操作時以文本格式顯示結果。可點擊下方按鈕下載最新版體驗。
識別掃描的圖像和照片
準確率高
處理旋轉和透視圖像
從TXT文件生成OMR模板
識別來自測試,考試,問卷,調查的數(shù)據
將結果保存為CSV和JSON格式
接下來,讓我們快速瀏覽一下上述Java API的功能,以了解如何識別各種圖像格式的光學標記,以及如何從包含MCQ的調查,問卷或測試中捕獲人類標記的數(shù)據。
Aspose.OMR for Java提供了從創(chuàng)建OMR模板到識別光學標記以捕獲數(shù)據的完整功能集。該API支持通過簡單的文本標記生成OMR模板文件或圖像。您只需將模板的文本標記傳遞給API,它將為您生成模板。以下是OMR模板的示例文本標記。
我們可以簡單地將文本標記保存在擴展名為.txt的文本文件中。完成后,可以使用以下步驟生成模板:
下面的代碼示例演示如何使用Java從文本標記生成OMR模板。
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]); }
輸出結果:
為了在圖像中執(zhí)行OMR,只需要兩件事–準備的OMR模板(.omr)和圖像(用戶填寫的表單/工作表)就可以執(zhí)行OMR。API支持以下圖像格式的OMR:
以下是在圖像中執(zhí)行OMR的步驟:
下面的代碼示例演示如何使用Java識別圖像中的光學標記:
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); }
可以通過在0到100之間定義一個自定義閾值來微調OMR結果。增大閾值會使API在識別答案時更加嚴格。可以在TemplateProcessor.recognizeImage()方法中將閾值設置 為第二個參數(shù),如以下Java代碼示例所示。
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); }
在某些情況下,您可能需要使用不同的閾值重新計算OMR結果。在這種情況下,不必一次又一次地調用TemplateProcessor.recognizeImage(),而是可以使用TemplateProcessor.recalculate()方法配置用于自動重新計算的API,以提高圖像處理效率。下面的代碼示例演示如何實現(xiàn)OMR結果的重新計算。
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(); }
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn