接口地址
https://cloud.baidu.com/doc/OCR/s/Bk3h7ydue
<?php
require_once 'baiduocr/AipOcr.php';
const APP_ID = 'xxxxxx';
const API_KEY = 'xxxxxx';
const SECRET_KEY = 'xxxxxx';
$client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
// 调用通用文字识别, 图片参数为本地图片
$image = file_get_contents('images/yuandan.jpg');
// 如果有可选参数
$options = [];
$options["language_type"] = "CHN_ENG";
$options["detect_direction"] = "true";
$options["detect_language"] = "true";
$options["probability"] = "true";
$imgRes = $client->basicGeneral($image, $options);
echo '<pre>';
var_dump($imgRes);
$imageHigh = file_get_contents('images/wuhan.jpg');
// 如果有可选参数
$optionsHigh = [];
$optionsHigh["detect_direction"] = "true";
$optionsHigh["probability"] = "true";
$imgHighRes = $client->basicGeneral($imageHigh, $optionsHigh);
echo '<pre>';
var_dump($imgHighRes);
$imageHigh2 = file_get_contents('images/image1.jpg');
// 如果有可选参数
$optionsHigh2 = [];
$optionsHigh2["language_type"] = "CHN_ENG";
$optionsHigh2["detect_direction"] = "true";
$optionsHigh2["detect_language"] = "true";
$optionsHigh2["probability"] = "true";
$imgHigh2Res = $client->basicGeneral($imageHigh2, $optionsHigh2);
echo '<pre>';
var_dump($imgHigh2Res);
$chepai = file_get_contents('images/chepai.jpg');
$chepaiRes = $client->licensePlate($chepai);
echo '<pre>';
var_dump($chepaiRes);
?>
对于图片中文字识别还是有很多字体不能识别,一些常用字体能识别,如黑体、宋体等,一些特殊字体。如下面3张图:
第一张能识别,第二张和第三张都不能很好的识别。