原創|使用教程|編輯:郝浩|2013-08-14 11:12:19.000|閱讀 810 次
概述:由于移動設備的處理能力和儲存空間限制,在移動設備上執行光學字符識別(OCR)一直以來都是一項較大的挑戰。隨著LEADTOOLS HTML5的出現,在移動設備上執行光學字符識別(OCR)變成可能。憑借LEADTOOLS HTML5提供的HTML5查看器和RESTful Web服務,開發人員可以在任何桌面,平板電腦和移動設備上面創建難以置信的光學字符識別(OCR)應用程序。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
由于移動設備的處理能力和儲存空間限制,在移動設備上執行光學字符識別(OCR)一直以來都是一項較大的挑戰。隨著LEADTOOLS HTML5的出現,在移動設備上執行光學字符識別(OCR)變成可能。憑借LEADTOOLS HTML5提供的HTML5查看器和RESTful Web服務,開發人員可以在任何桌面,平板電腦和移動設備上面創建難以置信的光學字符識別(OCR)應用程序。接下來,我們將展示如何在通過RESTful Web服務實現整頁識別。
在無需下載大型的語言識別庫和可執行文件的情況下,LEADTOOLS OCR RESTful Web服務提供了一項非常簡便的方法將OCR識別添加到應用程序。通過簡單的參數設置,并返回一個易于解析的帶有文本的JSON結構。
通過查看器內置的rubber band事件,選擇一塊矩形區域。使用鼠標點擊,并拖動鼠標,或者在觸屏上滑動手指,用戶可以在圖像上選擇一塊矩形區域,然后處理事件,并將坐標傳遞到Web服務。一旦服務完成處理任務,接下來用戶就可以使用JSON來解析響應并根據應用程序需要來顯示或者使用所識別的文本。下面的例子,我們只是簡單地顯示了提示框中的文本。
_selectRecognizeArea_RubberBandCompleted$1: function HTML5DemosLibrary__ocrDemo$_selectRecognizeArea_RubberBandCompleted$1(sender, e) { // Get the selected area and use that as a zone for the OCR service var searchArea = Leadtools.LeadRectD.fromLTRB(e.get_point1().get_x(), e.get_point1().get_y(), e.get_point2().get_x(), e.get_point2().get_y()); var visibleRect = _viewer.imageControlRectangle(true); searchArea.intersect(visibleRect); searchArea = _viewer.convertRect(Leadtools.Controls.CoordinateType.control, Leadtools.Controls.CoordinateType.image, searchArea); if (searchArea.get_width() > 3 && searchArea.get_height() > 3) { this._recognize$1(searchArea); } }, _recognize$1: function HTML5DemosLibrary__ocrDemo$_recognize$1(searchArea) { // display the loading gif while we wait this.beginOperation(); // build the service request var rest = this.buildServiceUrl('ocr.svc'); rest += '/GetText?uri='; rest += _viewer.get_imageUrl(); var imageSize = _viewer.get_imageSize(); rest += '&width='; rest += parseInt(imageSize.get_width()); rest += '&height='; rest += parseInt(imageSize.get_height()); if (!searchArea.get_isEmpty()) { // no selection was made, recognize the whole image rest += '&left='; rest += parseInt(searchArea.get_left()); rest += '&top='; rest += parseInt(searchArea.get_top()); rest += '&right='; rest += parseInt(searchArea.get_right()); rest += '&bottom='; rest += parseInt(searchArea.get_bottom()); } // create the request and event handler var request = new XMLHttpRequest(); var _this = this; var readyStateChanged = function() { if (request.readyState === 4) { if (request.status === 200) { var results = null; if (request.responseText != null && request.responseText.length > 0) { results = JSON.parse(request.responseText); } else { alert('No text was found in the specified area, please select another area that contains text and try again.'); } request.onreadystatechange = null; request = null; _this.endOperation(false); if (results != null) { alert (results); } } else { _this.showRequestError(request); } } }; // send the request request.onreadystatechange = readyStateChanged; request.open('GET', rest, true); request.send(); },
運行上面的代碼,你會發現如果沒有矩形傳遞給識別功能,LEADTOOLS會創建一個完整的圖像然后調用web服務。因此,你需要創建一個非常簡單的按鈕處理程序來完成整頁識別。
var recognizeButton = document.getElementById('recognizeButton'); recognizeButton.addEventListener('click', function(e) { // recognize the entire image by sending an empty zone _this._recognize$1(Leadtools.LeadRectD.get_empty()); }, false);
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網