OCR识别
发布于 4 年前 作者 lei90 4326 次浏览 来自 分享

声明:

由于本人对社区不是很熟悉,在提问里进行了同样发表;不知道怎么删除提问,望各位谅解;该代码是在网上看的编程小石头的代码进行编写的,在此感谢。

OCR识别我是用的云调用进行的银行卡识别。直接把图片上传到云存储里。然后调用云函数进行识别。在识别的过程中发现,无论上传哪一张银行卡照片,都会识别到第一张银行卡的卡号,只有在云存储里进行刷新后,才可以进行识别最新的卡号。经过分析代码后,怀疑可能是覆盖的原因吧。我是在上传图片的时候,图片的名称没有改变,比如图片的名称都是aa.png。后来我用时间进行定义后,每次上传图片都可以正常识别到了;在此还有一个疑问就是,如果上传图片是进行上传原图,会识别失败,不知为何?

function photo(){

let that = this

wx.chooseImage({

count: 1,

sizeType: ['compressed'],

sourceType: ['album', "camera"],

success(res) {

// tempFilePath可以作为img标签的src属性显示图片

let imgUrl = res.tempFilePaths[0];

console.log(res.tempFilePaths)

console.log(imgUrl)

uploadImg(new Date().getTime(), imgUrl)//用的时间代表的图片名称

}

})

function uploadImg(type, imgUrl) {

console.log("上传成功")

let that = this

wx.cloud.uploadFile({

cloudPath: 'ocr/' + type + '.png',

filePath: imgUrl, // 文件路径

success(res) {

console.log("上传成功", res.fileID)

getImgUrl( res.fileID)

},

fail(err) {

console.log("上传失败", err)

}

})

}

function getImgUrl(imgUrl){

let that = this

wx.cloud.getTempFileURL({

fileList: [imgUrl],

success: res => {

let imgUrl = res.fileList[0].tempFileURL

console.log("获取图片url成功", imgUrl)

// that.shibie(type, imgUrl)

wx.cloud.callFunction({

name: "ly_bankid",

data: {

//type: type,

a1: imgUrl//"https://7465-text-847781006-g1sgp-1300781309.tcb.qcloud.la/ocr/type.png"

},

success(res) {

console.log("识别成功", res)

},

fail(res) {

console.log("识别失败", res)

}

})

},

fail: err => {

console.log("获取图片url失败", err)

}

})

}

回到顶部