-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVidadoRecognitionScript.cs
81 lines (66 loc) · 2.79 KB
/
VidadoRecognitionScript.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Kofax.AscentCapture.NetScripting;
using Kofax.Capture.CaptureModule.InteropServices;
using System.Text.Json;
namespace KofaxVidadoRead
{
public class Vidado__Response
{
public float confidence {get; set;}
public string value { get; set; }
public string filename { get; set; }
public string request_id { get; set; }
}
public class Vidado__READ : RecognitionScript
{
public Vidado__READ() : base()
{
this.BatchLoading += Vidado__READ_BatchLoading;
this.BatchUnloading += Vidado__READ_BatchUnloading;
}
void Vidado__READ_BatchLoading(object sender, ref bool ImageFileRequired)
{
this.RecognitionPostProcessing += Vidado__READ_RecognitionPostProcessing;
ImageFileRequired = true;
}
void Vidado__READ_BatchUnloading(object sender)
{
this.BatchLoading -= Vidado__READ_BatchLoading;
this.RecognitionPostProcessing -= Vidado__READ_RecognitionPostProcessing;
this.BatchUnloading -= Vidado__READ_BatchUnloading;
}
void Vidado__READ_RecognitionPostProcessing(object sender, PostRecognitionEventArgs e)
{
//Get VIDADO READ API token from https://api.vidado.ai/portal
var apiToken = "";
var api = "https://api.vidado.ai/read/text";
var imageData = File.ReadAllBytes(e.ImangeFile);
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", apiToken);
using (var content = new MultipartFormDataContent())
{
content.Add(new StreamContent(new MemoryStream(imageData)), "image", "image.tiff");
var result = client.PostAsync(new Uri(api), content).Result;
try
{
result.EnsureSuccessStatusCode();
//var responseData = result.Content.ReadAsStringAsync();
Task<string> responseData = result.Content.ReadAsStringAsync();
var res = responseData.Result;
var digitization_response = JsonSerializer.Deserialize<Vidado__Response>(res);
e.value = digitization_response.value;
e.confidence = Convert.ToInt32(digitization_response.confidence * 100);
}
catch (HttpRequestException)
{
throw;
}
}
}
}
}
}