代码如下
doIdentify() {
let ctx = uni.createCameraContext();
ctx.takePhoto({
quality: 'high',
success: res => {
this.shooting = false;
this.tempImg = res.tempImagePath;
uni.showLoading({
title: '识别中'
})
uni.getFileSystemManager().readFile({
filePath: res.tempImagePath,
encoding: 'base64',
success: imgInfo => {
request.post('marketing/product/search', {
picture: 'data:image/jpeg;base64,' + imgInfo.data
}).then(rel => {
uni.hideLoading();
this.isBottle = rel.data.result;
if (this.isBottle) return;
uni.showToast({
title: '没识别出来呢,再拍一次吧',
duration: 1000
})
setTimeout(this.reShoot, 500)
})
},
});
}
})
},