【uniapp】调用阿里云OCR图片识别文字:

文章目录


一、效果:
二、实现:

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

javascript 复制代码
<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>
相关推荐
洗发水很好用3 分钟前
uniapp纯css实现基础多选组件
前端·css·uni-app
DisonTangor5 分钟前
【小红书拥抱开源】rednote-hilab团队开源SOTA级性能OCR模型——dots.mocr
人工智能·计算机视觉·开源·ocr
同聘云1 小时前
阿里云国际站服务器浅谈DDOS攻击与防御
服务器·阿里云·ddos
2501_915918411 小时前
WebKit 抓包,WKWebView 请求的完整数据获取方法
android·前端·ios·小程序·uni-app·iphone·webkit
AnalogElectronic2 小时前
uniapp学习1,hello world 项目,打包到微信小程序,贪吃蛇小游戏
学习·微信小程序·uni-app
雪芽蓝域zzs2 小时前
uniapp 真机上传图片提示打包未添加Camera模块
android·uni-app
不爱说话郭德纲17 小时前
uni-app x iOS 离线打包踩坑总结
uni-app·xcode
pengles1 天前
基于RuoYi-Vue-Plus项目实现移动端项目
java·vue.js·uni-app
Skilce1 天前
ZrLog 高可用部署
运维·服务器·数据库·阿里云·maven
Ynchen. ~2 天前
告别 OSS 强制下载!阿里云 OSS 绑定自定义域名实现文件在线预览全记录
阿里云·云计算·oss