PHP + Baidu AI OCR character recognition realizes the character recognition function of pictures

Time:2019-12-2

The first step is to get three things of Baidu. You need to register on Baidu AI website (http://ai.baidu.com/) and then get

-Const app_id = 'please fill in your app ID';
-Const api_key = 'please fill in your api_key';
-Const secret_key = 'please fill in your secret_key';

Step 2 download SDK

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

Or use the official http://ai.baidu.com/sdk to download

Step 3 then run the demo file, demoaipcocr.php

All the pictures in it are OK

I tried it myself here

The data returned is

After JSON transfer

{
  "log_id": 3394339616,
  "words_result_num": 3,
  "classify_result": {
    "lottery": "unknown"
  },
  "words_result": [
    {
      "Words": "friendship"
    },
    {
      "Words": "choose friends with the same values,"
    },
    {
      "Words": "whether rich or poor. "
    }
  ]
}

I think it’s good

If the error is reported:Fatal error: Call to undefined function getimagesizefromstring() 

Because the program will call the getimagesizefromstring function – get the size of an image from a string to convert the image into characters, the PHP version is required (PHP 5 > = 5.4.0, PHP 7)

The above is the whole content of this article. I hope it will help you in your study, and I hope you can support developepaer more.