doododo / ocr
ocr 是一个用于OCR图像的包
1.0.0
2019-12-07 15:22 UTC
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^6.2
This package is auto-updated.
Last update: 2024-09-21 08:37:42 UTC
README
支持
环境需求
- PHP > 7.1
- composer
安装
composer require doododo/ocr
使用
注册腾讯 AI 控制台后,可获取APP_ID 及 APP_KEY
基本使用
$image 参数支持
- 文件路径(绝对路径)
SplFileInfo对象- 在线图片地址
$ocr = new \Doododo\OCR\OCR([ 'app_id' => 'xxxx', 'app_key' => 'xxxx' ]); $ocr->idCard($image); // 注意绝对路径或URL
Laravel 使用
# 1. 创建 `ocr.php` 文件 return [ 'app_id' => 'xxxx', 'app_key' => 'xxxx' ]; # 2. 修改 `AppServiceProvider.php` 的 `boot()` 添加 use Doododo\OCR\OCR; $this->app->singleton(OCR::class, function () { return new OCR(config('ocr')); }); $this->app->alias(OCR::class, 'ocr'); # 3. 使用 $ocr = app('ocr'); $ocr->idCard($image); // 注意绝对路径或URL
文档
身份证识别
// 身份证正面 $ocr->idCard($image); // 身份证反面 $ocr->idCard($image, 1);
返回值(Array)
例如:
{
"name": "艾米",
"sex": "女",
"nation": "汉",
"birth": "1986/4/23",
"address": "上海徐汇区田林路397号腾云大厦6F",
"id": "310104198604230289",
"authority": "",
"valid_date": ""
}
行驶证/驾驶证识别
// 行驶证 $ocr->driverLicense($image); // 驾驶证 $ocr->driverLicense($image, 1);
行驶证返回值(Array)
例如:
{
"plate_no": "沪AA1234",
"owner": "李明",
"address": "上海市徐汇区田林路397号腾云大厦6F",
"use_character": "非营运",
"model": "大众汽车牌G4SVW71612RS",
"vin": "ABCDEFGH123456789",
"engine_no": "8B54321",
"register_date": "2011-10-10",
"issue_date": "2011-10-10",
"stamp": "上海市公安局交通警察总队"
}
驾照返回值(Array)
例如:
{
"driver_no": "610333199012213125",
"name": "艾米",
"sex": "女",
"nationality": "中国",
"address": "深圳市南山区高新科技园科技中一路腾讯大厦",
"brithday": "1990-12-21",
"issue_date": "2015-01-01",
"class": "C1",
"start_date": "2015-01-01",
"end_date": "2021-01-01",
"stamp": "广东省深圳市公安局交通警察支队"
}
通用识别
$ocr->generic('https://cdn.ai.qq.com/aiplat/static/ai-demo/large/o-1.jpg');
返回值(Array)
例如:
[
"夏天的飞鸟,飞到我窗前唱歌,又飞去了。",
"秋天的黄叶,它们没有什么可唱,只叹息一声,飞落在那里。",
"Stray birds of summer come to my window to sing and fly away.",
"And yellow leaves of autumn, which have no songs, futter and fall there with a sign.",
"飞鸟集",
"STRAY",
"BIRDS"
]
营业执照识别
$ocr->businessLicense('https://cdn.ai.qq.com/aiplat/static/ai-demo/large/odemo-pic-5.jpg');
返回值(Array)
例如:
{
"business_license": "91440300708461136T",
"legal_person": "马化腾",
"company_code": "深圳市腾讯计算机系统有限公司",
"company_address": "深圳市南山区深南大道10000号",
"business_time": "1998年11月11日至长期"
}
银行卡识别
$ocr->businessLicense('https://cdn.ai.qq.com/aiplat/static/ai-demo/large/odemo-pic-5.jpg');
返回值(Array)
例如:
{
"card_no": "6225760088888888",
"card_type": "贷记卡",
"card_name": "招商银行信用卡",
"bank": "招商银行(03080000)",
"card_time": "08/2022"
}
手写体识别
$ocr->handwrite('https://cdn.ai.qq.com/ai/assets/ai-demo/large/hd-5-lg.jpg');
返回值(Array)
例如:
[
"这个忧伤而明",
"媚的三月,从我单",
"薄的青春里打马",
"而过,穿过紫堇穿",
"过木棉。穿过时",
"隐时现的悲喜和",
"无常"
]
车牌识别
$ocr->plateLicense('https://cdn.ai.qq.com/ai/assets/ai-demo/large/plate-1-lg.jpg')
返回值(Array)
例如:
{
"plate_no": "京N0L9U8"
}
名片识别
$ocr->businessCard('https://cdn.ai.qq.com/aiplat/static/ai-demo/large/odemo-pic-2.jpg');
返回值(Array)
例如:
{
"name": "李明",
"position": "产品经理",
"company": "Tencent腾讯",
"address": "深圳市南山区深南大道10000号腾讯大厦",
"email": "8888asss@tencent.com",
"mobile": "13888882222",
"wechat": "limig"
}
MIT