Alt + S 截图并 comicocr
Browse files- src/WpfEditor/ComicOcr.cs +11 -4
- src/WpfEditor/TreeMenuPage.xaml.cs +14 -0
src/WpfEditor/ComicOcr.cs
CHANGED
|
@@ -90,7 +90,7 @@ namespace WpfEditor
|
|
| 90 |
}
|
| 91 |
|
| 92 |
|
| 93 |
-
public static async Task<string> RecognizeImage(string imagePath)
|
| 94 |
{
|
| 95 |
string pth_config = Path.Combine(Constant.ExecutablePath, "config.json");
|
| 96 |
if (!System.IO.File.Exists(pth_config))
|
|
@@ -105,12 +105,19 @@ namespace WpfEditor
|
|
| 105 |
|
| 106 |
|
| 107 |
byte[] bytes = null;
|
| 108 |
-
|
| 109 |
-
using (BinaryReader reader = new BinaryReader(new BufferedStream(stream)))
|
| 110 |
{
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
}
|
| 113 |
|
|
|
|
| 114 |
//Stream strm = new MemoryStream(bytes);
|
| 115 |
|
| 116 |
string img_b64_str = Base64.Base64Encode(bytes);
|
|
|
|
| 90 |
}
|
| 91 |
|
| 92 |
|
| 93 |
+
public static async Task<string> RecognizeImage(string imagePath, byte[] bts = null)
|
| 94 |
{
|
| 95 |
string pth_config = Path.Combine(Constant.ExecutablePath, "config.json");
|
| 96 |
if (!System.IO.File.Exists(pth_config))
|
|
|
|
| 105 |
|
| 106 |
|
| 107 |
byte[] bytes = null;
|
| 108 |
+
if (bts == null)
|
|
|
|
| 109 |
{
|
| 110 |
+
using (FileStream stream = new FileStream(imagePath, FileMode.Open, FileAccess.Read))
|
| 111 |
+
using (BinaryReader reader = new BinaryReader(new BufferedStream(stream)))
|
| 112 |
+
{
|
| 113 |
+
bytes = reader.ReadBytes(Convert.ToInt32(stream.Length));
|
| 114 |
+
}
|
| 115 |
+
} else
|
| 116 |
+
{
|
| 117 |
+
bytes = bts;
|
| 118 |
}
|
| 119 |
|
| 120 |
+
|
| 121 |
//Stream strm = new MemoryStream(bytes);
|
| 122 |
|
| 123 |
string img_b64_str = Base64.Base64Encode(bytes);
|
src/WpfEditor/TreeMenuPage.xaml.cs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
using ScreenGrab;
|
|
|
|
| 2 |
using System.Windows;
|
| 3 |
using System.Windows.Controls;
|
| 4 |
using System.Windows.Input;
|
|
@@ -42,7 +43,20 @@ namespace WpfEditor
|
|
| 42 |
return;
|
| 43 |
}
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
var win = new OCRResultWindow("just a test.");
|
|
|
|
|
|
|
| 46 |
win.Show();
|
| 47 |
}
|
| 48 |
|
|
|
|
| 1 |
using ScreenGrab;
|
| 2 |
+
using System.IO;
|
| 3 |
using System.Windows;
|
| 4 |
using System.Windows.Controls;
|
| 5 |
using System.Windows.Input;
|
|
|
|
| 43 |
return;
|
| 44 |
}
|
| 45 |
|
| 46 |
+
// 将 bitmap 转成 bytes
|
| 47 |
+
byte[] bytes;
|
| 48 |
+
using (var ms = new MemoryStream())
|
| 49 |
+
{
|
| 50 |
+
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
|
| 51 |
+
bytes = ms.ToArray();
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// run first -> huggingface/comicocr/main.py
|
| 55 |
+
string result = await ComicOcr.RecognizeImage("", bytes);
|
| 56 |
+
|
| 57 |
var win = new OCRResultWindow("just a test.");
|
| 58 |
+
win.Owner = this;
|
| 59 |
+
win.WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
| 60 |
win.Show();
|
| 61 |
}
|
| 62 |
|