00. 目录
01. 车牌识别概述
支持识别中国大陆机动车蓝牌、黄牌(单双行)、绿牌、大型新能源(黄绿)、领使馆车牌、警牌、武警牌(单双行)、军牌(单双行)、港澳出入境车牌、农用车牌、民航车牌的地域编号和车牌号,并能同时识别图像中的多张车牌。
视频教程请参见 车牌识别API调用教程(视频版)
02. 车牌识别功能演示
网址:https://ai.baidu.com/tech/ocr_cars/plate
03. 车牌识别应用场景
车辆进出场识别
自动识别车辆车牌信息,应用于停车场、小区、工厂等场景,实现无卡、无人的车辆进出场自动化、规范化管理,有效降低人力成本和通行卡证制作成本,大幅度提升管理效率。
交通违章检测
自动识别定位违章车辆信息,实时检测并记录交通违章行为,有效降低人力监控成本,提升管理效率。
04. 车牌识别特点
多颜色识别
可识别多种颜色大陆机动车车牌,包括蓝色、绿色、黄色、白色等,自动检测并识别车牌号码、车牌颜色、车牌位置。
多车牌识别
支持识别同一张图片中的多张车牌,针对车牌占比过小情况做专项优化,提升在路侧、监控高拍场景下的识别准确率。
夜间车牌识别
支持夜间、弱光场景下的车牌识别,针对复杂光线、车牌反光等情况进行专项优化。
05. 在线调试
您可以在 示例代码中心 中调试该接口,可进行签名验证、查看在线调用的请求内容和返回结果、示例代码的自动生成。
06. 请求说明
请求示例
HTTP 方法: POST
请求URL: https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate
URL参数:
参数 | 值 |
---|---|
access_token | 通过API Key和Secret Key获取的access_token,参考“Access Token获取” |
Header如下:
参数 | 值 |
---|---|
Content-Type | application/x-www-form-urlencoded |
Body中放置请求参数,参数详情如下:
请求参数
参数 | 是否必选 | 类型 | 说明 |
---|---|---|---|
image | 和url二选一 | string | 图像数据,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式 |
url | 和image二选一 | string | 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式,当image字段存在时url字段失效 请注意关闭URL防盗链 |
multi_detect | 否 | string | 是否检测多张车牌,默认为false,当置为true的时候可以对一张图片内的多张车牌进行识别 |
multi_scale | 否 | string | 在高拍等车牌较小的场景下可开启,默认为false,当置为true时,能够提高对较小车牌的检测和识别 |
请求代码示例
提示一:使用示例代码前,请记得替换其中的示例Token、图片地址或Base64信息。
提示二:部分语言依赖的类或库,请在代码注释中查看下载地址。
命令
curl -i -k 'https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate?access_token=【调用鉴权接口获取的token】' --data 'image=【图片Base64编码,需UrlEncode】' -H 'Content-Type:application/x-www-form-urlencoded'
C++代码
#include <iostream>
#include <curl/curl.h>
// libcurl库下载链接:https://curl.haxx.se/download.html
// jsoncpp库下载链接:https://github.com/open-source-parsers/jsoncpp/
const static std::string request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate";
static std::string licensePlate_result;
/**
* curl发送http请求调用的回调函数,回调函数中对返回的json格式的body进行了解析,解析结果储存在全局的静态变量当中
* @param 参数定义见libcurl文档
* @return 返回值定义见libcurl文档
*/
static size_t callback(void *ptr, size_t size, size_t nmemb, void *stream) {
// 获取到的body存放在ptr中,先将其转换为string格式
licensePlate_result = std::string((char *) ptr, size * nmemb);
return size * nmemb;
}
/**
* 车牌识别
* @return 调用成功返回0,发生错误返回其他错误码
*/
int licensePlate(std::string &json_result, const std::string &access_token) {
std::string url = request_url + "?access_token=" + access_token;
CURL *curl = NULL;
CURLcode result_code;
int is_success;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.data());
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_httppost *post = NULL;
curl_httppost *last = NULL;
curl_formadd(&post, &last, CURLFORM_COPYNAME, "image", CURLFORM_COPYCONTENTS, "【base64_img】", CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback);
result_code = curl_easy_perform(curl);
if (result_code != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s",
curl_easy_strerror(result_code));
is_success = 1;
return is_success;
}
json_result = licensePlate_result;
curl_easy_cleanup(curl);
is_success = 0;
} else {
fprintf(stderr, "curl_easy_init() failed.");
is_success = 1;
}
return is_success;
}
07. 返回说明
返回示例
{
"words_result": [
{
"color": "blue",
"number": "京KBT355",
"probability": [
0.9999992847,
0.999999404,
0.9999910593,
0.9999765158,
0.999994874,
0.9998959303,
0.9999984503,
0.9999793768
],
"vertexes_location": [
{
"x": 495,
"y": 589
},
{
"x": 800,
"y": 587
},
{
"x": 800,
"y": 676
},
{
"x": 496,
"y": 678
}
]
}
],
"log_id": "6845817085824549137"
}
返回参数
参数 | 是否必须 | 类型 | 说明 |
---|---|---|---|
log_id | 是 | uint64 | 唯一的log id,用于问题定位 |
words_result | 是 | array[] | 识别结果数组 |
+ color | 是 | string | 车牌颜色:支持blue、green、yellow、white、black、yellow_green(新能源大型汽车黄绿车牌)、unknow(未知颜色) |
+ number | 是 | string | 车牌号码 |
+ probability | 是 | string | 前7个数字为车牌中每个字符的置信度,第8个数字为平均置信度,区间为0-1 |
+ vertexes_location | 是 | array[] | 返回文字外接多边形顶点位置 |
++ x | 是 | uint32 | 水平坐标(坐标0点为左上角) |
++ y | 是 | uint32 | 垂直坐标(坐标0点为左上角) |