zoukankan      html  css  js  c++  java
  • 腾讯优图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/>");
    }
  • 相关阅读:
    Pagodas
    Bazinga
    取石子问题
    Sudoku Killer(hdu 1426 数独)
    欧拉函数
    CCPC Ancient Go
    ZZNU 1992: 情人节的尴尬
    fzu Problem 2128 最长子串(KMP + strstr 经典好题)
    POJ
    HDU
  • 原文地址:https://www.cnblogs.com/Bhi9712/p/9741841.html
Copyright © 2011-2022 走看看