|
|
|
@ -12,96 +12,179 @@ namespace testRjgc
|
|
|
|
|
{
|
|
|
|
|
internal class AllClassAndInterfaceWellBeManipulatedInThisFileAndCallThroughFunction
|
|
|
|
|
{
|
|
|
|
|
AllClassAndInterfaceWellBeManipulatedInThisFileAndCallThroughFunction() { }
|
|
|
|
|
public AllClassAndInterfaceWellBeManipulatedInThisFileAndCallThroughFunction() { }
|
|
|
|
|
|
|
|
|
|
TranslationPrivateIn trin = new TranslationPrivateIn();
|
|
|
|
|
TranslationApiStr trstr = new translationPrivateOut();
|
|
|
|
|
TranslationApiInt trint = new translationPublic();
|
|
|
|
|
TranslationScnToJson scnjson = new TranslationScnToJson();
|
|
|
|
|
Sofia sof = new OcrSofia();
|
|
|
|
|
Messiah jsonnet = new jsonNet();
|
|
|
|
|
|
|
|
|
|
public void InputPrivateBaidu(string name, string id, string key)
|
|
|
|
|
{
|
|
|
|
|
TranslationPrivateIn tr = new TranslationPrivateIn();
|
|
|
|
|
tr.InputBaiduPrivate(name, id, key);
|
|
|
|
|
trin.InputBaiduPrivate(name, id, key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InPutPrivateA(string name, List<string> list)
|
|
|
|
|
{
|
|
|
|
|
TranslationPrivateIn tr = new TranslationPrivateIn();
|
|
|
|
|
tr.InPutPrivate(name, list);
|
|
|
|
|
trin.InPutPrivate(name, list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<string> OutputNameList()
|
|
|
|
|
{
|
|
|
|
|
TranslationApiStr tr = new translationPrivateOut();
|
|
|
|
|
List<string> list = tr.OutputTranslationNameList();
|
|
|
|
|
List<string> list = trstr.OutputTranslationNameList();
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<string> OutputStr(string id)
|
|
|
|
|
{
|
|
|
|
|
TranslationApiStr str = new translationPrivateOut();
|
|
|
|
|
List<string> li = str.OutputTranslationS(id);
|
|
|
|
|
List<string> li = trstr.OutputTranslationS(id);
|
|
|
|
|
return li;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<string> OutputChoicPublic(int id)
|
|
|
|
|
{
|
|
|
|
|
TranslationApiInt sin = new translationPublic();
|
|
|
|
|
List<string> li = sin.OutputTranslationI(id);
|
|
|
|
|
List<string> li = trint.OutputTranslationI(id);
|
|
|
|
|
return li;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartSCNTransJSON()
|
|
|
|
|
{
|
|
|
|
|
TranslationScnToJson scn = new TranslationScnToJson();
|
|
|
|
|
scn.StartTrans();
|
|
|
|
|
scnjson.StartTrans();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartTransOneself(string spa, string dps)
|
|
|
|
|
{
|
|
|
|
|
TranslationScnToJson scn = new TranslationScnToJson();
|
|
|
|
|
scn.StopTrans(spa, dps);
|
|
|
|
|
scnjson.StopTrans(spa, dps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string WindowsOcrToGetString(string name)
|
|
|
|
|
{
|
|
|
|
|
Sofia so = new OcrSofia();
|
|
|
|
|
string temp = so.WindowsOcrToGetStringAndTranslate(name);
|
|
|
|
|
return temp;
|
|
|
|
|
return sof.WindowsOcrToGetStringAndTranslate(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string NetBaiDu(string input)
|
|
|
|
|
{
|
|
|
|
|
Messiah me = new jsonNet();
|
|
|
|
|
return me.RequestJsonBaiDu(input);
|
|
|
|
|
return jsonnet.RequestJsonBaiDu(input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string NetAllBaiDu(string input, string srcl, string dstl, string aid, string kkey)
|
|
|
|
|
{
|
|
|
|
|
Messiah me = new jsonNet();
|
|
|
|
|
return me.RequestJsonPrivateBaiDu(input, srcl, dstl, aid, kkey);
|
|
|
|
|
return jsonnet.RequestJsonPrivateBaiDu(input, srcl, dstl, aid, kkey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string NetLanBaiDu(string input, string srcl, string dstl)
|
|
|
|
|
{
|
|
|
|
|
Messiah me = new jsonNet();
|
|
|
|
|
return me.RequestJsonLanguageChangeBaiDu(input, srcl, dstl);
|
|
|
|
|
return jsonnet.RequestJsonLanguageChangeBaiDu(input, srcl, dstl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string NetXunFei(string input)
|
|
|
|
|
{
|
|
|
|
|
Messiah me = new jsonNet();
|
|
|
|
|
return me.RequestJsonXunFei(input);
|
|
|
|
|
return jsonnet.RequestJsonXunFei(input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string NetLanXunFei(string input, string srcl, string dstl)
|
|
|
|
|
{
|
|
|
|
|
Messiah me = new jsonNet();
|
|
|
|
|
return me.RequestJsonLanguageChangeXunFei(input, srcl, dstl);
|
|
|
|
|
return jsonnet.RequestJsonLanguageChangeXunFei(input, srcl, dstl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string NetAllXunFei(string input, string srcl, string dstl, string xid, string xsecret, string xkey)
|
|
|
|
|
{
|
|
|
|
|
Messiah me = new jsonNet();
|
|
|
|
|
return me.RequestJsonPrivateXunFei(input, srcl, dstl, xid, xsecret, xkey);
|
|
|
|
|
return jsonnet.RequestJsonPrivateXunFei(input, srcl, dstl, xid, xsecret, xkey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace OCRConsoleApp
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
using IHost host = CreateHostBuilder(args).Build();
|
|
|
|
|
|
|
|
|
|
var ocrService = host.Services.GetRequiredService<IOcrService>();
|
|
|
|
|
|
|
|
|
|
// 截图并保存到本地文件
|
|
|
|
|
var bitmap = ocrService.CaptureScreen();
|
|
|
|
|
bitmap.Save("screenshot.png", ImageFormat.Png);
|
|
|
|
|
|
|
|
|
|
// 识别图片中的文字
|
|
|
|
|
var text = ocrService.RecognizeText(bitmap);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
|
|
|
Host.CreateDefaultBuilder(args)
|
|
|
|
|
.ConfigureLogging(logging =>
|
|
|
|
|
{
|
|
|
|
|
logging.ClearProviders();
|
|
|
|
|
logging.AddConsole();
|
|
|
|
|
})
|
|
|
|
|
.ConfigureServices((hostContext, services) =>
|
|
|
|
|
{
|
|
|
|
|
services.AddHostedService<Worker>();
|
|
|
|
|
services.AddSingleton<IOcrService>(new OcrService());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IOcrService
|
|
|
|
|
{
|
|
|
|
|
Bitmap CaptureScreen();
|
|
|
|
|
string RecognizeText(Bitmap bitmap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class OcrService : IOcrService
|
|
|
|
|
{
|
|
|
|
|
public Bitmap CaptureScreen()
|
|
|
|
|
{
|
|
|
|
|
var screenBounds = ScreenHelper.GetScreenBounds();
|
|
|
|
|
var bitmap = new Bitmap(screenBounds.Width, screenBounds.Height);
|
|
|
|
|
|
|
|
|
|
using (var graphics = Graphics.FromImage(bitmap))
|
|
|
|
|
graphics.CopyFromScreen(screenBounds.X, screenBounds.Y, 0, 0, screenBounds.Size);
|
|
|
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string RecognizeText(Bitmap bitmap)
|
|
|
|
|
{
|
|
|
|
|
var ocrEngine = new IronOcr.AutoOcr();
|
|
|
|
|
|
|
|
|
|
var result = ocrEngine.Read(bitmap);
|
|
|
|
|
|
|
|
|
|
return result.Text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class ScreenHelper
|
|
|
|
|
{
|
|
|
|
|
[System.Runtime.InteropServices.DllImport("user32.dll")]
|
|
|
|
|
private static extern bool GetCursorPos(out Point lpPoint);
|
|
|
|
|
|
|
|
|
|
public static Rectangle GetScreenBounds()
|
|
|
|
|
{
|
|
|
|
|
GetCursorPos(out Point point);
|
|
|
|
|
|
|
|
|
|
var screenBounds = Screen.FromPoint(point).Bounds;
|
|
|
|
|
|
|
|
|
|
return screenBounds;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|