现在是只能识别一个图片,跳转到一个页面,我这边的需求是:识别12个图片,识别成功之后,可以跳转到对应识别图的页面,我现在遇到的问题是:识别图的Token值是唯一的,图片不会区分,该怎么区分图片,怎么在小程序里识别的mate该怎么保存。希望可以得到帮助谢谢。以下是代码片段:
//pages/recognition/recognition.js
//import upng from ‘…/…/UPNG.js’
Page({
data: {
height: ‘500’,
width: ‘20’,
status: false,
scanStatus: ‘none’,
color: ’ #6495ED’,
msg: “”,
src: ‘’,
isShow:true , //花边
isperson:true//人
},
onLoad: function (options) {
this.ctx = wx.createCameraContext();
wx.getSystemInfo({
success: res => {
this.setData({ height: res.windowHeight *0.8, width: res.windowWidth});
}
});
},
stopScan: function () {
this.setData({ scanStatus: ‘none’, msg: ‘111111’});
},
onShow: function () {
this.setData({
msg: ‘点击识别名片’,
isShow: true, //花边
isperson: false
});
},
error: function (e) {
this.setData({ msg: ‘请重新点击识别’ });
},
urlTobase64(imgPath) {
let that = this;
wx.getFileSystemManager().readFile({
filePath: imgPath, //选择图片返回的相对路径
encoding: ‘base64’, //编码格式
success: res => { //成功的回调
console.log(‘data:image/png;base64,’ + res.data)
that.searchPhotp(res.data)
}
})
},
searchPhotp: function(imageBase64) {
let that = this;
wx.request({
url: ‘https://cn1-crs.easyar.com:8443/search’,
data: {
image: imageBase64
},
header: {
‘Authorization’: ‘g7BVXzTjfuuM3RNg3KOSLcRzwx8chRtNUo+79iEFkuEudgZswH9a6c8GnKY1btGFoq/O8x72TrnO/tr27+MIiA==’,
‘content-type’: ‘application/json’ // 默认值
},
method: ‘POST’,
success(res) {
if (res.data.statusCode == 0) {
console.log(“成功”);
that.setData({
msg: ‘识别成功’,
isShow:false
});
setTimeout(() => {
console.info(‘go to webar’);
that.setData({
msg: ‘’,
//出效果
isperson:true
});
}, 500);
setTimeout(() => {
console.info(‘go to webar’);
wx.navigateTo({
url: ‘…/show/show’
});
}, 5000);
} else {
that.status = false;
that.setData({ msg: ‘识别失败,请重试’});
}
},
fail(err) {
console.log(err)
that.status = false;
that.setData({ msg: ‘识别失败,请重试’});
}
})
},
takePhoto: function (e) {
//if (this.status) return;
console.log(11111)
this.status = true;
this.ctx.takePhoto({
quality: ‘low’,
success: res => {
this.setData({ msg: ‘识别中…’, src: res.tempImagePath});
this.urlTobase64(res.tempImagePath);
},
fail: err => {
this.stopScan();
this.setData({ msg: ‘未识别到目标’ });
}
});
}
})
以下是图片说明: