请选择 进入手机版 | 继续访问电脑版
帖子
帖子
用户
博客
课程
123下一页
返回列表 发新帖
显示全部楼层
20
帖子
0
勋章
6613
Y币

baiduOCRRecognizer 模块分享

[复制链接]
发表于 2019-11-6 09:50:29
baiduOCRRecognizer

概述
baiduOCRRecognizer模块封装了百度AI文字识别功能,使用此模块可实现百度通用文字识别、通用文字识别(高精度版)、通用文字识别(含位置信息版)、通用文字识别(高精度含位置版)、通用文字识别(含生僻字版)、网络图片文字识别、身份证识别、银行卡识别、驾驶证识别、行驶证识别、车牌识别、营业执照识别、通用票据识别。。详情请参考网站帮助
注意:本模块 iOS 平台上最低适配系统版本为 iOS 8.0
本模块使用无需 配置config 文件,需要初始化时传入 appKey,appSecret,这两个参数需要去百度的开放平台创建应用获取
运行截图
主要代码
  1. <!DOCTYPE html>
  2.   <html>
  3.   <head>
  4.       <meta charset="utf-8">
  5.       <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
  6.       <title>title</title>
  7.       <link rel="stylesheet" type="text/css" href="../css/api.css"/>
  8.       <style>
  9.           body{

  10.           }
  11.           .btn{
  12.             width: 100%;
  13.             height: 300px;
  14.             position: absolute;
  15.             bottom: 0;
  16.             text-align: center;
  17.           }
  18.           button{
  19.             height: 50px;
  20.             padding: 0 10px;
  21.             background-color: green;
  22.             color: #fff;
  23.             margin-top: 10px;
  24.             margin-left: 10px;
  25.             border-radius: 5px;
  26.           }
  27.       </style>
  28.   </head>
  29.   <body>

  30.   <div class="btn">
  31.     <button type="button" name="button" onclick="initOCR()">初始化</button>
  32.     <button type="button" name="button" onclick="getPath()">拍照</button>
  33.     <button type="button" name="button" onclick="recognizeAccurateOCR()">文字识别</button>
  34.     <button type="button" name="button" onclick="recognizeWebimageOCR()">识别图片</button>
  35.     <button type="button" name="button" onclick="recognizeIDCardOCR()">身份证正识别</button>
  36.     <button type="button" name="button" onclick="recognizeBankCardOCR()">银行卡正识别</button>
  37.     <button type="button" name="button" onclick="recognizeLicensePlateOCR()">车牌识别</button>

  38.   </div>
  39.   </body>
  40.   <script type="text/javascript" src="../script/api.js"></script>
  41.   <script type="text/javascript">
  42.       var OCR = '';
  43.       var ocrPath = '';
  44.       apiready = function(){
  45.           OCR = api.require('baiduOCRRecognizer');
  46.       };
  47.       //获取图片 -- 拍照
  48.       function getPath() {
  49.         api.getPicture({
  50.             sourceType: 'camera',
  51.             encodingType: 'jpg',
  52.             mediaValue: 'pic',
  53.             destinationType: 'url',
  54.             allowEdit: true,
  55.             quality: 50,
  56.             targetWidth: 100,
  57.             targetHeight: 100,
  58.             saveToPhotoAlbum: false
  59.         }, function(ret, err){
  60.             if(ret){
  61.                  alert(JSON.stringify(ret.data));
  62.                  ocrPath = ret.data
  63.             }else{
  64.                  alert(JSON.stringify(err));
  65.             }
  66.         });

  67.       }
  68.       //初始化
  69.       function initOCR() {
  70.          OCR.init({
  71.            appKey :'Cfsf1#########6Gae',
  72.            appSecret : 'G##########97R1D8'
  73.          },
  74.            function(ret){
  75.              api.alert({ msg:JSON.stringify(ret)});
  76.          });
  77.       }
  78.       //通用文字识别高精度
  79.       function recognizeAccurateBasicOCR() {
  80.         OCR.recognizeAccurateBasic({
  81.            // path:'widget://image/text.png',
  82.             path: ocrPath,
  83.             DetectDirection:false,
  84.             },function(ret,err){
  85.                api.alert({ msg:JSON.stringify(ret)});
  86.         });
  87.       }

  88.       //图片识别
  89.       function recognizeWebimageOCR() {
  90.          OCR.recognizeWebimage({
  91.          path: ocrPath,
  92.          DetectDirection:true,
  93.         },function(ret,err) {
  94.            api.alert({ msg:JSON.stringify(ret)});
  95.            api.alert({ msg:JSON.stringify(err)});
  96.                 }
  97.        );
  98.       }
  99.       //身份证识别
  100.       function recognizeIDCardOCR() {
  101.          OCR.recognizeIDCard({
  102.          path: 'widget://image/idcard.png',
  103.          DetectDirection : true,
  104.          isFront: false ,
  105.          //accuracy: 'high'
  106.         },function(ret,err) {
  107.           if (ret) {
  108.             api.alert({ msg:JSON.stringify(ret)});

  109.           }else {
  110.             api.alert({ msg:JSON.stringify(err)});

  111.           }
  112.         }
  113.        );
  114.       }
  115.       //银行卡识别
  116.       function recognizeBankCardOCR() {
  117.          OCR.recognizeBankCard({
  118.          path: 'widget://image/bankcard.png',
  119.         },function(ret,err) {
  120.            api.alert({ msg:JSON.stringify(ret)});
  121.            api.alert({ msg:JSON.stringify(err)});
  122.                 }
  123.        );
  124.       }
  125.       //车牌识别
  126.       function recognizeLicensePlateOCR() {
  127.         var demo =api.require('baiduOCRRecognizer');
  128.          demo.recognizeLicensePlate({
  129.          path: ocrPath,
  130.         },function(ret,err) {
  131.            api.alert({ msg:JSON.stringify(ret)});
  132.            api.alert({ msg:JSON.stringify(err)});
  133.                 }
  134.        );
  135.       }
  136.   </script>
  137.   </html>
复制代码
可以用getpicture 接口获取fs 地址图片路径  也可以使用widget 路径
如有bug,欢迎指出



本帖子中包含更多资源,您需要 登录 才可以下载或查看,没有帐号?立即注册

X
37
帖子
2
勋章
3711
Y币
感谢分享
30
帖子
0
勋章
186
Y币
密集型,以及文字小的都识别不了。
30
帖子
0
勋章
186
Y币
appKey :'Cfsf1#########6Gae',
appSecret : 'G##########97R1D8'

这上边还要加个  appid :'######',  才能正常使用。
2
帖子
0
勋章
27
Y币
行驶证怎么没实现识别副页?只能识别主页?
20
帖子
0
勋章
6613
Y币
DamonJiang 发表于 2020-4-27 09:14
行驶证怎么没实现识别副页?只能识别主页?

你好 ,文档没有的即为不支持
2
帖子
0
勋章
27
Y币
yxWin 发表于 2020-4-27 10:51
你好 ,文档没有的即为不支持

那我自己试试实现一下,不知道版主在实现的时候是因为需求不大而没有实现?还是有什么坑在里面?麻烦告知一下,以免走弯路,谢谢版主。
0
帖子
0
勋章
4
Y币
身份证识别不能通过拍照获取吗
20
帖子
0
勋章
6613
Y币
有固定接口  接口打开相机  扫描
11
帖子
0
勋章
62
Y币
我在apploader显示模块未绑定,这个如何解决
123下一页
您需要登录后才可以回帖 登录

本版积分规则