赞
踩
<template>
<view class="container">
<!-- 选择图片 -->
<button @click="imageOcrRecognition">选择图片</button>
<view v-html="content"></view>
</view>
</template>
<script>
import { pathToBase64, base64ToPath } from 'image-tools'//npm i image-tools --save
export default {
data() {
return {
content: '',
}
},
methods: {
imageOcrRecognition() {
const that = this;
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
pathToBase64(res.tempFilePaths[0]).then(base64 => {
uni.request({
url: 'https://gjbsb.market.alicloudapi.com/ocrserve/advanced',
dataType: 'json',
header: {
'Authorization': `APPCODE 你的AppCode`
},
data: { img: base64.substring(base64.indexOf(',') + 1) },
method: 'POST',
success(res) {
console.log(res);
that.content = res.data.content;
}
})
})
}
})
},
},
}
</script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。