#include“ ltocr.h”
l_ltocr_api皮棉ext_functionl_ocrdocument_savexml(文档,文件名,XMloptions,OutputOptions)
将存储在此OCR文档页面中的累积识别结果转换为XML数据,并将其存储在带有XML选项的磁盘文件中。
处理OCR文档。
输出文件名将XML数据保存到。
创建XML数据时使用的选项。
指定XML生成选项的一个或多个OCRXMLOUTPUTPTIOPTIONS枚举成员的组合。
| 价值 | 意义 |
|---|---|
| 成功 | 功能成功。 |
| <1 | 发生错误。参考返回代码。 |
将存储在此OCR文档页面中的累积识别结果转换为XML数据,并将其存储在带有XML选项的磁盘文件中。
必需的DLL和库
l_int l_ocrdocument_savexmlexample(){bitmaphandle bitmap = {0};l_ocrengine ocrengine = null;l_ocrpage ocrpage = null;l_ocrdocumentManager ocrdocumentManager = null;l_ocrdocument ocrdocument = null;//创建引擎实例l_int retcode = l_ocrenginemanager_createengine(l_ocrenginetype_advantage,&ocrengine);如果(retcode!=成功)返回retcode;//使用默认参数启动引擎l_ocrengine_startup(ocrengine,null,ocr_advantage_runtime_dir);//加载图像进行处理l_loadbitmap(make_image_path(l_text)(l_text(“ ocr1.tif”),&bitmap,大小(bitmaphandle),0,order_rgb,null,null);//将图像添加到OCR页面l_ockpage_frombitmap(Ocrengine,&ocrpage,&bitmap,l_ocrbitmapsharingmode_autofree,null,null);//将所有权转移到OCR页面bitmap.flags.alcated = 0;//识别它l_ockpage_recognize(ocrpage,null,null);//创建一个OCR文档l_ocrengine_getDocumentManager(Ocrengine,&ocrdocumentManager);// l_ocrdocumentManager_createDocument(ocrdocumentManager,&ocrdocument,l_ocrcreateDocumentOptions_autodeletefile,null);l_ocrdocumentManager_createDocument(ocrdocumentManager,&ocrdocument,l_ocrcreateDocumentOptions_inmemory,null);//在文档文件模式下,识别后,将ocrpage添加到ocrdocumentl_ocrdocument_addpage(ocrdocument,ocrpage);//这样做,因此我们可以处理它。l_ockpage_destroy(ocrpage);ocrpage = null;//将结果XML保存到磁盘文件//仅保存单词而不是字符,如果我们想要字符//我们需要将选项更改为ocrxmloutputoptions.charactersl_ocrwritexmloptions ocrwritexmloptions;ocrwritexmloptions.structsize =大小(l_ocrwritexmloptions);ocrwritexmloptions.encoding = l_ocrxmlencoding_utf8;ocrwritexmloptions.formatted =真的;wsprintf(ocrwritexmloptions.indent,text(“”);retcode = l_ocrdocument_savexml(ocrdocument,make_image_path(l_text)(l_text(“ ocr1.xml”),&ocrwritexmloptions,l_ocrxmloutputoptions_none);//清理如果(bitmap.flags.pated)l_freebitmap(&bitmap);如果(ocrpage!= null)l_ockpage_destroy(ocrpage);如果(ocrdocument!= null)l_ocrdocument_destroy(ocrdocument);如果(ocrengine!= null)l_ocrengine_destroy(Ocrengine);返回成功;}