public static function ocr($url, $path) { //屏蔽错误 error_reporting(E_ALL || ~E_NOTICE); $var = array('language' => 'eng', 'service' => 'OcrKingForCaptcha', 'charset' => '7', 'gbk' => false, 'type' => $url); //实例化OcrKing识别 $ocrking = new \OcrKing(config('api')); //上传图片识别 请在doOcrKing方法前调用 $ocrking->setFilPath($path); //提交识别 $ocrking->doOcrKing($var); //获取识别结果 $result = $ocrking->getResult(); return $result['ResultList']['Item']['Result']; }
echo '<br /><br />原始图片: <br /><br /><img src="' . $result['ResultList']['Item']['SrcFile'] . '">'; echo '<br /><br />处理后的图片是: <br /><br /><img src="' . $result['ResultList']['Item']['DesFile'] . '">'; echo '<br /><br />识别的结果是:' . $result['ResultList']['Item']['Result']; } //以下为识别本地验证码图片过程 //如验证码图片的原始地址 https://www.bestpay.com.cn/api/captcha/getCode?1408294248050 //识别参数请根据上面的进行修改 $var = array('language' => 'eng', 'service' => 'OcrKingForCaptcha', 'charset' => 7, 'gbk' => true, 'type' => 'https://www.bestpay.com.cn/api/captcha/getCode?1408294248050'); //保存验证码图片到本地,同时保存对应的cookie $down = getRemoteFile('https://www.bestpay.com.cn/api/captcha/getCode?1408294248050', '.png'); //实例化OcrKing识别 $ocrking = new OcrKing(API_KEY); //上传图片识别 请在doOcrKing方法前调用 $ocrking->setFilePath($down['imagepath']); //提交识别 $ocrking->doOcrKing($var); //检查识别状态 if (!$ocrking->getStatus()) { die($ocrking->getError()); } //获取识别结果 $result = $ocrking->getResult(); //原始结果 xml格式,一般用于出错时调试 //echo $ocrking->getRawResult(); //打印识别结果数组 //print_r($result); //仅显示需要的内容 //echo $result['ResultList']['Item']['Result']; //echo $result['ResultList']['Item']['Status']; //echo $result['ResultList']['Item']['DesFile']; echo '<br /><br /><br /><br />本地图片识别开始:<br /><br />';