2020-12-20 18:03:20 +01:00
|
|
|
|
using Serwer.Core.Domain;
|
|
|
|
|
using Serwer.Infrastructure.Settings;
|
|
|
|
|
using System;
|
2020-12-12 14:18:31 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-12-20 18:03:20 +01:00
|
|
|
|
using Tesseract;
|
2020-12-12 14:18:31 +01:00
|
|
|
|
|
|
|
|
|
namespace Serwer.Infrastructure.Services
|
|
|
|
|
{
|
2020-12-20 18:03:20 +01:00
|
|
|
|
public class ImageHandler : IImageHandler
|
2020-12-12 14:18:31 +01:00
|
|
|
|
{
|
2020-12-20 18:03:20 +01:00
|
|
|
|
private readonly ISet<File> _files = new HashSet<File>();
|
|
|
|
|
private readonly string _env;
|
|
|
|
|
public ImageHandler(IHostEnviroment hostEnviroment)
|
|
|
|
|
{
|
|
|
|
|
_env = hostEnviroment.RootPath;
|
|
|
|
|
}
|
|
|
|
|
public async Task<string> Process(string name, string contentType, byte[] bytes)
|
|
|
|
|
{
|
|
|
|
|
var engine = new TesseractEngine(System.IO.Path.Combine(_env, "tessdata"),"eng+equ", EngineMode.Default);
|
|
|
|
|
var img = Pix.LoadFromMemory(bytes);
|
|
|
|
|
var res = engine.Process(img);
|
|
|
|
|
var txt = res.GetText();
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(txt);
|
|
|
|
|
}
|
2020-12-12 14:18:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|