//图片识别 $image is path or base64
function ocr($appcode,$image){
$host = "https://tysbgpu.market.alicloudapi.com";
$path = "/api/predict/ocr_general";
$method = "POST";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
//根据API的要求,定义相对应的Content-Type
array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
$querys = "";
$data=array();
$data['image']=$image;
$data['configure']=array();
$data['configure']['min_size']=12;
$data['configure']['output_prob']=true;
$data['configure']['output_keypoints']=false;
$data['configure']['skip_detection']=false;
$data['configure']['without_predicting_direction']=false;
$bodys =json_encode($data);
//$bodys = "{\"image\":\"图片二进制数据的base64编码/图片url\",\"configure\":{\"min_size\":16,#图片中文字的最小高度,单位像素\"output_prob\":true,#是否输出文字框的概率\"output_keypoints\":false,#是否输出文字框角点\"skip_detection\":false#是否跳过文字检测步骤直接进行文字识别\"without_predicting_direction\":false#是否关闭文字行方向预测}}";
$url = $host . $path;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTomrEQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
$r=(curl_exec($curl));
$r=explode('{"request_id"',$r);
if(!isset($r[1])){return false;}
$r='{"request_id"'.$r[1];
$r=json_decode($r,1);
if(!$r['success'] || !isset($r['ret'])){return false;}
$line=array();
foreach($r['ret'] as $v){
$line[]=$v['word'];
}
if(!isset($line[0])){return false;}
return $line;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。