函数RunJob (_
按值传递工作作为IOcrAutoRecognizeJob_
)作为OcrAutoRecognizeManagerJobStatus
——(LTOcrAutoRecognizeManagerJobStatus) runJob:(LTOcrAutoRecognizeJob *)工作错误:错误(NSError * *)
公共OcrAutoRecognizeManagerJobStatus runJob (OcrAutoRecognizeJob工作)
工作
的IOcrAutoRecognizeJob该参数不能运行零(没有什么在VB)。使用CreateJob创建一个工作。
一个OcrAutoRecognizeManagerJobStatus枚举成员决定工作是否成功完成或中止由于错误或用户操作。
如果你从相同的线程调用这个方法IOcrAutoRecognizeManager,然后直到该方法返回当前线程将阻塞。异步运行工作,使用RunJobAsync。
这个方法返回时,IOcrAutoRecognizeJob.Errors的成员工作将包含在识别过程中可能发生的任何错误。
使用这种方法,初始化一个新的OcrAutoRecognizeJobData对象与工作参数(输入图像文件名、页面输出文档格式,输出文档名称,可选的区域文件名称,等等),然后使用CreateJob创建IOcrAutoRecognizeJob对象传递工作这个方法。最后,调用RunJob通过IOcrAutoRecognizeJob对象。
该方法将执行以下操作:
的JobStarted事件被触发。
创建一个或多个IOcrDocument对象来存储页面。OCR文档的数量取决于创建MaximumThreadsPerJob。如果这个值为0(最大cpu /核)或大于1和支持多个线程引擎,然后可以创建多个文档参与识别过程。基于磁盘的文件将被创建。
循环遍历页面中指定OcrAutoRecognizeJobData.FirstPageNumber而在OcrAutoRecognizeJobData.LastPageNumber在OcrAutoRecognizeJobData.ImageFileName或OcrAutoRecognizeJobData.ImageStream对于每个页面:
使用创建的页面IOcrEngine.CreatePage。
如果OcrAutoRecognizeJobData.ZonesFileName包含一个有效的多页区域文件名称和当前页面的条目,然后装载区IOcrPage。pageNumber LoadZones(文件名)并应用到页面。如果OcrAutoRecognizeJobData.ZonesFileName是一个零(没有什么在VB)引用或它不包含一个等价的页码,页面的auto-decomposing执行相反IOcrPage.AutoZone。有效的多页区域文件条目的所有文档页面是由储蓄文档区域使用IOcrDocument.SaveZones不IOcrPage.SaveZones自IOcrPage.SaveZones不保存该页面数量。
IOcrPage.Recognize被称为OCR页面的数据。
LEADTOOLS OCR模块——导致引擎,使用IOcrDocument.Pages.Add添加到文档的页面。
其他引擎,LEADTOOLS OCR模块——导致引擎:如果使用多个文档或当前公认的页数大于中指定的最大值MaximumPagesBeforeLtd那么当前识别数据保存到一个临时有限公司文件和OCR文档清除。
当他们处理所有页面保存到结果中指定文件名OcrAutoRecognizeJobData.DocumentFileName使用指定的格式OcrAutoRecognizeJobData.Format如果有限公司使用,使用临时文件转化为最终的文档DocumentWriter.Convert和(可选)DocumentWriter.AppendLtd。
所有OCR文件和临时文件删除。
的JobCompleted事件被触发。
您可以使用JobProgress事件显示操作进展或中止,如果不使用线程。为更多的信息和一个例子,请参考OcrProgressCallback。
您可以使用JobOperation事件得到信息关于当前正在执行操作。为更多的信息和一个例子,请参考JobOperation。
的IOcrAutoRecognizeManager界面也使用这种方法有以下选择:
选项 | 描述 |
---|---|
MaximumPagesBeforeLtd | 添加对转换文档的支持无限数量的页面。OCR识别操作在一个文档,其中包含大量的页面(10和更多)可能会导致内存溢出错误。 所有的LEADTOOLS OCR引擎支持中间识别结果保存到一个临时有限公司文件(DocumentFormat.LTD)。后续的结果页将被附加到这个临时文件。当所有文档的页面已经公认,引擎将临时有限公司文件转换为所需的输出格式。 的MaximumPagesBeforeLtd属性定义了最大数量的页面作为一个整体来处理。例如,如果原始文档有20页,这个属性的值是8,引擎将识别前8页并将结果保存到一个临时文件,承认第二8页,添加结果,最后,认识到最后4页和临时文件转换为最终的格式。 |
PreprocessPageCommands | 一个数组的OcrAutoPreprocessPageCommand项目控制auto-preprocess操作执行之前在每个页面文档识别。 |
MaximumThreadsPerJob | 每工作最大数量的线程使用。你可以指示IOcrAutoRecognizeManager使用所有可用的机器的cpu /核心当认识一个文档。这将大大减少所需的时间完成OCR操作。 |
JobErrorMode | 简历上没有一个关键错误的能力。例如,如果一个源文档页面,无法识别。的页面将被添加到最终的文档作为一个图形图像和识别将继续下一个页面。 |
JobStarted,JobProgress,JobOperation和JobCompleted事件 | 事件跟踪时同步和异步工作已经开始,运行和完成。 |
AbortAllJobs | 中止所有正在运行,等待工作。 |
EnableTrace | 输出调试信息标准的。net跟踪侦听器。 |
这个例子将OCR图像在一个给定的文件夹并将其转换成PDF文档。它使用多个线程来最大化识别性能,支持堕胎和继续非关键错误。这个例子支持转换图像的任意数量的页面。
使用Leadtools;
使用Leadtools.Codecs;
使用Leadtools.Ocr;
使用Leadtools.Document.Writer;
使用Leadtools.Forms.Common;
使用Leadtools.WinForms;
公共类RunJobExample
{
/ /等待的文档的数量
私人int_documentsPending;
/ /事件触发时,所有文件都完成了
私人AutoResetEvent _allDocumentsFinishedEvent;
公共无效Start ()
{
字符串imagesDirectory = LEAD_VARS.ImagesDir;
字符串documentsDirectory = Path.Combine (LEAD_VARS.ImagesDir,“RunJobExample”);
/ /创建输出(文件)的目录
如果(! Directory.Exists (documentsDirectory))
{
Directory.CreateDirectory (documentsDirectory);
}
/ /得到所有TIF文件输入(图像)目录
字符串[]imageFileNames = Directory.GetFiles (imagesDirectory,“* .tif”);
如果(imageFileNames。长度= = 0)
{
Console.WriteLine (“没有图片OCR”);
返回;
}
/ /创建一个新的OCR引擎实例
OcrEngineType engineType = OcrEngineType.LEAD;
Console.WriteLine (字符串.Format (“启动{0}引擎”engineType));
使用(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine (engineType))
{
ocrEngine.Startup (零,零,零,LEAD_VARS.OcrLEADRuntimeDir);
/ /设置PDF文档保存选项:图像/文本与CCITT G4编码为B / W
DocumentWriter docWriter = ocrEngine.DocumentWriterInstance;
PdfDocumentOptions pdfOptions = docWriter.GetOptions (DocumentFormat.Pdf)作为PdfDocumentOptions;
pdfOptions。ImageOverText =真正的;
pdfOptions。文档Type = PdfDocumentType.Pdf;
pdfOptions。FontEmbedMode = DocumentFontEmbedMode.None;
pdfOptions。OneBitImageCompression = OneBitImageCompressionType.FaxG4;
docWriter.SetOptions (DocumentFormat。Pdf, pdfOptions);
/ /我们要使用多个线程,因此禁用线程
/ / IOcrAutoRecognizeManager
IOcrAutoRecognizeManager autoRecognizeManager = ocrEngine.AutoRecognizeManager;
autoRecognizeManager。MaximumThreadsPerJob=1;
/ /告诉认识经理继续错误
autoRecognizeManager。JobErrorMode=OcrAutoRecognizeManagerJobErrorMode.Continue;
/ /而不是使用事件来触发当文档完成,
/ /我们将使用IOcrAutoRecognizeManager JobCompleted事件
/ /减量计数器和触发一个事件当计数器达到0
autoRecognizeManager。JobStarted + =新EventHandler < OcrAutoRecognizeRunJobEventArgs > (autoRecognizeManager_JobStarted);
autoRecognizeManager。JobCompleted + =新EventHandler < OcrAutoRecognizeRunJobEventArgs > (autoRecognizeManager_JobCompleted);
int数= imageFileNames.Length;
_documentsPending =计数;
_allDocumentsFinishedEvent =新AutoResetEvent (假);
为(int我= 0;我<数;我+ +)
{
/ /创建数据的工作
字符串imageFileName = imageFileNames[我];
字符串name =“文档”+ (i + 1) .ToString ();
Console.WriteLine (“排队{1}{0}文件”、名称、imageFileName);
JobData data =新JobData ();
数据。AutoRecognizeManager = AutoRecognizeManager;
数据。ImageFileName = ImageFileName;
数据。DocumentFileName =路径。结合(documentsDirectory Path.GetFileNameWithoutExtension (imageFileName) +. pdf”);
数据。JobName =名称;
/ /队列这个工作
ThreadPool.QueueUserWorkItem (新WaitCallback (RunJob)、数据);
}
/ /等待所有文件完成
_allDocumentsFinishedEvent.WaitOne ();
_allDocumentsFinishedEvent.Close ();
autoRecognizeManager。JobStarted - =新EventHandler < OcrAutoRecognizeRunJobEventArgs > (autoRecognizeManager_JobStarted);
autoRecognizeManager。JobCompleted - =新EventHandler < OcrAutoRecognizeRunJobEventArgs > (autoRecognizeManager_JobCompleted);
Console.WriteLine (“所有文件完成后,检查结果文件“{0},documentsDirectory);
}
}
私人无效autoRecognizeManager_JobStarted (对象发送方,OcrAutoRecognizeRunJobEventArgs e)
{
/ /这不是严格需要在这个例子中,我们将
/ /使用它来显示信息
Console.WriteLine (“{0}开始……”,e.Job.JobData.JobName);
/ /检查是否我们需要中止
如果(AbortJobs (e.Job))
{
/ /是的,中止所有工作
e.Job.AutoRecognizeManager.AbortAllJobs ();
}
}
私人无效autoRecognizeManager_JobCompleted (对象发送方,OcrAutoRecognizeRunJobEventArgs e)
{
字符串消息=字符串.Format (“{0}”完成,e.Job.JobData.JobName);
IOcrAutoRecognizeJob工作= e.Job;
/ /显示任何错误
如果(job.Errors。数= = 0)
{
消息+ =“成功……”;
}
其他的
{
消息+ =”错误,第一个错误是“+ job.Errors [0] .Exception.Message;
/ /并保存文档中的错误到一个文本文件目录
字符串documentFileName = job.JobData.DocumentFileName;
字符串textPathName = Path.Combine (Path.GetDirectoryName (documentFileName) Path.GetFileNameWithoutExtension (documentFileName) +“_errors.txt”);
使用(StreamWriter作家= File.CreateText (textPathName))
{
writer.WriteLine (job.JobData.JobName);
writer.WriteLine (“数据:);
writer.WriteLine (“图像文件的名字:“+ job.JobData.ImageFileName);
writer.WriteLine (“第一个页码:”+ job.JobData.FirstPageNumber);
writer.WriteLine (“最后的页码:“+ job.JobData.LastPageNumber);
writer.WriteLine (”格式:“+ job.JobData.Format);
writer.WriteLine (“文档文件的名字:“+ job.JobData.DocumentFileName);
writer.WriteLine (错误:“);
foreach(OcrAutoRecognizeManagerJobError错误在job.Errors)
{
writer.WriteLine (”页面:{0}在{1}。错误:{2}”、错误。ImagePageNumber,错误。操作,error.Exception.Message);
}
}
}
Console.WriteLine(消息);
/ /减量的文件数,当我们达到0,做完了
/ /因为这将从多个线程调用,我们所需要的
/ /使用一个线程安全的过程
int等待= Interlocked.Decrement (裁判_documentsPending);
/ /如果我们过去的文档,等待主线程
如果(等待= = 0)
{
_allDocumentsFinishedEvent.Set ();
}
}
私人类JobData
{
公共IOcrAutoRecognizeManager AutoRecognizeManager;
公共字符串ImageFileName;
公共字符串DocumentFileName;
公共字符串JobName;
}
私人无效RunJob (对象状态)
{
JobData数据=状态作为JobData;
Console.WriteLine (“{0}”,data.JobName);
/ /运行它
OcrAutoRecognizeJobData jobData =新OcrAutoRecognizeJobData(数据。ImageFileName,文档为mat.Pdf, data.DocumentFileName);
jobData。JobName=数据。JobName;
IOcrAutoRecognizeJob工作= data.AutoRecognizeManager.CreateJob (jobData);
data.AutoRecognizeManager.RunJob(工作);
}
私人boolAbortJobs (IOcrAutoRecognizeJob ocrJob)
{
/ /在应用程序中,您可以检查是否堕胎是必需的,例如,如果用户
/ /进度条上按下取消按钮或如果你的服务是关闭的。
/ /在这个例子中,我们永远不会中止,但你可以改变这段代码返回true
/ /在任何条件(或当一个特定的工作即将开始)
/ /引擎将中止所有当前和等待工作
返回假;
}
}
静态类LEAD_VARS
{
公共常量字符串ImagesDir =@“C: \ LEADTOOLS21 \ Resources \图片”;
公共常量字符串OcrLEADRuntimeDir =@“C: \ LEADTOOLS21 \ Bin \常见\ OcrLEADRuntime”;
}
进口Leadtools
进口Leadtools.Codecs
进口Leadtools.Ocr
进口Leadtools.Document.Writer
进口Leadtools.Forms.Common
进口Leadtools.WinForms
公共类RunJobExample
未决的文档的数量
私人_documentsPending作为整数
当完成所有文档’事件触发
私人_allDocumentsFinishedEvent作为AutoResetEvent
公共子Start ()
昏暗的imagesDirectory作为字符串= LEAD_VARS.ImagesDir
昏暗的documentsDirectory作为字符串= Path.Combine (LEAD_VARS.ImagesDir“RunJobExample”)
“创建输出(文件)的目录
如果不Directory.Exists (documentsDirectory)然后
Directory.CreateDirectory (documentsDirectory)
结束如果
气管无名动脉瘘管的”把所有输入(图像)目录中的文件
昏暗的imageFileNames作为字符串()= Directory.GetFiles (imagesDirectory,“* .tif”)
如果imageFileNames。长度= 0然后
Console.WriteLine (“没有图片OCR”)
返回
结束如果
“创建一个新的OCR引擎实例
昏暗的engineType作为OcrEngineType = OcrEngineType.LEAD
Console.WriteLine (字符串.Format (“启动{0}引擎”,engineType))
使用ocrEngine作为IOcrEngine = OcrEngineManager.CreateEngine (engineType)
ocrEngine.Startup (没有什么,没有什么,没有什么LEAD_VARS.OcrLEADRuntimeDir)
“设置文件PDF保存选项:图像/文本与CCITT G4编码为B / W
昏暗的docWriter作为DocumentWriter = ocrEngine.DocumentWriterInstance
昏暗的pdfOptions作为PdfDocumentOptions = TryCast (docWriter.GetOptions (DocumentFormat.Pdf) PdfDocumentOptions)
pdfOptions。ImageOverText =真正的
pdfOptions。文档Type = PdfDocumentType.Pdf
pdfOptions。FontEmbedMode = DocumentFontEmbedMode.None
pdfOptions。OneBitImageCompression = OneBitImageCompressionType.FaxG4
docWriter.SetOptions (DocumentFormat。Pdf, pdfOptions)
我们要使用多个线程,所以禁用线程
“IOcrAutoRecognizeManager
昏暗的autoRecognizeManager作为IOcrAutoRecognizeManager = ocrEngine.AutoRecognizeManager
autoRecognizeManager。MaximumThreadsPerJob=1
“告诉认识经理继续错误
autoRecognizeManager。JobErrorMode=OcrAutoRecognizeManagerJobErrorMode.[继续]
”而不是使用事件来触发当文档完成了,
我们将使用JobCompleted IOcrAutoRecognizeManager的事件
“减量计数器和触发一个事件当计数器达到0
AddHandlerautoRecognizeManager.JobStarted,AddressOfautoRecognizeManager_JobStarted
AddHandlerautoRecognizeManager.JobCompleted,AddressOfautoRecognizeManager_JobCompleted
昏暗的数作为整数= imageFileNames.Length
_documentsPending =数
_allDocumentsFinishedEvent =新AutoResetEvent (假)
为我作为整数= 0来数- 1
“创建工作的数据
昏暗的imageFileName作为字符串= imageFileNames(我)
昏暗的的名字作为字符串=“文档”& (i + 1) .ToString ()
Console.WriteLine (“排队{1}{0}文件”、名称、imageFileName)
昏暗的数据作为新JobData ()
数据。AutoRecognizeManager = AutoRecognizeManager
数据。ImageFileName = ImageFileName
数据。DocumentFileName =路径。结合(documentsDirectory Path.GetFileNameWithoutExtension (imageFileName) &. pdf”)
数据。JobName =名字
队列的这份工作
ThreadPool.QueueUserWorkItem (新WaitCallback (AddressOfRunJob),数据)
下一个
“等待所有文件完成
_allDocumentsFinishedEvent.WaitOne ()
_allDocumentsFinishedEvent.Close ()
RemoveHandlerautoRecognizeManager.JobStarted,AddressOfautoRecognizeManager_JobStarted
RemoveHandlerautoRecognizeManager.JobCompleted,AddressOfautoRecognizeManager_JobCompleted
Console.WriteLine (“所有文件完成后,检查结果文件“{0}documentsDirectory)
结束使用
结束子
私人子autoRecognizeManager_JobStarted(发送方作为对象e作为OcrAutoRecognizeRunJobEventArgs)
“这不是严格需要在这个例子中,我们将
用它来显示信息
Console.WriteLine (“{0}开始……”e.Job.JobData.JobName)
检查是否我们需要中止
如果AbortJobs (e.Job)然后
“是的,中止所有工作
e.Job.AutoRecognizeManager.AbortAllJobs ()
结束如果
结束子
私人子autoRecognizeManager_JobCompleted(发送方作为对象e作为OcrAutoRecognizeRunJobEventArgs)
昏暗的消息作为字符串=字符串.Format (“{0}”完成e.Job.JobData.JobName)
昏暗的工作作为IOcrAutoRecognizeJob = e.Job
显示任何错误
如果job.Errors。数= 0然后
消息+ =“成功……”
其他的
消息+ =”错误,第一个错误是“+ job.Errors .Exception.Message (0)
”并保存文档中的错误到一个文本文件目录
昏暗的documentFileName作为字符串= job.JobData.DocumentFileName
昏暗的textPathName作为字符串=
Path.Combine (Path.GetDirectoryName (documentFileName) Path.GetFileNameWithoutExtension (documentFileName) &“_errors.txt”)
使用作家作为StreamWriter = File.CreateText (textPathName)
writer.WriteLine (job.JobData.JobName)
writer.WriteLine (“数据:)
writer.WriteLine (“图像文件的名字:“& job.JobData.ImageFileName)
writer.WriteLine (“第一个页码:”& job.JobData.FirstPageNumber)
writer.WriteLine (“最后的页码:“& job.JobData.LastPageNumber)
writer.WriteLine (”格式:“& job.JobData.Format)
writer.WriteLine (“文档文件的名字:“& job.JobData.DocumentFileName)
writer.WriteLine (错误:“)
为每一个(错误]作为OcrAutoRecognizeManagerJobError在job.Errors
writer.WriteLine (”页面:{0}在{1}。错误:{2}”,(错误]。ImagePageNumber, (错误]。操作,错误].Exception.Message)
下一个
结束使用
结束如果
Console.WriteLine(消息)
“减量文档计数,当我们达到0,做完了
因为这将从多个线程中被调用,我们所需要的
使用一个线程安全的过程
昏暗的等待作为整数= Interlocked.Decrement (_documentsPending)
如果我们是最后文档,等待主线程
如果等待= 0然后
_allDocumentsFinishedEvent。集()
结束如果
结束子
私人类JobData
公共AutoRecognizeManager作为IOcrAutoRecognizeManager
公共ImageFileName作为字符串
公共DocumentFileName作为字符串
公共JobName作为字符串
结束类
私人子RunJob(国家作为对象)
昏暗的数据作为JobData JobData = TryCast(状态)
Console.WriteLine (“{0}”data.JobName)
“运行它
昏暗的jobData作为新OcrAutoRecognizeJobData(数据。ImageFileName,文档为mat.Pdf, data.DocumentFileName)
jobData。JobName=数据。JobName
昏暗的工作作为IOcrAutoRecognizeJob = data.AutoRecognizeManager.CreateJob (jobData)
data.AutoRecognizeManager.RunJob(工作)
结束子
私人函数AbortJobs (ocrJob作为IOcrAutoRecognizeJob)作为布尔
在您的应用程序,您可以检查如果堕胎是必需的,例如,如果用户
”按下取消按钮在进度栏或如果你的服务是关闭的。
在这个例子中,我们永远不会中止,但你可以改变这段代码返回true
在任何条件(或当一个特定的工作即将开始)
”和引擎将中止所有当前和等待工作
返回假
结束函数
结束类
公共NotInheritable类LEAD_VARS
公共常量ImagesDir作为字符串=“C: \ LEADTOOLS21 \ Resources \图片”
公共常量OcrLEADRuntimeDir作为字符串=“C: \ LEADTOOLS21 \ Bin \常见\ OcrLEADRuntime”
结束类
帮助收藏
光栅net|C API|c++类库|HTML5 JavaScript
文档net|C API|c++类库|HTML5 JavaScript
医疗net|C API|c++类库|HTML5 JavaScript
医疗Web查看器net
188宝金博怎么下载
支持的平台上
net, Java, Android和iOS / macOS组件
C / c++类库的API
HTML5 JavaScript库
你的邮件已经发送到支持!有人应该联系!如果你的问题是紧急请回到聊天。
聊天时间:
周一——周五,上午6点等
谢谢你的反馈!
请填写表单重新开始一个新的聊天。
所有代理目前离线。
聊天时间:
周一-周五
早上8:30 - 6点
联系我们请填写这张表格,我们将通过电子邮件联系你。