一、什么是通用文字识别?
通用文字识别是一种技术,它能够将图像中的文字转换为可编辑的文本格式。
二、通用文字识别适用哪些场景?
例如:商业场景
1.广告数据分析:可以识别户外广告、宣传海报上的文字内容,结合大数据分析技术,了解广告投放效果和市场趋势。
2.电商商品信息录入:商家可以通过文字识别快速将商品的说明书、标签等信息录入到电商平台,提高商品上架速度。
3.物流行业:识别快递单上的地址、姓名、电话等信息,实现自动化的物流信息录入和分拣。
三、如何用C#进行通用文字识别接口调用?
下面我们以阿里云为例,通过C#实现调用:
//using System.IO;
//using System.Text;
//using System.Net;
//using System.Net.Security;
//using System.Security.Cryptography.X509Certificates;
private const String host = "https://kzwordocr.market.alicloudapi.com";
private const String path = "/api-mall/api/general/ocr";
private const String method = "POST";
private const String appcode = "你自己的AppCode";
static void Main(string[] args)
{
String querys = "";
String bodys = "image=image&url=url";
String url = host + path;
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
if (0 < querys.Length)
{
url = url + "?" + querys;
}
if (host.Contains("https://"))
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
}
else
{
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = method;
httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
//根据API的要求,定义相对应的Content-Type
httpRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
if (0 < bodys.Length)
{
byte[] data = Encoding.UTF8.GetBytes(bodys);
using (Stream stream = httpRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
try
{
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
}
catch (WebException ex)
{
httpResponse = (HttpWebResponse)ex.Response;
}
Console.WriteLine(httpResponse.StatusCode);
Console.WriteLine(httpResponse.Method);
Console.WriteLine(httpResponse.Headers);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("\n");
}
public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
正确返回示例如下:
{
"msg": "成功",
"success": true,
"code": 200,
"data": {
"orderNo": "202407102026336827870",
"info": [
{
"line_no": 0, //文本行编号,按从左至右、从上至下顺序依次排列
"confidence": 0.96655273, //行文本识别置信度 0-1
"line_content": "姓名", //识别出的文本行内容
"line_position": {
"x": 53,
"width": 53,
"y": 66,
"line_direction": 0,
"height": 22
}
},
{
"line_no": 1,
"confidence": 0.98909503,
"line_content": "陈海江",
"line_position": {
"x": 102,
"width": 63,
"y": 63,
"line_direction": 0,
"height": 23
}
}
]
}
}
line_no 文本行编号,按从左至右、从上至下顺序依次排列
line_content 识别出的文本行内容
confidence 行文本识别置信度
line_position 文本行位置信息,表示为坐标和旋转角度(左上角X,左上角Y,宽Width,高Height,旋转角度Line Position)+x左上角顶点横坐标X +y 左上角顶点纵坐标Y
width 矩形框的宽
height 矩形框的高
line_direction 文本行的旋转角度
words 文本行内单字符的内容数组,数组元素为一个Json结构,包含character和confidence
character 候选字符character
confidence 单字符的识别置信度
标签:httpRequest,调用,String,C#,url,httpResponse,line,识别
From: https://blog.csdn.net/loosenivy/article/details/141824708