aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerghei Cebotari <serghei@cebotari.ru>2024-11-08 09:23:36 +0300
committerSerghei Cebotari <serghei@cebotari.ru>2024-11-08 09:23:36 +0300
commitcd9c2734f08f45d19e92f39c5c2c0b1344652b58 (patch)
treec18778b0f2f700241bcd46f8176092409ee23431
parentc3da89678e5417548815f74fa69edb12be49cbe6 (diff)
Add Yandex Vision OCR client
-rw-r--r--RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs3
-rw-r--r--RhSolutions.AddIn/RhSolutions.AddIn.csproj3
-rw-r--r--RhSolutions.AddIn/Tools/OcrTool.cs7
-rw-r--r--RhSolutions.AddIn/Tools/ToolFactory.cs7
-rw-r--r--RhSolutions.sln6
-rw-r--r--VisionClient/Models/VisionResponse.cs5
-rw-r--r--VisionClient/Services/IYandexVisionClient.cs24
-rw-r--r--VisionClient/VisionClient.csproj14
8 files changed, 65 insertions, 4 deletions
diff --git a/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs b/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs
index 1666df4..ac83200 100644
--- a/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs
+++ b/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs
@@ -1,4 +1,5 @@
using System.Net;
+using VisionClient.Services;
namespace RhSolutions.AddIn;
@@ -39,6 +40,8 @@ public sealed class RhSolutionsAddIn : IExcelAddIn
.AddTransient<IFittingsCalculator, CouplingsCalculator>(s => s.GetService<CouplingsCalculator>());
Services.AddTransient<SleevesCalculator>()
.AddTransient<IFittingsCalculator, SleevesCalculator>(s => s.GetService<SleevesCalculator>());
+
+ Services.AddTransient<IYandexVisionClient, YandexVisionClient>();
Services.AddSingleton<ToolFactory>();
diff --git a/RhSolutions.AddIn/RhSolutions.AddIn.csproj b/RhSolutions.AddIn/RhSolutions.AddIn.csproj
index 4589a49..6e34066 100644
--- a/RhSolutions.AddIn/RhSolutions.AddIn.csproj
+++ b/RhSolutions.AddIn/RhSolutions.AddIn.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
<LangVersion>10</LangVersion>
@@ -30,6 +30,7 @@
<ItemGroup>
<ProjectReference Include="..\RhSolutions.ProductSku\RhSolutions.ProductSku.csproj" />
<ProjectReference Include="..\SnippingTool\SnippingTool.csproj" />
+ <ProjectReference Include="..\VisionClient\VisionClient.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Images\Coupling.png">
diff --git a/RhSolutions.AddIn/Tools/OcrTool.cs b/RhSolutions.AddIn/Tools/OcrTool.cs
index f407db8..b717bba 100644
--- a/RhSolutions.AddIn/Tools/OcrTool.cs
+++ b/RhSolutions.AddIn/Tools/OcrTool.cs
@@ -1,14 +1,17 @@
using System.Threading.Tasks;
using SnippingTool;
+using VisionClient.Services;
namespace RhSolutions.Tools;
internal class OcrTool : Tool
{
public Application Application { get; set; }
- public OcrTool(ReaderFactory readerFactory, WriterFactory writerFactory, Application application) : base(readerFactory, writerFactory)
+ private IYandexVisionClient client;
+ public OcrTool(ReaderFactory readerFactory, WriterFactory writerFactory, Application application, IYandexVisionClient visionClient) : base(readerFactory, writerFactory)
{
Application = application;
+ client = visionClient;
}
public override void Execute()
@@ -20,6 +23,8 @@ internal class OcrTool : Tool
}).Wait();
string shot = Snipper.SnipBase64();
+ var result = client.ProcessImage(shot);
+
Application.Visible = true;
}
} \ No newline at end of file
diff --git a/RhSolutions.AddIn/Tools/ToolFactory.cs b/RhSolutions.AddIn/Tools/ToolFactory.cs
index 045e893..0cb740c 100644
--- a/RhSolutions.AddIn/Tools/ToolFactory.cs
+++ b/RhSolutions.AddIn/Tools/ToolFactory.cs
@@ -1,4 +1,6 @@
-namespace RhSolutions.Tools;
+using VisionClient.Services;
+
+namespace RhSolutions.Tools;
internal class ToolFactory
{
@@ -6,6 +8,7 @@ internal class ToolFactory
static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
static FittingsCalculatorFactory fittingsCalculatorFactory = RhSolutionsAddIn.ServiceProvider.GetService<FittingsCalculatorFactory>();
static Application application = RhSolutionsAddIn.ServiceProvider.GetService<Application>();
+ static IYandexVisionClient yandexClinet = RhSolutionsAddIn.ServiceProvider.GetService<IYandexVisionClient>();
public Tool GetTool(string toolName)
{
@@ -18,7 +21,7 @@ internal class ToolFactory
"guess" => new GuessTool(readerFactory, writerFactory),
"fillsleeves" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Sleeves"),
"fillcouplings" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Couplings"),
- "ocr" => new OcrTool(readerFactory, writerFactory, application),
+ "ocr" => new OcrTool(readerFactory, writerFactory, application, yandexClinet),
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
};
return tool;
diff --git a/RhSolutions.sln b/RhSolutions.sln
index a47ff74..ccbd318 100644
--- a/RhSolutions.sln
+++ b/RhSolutions.sln
@@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.ProductSku", "R
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnippingTool", "SnippingTool\SnippingTool.csproj", "{DDB517C7-DF61-4C26-B691-956D0E5906C3}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisionClient", "VisionClient\VisionClient.csproj", "{53F322B3-F477-4831-8E16-EA76934A0D59}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +35,10 @@ Global
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {53F322B3-F477-4831-8E16-EA76934A0D59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {53F322B3-F477-4831-8E16-EA76934A0D59}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {53F322B3-F477-4831-8E16-EA76934A0D59}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {53F322B3-F477-4831-8E16-EA76934A0D59}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/VisionClient/Models/VisionResponse.cs b/VisionClient/Models/VisionResponse.cs
new file mode 100644
index 0000000..23a32fd
--- /dev/null
+++ b/VisionClient/Models/VisionResponse.cs
@@ -0,0 +1,5 @@
+namespace VisionClient.Models;
+
+public class VisionResponse
+{
+} \ No newline at end of file
diff --git a/VisionClient/Services/IYandexVisionClient.cs b/VisionClient/Services/IYandexVisionClient.cs
new file mode 100644
index 0000000..77105be
--- /dev/null
+++ b/VisionClient/Services/IYandexVisionClient.cs
@@ -0,0 +1,24 @@
+using VisionClient.Models;
+using System.Net.Http;
+
+namespace VisionClient.Services;
+
+public interface IYandexVisionClient
+{
+ public Task<VisionResponse> ProcessImage(string base64Image);
+}
+
+public class YandexVisionClient : IYandexVisionClient
+{
+ private readonly HttpClient _httpClient;
+
+ public YandexVisionClient(HttpClient httpClient)
+ {
+ _httpClient = httpClient;
+ }
+
+ public Task<VisionResponse> ProcessImage(string base64Image)
+ {
+ throw new NotImplementedException();
+ }
+} \ No newline at end of file
diff --git a/VisionClient/VisionClient.csproj b/VisionClient/VisionClient.csproj
new file mode 100644
index 0000000..4f78021
--- /dev/null
+++ b/VisionClient/VisionClient.csproj
@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
+ <LangVersion>10</LangVersion>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="System.Net.Http" Version="4.3.4" />
+ </ItemGroup>
+
+</Project>