←选择平台

RunJob方法

总结
运行工作
语法
c#
VB
objective - c
c++
Java
函数RunJob (_按值传递工作作为IOcrAutoRecognizeJob_)作为OcrAutoRecognizeManagerJobStatus
——(LTOcrAutoRecognizeManagerJobStatus) runJob:(LTOcrAutoRecognizeJob *)工作错误:错误(NSError * *)
公共OcrAutoRecognizeManagerJobStatus runJob (OcrAutoRecognizeJob工作)

参数

工作
IOcrAutoRecognizeJob该参数不能运行(没有什么在VB)。使用CreateJob创建一个工作。

返回值

一个OcrAutoRecognizeManagerJobStatus枚举成员决定工作是否成功完成或中止由于错误或用户操作。

讲话

如果你从相同的线程调用这个方法IOcrAutoRecognizeManager,然后直到该方法返回当前线程将阻塞。异步运行工作,使用RunJobAsync

这个方法返回时,IOcrAutoRecognizeJob.Errors的成员工作将包含在识别过程中可能发生的任何错误。

使用这种方法,初始化一个新的OcrAutoRecognizeJobData对象与工作参数(输入图像文件名、页面输出文档格式,输出文档名称,可选的区域文件名称,等等),然后使用CreateJob创建IOcrAutoRecognizeJob对象传递工作这个方法。最后,调用RunJob通过IOcrAutoRecognizeJob对象。

该方法将执行以下操作:

  1. JobStarted事件被触发。

  2. 创建一个或多个IOcrDocument对象来存储页面。OCR文档的数量取决于创建MaximumThreadsPerJob。如果这个值为0(最大cpu /核)或大于1和支持多个线程引擎,然后可以创建多个文档参与识别过程。基于磁盘的文件将被创建。

  3. 循环遍历页面中指定OcrAutoRecognizeJobData.FirstPageNumber而在OcrAutoRecognizeJobData.LastPageNumberOcrAutoRecognizeJobData.ImageFileNameOcrAutoRecognizeJobData.ImageStream对于每个页面:

  4. 当他们处理所有页面保存到结果中指定文件名OcrAutoRecognizeJobData.DocumentFileName使用指定的格式OcrAutoRecognizeJobData.Format如果有限公司使用,使用临时文件转化为最终的文档DocumentWriter.Convert和(可选)DocumentWriter.AppendLtd

  5. 所有OCR文件和临时文件删除。

  6. JobCompleted事件被触发。

  7. 您可以使用JobProgress事件显示操作进展或中止,如果不使用线程。为更多的信息和一个例子,请参考OcrProgressCallback

  8. 您可以使用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,JobOperationJobCompleted事件

事件跟踪时同步和异步工作已经开始,运行和完成。

AbortAllJobs

中止所有正在运行,等待工作。

EnableTrace

输出调试信息标准的。net跟踪侦听器。

例子

这个例子将OCR图像在一个给定的文件夹并将其转换成PDF文档。它使用多个线程来最大化识别性能,支持堕胎和继续非关键错误。这个例子支持转换图像的任意数量的页面。

c#
VB
使用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 / WDocumentWriter 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);/ /我们要使用多个线程,因此禁用线程/ / IOcrAutoRecognizeManagerIOcrAutoRecognizeManager autoRecognizeManager = ocrEngine.AutoRecognizeManager;autoRecognizeManager。MaximumThreadsPerJob=1;/ /告诉认识经理继续错误autoRecognizeManager。JobErrorMode=OcrAutoRecognizeManagerJobErrorMode.Continue;/ /而不是使用事件来触发当文档完成,/ /我们将使用IOcrAutoRecognizeManager JobCompleted事件/ /减量计数器和触发一个事件当计数器达到0autoRecognizeManager。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.LEADConsole.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.PdfpdfOptions。FontEmbedMode = DocumentFontEmbedMode.NonepdfOptions。OneBitImageCompression = OneBitImageCompressionType.FaxG4docWriter.SetOptions (DocumentFormat。Pdf, pdfOptions)我们要使用多个线程,所以禁用线程“IOcrAutoRecognizeManager昏暗的autoRecognizeManager作为IOcrAutoRecognizeManager = ocrEngine.AutoRecognizeManagerautoRecognizeManager。MaximumThreadsPerJob=1“告诉认识经理继续错误autoRecognizeManager。JobErrorMode=OcrAutoRecognizeManagerJobErrorMode.[继续]”而不是使用事件来触发当文档完成了,我们将使用JobCompleted IOcrAutoRecognizeManager的事件“减量计数器和触发一个事件当计数器达到0AddHandlerautoRecognizeManager.JobStarted,AddressOfautoRecognizeManager_JobStartedAddHandlerautoRecognizeManager.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_JobStartedRemoveHandlerautoRecognizeManager.JobCompleted,AddressOfautoRecognizeManager_JobCompletedConsole.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 (错误:“)每一个(错误]作为OcrAutoRecognizeManagerJobErrorjob.Errorswriter.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在任何条件(或当一个特定的工作即将开始)”和引擎将中止所有当前和等待工作返回结束函数结束公共NotInheritableLEAD_VARS公共常量ImagesDir作为字符串=“C: \ LEADTOOLS21 \ Resources \图片”公共常量OcrLEADRuntimeDir作为字符串=“C: \ LEADTOOLS21 \ Bin \常见\ OcrLEADRuntime”结束
需求

目标平台

Leadtools.Ocr作为sembly
188金宝搏的网址客服|支持|联系我们|知识产权的通知
©1991 - 2021领先的技术公司。保留所有权利。