Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
结果页面加入重新识别按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
NPCDW committed Jan 30, 2022
1 parent 34142e4 commit 685527c
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 59 deletions.
8 changes: 6 additions & 2 deletions WindowsFormsOCR/BaiduCloudHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ public class BaiduCloudHelper
{
private static String baseUrl = "https://aip.baidubce.com";

public static String ocr(Bitmap bmp)
public static String ocr(Bitmap bmp, String ocrType = null)
{
if (string.IsNullOrWhiteSpace(ocrType))
{
ocrType = GlobalConfig.Common.defaultOcrType;
}
try
{
String url = baseUrl + "/rest/2.0/ocr/v1/" + GlobalConfig.Common.defaultOcrType + "?access_token=" + GetAccessToken();
String url = baseUrl + "/rest/2.0/ocr/v1/" + ocrType + "?access_token=" + GetAccessToken();
String base64 = Utils.BitmapToBase64String(bmp);
String body = "image=" + HttpUtility.UrlEncode(base64, Encoding.UTF8);
Dictionary<String, String> headers = new Dictionary<String, String>();
Expand Down
4 changes: 2 additions & 2 deletions WindowsFormsOCR/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.0")]
[assembly: AssemblyFileVersion("0.4.0")]
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
25 changes: 12 additions & 13 deletions WindowsFormsOCR/SettingForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions WindowsFormsOCR/TencentCloudHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ public static String translate(String text)
}
}

public static String ocr(Bitmap bmp)
public static String ocr(Bitmap bmp, String ocrType = null)
{
if (string.IsNullOrWhiteSpace(ocrType))
{
ocrType = GlobalConfig.Common.defaultOcrType;
}
try
{
Credential cred = new Credential
Expand All @@ -67,21 +71,21 @@ public static String ocr(Bitmap bmp)
OcrClient client = new OcrClient(cred, "ap-beijing", clientProfile);
String jsonStr = "{}";
String base64 = Utils.BitmapToBase64String(bmp);
if ("GeneralBasicOCR".Equals(GlobalConfig.Common.defaultOcrType))
if ("GeneralBasicOCR".Equals(ocrType))
{
GeneralBasicOCRRequest req = new GeneralBasicOCRRequest();
req.ImageBase64 = base64;
GeneralBasicOCRResponse resp = client.GeneralBasicOCRSync(req);
jsonStr = AbstractModel.ToJsonString(resp);
}
else if ("GeneralAccurateOCR".Equals(GlobalConfig.Common.defaultOcrType))
else if ("GeneralAccurateOCR".Equals(ocrType))
{
GeneralAccurateOCRRequest req = new GeneralAccurateOCRRequest();
req.ImageBase64 = base64;
GeneralAccurateOCRResponse resp = client.GeneralAccurateOCRSync(req);
jsonStr = AbstractModel.ToJsonString(resp);
}
else if ("GeneralHandwritingOCR".Equals(GlobalConfig.Common.defaultOcrType))
else if ("GeneralHandwritingOCR".Equals(ocrType))
{
GeneralHandwritingOCRRequest req = new GeneralHandwritingOCRRequest();
req.ImageBase64 = base64;
Expand Down
127 changes: 109 additions & 18 deletions WindowsFormsOCR/TranslateAndOCRForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 685527c

Please sign in to comment.