找了半天没找到一个合适的图片识别文字api,好不容易找到PaddlePaddle可是没有php语言实例,下面是项目说明跟我写的php实例.
项目说明
PaddleOCR是百度PaddlePaddle推出的开源OCR项目。旨在打造一套丰富、领先、且实用的OCR工具库,助力开发者训练出更好的模型,并应用落地。
repo: /PaddlePaddle/PaddleOCR
所有版权属于原repo作者,本项目仅为学习目的示例。
项目原文介绍地址:PaddlePaddle文字识别OCR | DEMO/API/pretrained_Thor9king的博客-CSDN博客_paddlepaddle文字识别
1.、获取API验证码。项目原介绍有说怎么获取
2、API调用
php请求代码
header("Content-type: text/html; charset=utf-8");function curl($img) {$ch = curl_init();$url = ':7001/api_req'; //ocr api$header = array("Content-Type:multipart/form-data;charset=UTF-8",);//封装必要参数$data = array('password' =>'去公众号获取秘钥','reqmode' =>'ocr_pp','image_ocr_pp' => new \CURLFile(realpath($img)));curl_setopt($ch, CURLOPT_HTTPHEADER , $header); // curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // 添加参数curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch , CURLOPT_URL , $url); // 执行HTTP请求$res = curl_exec($ch);if ($res === FALSE) {echo "cURL Error: " . curl_error($ch);}curl_close($ch);$temp_var = json_decode($res,true);return $temp_var;}// 图片地址$wordArr = curl('C:/phpstudy_pro/WWW/33f/1b48705575583be4fc83e2af9079766e.jpeg');if($wordArr['code'] == 0) {var_dump($wordArr);} else {echo "识别出错:".$wordArr;}
3,回应示例:
{"code": 0,"data": ["csdn","csdn"]}
data键值对应的是识别的文字,一行对应数组中的一项。