fasdfsa commited on
Commit
ec88cef
·
1 Parent(s): a71c77e

ali ocr 的坐标不准了,旋转的原因?

Browse files
src/WeChatOcrCpp/ocr_aliyun.py CHANGED
@@ -64,6 +64,9 @@ from alibabacloud_tea_console.client import Client as ConsoleClient
64
  from alibabacloud_tea_util.client import Client as UtilClient
65
 
66
 
 
 
 
67
  class Sample:
68
  def __init__(self):
69
  pass
@@ -77,8 +80,8 @@ class Sample:
77
  """
78
 
79
  cfg = json_load("../../src/WpfEditor/config.json")
80
- access_key_id = cfg["aliOCR"]["AccessKeyID"]
81
- access_key_secret = cfg["aliOCR"]["AccessKeySecret"]
82
 
83
  # 工程代码建议使用更安全的无AK方式,凭据配置方式请参见:https://help.aliyun.com/document_detail/378659.html。
84
  credential = CredentialClient()
@@ -101,37 +104,35 @@ class Sample:
101
  def main(
102
  args: List[str],
103
  ) -> None:
104
- client = Sample.create_client()
105
- # 需要安装额外的依赖库,直接点击下载完整工程即可看到所有依赖。
106
- body_stream = StreamClient.read_from_file_path('../../data/0003.jpg')
107
- recognize_advanced_request = ocr_api_20210707_models.RecognizeAdvancedRequest(
108
- body=body_stream
109
- )
110
- runtime = util_models.RuntimeOptions()
111
- try:
112
- resp = client.recognize_advanced_with_options(recognize_advanced_request, runtime)
113
- ConsoleClient.log(UtilClient.to_jsonstring(resp))
114
- except Exception as error:
115
- # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
116
- # 错误 message
117
- print(error.message)
118
- # 诊断地址
119
- print(error.data.get("Recommend"))
120
- UtilClient.assert_as_string(error.message)
121
 
122
- @staticmethod
123
- async def main_async(
124
- args: List[str],
125
- ) -> None:
126
  client = Sample.create_client()
127
  # 需要安装额外的依赖库,直接点击下载完整工程即可看到所有依赖。
128
- body_stream = StreamClient.read_from_file_path('<your-file-path>')
129
  recognize_advanced_request = ocr_api_20210707_models.RecognizeAdvancedRequest(
130
- body=body_stream
 
 
 
 
131
  )
132
  runtime = util_models.RuntimeOptions()
 
 
133
  try:
134
- resp = await client.recognize_advanced_with_options_async(recognize_advanced_request, runtime)
 
 
 
135
  ConsoleClient.log(UtilClient.to_jsonstring(resp))
136
  except Exception as error:
137
  # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
@@ -140,7 +141,9 @@ class Sample:
140
  # 诊断地址
141
  print(error.data.get("Recommend"))
142
  UtilClient.assert_as_string(error.message)
143
-
 
 
144
 
145
  if __name__ == '__main__':
146
  Sample.main(sys.argv[1:])
 
64
  from alibabacloud_tea_util.client import Client as UtilClient
65
 
66
 
67
+ def showReslut(jsn, pth_img):
68
+ pass
69
+
70
  class Sample:
71
  def __init__(self):
72
  pass
 
80
  """
81
 
82
  cfg = json_load("../../src/WpfEditor/config.json")
83
+ access_key_id = cfg["aliOCR"]["myAccessKeyID"]
84
+ access_key_secret = cfg["aliOCR"]["myAccessKeySecret"]
85
 
86
  # 工程代码建议使用更安全的无AK方式,凭据配置方式请参见:https://help.aliyun.com/document_detail/378659.html。
87
  credential = CredentialClient()
 
104
  def main(
105
  args: List[str],
106
  ) -> None:
107
+
108
+ pth_img = '../../data/0003.jpg'
109
+
110
+ import os
111
+ if os.path.exists('out.json'):
112
+ jsn = json_load('out.json')
113
+ showReslut(jsn, pth_img)
114
+ return
115
+
116
+
 
 
 
 
 
 
 
117
 
 
 
 
 
118
  client = Sample.create_client()
119
  # 需要安装额外的依赖库,直接点击下载完整工程即可看到所有依赖。
120
+ body_stream = StreamClient.read_from_file_path(pth_img)
121
  recognize_advanced_request = ocr_api_20210707_models.RecognizeAdvancedRequest(
122
+ body=body_stream,
123
+ need_rotate=False,
124
+ need_sort_page=False,
125
+ output_char_info=True
126
+
127
  )
128
  runtime = util_models.RuntimeOptions()
129
+
130
+ data = None
131
  try:
132
+ resp = client.recognize_advanced_with_options(recognize_advanced_request, runtime)
133
+ if resp.status_code == 200:
134
+ data = json_parse(resp.body.data)
135
+
136
  ConsoleClient.log(UtilClient.to_jsonstring(resp))
137
  except Exception as error:
138
  # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
 
141
  # 诊断地址
142
  print(error.data.get("Recommend"))
143
  UtilClient.assert_as_string(error.message)
144
+
145
+ if data:
146
+ json_save('out.json', data)
147
 
148
  if __name__ == '__main__':
149
  Sample.main(sys.argv[1:])
src/WeChatOcrCpp/ocr_aliyunV2.js CHANGED
@@ -66,18 +66,19 @@
66
 
67
  let recognizeAdvancedRequest = new ocr_api20210707.RecognizeAdvancedRequest({
68
  body: readStream,
69
- prob: true,
70
- charInfo: true,
71
- table: true,
72
- sortPage: true,
73
- NeedRotate: true
74
  })
75
  let runtime = new Util.RuntimeOptions({})
76
 
77
-
78
  try {
79
- let resp = await client.recognizeAdvancedWithOptions(recognizeAdvancedRequest, runtime);
80
- Console.log(Util.toJSONString(resp));
 
 
81
  } catch (err) {
82
  let a = 1
83
  }
 
66
 
67
  let recognizeAdvancedRequest = new ocr_api20210707.RecognizeAdvancedRequest({
68
  body: readStream,
69
+ outputCharInfo: true,
70
+ outputTable: true,
71
+ needSortPage: true,
72
+ needRotate: true
 
73
  })
74
  let runtime = new Util.RuntimeOptions({})
75
 
76
+ let data = null
77
  try {
78
+ let resp = await client.recognizeAdvancedWithOptions(recognizeAdvancedRequest, runtime)
79
+ if (resp.statusCode == 200) {
80
+ data = JSON.parse(resp.body.data)
81
+ }
82
  } catch (err) {
83
  let a = 1
84
  }
src/WpfEditor/AliOcr.cs CHANGED
@@ -134,8 +134,8 @@ namespace WpfEditor
134
  {
135
  Body = strm,
136
  OutputCharInfo = true,
137
- NeedSortPage = true,
138
- NeedRotate = true
139
  };
140
  AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
141
  try
 
134
  {
135
  Body = strm,
136
  OutputCharInfo = true,
137
+ NeedSortPage = false,
138
+ NeedRotate = false
139
  };
140
  AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
141
  try
src/WpfEditor/MainWindow.xaml.cs CHANGED
@@ -85,7 +85,8 @@ namespace WpfEditor
85
  private bool _textChanged = false;
86
  private double _imageZoomFactor = 1.0;
87
  private EditorMode _mode = EditorMode.ImageOCR;
88
-
 
89
  // 添加框选相关变量
90
  private bool _isSelecting = false;
91
  private Point _selectionStartPoint;
@@ -837,7 +838,7 @@ namespace WpfEditor
837
  {
838
  string pthimg = selectedImage.FullPath;
839
 
840
- var (jsn, m5, pth_img, pth_json) = Global.img_md5_jsn(pthimg);
841
 
842
  if (this._mode == EditorMode.ImageOCR)
843
  {
@@ -1065,7 +1066,7 @@ namespace WpfEditor
1065
 
1066
  //OnOpenImage_Click(openFileDialog.FileName);
1067
 
1068
- var (jsn, m5, pth_img, pth_json) = Global.img_md5_jsn(openFileDialog.FileName, OcrMode.WeChatOcr);
1069
 
1070
  // 加载原图
1071
  string b64_str = File.ReadAllText(pth_img, Encoding.UTF8);
@@ -1255,14 +1256,17 @@ namespace WpfEditor
1255
  case "wechat":
1256
  // 切换到微信OCR
1257
  StatusText.Text = "当前识别方法:微信OCR";
 
1258
  break;
1259
  case "ppocr":
1260
  // 切换到PaddleOCR
1261
  StatusText.Text = "当前识别方法:PaddleOCR";
 
1262
  break;
1263
  case "aliocr":
1264
  // 切换到阿里OCR
1265
  StatusText.Text = "当前识别方法:阿里OCR";
 
1266
  break;
1267
  }
1268
  }
 
85
  private bool _textChanged = false;
86
  private double _imageZoomFactor = 1.0;
87
  private EditorMode _mode = EditorMode.ImageOCR;
88
+ public OcrMode _ocrMode = OcrMode.WeChatOcr;
89
+
90
  // 添加框选相关变量
91
  private bool _isSelecting = false;
92
  private Point _selectionStartPoint;
 
838
  {
839
  string pthimg = selectedImage.FullPath;
840
 
841
+ var (jsn, m5, pth_img, pth_json) = Global.img_md5_jsn(pthimg, _ocrMode);
842
 
843
  if (this._mode == EditorMode.ImageOCR)
844
  {
 
1066
 
1067
  //OnOpenImage_Click(openFileDialog.FileName);
1068
 
1069
+ var (jsn, m5, pth_img, pth_json) = Global.img_md5_jsn(openFileDialog.FileName, _ocrMode);
1070
 
1071
  // 加载原图
1072
  string b64_str = File.ReadAllText(pth_img, Encoding.UTF8);
 
1256
  case "wechat":
1257
  // 切换到微信OCR
1258
  StatusText.Text = "当前识别方法:微信OCR";
1259
+ _ocrMode = OcrMode.WeChatOcr;
1260
  break;
1261
  case "ppocr":
1262
  // 切换到PaddleOCR
1263
  StatusText.Text = "当前识别方法:PaddleOCR";
1264
+ _ocrMode = OcrMode.PPOCR;
1265
  break;
1266
  case "aliocr":
1267
  // 切换到阿里OCR
1268
  StatusText.Text = "当前识别方法:阿里OCR";
1269
+ _ocrMode = OcrMode.AliOCR;
1270
  break;
1271
  }
1272
  }