【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>
相关推荐
anyup16 小时前
弃用 vue-i18n?只用 uView Pro 我照样做国际化!
前端·架构·uni-app
xier_ran17 小时前
【第二周】RAG与Agent实战12:LangChain访问阿里云嵌入模型
阿里云·自然语言处理·langchain·云计算·agent·rag
明月(Alioo)20 小时前
OpenClaw 从本地到云端:阿里云百炼免费模型配置实战指南
阿里云·ai·aigc·agent
geovindu21 小时前
python: 初养龙虾微信纯文字自动回复using workBuddy
开发语言·python·ocr·腾讯云ai代码助手
桌面运维家1 天前
Windows桌面审计:用OCR高效提取VHD磁盘内容
ocr
桌面运维家1 天前
Windows桌面审计:高效OCR屏幕内容抓取指南
windows·ocr
是烨笙啊1 天前
五分钟上线:基于DeepSeek-OCR的多功能web应用
人工智能·aigc·ocr
returnthem1 天前
怎么发布镜像到dockerhub与阿里云容器里
阿里云·eureka·云计算
张彦峰ZYF1 天前
阿里云云计算ACA - ACP认证考试模拟试卷一
阿里云·云计算·aca - acp
xier_ran1 天前
【第二周】RAG与Agent实战09:LangChain访问阿里云通义大模型
阿里云·langchain·云计算