脚本使用的是百度的OCR服务,卡片识别接口,传送门:https://cloud.baidu.com/product/ocr/idcard

SDK下载地址 https://ai.baidu.com/sdk#sdk-category-ocr

运行方式:php idcard.php

<?php
include_once './db.class.php';
include_once '../AipOcr.php';
$dbConf = array(
        'host'=>'localhost',
        'port'=>'3306',
        'user'=>'root',
        'passwd'=>'root',
        'dbname'=>'test'
    );
const APP_ID = '';
const API_KEY = '';
const SECRET_KEY = '';
$aipOcr = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
$mysql = new MMysql($dbConf);
$dir="../img/";
$file=scandir($dir);
foreach ($file as $key => $value) {
    if(!in_array($key, array(0,1))){
        $result = array();
        $result = $aipOcr->idcard(file_get_contents('../img/'.$value),true);
        if ($result['image_status'] == 'normal') {
            $data = array();
            $data = array(
                'id'=>$result['log_id'],
                'addr'=>$result['words_result']['住址']['words'],
                'name'=>$result['words_result']['姓名']['words'],
                'idcard'=>$result['words_result']['公民身份号码']['words'],
                );
            $result = $mysql->insert('t_table',$data);
            if($result > 0){
                echo $value." ----- ok \n";
            }
        }else{
            echo $value." ----- error \n";
        }
        // die;
    }
}

视频