PHP code example of kylin987 / baidu-ocr
1. Go to this page and download the library: Download kylin987/baidu-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/ */
kylin987 / baidu-ocr example snippets
//本地图片识别
$client = new baidu\ocr\AipOcr(APP_ID, API_KEY, SECRET_KEY);
$image = file_get_contents(__DIR__ . '/test.png'); // 图片地址 (远程地址https可用这个)
$result = $client->basicGeneral($image);
$config = [
'app_id' => 'app_id',
'api_key' => 'api_key',
'secret_key'=> 'secret_key'
];
$client = new \baidu\ocr\Ocr($config);
$image = file_get_contents($imgUrl);
$client->setSimpleResult(true); //输出简易信息
$client->setImage($image);
$result = $client->idcard('front');