PHP: OCR Text Recognition Based on Baidu brain api,
There is a project that uses text recognition. I found a lot of information on the Internet, and the results were not very good. By chance, I came into contact with Baidu brain. Baidu brain provides many solutions, one of which is text recognition. Baidu provides three types of Text Recognition: bank card recognition, ID card recognition, and general text recognition. Let's test them.
Step 1: Download the PHP text recognition demo
: Https://git.oschina.net/jianqingwang/ocr
Step 2: apply for an api
Go to Baidu brain https://ai.baidu.com/tech/ocr/generalapplication API
Sa
Baidu brain application api
After the application is completed, create an application and obtain two pieces of information: AppID, API Key, and Secret Key.
Open DemoAipOcr. php In demo. Let's configure the interface information together!
<? Php // introduce the OCR SDKrequire_once '.. /AipOcr. php '; // define the constant const APP_ID = 'Write your id'; const API_KEY = 'Write your key'; const SECRET_KEY = 'Write your secret_key '; // initialize $ aipOcr = new AipOcr (APP_ID, API_KEY, SECRET_KEY); // ID card recognition // var_dump ($ aipOcr-> idcard(file_get_contents('idcard.jpg '), true )); // bank card recognition // var_dump ($ aipOcr-> bankcard(file_get_contents('bankcard.jpg '); // general text recognition $ rescult = $ aipOcr-> comment ')); $ words = $ rescult ['words _ result']; var_dump ($ words [0]); // var_dump ($ aipOcr-> general(file_get_contents('20170413195205.jpg ')));
The preceding three identification systems are shown. You only need to test the comments on the methods for canceling bank card recognition and ID card recognition.
Source image:
Universal text recognition test image
Let's take a look at the recognition effects of my images 20170413195205.jpg:
Array (12) {[0] => array (2) {["location"] => array (4) {["left"] => int (34) ["top"] => int (13) ["width"] => int (96) ["height"] => int (20 )} ["words"] => string (15) "Adi mail"} [1] => array (2) {["location"] => array (4) {["left"] => int (770) ["top"] => int (14) ["width"] => int (35) ["height"] => int (19)} ["words"] => string (6) "Homepage"} [2] => array (2) {["location"] => array (4) {["left"] => int (848) ["top"] => int (15) ["Width"] => int (42) ["height"] => int (18)} ["words"] => string (9) "Send mail"} [3] => array (2) {["location"] => array (4) {["left"] => int (928) ["top"] => int (14) ["width"] => int (250) ["height"] => int (19 )} ["words"] => string (33) "Contact Us To register for Logon"} [4] => array (2) {["location"] => array (4) {["left"] => int (456) ["top"] => int (118) ["width"] => int (289) ["height"] => int (27)} ["words"] => string (40) "We provide the most comprehensive email marketing materials Source !"} [5] => array (2) {["location"] => array (4) {["left"] => int (487) ["top"] => int (176) ["width"] => int (228) ["height"] => int (26 )} ["words"] => string (31) "start to use Adi email marketing!"} [6] => array (2) {["location"] => array (4) {["left"] => int (32) ["top"] => int (331) ["width"] => int (129) ["height"] => int (33 )} ["words"] => string (12) "Full Channel"} [7] => array (2) {["location"] => array (4) {["left"] => int (423) ["top"] => int (331) ["width"] => int (157) ["height"] => int (34)} ["words"] => string (15) "Unlimited content"} [8] => array (2) {["location"] => array (4) {["left"] => int (811) ["top"] => int (329) ["Width"] => int (127) ["height"] => int (39)} ["words"] => string (12) "offline sending"} [9] => array (2) {["location"] => array (4) {["left"] => int (31) ["top"] => int (374) ["width"] => int (1140) ["height"] => int (21 )} ["words"] => string (214) "aggregates excellent email service providers at home and abroad to provide users with the most comprehensive mail sending proxy. If the customer chooses the China baby service provider, we will not review the content, because the system executes the directmail Service 24 hours a day, you don't have to wait, as long as you submit the mail "} [10] => array (2) {[" location "] => array (4) {["left"] => int (30) ["top"] => int (391) ["width"] => Int (1076) ["height"] => int (26)} ["words"] => string (195) "service. As long as we use it, we can use Railgun and Sendmall for all mail service channels outside China. Compared with other service providers, we insist on the content, and our system will automatically push it to the recipient !"} [11] => array (2) {["location"] => array (4) {["left"] => int (33) ["top"] => int (410) ["width"] => int (721) ["height"] => int (23 )} ["words"] => string (143) "Simple Mail and other mass mailing services at home and abroad, which can be seamlessly sent to users in the world who are good buyers, no. participate in or interfere with the user's sending content." }}
Now, register an account and test the Baidu ocr function!
My blog address: PHP: OCR Text Recognition Based on Baidu brain api