在Web应用程序中快速实现文本识别
【Dynamic Web TWAIN最新版免费下载>>>】
如何实现
对Core JavaScript文件的引用
<script type="text/javascript" src="../dist/dynamsoft.webtwain.initiate.js"></script><script type="text/javascript" src="../dist/dynamsoft.webtwain.config.js"></script><script type="text/javascript" src="../dist/addon/dynamsoft.webtwain.addon.ocr.js"></script><script type="text/javascript" src="../dist/addon/dynamsoft.webtwain.addon.pdf.js"></script>
这里引用的文件是
用于核心SDK Dynamic Web TWAIN的JS库
- node_modulesdwtdisdynamsoft.webtwain.initiate.js
- node_modulesdwtdisdynamsoft.webtwain.config.js
Dynamsoft OCR Basic的JS库
- node_modulesdwtdistaddondynamsoft.webtwain.addon.ocr.js
- node_modulesdwtdistaddondynamsoft.webtwain.addon.pdf.js
如果你以前在本地安装了Dynamic Web TWAIN,则还可以在以下目录中找到相同的文件(dynamsoft.webtwain.addon.pdf.js除外)。
C:Program Files (x86)DynamsoftDynamic Web TWAIN SDK {version number} {Trial}Resource
Dynamsoft OCR Basic runtime安装代码
function downloadOCRBasic(bDownloadDLL) { var strOCRPath = Dynamsoft.WebTwainEnv.ResourcesPath + "/OCRResources/OCR.zip", strOCRLangPath = Dynamsoft.WebTwainEnv.ResourcesPath + '/OCRResources/OCRBasicLanguages/English.zip'; if (bDownloadDLL) { DWObject.Addon.OCR.Download( strOCRPath, function () {/*console.log('OCR dll is installed');*/ downloadOCRBasic(false); }, function (errorCode, errorString) { console.log(errorString); } ); } else { DWObject.Addon.OCR.DownloadLangData( strOCRLangPath, function () { }, function (errorCode, errorString) { console.log(errorString); }); }}
如上面的代码所示,Dynamsoft OCR Basic安装需要两个步骤。第一步是使用 DWObject.Addon.OCR.Download 接口安装核心DLL(来自“/OCRResources/OCR.zip”的DynamicOCR.dll)。 第二步是使用DWObject.Addon.OCR.DownloadLangData 接口安装OCR语言包或识别字典(’/ OCRResources / OCRBasicLanguages / English.zip’)。此处仅安装英语词典,因此该程序只能识别英语。 如果你需要识别其他语言(总共27种主要语言),你可以下载完整的示例或参考此在线示例。
扫描文档和客户端OCR基础
支持的语言:Arabic, Bengali, Chinese_Simplified, Chinese_Traditional, English, French, German, Hindi, Indonesian, Italian, Japanese, Javanese, Korean, Malay, Marathi, Panjabi, Persian, Portuguese, Russian, Spanish, Swahili, Tamil, Telugu, Thai, Turkish, Vietnamese, Urdu.
使用插件
function DoOCR() { if (DWObject) { if (DWObject.HowManyImagesInBuffer == 0) { alert("Please scan or load an image first."); return; } DWObject.Addon.OCR.SetLanguage('eng'); DWObject.Addon.OCR.SetOutputFormat(EnumDWT_OCROutputFormat.OCROF_TEXT); DWObject.Addon.OCR.Recognize( DWObject.CurrentImageIndexInBuffer, function (sImageIndex, result) { if (result == null) return null; var _textResult = (Dynamsoft.Lib.base64.decode(result.Get())).split(/rn/g), _resultToShow = []; for (var i = 0; i < _textResult.length; i++) { if (i == 0 && _textResult[i].trim() == "") continue; _resultToShow.push(_textResult[i] + '<br />'); } _resultToShow.splice(0, 0, '<p style="padding:5px; margin:0;">'); _resultToShow.push('</p>'); document.getElementById('divNoteMessage').innerHTML = _resultToShow.join(''); }, function (errorcode, errorstring, result) { alert(errorstring); } );
核心代码是
DWObject.Addon.OCR.SetLanguage('eng'); //Set the language to be recognizedDWObject.Addon.OCR.SetOutputFormat(EnumDWT_OCROutputFormat.OCROF_TEXT); //Set the output formatDWObject.Addon.OCR.Recognize(... //Start Reconizing
查看支持的输出格式 EnumDWT_OCROutputFormat。
相关方法是 SetLanguage( ), SetOutputFormat( ),Recognize( ), RecognizeFile( ), RecognizeRect( ), RecognizeSelectedImages( )。
关于Dynamic Web TWAIN使用OCR插件的教程就到此结束啦,希望对你有所帮助~
想要购买正版授权,或者获取更多Dynamic Web TWAIN相关信息的朋友可以点击” 咨询在线客服 “~

标签:扫描识别图像处理扫描与图像
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!