用百度AI的OCR文字识别结合PHP实现了图片的文字识别功能

第一步可定要获取百度的三个东西 要到百度AI网站(http://ai.baidu.com/)去注册 然后获得 

 

 -const APP_ID = '请填写你的appid';

  -const API_KEY = '请填写你的API_KEY';

  -const SECRET_KEY = '请填写你的SECRET_KEY';

 

第二步下载SDK  

https://github.com/jankinsun/New/tree/master/OCR/character_recognition

或者使用官方的 http://ai.baidu.com/sdk 下载

 

第三步 然后就直接运行demo 的文件 DemoAipOcr.PHP

 

里面的图片都可以 

我这里自己试了一下

 

返回的数据是

 

转json后

 

 

 

[html] view plain copy
 
  1.   

{
    "log_id": 3394339616,
    "words_result_num": 3,
    "classify_result": {
        "lottery": "unknown"
    },
    "words_result": [
        {
            "words": "友谊"
        },
        {
            "words": "以相同的价值观选择朋友,"
        },
        {
            "words": "无论对方富有或贫穷。"
        }
    ]
}

 

 

感觉还是不错的

 

 

 

如果报错了  :  Fatal error: Call to undefined function getimagesizefromstring() 

 

因为程序运行的过程中会调用getimagesizefromstring 函数 — Get the size of an image from a string 把图像转化成字符 所以要求php版本(PHP 5 >= 5.4.0, PHP 7)

 

posted @ 2017-07-29 17:03  阿拉善的樵夫  阅读(3187)  评论(2编辑  收藏  举报