腾讯云:
搜索:OCR 或者 名片识别
依赖环境
- PHP 5.6.33 版本及以上。
- 获取安全凭证。安全凭证包含 SecretId 及 SecretKey 两部分。SecretId 用于标识 API 调用者的身份,SecretKey 用于加密签名字符串和服务器端验证签名字符串的密钥。
在项目下执行:
//最好使用 Git 打开
composer require tencentcloud/tencentcloud-sdk-php
建议使用新版的:OCR-名片识别(V2)新版名片识别
public function getOCR(){
$img = input("imageSrc");
if($img){
try {
$cred = new Credential("SecretId", "SecretKey");
$httpProfile = new HttpProfile();
$httpProfile->setEndpoint("ocr.tencentcloudapi.com");
$clientProfile = new ClientProfile();
$clientProfile->setHttpProfile($httpProfile);
$client = new OcrClient($cred, "ap-guangzhou", $clientProfile);
$req = new BusinessCardOCRRequest();
$params = array(
"ImageBase64" => $img
//"ImageUrl" => "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=967415216,1615300876&fm=26&gp=0.jpg"
);
$req->fromJsonString(json_encode($params));
$resp = $client->BusinessCardOCR($req);
//print_r($resp->toJsonString());
return json($resp);
}
catch(TencentCloudSDKException $e) {
return $e;
}
}
}