PHP code example of surpaimb / baidu-aip

1. Go to this page and download the library: Download surpaimb/baidu-aip 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/ */

    

surpaimb / baidu-aip example snippets




namespace App\Http\Controllers;

use Baidu\Aip\AipOcr;

class ExampleController extends Controller
{

    public $client;
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
        $this->client = new AipOcr(APP_ID, APP_KEY, SECRET_KEY);
    }

    //
    
    public function ocr($filename)
    {
        $image = file_get_contents($filename);
        $templateSign = null;
        $param = ['classifierId' => '1'];

        // 调用自定义模板文字识别
        return $this->client->custom($image, $templateSign ,$param);
    }
}