fix 拆解功换图片点字出图
Browse files
src/WpfEditor/MainWindow.xaml
CHANGED
|
@@ -41,8 +41,8 @@
|
|
| 41 |
</MenuItem>
|
| 42 |
<MenuItem Header="识别">
|
| 43 |
<MenuItem Header="wechat" IsCheckable="True" IsChecked="True" Click="OnRecognitionMethod_Click" Tag="wechat"/>
|
| 44 |
-
<MenuItem Header="ppocr" IsCheckable="True" IsChecked="False" Click="OnRecognitionMethod_Click" Tag="ppocr"/>
|
| 45 |
<MenuItem Header="aliocr" IsCheckable="True" IsChecked="False" Click="OnRecognitionMethod_Click" Tag="aliocr"/>
|
|
|
|
| 46 |
</MenuItem>
|
| 47 |
</Menu>
|
| 48 |
|
|
|
|
| 41 |
</MenuItem>
|
| 42 |
<MenuItem Header="识别">
|
| 43 |
<MenuItem Header="wechat" IsCheckable="True" IsChecked="True" Click="OnRecognitionMethod_Click" Tag="wechat"/>
|
|
|
|
| 44 |
<MenuItem Header="aliocr" IsCheckable="True" IsChecked="False" Click="OnRecognitionMethod_Click" Tag="aliocr"/>
|
| 45 |
+
<MenuItem Header="ppocr" IsCheckable="True" IsChecked="False" Visibility="Hidden" Click="OnRecognitionMethod_Click" Tag="ppocr"/>
|
| 46 |
</MenuItem>
|
| 47 |
</Menu>
|
| 48 |
|
src/WpfEditor/MainWindow.xaml.cs
CHANGED
|
@@ -161,6 +161,8 @@ namespace WpfEditor
|
|
| 161 |
private double _previousImageWidth = 0;
|
| 162 |
private double _previousImageHeight = 0;
|
| 163 |
|
|
|
|
|
|
|
| 164 |
public MainWindow(EditorMode mode = EditorMode.ImageOCR)
|
| 165 |
{
|
| 166 |
InitializeComponent();
|
|
@@ -1588,7 +1590,6 @@ namespace WpfEditor
|
|
| 1588 |
}
|
| 1589 |
|
| 1590 |
} else if (this._mode == EditorMode.MenuSplit) {
|
| 1591 |
-
// 目录拆解模式只能看不能动
|
| 1592 |
|
| 1593 |
Editor._lines.Clear();
|
| 1594 |
|
|
@@ -1606,6 +1607,12 @@ namespace WpfEditor
|
|
| 1606 |
foreach (var pth in jpgs)
|
| 1607 |
{
|
| 1608 |
var (jsn_, m5_, pth_img_, pth_json_) = await Global.img_md5_jsn(pth, _ocrMode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1609 |
List<TextLine> lines = Global.loadJsonReviseEdit_FromOriginalPath(pth_json_);
|
| 1610 |
if (lines.Count > 0)
|
| 1611 |
{
|
|
@@ -2754,7 +2761,7 @@ namespace WpfEditor
|
|
| 2754 |
}
|
| 2755 |
|
| 2756 |
// 树形目录选择变化事件
|
| 2757 |
-
private void DirectoryTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
| 2758 |
{
|
| 2759 |
if (e.NewValue is DirectoryTreeNode selectedNode)
|
| 2760 |
{
|
|
@@ -2772,19 +2779,50 @@ namespace WpfEditor
|
|
| 2772 |
if (ImageMD5 != "")
|
| 2773 |
{
|
| 2774 |
|
| 2775 |
-
|
| 2776 |
|
| 2777 |
-
|
| 2778 |
|
| 2779 |
-
|
|
|
|
|
|
|
|
|
|
| 2780 |
|
| 2781 |
-
|
| 2782 |
|
| 2783 |
-
|
| 2784 |
-
{
|
| 2785 |
|
| 2786 |
-
|
| 2787 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2788 |
Editor._lines.Clear();
|
| 2789 |
|
| 2790 |
Editor._lines = Global.loadJsonReviseEdit_FromOriginalPath(pth_json);
|
|
@@ -2803,6 +2841,25 @@ namespace WpfEditor
|
|
| 2803 |
UpdateTitle();
|
| 2804 |
StatusText.Text = $"已打开: {_currentFilePath}";
|
| 2805 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2806 |
}
|
| 2807 |
|
| 2808 |
|
|
|
|
| 161 |
private double _previousImageWidth = 0;
|
| 162 |
private double _previousImageHeight = 0;
|
| 163 |
|
| 164 |
+
public Dictionary<string, string> _dic_m5_imgname = new Dictionary<string, string>();
|
| 165 |
+
|
| 166 |
public MainWindow(EditorMode mode = EditorMode.ImageOCR)
|
| 167 |
{
|
| 168 |
InitializeComponent();
|
|
|
|
| 1590 |
}
|
| 1591 |
|
| 1592 |
} else if (this._mode == EditorMode.MenuSplit) {
|
|
|
|
| 1593 |
|
| 1594 |
Editor._lines.Clear();
|
| 1595 |
|
|
|
|
| 1607 |
foreach (var pth in jpgs)
|
| 1608 |
{
|
| 1609 |
var (jsn_, m5_, pth_img_, pth_json_) = await Global.img_md5_jsn(pth, _ocrMode);
|
| 1610 |
+
|
| 1611 |
+
if (!_dic_m5_imgname.ContainsKey(m5_))
|
| 1612 |
+
{
|
| 1613 |
+
_dic_m5_imgname[m5_] = pth;
|
| 1614 |
+
}
|
| 1615 |
+
|
| 1616 |
List<TextLine> lines = Global.loadJsonReviseEdit_FromOriginalPath(pth_json_);
|
| 1617 |
if (lines.Count > 0)
|
| 1618 |
{
|
|
|
|
| 2761 |
}
|
| 2762 |
|
| 2763 |
// 树形目录选择变化事件
|
| 2764 |
+
private async void DirectoryTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
| 2765 |
{
|
| 2766 |
if (e.NewValue is DirectoryTreeNode selectedNode)
|
| 2767 |
{
|
|
|
|
| 2779 |
if (ImageMD5 != "")
|
| 2780 |
{
|
| 2781 |
|
| 2782 |
+
//_pthimg
|
| 2783 |
|
| 2784 |
+
// 要先找出真实图片名
|
| 2785 |
|
| 2786 |
+
if (!_dic_m5_imgname.ContainsKey(ImageMD5))
|
| 2787 |
+
{
|
| 2788 |
+
throw new Exception("Error: somthing wrong.");
|
| 2789 |
+
}
|
| 2790 |
|
| 2791 |
+
string image_pth = _dic_m5_imgname[ImageMD5];
|
| 2792 |
|
| 2793 |
+
this._currentFilePath = image_pth;
|
|
|
|
| 2794 |
|
| 2795 |
+
//string pth_ = this._currentFilePath;
|
| 2796 |
|
| 2797 |
+
//string dir = Path.GetDirectoryName(image_pth);
|
| 2798 |
+
|
| 2799 |
+
//string pth_json = Path.Combine([dir, "json", $"{ImageMD5}.json"]);
|
| 2800 |
+
//string pth_img = Path.Combine([dir, "img", $"{ImageMD5}.txt"]);
|
| 2801 |
+
|
| 2802 |
+
//if (!Path.Exists(pth_json) || !Path.Exists(pth_img))
|
| 2803 |
+
//{
|
| 2804 |
+
// throw new Exception($"{ImageMD5} json or img not found.");
|
| 2805 |
+
//}
|
| 2806 |
+
|
| 2807 |
+
|
| 2808 |
+
//var jsonstr = File.ReadAllText(pth_json, new System.Text.UTF8Encoding(false));
|
| 2809 |
+
|
| 2810 |
+
//JObject jsn = null;
|
| 2811 |
+
//try
|
| 2812 |
+
//{
|
| 2813 |
+
// jsn = JObject.Parse(jsonstr);
|
| 2814 |
+
//}
|
| 2815 |
+
//catch (Exception ex)
|
| 2816 |
+
//{
|
| 2817 |
+
// MessageBox.Show("json 解析失败", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
| 2818 |
+
//}
|
| 2819 |
+
|
| 2820 |
+
//pth_json = Path.GetFullPath(pth_json);
|
| 2821 |
+
|
| 2822 |
+
var (jsn, m5, pth_img, pth_json) = await Global.img_md5_jsn(image_pth, _ocrMode);
|
| 2823 |
+
|
| 2824 |
+
if (Path.Exists(pth_json))
|
| 2825 |
+
{
|
| 2826 |
Editor._lines.Clear();
|
| 2827 |
|
| 2828 |
Editor._lines = Global.loadJsonReviseEdit_FromOriginalPath(pth_json);
|
|
|
|
| 2841 |
UpdateTitle();
|
| 2842 |
StatusText.Text = $"已打开: {_currentFilePath}";
|
| 2843 |
}
|
| 2844 |
+
|
| 2845 |
+
// 加载原图
|
| 2846 |
+
string b64_str = File.ReadAllText(pth_img, Encoding.UTF8);
|
| 2847 |
+
byte[] img_bytes = Base64.Base64Decode(b64_str);
|
| 2848 |
+
Mat im_orig = Cv2.ImDecode(img_bytes, ImreadModes.Color);
|
| 2849 |
+
BitmapSource source = TextEditorControl.MatToBitmapSource(im_orig);
|
| 2850 |
+
ViewModel.Image = source;
|
| 2851 |
+
ViewModel.ClearAllRectangles();
|
| 2852 |
+
|
| 2853 |
+
|
| 2854 |
+
// 重置图片尺寸记录
|
| 2855 |
+
_previousImageWidth = 0;
|
| 2856 |
+
_previousImageHeight = 0;
|
| 2857 |
+
|
| 2858 |
+
|
| 2859 |
+
Editor._pthimg = image_pth;
|
| 2860 |
+
Editor._jsn_OpenImg = jsn;
|
| 2861 |
+
Editor._md5_OpenImg = ImageMD5;
|
| 2862 |
+
|
| 2863 |
}
|
| 2864 |
|
| 2865 |
|