【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>
相关推荐
石榴树下的七彩鱼6 分钟前
OCR 识别不准确怎么办?模糊 / 倾斜 / 反光图片优化实战(附完整解决方案 + 代码示例)
图像处理·人工智能·后端·ocr·api·文字识别·图片识别
Ztopcloud极拓云视角3 小时前
阿里云涨价生效日:多云成本优化实战指南(含Claude Opus 4.7接入对比)
阿里云·云计算·anthropic·claude opus 4.7
开开心心_Every5 小时前
安卓图片压缩工具,无损缩放尺寸免费好用
人工智能·pdf·计算机外设·ocr·语音识别·团队开发·规格说明书
Klong.k5 小时前
话不多说 直接上glm-ocr的工具类
ocr
tian_jiangnan6 小时前
把 Docker 镜像推送到 阿里云容器镜像服务 ACR
阿里云·docker·容器
无心水9 小时前
13、云端OCR终极指南|百度/阿里/腾讯API高精度文字提取实战
百度·架构·pdf·ocr·dubbo·pdf解析·pdf抽取
Chef_Chen19 小时前
论文解读:不需要OCR,不需要描述生成——ColPali重构了文档检索的底层逻辑
重构·ocr
北极糊的狐1 天前
4.1阿里云 OSS 的跨域访问 CORS 限制本地直接打开 HTML 无法正常播放 OSS 音频、视频
阿里云·云计算
笨笨狗吞噬者1 天前
uni-app 运行时揭秘:styleIsolation 的转化
前端·微信小程序·uni-app
TG_yunshuguoji1 天前
阿里云代理商:阿里云数字短信全面开放!触达新方案
阿里云·云计算·云服务器