一、效果:

二、实现:
【阿里官方】高精版OCR文字识别【最新版】-云市场-阿里云


<template>
<view class="container">
<!-- 选择图片 -->
<button @click="imageOcrRecognition">选择图片</button>
<view v-html="content"></view>
</view>
</template>
<script>
import { pathToBase64, base64ToPath } from 'image-tools'
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>