44 lines
2.2 KiB
C++
44 lines
2.2 KiB
C++
|
#include <iostream>
|
||
|
#include "ocr.h" // 用于调用接口
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
int main(int argc, char const *argv[])
|
||
|
{
|
||
|
if (argc < 2)
|
||
|
{
|
||
|
cout << "用法: " << argv[0] << " 驾驶证照片" << endl;
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
string app_id = "35475147"; // 你的 App ID
|
||
|
string api_key = "CSneGCoRs8zMD1F1PPnXyzPP"; // 你的 Api Key
|
||
|
string secret_key = "wlKjVS2lE9xPFVV7G5EI3gYm7Zk3tnu1"; // 你的 Secret Key
|
||
|
|
||
|
aip::Ocr client(app_id, api_key, secret_key); // 新建一个对象, 用于调用接口, 调用通用文字识别, 图片参数为本地图片
|
||
|
// cout << "ok" << endl;
|
||
|
|
||
|
// 定义 json 格式的数据类型 Value, result 是 json 类型的 Value 类实例, 用于存储返回的结果
|
||
|
Json::Value result;
|
||
|
string image;
|
||
|
|
||
|
// 加载本地的驾驶证图片内容到 image 对象中, 用于调用驾驶证识别
|
||
|
aip::get_file_content(argv[1], &image);
|
||
|
|
||
|
// 客户端发送图片内容到百度服务器, 并返回结果到 result 对象中
|
||
|
result = client.driving_license(image, aip::null);
|
||
|
cout << "识别到的驾驶证信息如下: " << endl;
|
||
|
// cout << result << endl;
|
||
|
cout << "姓名: " << result["words_result"]["姓名"]["words"].asString() << endl;
|
||
|
cout << "出生日期: " << result["words_result"]["出生日期"]["words"].asString() << endl;
|
||
|
cout << "证号: " << result["words_result"]["证号"]["words"].asString() << endl;
|
||
|
cout << "住址: " << result["words_result"]["住址"]["words"].asString() << endl;
|
||
|
cout << "发证单位: " << result["words_result"]["发证单位"]["words"].asString() << endl;
|
||
|
cout << "初次领证日期: " << result["words_result"]["初次领证日期"]["words"].asString() << endl;
|
||
|
cout << "国籍: " << result["words_result"]["国籍"]["words"].asString() << endl;
|
||
|
cout << "准驾车型: " << result["words_result"]["准驾车型"]["words"].asString() << endl;
|
||
|
cout << "性别: " << result["words_result"]["性别"]["words"].asString() << endl;
|
||
|
cout << "有效期限: " << result["words_result"]["有效期限"]["words"].asString() << " 至 " << result["words_result"]["至"]["words"].asString() << endl;
|
||
|
|
||
|
return 0;
|
||
|
}
|