Add Yandex Vision OCR client
This commit is contained in:
parent
c3da89678e
commit
cd9c2734f0
@ -1,4 +1,5 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
|
using VisionClient.Services;
|
||||||
|
|
||||||
namespace RhSolutions.AddIn;
|
namespace RhSolutions.AddIn;
|
||||||
|
|
||||||
@ -39,6 +40,8 @@ public sealed class RhSolutionsAddIn : IExcelAddIn
|
|||||||
.AddTransient<IFittingsCalculator, CouplingsCalculator>(s => s.GetService<CouplingsCalculator>());
|
.AddTransient<IFittingsCalculator, CouplingsCalculator>(s => s.GetService<CouplingsCalculator>());
|
||||||
Services.AddTransient<SleevesCalculator>()
|
Services.AddTransient<SleevesCalculator>()
|
||||||
.AddTransient<IFittingsCalculator, SleevesCalculator>(s => s.GetService<SleevesCalculator>());
|
.AddTransient<IFittingsCalculator, SleevesCalculator>(s => s.GetService<SleevesCalculator>());
|
||||||
|
|
||||||
|
Services.AddTransient<IYandexVisionClient, YandexVisionClient>();
|
||||||
|
|
||||||
Services.AddSingleton<ToolFactory>();
|
Services.AddSingleton<ToolFactory>();
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
|
<TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
|
||||||
<LangVersion>10</LangVersion>
|
<LangVersion>10</LangVersion>
|
||||||
@ -30,6 +30,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\RhSolutions.ProductSku\RhSolutions.ProductSku.csproj" />
|
<ProjectReference Include="..\RhSolutions.ProductSku\RhSolutions.ProductSku.csproj" />
|
||||||
<ProjectReference Include="..\SnippingTool\SnippingTool.csproj" />
|
<ProjectReference Include="..\SnippingTool\SnippingTool.csproj" />
|
||||||
|
<ProjectReference Include="..\VisionClient\VisionClient.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="Images\Coupling.png">
|
<None Update="Images\Coupling.png">
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using SnippingTool;
|
using SnippingTool;
|
||||||
|
using VisionClient.Services;
|
||||||
|
|
||||||
namespace RhSolutions.Tools;
|
namespace RhSolutions.Tools;
|
||||||
|
|
||||||
internal class OcrTool : Tool
|
internal class OcrTool : Tool
|
||||||
{
|
{
|
||||||
public Application Application { get; set; }
|
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;
|
Application = application;
|
||||||
|
client = visionClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Execute()
|
public override void Execute()
|
||||||
@ -20,6 +23,8 @@ internal class OcrTool : Tool
|
|||||||
}).Wait();
|
}).Wait();
|
||||||
|
|
||||||
string shot = Snipper.SnipBase64();
|
string shot = Snipper.SnipBase64();
|
||||||
|
var result = client.ProcessImage(shot);
|
||||||
|
|
||||||
Application.Visible = true;
|
Application.Visible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
namespace RhSolutions.Tools;
|
using VisionClient.Services;
|
||||||
|
|
||||||
|
namespace RhSolutions.Tools;
|
||||||
|
|
||||||
internal class ToolFactory
|
internal class ToolFactory
|
||||||
{
|
{
|
||||||
@ -6,6 +8,7 @@ internal class ToolFactory
|
|||||||
static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
|
static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
|
||||||
static FittingsCalculatorFactory fittingsCalculatorFactory = RhSolutionsAddIn.ServiceProvider.GetService<FittingsCalculatorFactory>();
|
static FittingsCalculatorFactory fittingsCalculatorFactory = RhSolutionsAddIn.ServiceProvider.GetService<FittingsCalculatorFactory>();
|
||||||
static Application application = RhSolutionsAddIn.ServiceProvider.GetService<Application>();
|
static Application application = RhSolutionsAddIn.ServiceProvider.GetService<Application>();
|
||||||
|
static IYandexVisionClient yandexClinet = RhSolutionsAddIn.ServiceProvider.GetService<IYandexVisionClient>();
|
||||||
|
|
||||||
public Tool GetTool(string toolName)
|
public Tool GetTool(string toolName)
|
||||||
{
|
{
|
||||||
@ -18,7 +21,7 @@ internal class ToolFactory
|
|||||||
"guess" => new GuessTool(readerFactory, writerFactory),
|
"guess" => new GuessTool(readerFactory, writerFactory),
|
||||||
"fillsleeves" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Sleeves"),
|
"fillsleeves" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Sleeves"),
|
||||||
"fillcouplings" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Couplings"),
|
"fillcouplings" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Couplings"),
|
||||||
"ocr" => new OcrTool(readerFactory, writerFactory, application),
|
"ocr" => new OcrTool(readerFactory, writerFactory, application, yandexClinet),
|
||||||
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
|
_ => throw new Exception($"Неизвестный инструмент {toolName}"),
|
||||||
};
|
};
|
||||||
return tool;
|
return tool;
|
||||||
|
@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.ProductSku", "R
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnippingTool", "SnippingTool\SnippingTool.csproj", "{DDB517C7-DF61-4C26-B691-956D0E5906C3}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnippingTool", "SnippingTool\SnippingTool.csproj", "{DDB517C7-DF61-4C26-B691-956D0E5906C3}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisionClient", "VisionClient\VisionClient.csproj", "{53F322B3-F477-4831-8E16-EA76934A0D59}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{DDB517C7-DF61-4C26-B691-956D0E5906C3}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
5
VisionClient/Models/VisionResponse.cs
Normal file
5
VisionClient/Models/VisionResponse.cs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
namespace VisionClient.Models;
|
||||||
|
|
||||||
|
public class VisionResponse
|
||||||
|
{
|
||||||
|
}
|
24
VisionClient/Services/IYandexVisionClient.cs
Normal file
24
VisionClient/Services/IYandexVisionClient.cs
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
14
VisionClient/VisionClient.csproj
Normal file
14
VisionClient/VisionClient.csproj
Normal file
@ -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>
|
Loading…
Reference in New Issue
Block a user