事先说明,博文中只是一个简单的demo。阿里云的ocr识别有一定误差,图片的清晰光暗程度也会影响识别结果。
更完善的ocr识别名片程序,本人有两种想法:
一种是使用全能名片王的api,有收费部分。
一种是同时使用阿里云的名片识别接口和普通图片文字识别接口,在后台进行对比修正后再返回;同时看能否找到自动裁剪图片的方法。目前正在尝试此种方法,但是代码不方便放上来。有兴趣的可以自己研究。
源码地址:https://github.com/imiros/java-ocr-wxminipro
小程序主要代码---index.js
const app = getApp()
Page({
data: {
imageSrc: "",
showView: false
},
chooseImage: function () {
var that = this;
wx.chooseImage({
count: 1,
success: function (e) {
console.log(e.tempFilePaths[0])
that.setData({
imageSrc: e.tempFilePaths[0]
})
wx.showToast({
title: '数据加载中',
icon: 'loading',
duration: 2000
});
wx.getFileSystemManager().readFile({
filePath: e.tempFilePaths[0], //选择图片返回的相对路径
encoding: 'base64', //编码格式
success: res => {
console.log("图片转码回调");
wx.request({
url: 'https://dm-57.data.aliyun.com/rest/160601/ocr/ocr_business_card.json',
data: {
"image": res.data
},
header: {
"Authorization": "APPCODE e5d382e5d0a4*****0638b1e14a" //阿里云ocr名片识别code
},
method: 'POST',
dataType: 'json',
responseT