PHP code example of skytian / ocr

1. Go to this page and download the library: Download skytian/ocr library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

skytian / ocr example snippets


use Godruoyi\OCR\Application;

$app = new Application([
    'ocrs' => [
        'baidu' => [
            'app_key' => 'app_key',
            'secret_key' => 'secret_key'
        ],
    ]
]);

//身份证识别
$result = $app->baidu->idcard($filePath);


$app->platform->$method($files, $options = [])

$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,      //是否检测图像朝向
]);

use Godruoyi\OCR\Application;

$app = new Application([
    'ocrs' => [
        'aliyun' => [
            'appcode' => '40bc103c7fe6417b87152f6f68bead2f',
        ]
    ]
]);

$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'
        ],
    ]
]);

$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, []);       //无可选参数

$app->tencent->bankcard($file, []);      //无可选参数

$app->tencent->plate($file, []);         //无可选参数

$app->tencent->bizlicense($file, []);    //无可选参数

use Godruoyi\OCR\Application;

$app = new Application([
    'ocrs' => [
        'tencentai' => [
          'app_id' => '1106584682',
          'app_key' => 'XGgkqVif73v8wH6W',
        ],
    ]
]);

$app->tencentai->idcard($file, [
    'card_type'             => 0,          //0 为身份证有照片的一面,1为身份证有国徽的一面 默认0
]);

$app->tencentai->namecard($file, []);

$app->tencentai->driverlicen($file, [
    'type'                  => 0,          //识别类型,0表示行驶证,1表示驾驶证,默认0
]);

$app->tencentai->bankcard($file, []);      //无可选参数

$app->tencentai->general($file, []);       //无可选参数

$app->tencentai->bizlicense($file, []);    //无可选参数