【六期】行驶证识别
风搅火 发布于2019-11 浏览:2756 回复:4
1
收藏
最后编辑于2022-04

百度行驶证识别,对机动车行驶证主页及副页所有21个字段进行结构化识别,包括号牌号码、车辆类型、所有人、品牌型号、车辆识别代码、发动机号码、核定载人数、质量、检验记录等

功能接入:
进入百度AI管理界面:https://console.bce.baidu.com/
进入界面后点击“创建应用”

输入应用信息及需要的AI功能即可。


百度现在提供每天一定量的免费调用额度,足够大家测试使用了。


获取Access Token
调用行驶证识别功能前需要先调用鉴权API,确保安全。
具体说明请查阅:http://ai.baidu.com/docs#/Auth/top

请求URL数据格式
向授权服务地址https://aip.baidubce.com/oauth/2.0/token发送请求(推荐使用POST),并在URL中带上以下参数:
grant_type: 必须参数,固定为client_credentials;
client_id: 必须参数,应用的API Key;
client_secret: 必须参数,应用的Secret Key;
例如:
https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=Va5yQRHlA4Fq5eR3LT0vuXV4&client_secret=0rDSjzQ20XUj5itV6WRtznPQSzr5pVw2&


行驶证识别AP调用
行驶证识别的API说明链接为:https://ai.baidu.com/docs#/OCR-API-VehicleLicense/top

接口描述
对机动车行驶证主页及副页所有21个字段进行结构化识别

请求说明
请求URL: https://aip.baidubce.com/rest/2.0/ocr/v1/vehicle_license

具体参数:


{
"errno": 0,
"msg": "success",
"data": {
"words_result_num": 10,
"words_result": {
"品牌型号": {
"words": "保时捷GT37182RUCRE"
},
"发证日期": {
"words": "20160104"
},
"使用性质": {
"words": "非营运"
},
"发动机号码": {
"words": "20832"
},
"号牌号码": {
"words": "苏A001"
},
"所有人": {
"words": "圆圆"
},
"住址": {
"words": "南京市江宁区弘景大道"
},
"注册日期": {
"words": "20160104"
},
"车辆识别代号": {
"words": "HCE58"
},
"车辆类型": {
"words": "小型轿车"
}
}
}
}


详细代码(C#):

public static class AccessToken
{
// 调用getAccessToken()获取的 access_token建议根据expires_in 时间 设置缓存
// 返回token示例
// 百度云中开通对应服务应用的 API Key 建议开通应用的时候多选服务
private static String clientId = "你获得的ID";
// 百度云中开通对应服务应用的 Secret Key
private static String clientSecret = "你获得的KEY";

public static String getAccessToken() {
String authHost = "https://aip.baidubce.com/oauth/2.0/token";
HttpClient client = new HttpClient();
List> paraList = new List>();
paraList.Add(new KeyValuePair("grant_type", "client_credentials"));
paraList.Add(new KeyValuePair("client_id", clientId));
paraList.Add(new KeyValuePair("client_secret", clientSecret));

HttpResponseMessage response = client.PostAsync(authHost, new FormUrlEncodedContent(paraList)).Result;
String result = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(result);
JObject jobject = (JObject)JsonConvert.DeserializeObject(result);
string token = jobject["access_token"].ToString();
return token;
//return result;
}
public class Program
{
// 行驶证识别
public static string vehicleLicense(String imagefilename)
{
string token = AccessToken.getAccessToken();
Console.WriteLine(token);
string host = "https://aip.baidubce.com/rest/2.0/ocr/v1/vehicle_license?access_token=" + token;
Encoding encoding = Encoding.Default;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host);
request.Method = "post";
request.KeepAlive = true;
// 图片的base64编码
string base64 = getFileBase64(imagefilename);
String str = "image=" + HttpUtility.UrlEncode(base64);
byte[] buffer = encoding.GetBytes(str);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
string result = reader.ReadToEnd();
Console.WriteLine("结果:");
Console.WriteLine(result);
return result;
}

public static String getFileBase64(String fileName) {
FileStream filestream = new FileStream(fileName, FileMode.Open);
byte[] arr = new byte[filestream.Length];
filestream.Read(arr, 0, (int)filestream.Length);
string baser64 = Convert.ToBase64String(arr);
filestream.Close();
return baser64;
}
}

功能测试(所有测试图片都来自网络):


分析结果:

结果:
{"log_id": 380398453175377688, "words_result_num": 10, "words_result": {"品牌型号": {"words": "思威牌DH60451R1CSE"}, "发证日期": {"words": ""}, "使用性质": {"words": "非营运"}, "发动机号码": {"words": ""}, "号牌号码": {"words": "京P895A0"}, "所有人": {"words": "林"}, "住址": {"words": ""}, "注册日期": {"words": ""}, "车辆识别代号": {"words": ""}, "车辆类型": {"words": "小型普客车"}}}

测试结论及建议
测试后发现效果很好,调用速度很快,结果准确,可以大大的提高人们的工作效率。

收藏
点赞
1
个赞
共4条回复 最后由用户已被禁言回复于2022-04
#5worddict回复于2019-12
#4 大手拉小手0123回复
别谦虚了,很厉害了

你也写几篇啊

0
#4大手拉小手0123回复于2019-11
#3 风搅火回复
是初学者,还有很多不太懂

别谦虚了,很厉害了

0
#3风搅火回复于2019-11
#2 worddict回复
写的不错

是初学者,还有很多不太懂

0
#2worddict回复于2019-11

写的不错

0
TOP
切换版块