activities
latest
false
重要 :
请注意此内容已使用机器翻译进行了部分本地化。
Document Understanding 活动
Last updated 2024年8月30日

OCR 异步代码活动类

定义

  • 命名空间: UiPath.OCR.Contracts.Activities
  • 程序集: UiPath.OCR.Contracts

描述

必须实现的抽象类,才能从 Workflow Foundation 框架构造 AsyncCodeActivity

成员

方法
  • BeforeExecute(System.Activities.AsyncCodeActivityContext, System.AsyncCallback, object) System.Collections.Generic.Dictionary<string, object> - 覆盖此方法以计算并提供除Image参数以外的所有活动输入参数,并以字典形式返回活动输入参数,其中键为参数名称,值为参数值。
    注意: 在设计时,当没有可用的上下文时,方法的参数为 null。 在这种情况下,无法读取活动参数,因此您可能需要为其提供默认值。
  • BeginExecute(System.Activities.AsyncCodeActivityContext, System.AsyncCallback, object) System.IAsyncResult - 您可以覆盖此方法以实施活动代码。 由工作流运行时调用,以异步执行活动。 它还提供对跟踪、变量和参数的访问权限。
  • EndExecute(System.Activities.AsyncCodeActivityContext, System.IAsyncResult) - System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Drawing.Rectangle, string>> - 您可以覆盖此方法,以通知工作流运行时关联的异步活动操作已完成。
  • OCRAsyncCodeActivity()
  • OnSuccess(System.Activities.AsyncCodeActivityContext, UiPath.OCR.Contracts.DataContracts.OCRResult) void OnSuccess - 计算 OCR 结果后调用此方法。 它可用于设置输出参数或任何其他最终操作。
  • PerformOCRAsync(System.Drawing.Image, System.Collections.Generic.Dictionary<string, object>, System.Threading.CancellationToken) System.Threading.Tasks.Task<UiPath.OCR.Contracts.DataContracts.OCRResult> - 处理图像并返回提取的文本信息。 “选项” 参数是一个活动参数字典,其中键为参数名称,值为参数值。
属性
  • ExtractWords - 获取或设置是否应提取单词。
  • Image System.Activities.InArgument<System.Drawing.Image> - 要处理的图像。
  • Language System.Activities.InArgument<string> - OCR 引擎从用户界面元素中提取字符串所使用的语言。 对于 Google OCR 引擎,该字段需要包含语言文件前缀,如表示罗马尼亚语的“ron”、表示意大利语的“ita”以及表示法语的“fra”。 您可以在该页面找到支持的语言前缀。
  • Output System.Activities.OutArgument<UiPath.OCR.Contracts.OcrActivityResult> - 活动输出。 Legacy,过时的参数。
  • Text System.Activities.OutArgument<string> - 文字的文本值。

代码示例

[DisplayName("Sample OCRAsyncCodeActivity")]
internal class SampleOCRAsyncCodeActivity : OCRAsyncCodeActivity
    {
        [Browsable(true)]
        public override InArgument<Image> Image { get; set; }

        public InArgument<string> CustomInput { get; set; }

        public OutArgument<string> CustomOutput { get; set; }

        public override Task<OCRResult> PerformOCRAsync(Image image, Dictionary<string, object> options, CancellationToken ct)
        {
            string customInput = options[nameof(CustomInput)] as string;
            string text = $"Text from {nameof(SampleOCRAsyncCodeActivity)} with custom input: {customInput}";
            return Task.FromResult(OCRResultHelper.FromText(text));
        }

        protected override void OnSuccess(AsyncCodeActivityContext context, OCRResult result)
        {
            CustomOutput.Set(context, $"Custom output: '{result.Text}' has {result.Words.Length} words.");
        }

        protected override Dictionary<string, object> BeforeExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            return new Dictionary<string, object>
            {
                { nameof(CustomInput), CustomInput.Get(context) }
            };
        }
    }[DisplayName("Sample OCRAsyncCodeActivity")]
internal class SampleOCRAsyncCodeActivity : OCRAsyncCodeActivity
    {
        [Browsable(true)]
        public override InArgument<Image> Image { get; set; }

        public InArgument<string> CustomInput { get; set; }

        public OutArgument<string> CustomOutput { get; set; }

        public override Task<OCRResult> PerformOCRAsync(Image image, Dictionary<string, object> options, CancellationToken ct)
        {
            string customInput = options[nameof(CustomInput)] as string;
            string text = $"Text from {nameof(SampleOCRAsyncCodeActivity)} with custom input: {customInput}";
            return Task.FromResult(OCRResultHelper.FromText(text));
        }

        protected override void OnSuccess(AsyncCodeActivityContext context, OCRResult result)
        {
            CustomOutput.Set(context, $"Custom output: '{result.Text}' has {result.Words.Length} words.");
        }

        protected override Dictionary<string, object> BeforeExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            return new Dictionary<string, object>
            {
                { nameof(CustomInput), CustomInput.Get(context) }
            };
        }
    }
  • 定义
  • 描述
  • 成员
  • 代码示例

此页面有帮助吗?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath Logo White
信任与安全
© 2005-2024 UiPath。保留所有权利。