baiduOCRRecognizer
概述baiduOCRRecognizer模块封装了百度AI文字识别功能,使用此模块可实现百度通用文字识别、通用文字识别(高精度版)、通用文字识别(含位置信息版)、通用文字识别(高精度含位置版)、通用文字识别(含生僻字版)、网络图片文字识别、身份证识别、银行卡识别、驾驶证识别、行驶证识别、车牌识别、营业执照识别、通用票据识别。。详情请参考网站帮助。 注意:本模块 iOS 平台上最低适配系统版本为 iOS 8.0 本模块使用无需 配置config 文件,需要初始化时传入 appKey,appSecret,这两个参数需要去百度的开放平台创建应用获取 运行截图 主要代码 - <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
- <title>title</title>
- <link rel="stylesheet" type="text/css" href="../css/api.css"/>
- <style>
- body{
- }
- .btn{
- width: 100%;
- height: 300px;
- position: absolute;
- bottom: 0;
- text-align: center;
- }
- button{
- height: 50px;
- padding: 0 10px;
- background-color: green;
- color: #fff;
- margin-top: 10px;
- margin-left: 10px;
- border-radius: 5px;
- }
- </style>
- </head>
- <body>
- <div class="btn">
- <button type="button" name="button" onclick="initOCR()">初始化</button>
- <button type="button" name="button" onclick="getPath()">拍照</button>
- <button type="button" name="button" onclick="recognizeAccurateOCR()">文字识别</button>
- <button type="button" name="button" onclick="recognizeWebimageOCR()">识别图片</button>
- <button type="button" name="button" onclick="recognizeIDCardOCR()">身份证正识别</button>
- <button type="button" name="button" onclick="recognizeBankCardOCR()">银行卡正识别</button>
- <button type="button" name="button" onclick="recognizeLicensePlateOCR()">车牌识别</button>
- </div>
- </body>
- <script type="text/javascript" src="../script/api.js"></script>
- <script type="text/javascript">
- var OCR = '';
- var ocrPath = '';
- apiready = function(){
- OCR = api.require('baiduOCRRecognizer');
- };
- //获取图片 -- 拍照
- function getPath() {
- api.getPicture({
- sourceType: 'camera',
- encodingType: 'jpg',
- mediaValue: 'pic',
- destinationType: 'url',
- allowEdit: true,
- quality: 50,
- targetWidth: 100,
- targetHeight: 100,
- saveToPhotoAlbum: false
- }, function(ret, err){
- if(ret){
- alert(JSON.stringify(ret.data));
- ocrPath = ret.data
- }else{
- alert(JSON.stringify(err));
- }
- });
- }
- //初始化
- function initOCR() {
- OCR.init({
- appKey :'Cfsf1#########6Gae',
- appSecret : 'G##########97R1D8'
- },
- function(ret){
- api.alert({ msg:JSON.stringify(ret)});
- });
- }
- //通用文字识别高精度
- function recognizeAccurateBasicOCR() {
- OCR.recognizeAccurateBasic({
- // path:'widget://image/text.png',
- path: ocrPath,
- DetectDirection:false,
- },function(ret,err){
- api.alert({ msg:JSON.stringify(ret)});
- });
- }
- //图片识别
- function recognizeWebimageOCR() {
- OCR.recognizeWebimage({
- path: ocrPath,
- DetectDirection:true,
- },function(ret,err) {
- api.alert({ msg:JSON.stringify(ret)});
- api.alert({ msg:JSON.stringify(err)});
- }
- );
- }
- //身份证识别
- function recognizeIDCardOCR() {
- OCR.recognizeIDCard({
- path: 'widget://image/idcard.png',
- DetectDirection : true,
- isFront: false ,
- //accuracy: 'high'
- },function(ret,err) {
- if (ret) {
- api.alert({ msg:JSON.stringify(ret)});
- }else {
- api.alert({ msg:JSON.stringify(err)});
- }
- }
- );
- }
- //银行卡识别
- function recognizeBankCardOCR() {
- OCR.recognizeBankCard({
- path: 'widget://image/bankcard.png',
- },function(ret,err) {
- api.alert({ msg:JSON.stringify(ret)});
- api.alert({ msg:JSON.stringify(err)});
- }
- );
- }
- //车牌识别
- function recognizeLicensePlateOCR() {
- var demo =api.require('baiduOCRRecognizer');
- demo.recognizeLicensePlate({
- path: ocrPath,
- },function(ret,err) {
- api.alert({ msg:JSON.stringify(ret)});
- api.alert({ msg:JSON.stringify(err)});
- }
- );
- }
- </script>
- </html>
复制代码可以用getpicture 接口获取fs 地址图片路径 也可以使用widget 路径 如有bug,欢迎指出
|