根据文档操作PHP SDK,无法返回文字识别数据
锋主宰 发布于2020-12 浏览:1430 回复:7
0
收藏

根据

https://cloud.baidu.com/doc/OCR/s/bkibizxba 

操作,设置了sdk,打开php网页,无任何返回数据。

Request Method:
GET

Status Code:
200 OK

收藏
点赞
0
个赞
共7条回复 最后由用户已被禁言回复于2022-04
#8用户已被禁言回复于2020-12
#5 锋主宰回复
// 带参数调用网络图片文字识别, 图片参数为远程url图片 $res = $client->webImageUrl($url, $options); print($res) 返回:Array 能否你们测试下发个示例  
展开

1
#7用户已被禁言回复于2020-12
#5 锋主宰回复
// 带参数调用网络图片文字识别, 图片参数为远程url图片 $res = $client->webImageUrl($url, $options); print($res) 返回:Array 能否你们测试下发个示例  
展开

经过我使用官方示例。貌似也OK。只是打印方式和你的不一样。我是百度hello world PHP代码。得到打印是echo  再百度了一下

PHP 转JSON。就输出了。但是输出是unicode编码。

webImageUrl($url, $options);
//我这样貌似可以输出。但是PHP还是显示是unicode。不会PHP。不知道还能怎么改
echo json_encode($res);

接口返回内容。是打开网页显示的

{"log_id":4483430086018871452,"direction":0,"words_result_num":2,"words_result":[{"words":"\u4e0e\u4f60\u62c7\u9047"},{"words":"\u597d\u5e78\u8fd0"}],"language":-1}
1
#6用户已被禁言回复于2020-12
#5 锋主宰回复
// 带参数调用网络图片文字识别, 图片参数为远程url图片 $res = $client->webImageUrl($url, $options); print($res) 返回:Array 能否你们测试下发个示例  
展开

JAVASDK示例代码

    public static void main(String[] args) {
        AipOcr client = new AipOcr("APPID", "APIKEY", "APPSECRET");
        String url = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg3.duitang.com%2Fuploads%2Fitem%2F201604%2F04%2F20160404125401_aCUWA.jpeg&refer=http%3A%2F%2Fimg3.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1611726347&t=0f88a2379e6a2e6184f3066d9212445b";
        JSONObject object = client.webImageUrl(url, null);
        System.out.println(object.toString(2));
}

接口返回内容

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/maven/maven-repository/org/slf4j/slf4j-simple/1.7.25/slf4j-simple-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/maven/maven-repository/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[main] INFO com.baidu.aip.client.BaseClient - get access_token success. current state: STATE_AIP_AUTH_OK
{
  "log_id": 6421445829693934364,
  "words_result": [
    {"words": "与你拇遇"},
    {"words": "好幸运"}
  ],
  "words_result_num": 2
}
1
#5锋主宰回复于2020-12

// 带参数调用网络图片文字识别, 图片参数为远程url图片
$res = $client->webImageUrl($url, $options);
print($res)

返回:Array

能否你们测试下发个示例

 

0
#4用户已被禁言回复于2020-12
#3 锋主宰回复
通用文字识别 识别图片中的文字信息接口。   [图片]      

PHP有类似System.out.print();或Print()的方法吗?

是不是得输出一下呢?

不管接口成功还是失败都会返回JSON格式字符串的。

 

1
#3锋主宰回复于2020-12

通用文字识别
识别图片中的文字信息接口。

 

 

 

 

0
#2用户已被禁言回复于2020-12

具体请求哪个接口。代码最好也贴一下

1
TOP
切换版块