活动
最新
False
横幅背景图像
Document Understanding 活动
上次更新日期 2024 年 4 月 10 日

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> - 处理图像并返回提取的文本信息。 options 参数是活动参数的字典,其键为参数名称,值为参数值。
属性
  • 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> - 活动输出。 旧版过时参数。
  • 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 白色徽标
信任与安全
© 2005-2024 UiPath. All rights reserved.