騰訊優圖OCR----識別圖片文字


首先需要到騰訊開發平台創建一個應用,獲取到appid 與 appkey擁有了appid與appkey就可以開始編寫源碼

源碼:

include('SDK/API.php');
include('SDK/Configer.php');
include('SDK/HttpUtil.php');
include('SDK/Signature.php');

$path = 'data/order05.png'; // 圖片地址
$data = file_get_contents($path); // 獲取到文件
$base64 = base64_encode($data); // 使用base64對$data進行編碼

$appid = 'XXX'; // appid
$appkey = 'XXX'; // appkey

Configer::setAppInfo($appid, $appkey);

$params = array(
'app_id' => $appid,
'image' => $base64,
'time_stamp' => strval(time()),
'nonce_str' => strval(rand()),
'sign' => '',
);
$params['sign'] = Signature::getReqSign($params, $appkey);

$url = 'https://api.ai.qq.com/fcgi-bin/ocr/ocr_generalocr';
$response = HttpUtil::doHttpPost($url, $params); // 發送請求接收返回值
$newArray = json_decode($response, true); // 轉換成php數組

// 返回格式
for($i=0;$i<count($newArray['data']['item_list']);$i++) {
print_r($newArray['data']['item_list'][$i]['itemstring']."<br/>");
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM