生成一个识别出图片中的文本的uniapp完整代码
时间: 2023-02-06 08:30:42 浏览: 74
嗯,那我就给你一个使用小程序云开发的代码例子。首先你需要在小程序云后台开通文本识别的能力。
首先,在 uni.request 中上传图片,然后调用云函数:
```
uni.chooseImage({
success: (res) => {
const filePath = res.tempFilePaths[0]
uni.cloud.callFunction({
name: 'orc',
data: {
filePath: filePath
},
success: res => {
console.log(res)
},
fail: err => {
console.error(err)
}
})
}
})
```
然后在云函数中调用文本识别 API:
```
const cloud = require('wx-server-sdk')
cloud.init()
const ORC = cloud.openapi.ocr
exports.main = async (event, context) => {
try {
const res = await ORC.advancedGeneral({
image: event.fileContent,
language_type: 'CHN_ENG'
})
return res
} catch (err) {
return err
}
}
```
希望这能帮到你!
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![vue](https://img-home.csdnimg.cn/images/20210720083646.png)
![js](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)