項目地址 https://github.com/godruoyi/ocrphp
今天是星期二,是發佈輪子的好日子。@overtruelaravel
composer require godruoyi/ocr複製代碼
基本使用(以百度OCR爲例)github
use Godruoyi\OCR\Application;
$app = new Application([
'ocrs' => [
'baidu' => [
'app_key' => 'app_key',
'secret_key' => 'secret_key'
],
]
]);
//身份證識別
$result = $app->baidu->idcard($filePath);複製代碼
返回結果web
{
"log_id": 530427582,
"image_status": "normal",
"words_result_num": 6,
"words_result": {
"住址": {
"words": "上海市閔行區華漕鎮紅衛村宗家巷1號"
},
"出生": {
"words": "19870723"
},
"姓名": {
"words": "鹿晗"
},
"公民身份號碼": {
"words": "123456789123456132X"
},
"性別": {
"words": "男"
},
"民族": {
"words": "漢"
}
}
}複製代碼
詳情請參考官方文檔json
全部平臺支持的方法中,都知足如下結構:api
$app->platform->$method($files, $options = [])複製代碼
$files
的值能夠爲緩存
SplFileInfo
對象Resource
Arraybash
注:
options
的值都是可選的網絡
目前採用 AccessToken
做爲 API
認證方式,查看鑑權認證機制
$app->baidu->generalBasic($file, [
'language_type' => 'CHN_ENG', //支持的語言,默認爲CHN_ENG(中英文混合)
'detect_direction' => false, //是否檢測圖像朝向
'detect_language' => false, //是否檢測語言,默認不檢測
'probability' => false, //是否返回識別結果中每一行的置信度
]);複製代碼
$app->baidu->accurateBasic($file, [
'detect_direction' => false, //是否檢測圖像朝向
'probability' => false, //是否返回識別結果中每一行的置信度
]);複製代碼
$app->baidu->general($file, [
'recognize_granularity' => 'big', //是否認位單字符位置
'language_type' => 'CHN_ENG', //CHN_ENG:中英文混合;默認爲CHN_ENG
'detect_direction' => false, //是否檢測圖像朝向
'detect_language' => false, //是否檢測語言,默認不檢測
'vertexes_location' => false, //是否返回文字外接多邊形頂點位置,不支持單字位置。默認爲false
'probability' => false, //是否返回識別結果中每一行的置信度
]);複製代碼
$app->baidu->accurate($file, [
'recognize_granularity' => 'big', //是否認位單字符位置
'detect_direction' => false, //是否檢測圖像朝向
'vertexes_location' => false, //是否返回文字外接多邊形頂點位置,不支持單字位置。默認爲false
'probability' => false, //是否返回識別結果中每一行的置信度
]);複製代碼
$app->baidu->generalEnhanced($file, [
'language_type' => 'CHN_ENG', //CHN_ENG:中英文混合;默認爲CHN_ENG
'detect_direction' => false, //是否檢測圖像朝向
'vertexes_location' => false, //是否返回文字外接多邊形頂點位置,不支持單字位置。默認爲false
'probability' => false, //是否返回識別結果中每一行的置信度
]);複製代碼
$app->baidu->webimage($file, [
'detect_direction' => false, //是否檢測圖像朝向
'detect_language' => false, //是否檢測語言,默認不檢測
]);複製代碼
$app->baidu->idcard($file, [
'detect_direction' => false, //是否檢測圖像朝向
'id_card_side' => 'front', //front:身份證正面;back:身份證背面 (注意,該參數必選)
'detect_risk' => false, //是否開啓身份證風險類型功能,默認false
]);複製代碼
$app->baidu->bankcard($file, [
]);複製代碼
$app->baidu->drivingLicense($file, [
'detect_direction' => false, //是否檢測圖像朝向
]);複製代碼
$app->baidu->vehicleLicense($file, [
'detect_direction' => false, //是否檢測圖像朝向
'accuracy' => 'normal' // normal 使用快速服務,1200ms左右時延,缺省或其它值使用高精度服務,1600ms左右時延
]);複製代碼
$app->baidu->licensePlate($file, [
'multi_detect' => false, //是否檢測多張車牌,默認爲false
]);複製代碼
$app->baidu->businessLicense($file, [
]);複製代碼
$app->baidu->receipt($file, [
'recognize_granularity' => 'big', //是否認位單字符位置
'probability' => false, //是否返回識別結果中每一行的置信度
'accuracy' => 'normal' // normal 使用快速服務,1200ms左右時延,缺省或其它值使用高精度服務,1600ms左右時延
'detect_direction' => false, //是否檢測圖像朝向
]);複製代碼
目前採用 APPCODE
做爲 API
認證方式,查看個人APPCODE
use Godruoyi\OCR\Application;
$app = new Application([
'ocrs' => [
'aliyun' => [
'appcode' => '40bc103c7fe6417b87152f6f68bead2f',
]
]
]);複製代碼
阿里雲OCR不支持在線圖片地址
$app->aliyun->idcard($file, [
'side' => 'face', //身份證正反面類型:face/back
]);複製代碼
$app->aliyun->vehicle($file, [
]);複製代碼
$app->aliyun->driverLicense($file, [
'side' => 'face', //駕駛證首頁/副頁:face/back
]);複製代碼
$app->aliyun->shopSign($file, [
]);複製代碼
$app->aliyun->english($file, [
]);複製代碼
$app->aliyun->businessLicense($file, [
]);複製代碼
$app->aliyun->bankCard($file, [
]);複製代碼
$app->aliyun->businessCard($file, [
]);複製代碼
$app->aliyun->trainTicket($file, [
]);複製代碼
$app->aliyun->vehiclePlate($file, [
'multi_crop' => false, //當設成true時,會作多crop預測,只有當多crop返回的結果一致,而且置信度>0.9時,才返回結果
]);複製代碼
$app->aliyun->general($file, [
'min_size' => 16, //圖片中文字的最小高度,
'output_prob' => false, //是否輸出文字框的機率,
]);複製代碼
use Godruoyi\OCR\Application;
$app = new Application([
'ocrs' => [
'tencent' => [
'app_id' => '1254032478',
'secret_id' => 'AKIDzODdB1nOELz0T8CEjTEkgKJOob3t2Tso',
'secret_key' => '6aHHkz236LOYu0nRuBwn5PwT0x3km7EL',
'bucket' => 'test1'
],
]
]);複製代碼
Tencent OCR 暫不支持在線圖片地址
$app->tencent->namecard($file, [
'ret_image' => 0, //0 不返回圖片,1 返回圖片,
]);複製代碼
$app->tencent->idcard($file, [
'card_type' => 0, //0 爲身份證有照片的一面,1爲身份證有國徽的一面
]);複製代碼
$app->tencent->drivingLicence($file, [
'type' => 0, //識別類型,0表示行駛證,1表示駕駛證,
]);複製代碼
$app->tencent->general($file, [
]);複製代碼