The Best Image OCR SDK For BAT.

The Best Image OCR SDK For BAT.

項目地址 https://github.com/godruoyi/ocrphp

今天是星期二,是發佈輪子的好日子。@overtruelaravel

Feature

  • 自定義緩存支持;
  • 符合 PSR 標準,能夠很方便的與你的框架結合;
  • 命名不那麼亂七八糟;
  • 支持目前市面多家服務商

Support

Requirement

Installation

composer require godruoyi/ocr複製代碼

Laravel 5 拓展包git

Usage

基本使用(以百度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 的值能夠爲緩存

  1. 文件路徑(完整)
  2. SplFileInfo 對象
  3. Resource
  4. 在線圖片地址(部分服務商不支持)
  5. Arraybash

    注:options 的值都是可選的網絡

百度OCR

目前採用 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,      //是否檢測圖像朝向
]);複製代碼

Aliyun OCR

目前採用 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,    //是否輸出文字框的機率,
]);複製代碼

Tencent OCR

可登陸 雲API密鑰控制檯查看你的我的 API 密鑰

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, [
]);複製代碼
相關文章
相關標籤/搜索