【百度AI】百度OCR之行驶证识别V1

00. 目录

01. 行驶证识别概述

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

在这里插入图片描述

视频教程请参见 行驶证识别API调用教程(视频版)

02. 行驶证识别功能演示

网址:https://ai.baidu.com/tech/ocr_cars/vehicle_license

03. 行驶证识别应用场景

司机身份认证

综合应用行驶证、驾驶证和身份证识别技术,自动识别录入用户身份信息和车辆信息,可应用于网约车用户注册、货车司机身份审查等场景,有效提升信息录入效率,优化用户体验。

车主信息服务

基于驾驶证和行驶证识别能力,结构化识别录入用户身份信息和车辆信息,可应用于个性化信息推送、违章信息查询等场景,有效降低用户输入成本,为用户提供信息推送和查询服务。

汽车后市场服务

使用汽车场景下多种卡证和票据识别服务,结构化识别录入用户身份信息和车辆信息,可应用于新能源汽车国家补贴申报、汽车金融保险、维修保养等后市场服务场景,有效提升信息录入效率,优化用户体验。

04. 行驶证识别特点

全字段识别

精准识别行驶证主页及副页所有22个字段,不同业务场景下快速提取任意字段信息,满足各类应用需求。

车辆证照混贴识别

支持识别行驶证正副页、驾驶证正副页在同一张图片上的混贴场景,自动分类并检测识别所有字段。

05. 在线调试

您可以在 示例代码中心 中调试该接口,可进行签名验证、查看在线调用的请求内容和返回结果、示例代码的自动生成。

06. 请求说明

请求示例

HTTP 方法:POST

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

URL参数:

参数
access_token通过API Key和Secret Key获取的access_token,参考“Access Token获取

Header如下:

参数
Content-Typeapplication/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防盗链
detect_directionstringtrue/false- false:默认值不进行图像方向自动矫正 - true: 开启图像方向自动矫正功能,可对旋转 90/180/270 度的图片进行自动矫正并识别
vehicle_license_sidestringfront/back- front:默认值,识别行驶证主页 - **back:**识别行驶证副页
unifiedstringtrue/false- false:默认值,不进行归一化处理 - **true:**对输出字段进行归一化处理,将新/老版行驶证的“注册登记日期/注册日期”统一为”注册日期“进行输出
quality_warnstringtrue/false是否开启质量检测功能,仅在行驶证正页识别时生效, - false:默认值,不输出质量告警信息 - true: 输出行驶证遮挡、不完整质量告警信息
risk_warnstringtrue/false是否开启风险检测功能, - false:默认值,不输出风险告警信息 - true:开启,输出行驶证复印、翻拍、PS等告警信息

请求代码示例

提示一:使用示例代码前,请记得替换其中的示例Token、图片地址或Base64信息。

提示二:部分语言依赖的类或库,请在代码注释中查看下载地址。

命令

curl -i -k 'https://aip.baidubce.com/rest/2.0/ocr/v1/vehicle_license?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/vehicle_license";
static std::string vehicleLicense_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格式
    vehicleLicense_result = std::string((char *) ptr, size * nmemb);
    return size * nmemb;
}
/**
* 行驶证识别
* @return 调用成功返回0,发生错误返回其他错误码
*/
int vehicleLicense(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 = vehicleLicense_result;
        curl_easy_cleanup(curl);
        is_success = 0;
    } else {
        fprintf(stderr, "curl_easy_init() failed.");
        is_success = 1;
    }
    return is_success;
}

07. 返回说明

返回示例(行驶证正页)


{
	"words_result": {
		"车辆识别代号": {
			"words": "SSVUDDTT2J2022558"
		},
		"住址": {
			"words": "中牟县三刘寨村"
		},
		"发证日期": {
			"words": "20180313"
		},
        "发证单位": {
			"words": "北京市公安局公安交通管理局"
		},
		"品牌型号": {
			"words": "大众汽车牌SVW6474DFD"
		},
		"车辆类型": {
			"words": "小型普通客车"
		},
		"所有人": {
			"words": "郑昆"
		},
		"使用性质": {
			"words": "非营运"
		},
		"发动机号码": {
			"words": "111533"
		},
		"号牌号码": {
			"words": "豫A99RR9"
		},
		"注册日期": {
			"words": "20180312"
		}
	},
	"log_id": "1290127183406170112",
	"words_result_num": 11
}

返回示例(行驶证副页)


{
    "words_result": {
        "检验记录": {
            "words": "2018年11月渝A()"
        },
        "核定载质量": {
            "words": "1490kg"
        },
        "整备质量": {
            "words": "2600kg"
        },
        "外廓尺寸": {
            "words": "5990X2500X4400mm"
        },
        "核定载人数": {
            "words": "2人"
        },
        "总质量": {
            "words": "4290kg"
        },
        "燃油类型": {
            "words": "柴油"
        },
        "准牵引总质量": {
            "words": ""
        },
        "备注": {
            "words": "2033-10-25"
        },
        "档案编号": {
            "words": ""
        },
        "号牌号码": {
            "words": "渝A2780RL"
        },
        "证芯编号": {
            "words": "50027372380230106"
        }
    },
    "words_result_num": 12,
    "log_id": 1483006324030440139
}

返回参数

字段必选类型说明
log_iduint64唯一的log id,用于问题定位
directionint32图像方向,当 detect_direction=true 时返回该字段。 - - 1:未定义, - 0:正向, - 1:逆时针90度, - 2:逆时针180度, - 3:逆时针270度
words_result_numuint32识别结果数,表示words_result的元素个数
words_resultobject识别结果
+ wordsstring识别结果字符串
warn_infosarray[]当输入参数 vehicle_license_side=front,且 quality_warn=true 时输出, - shield:行驶证证照存在遮挡告警提示 - incomplete:行驶证证照边框不完整告警提示
risk_typestring当输入参数 risk_warn=true 时返回识出的行驶证的类型:normal-正常行驶证;copy-复印件;screen-翻拍
edit_toolstring当输入参数 risk_warn=true 时返回,如果检测行驶证被编辑过,该字段指定编辑软件名称,如:Adobe Photoshop CC 2014 (Macintosh),如果没有被编辑过则返回值为空

08. C++ SDK

最低支持 C++ 11+

直接使用开发包步骤如下

1.在官方网站下载C++ SDK压缩包。

2.将下载的aip-cpp-sdk-version.zip解压, 其中文件为包含实现代码的头文件。

3.安装依赖库libcurl(需要支持https) openssl jsoncpp(>1.6.2版本,0.x版本将不被支持)。

4.编译工程时添加 C++11 支持 (gcc/clang 添加编译参数 -std=c++11), 添加第三方库链接参数 lcurl, lcrypto, ljsoncpp。

5.在源码中include ocr.h ,引入压缩包中的头文件以使用aip命名空间下的类和方法。

文字识别 C++ SDK目录结构

├── base
│  ├── base.h                                // 请求客户端基类
│  ├── base64.h                              // base64加密相关类
│  ├── http.h                                // http请求封装类
│  └── utils.h                               // 工具类
└── ocr.h                             // 文字识别 交互类

09. 新建client

client是文字识别的C++客户端,为使用文字识别的开发人员提供了一系列的交互方法。当您引入了相应头文件后就可以新建一个client对象。

用户可以参考如下代码新建一个client:

    #include "ocr.h"

    // 设置APPID/AK/SK
    std::string app_id = "你的 App ID";
    std::string api_key = "你的 Api key";
    std::string secret_key = "你的 Secret Key";

    aip::Ocr client(app_id, api_key, secret_key);

在上面代码中,常量APP_ID在百度智能云控制台中创建,常量API_KEYSECRET_KEY是在创建完毕应用后,系统分配给用户的,均为字符串,用于标识用户,为访问做签名验证,可在AI服务控制台中的应用列表中查看。

10. 行驶证识别API

对机动车行驶证所有关键字段进行识别

	Json::Value result;

    std::string image;
    aip::get_file_content("/assets/sample.jpg", &image);

    // 调用行驶证识别
    result = client.vehicle_license(image, aip::null);

    // 如果有可选参数
    std::map<std::string, std::string> options;
    options["detect_direction"] = "true";
    options["accuracy"] = "normal";

    // 带参数调用行驶证识别
    result = client.vehicle_license(image, options);

行驶证识别 请求参数详情

参数名称是否必选类型可选值范围默认值说明
imagestd::string图片数据的二进制字符串,可以使用aip::get_file_content函数获取
detect_directionstd::stringtrue falsefalse是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括: - true:检测朝向; - false:不检测朝向。
vehicle_license_sidestringfront/backfront**- front:**识别行驶证主页 **- back:**识别行驶证副页
unifiedstringtrue/falsefalse**- false:**不进行归一化处理 **- true:**对输出字段进行归一化处理,将新/老版行驶证的“注册登记日期/注册日期”统一为”注册日期“进行输出

行驶证识别 返回数据参数详情

字段必选类型说明
log_idnumber唯一的log id,用于问题定位
words_result_numnumber识别结果数,表示words_result的元素个数
words_resultarray(object)识别结果数组
+wordsstring识别结果字符串

行驶证识别 返回示例


{
  "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": "小型轿车"
      }
    }
  }
}

11. 行驶证识别V1

test.cpp

#include <iostream>
#include "ocr.h"

using namespace std;



int main(void)
{


    // 设置APPID/AK/SK
    std::string app_id = "360326215";
    std::string api_key = "OMlBgMaGMtadGz30AHRRQk4vWS";
    std::string secret_key = "YnwP0KplEgUq4XdfbqgII9tzmBPv0LGm6o";

    aip::Ocr client(app_id, api_key, secret_key);


    Json::Value result;

    std::string image;
    aip::get_file_content("./1.jpg", &image);

    // 调用行驶证识别
    result = client.vehicle_license(image, aip::null);

#if 0
    // 如果有可选参数
    std::map<std::string, std::string> options;
    options["detect_direction"] = "true";
    options["accuracy"] = "normal";

    // 带参数调用行驶证识别
    result = client.vehicle_license(image, options);
#endif

    cout << result << endl;




    return 0;
}

12. 附录

参考代码:vehicle-license-v1.rar

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值