PHP code example of efarsoft / baidu-aip

1. Go to this page and download the library: Download efarsoft/baidu-aip library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

efarsoft / baidu-aip example snippets


  composer 

  use BaiduAip\AipOcr;

    $client = new AipOcr($appId, $appKey, $appSecret);
    $image = file_get_contents( './test.jpg'); 
    $result = $client->businessLicense($image);
    var_dump( $result);


  //demo 文字识别
  use BaiduAip\AipOcr;
  $client = new AipOcr($appId, $appKey, $appSecret);
  $image = file_get_contents('example.jpg');
  
  // 调用通用文字识别, 图片参数为本地图片
  $client->basicGeneral($image);

  // 如果有可选参数
  $options = array();
  $options["language_type"] = "CHN_ENG";
  $options["detect_direction"] = "true";
  $options["detect_language"] = "true";
  $options["probability"] = "true";

  // 带参数调用通用文字识别, 图片参数为本地图片
  $client->basicGeneral($image, $options);
  $url = "https//www.x.com/sample.jpg";

  // 调用通用文字识别, 图片参数为远程url图片
  $client->basicGeneralUrl($url);

  // 如果有可选参数
  $options = array();
  $options["language_type"] = "CHN_ENG";
  $options["detect_direction"] = "true";
  $options["detect_language"] = "true";
  $options["probability"] = "true";

  // 带参数调用通用文字识别, 图片参数为远程url图片
  $client->basicGeneralUrl($url, $options);