【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>
相关推荐
2501_9159090614 小时前
iOS应用性能优化:十大策略提升用户体验与开发效率
android·ios·小程序·https·uni-app·iphone·webview
jiajia_lisa18 小时前
轻量化智能升级,降本增效赋能长效运营
ocr
阿里云大数据AI技术19 小时前
最佳实践:用 EMR Serverless StarRocks AI Function 实现金融行业文本分类_
starrocks·人工智能·sql·阿里云·ai function
MR_Colorful20 小时前
阿里云ECS部署YOLO教程
yolo·阿里云·云计算
万能小林子20 小时前
如何将网页在线转APP?5种打包工具对比速成指南(含在线/手机/电脑方案)
android·ios·uni-app·web app·wap2app·app打包·app封装
Komorebi_999921 小时前
OCR + 大模型融合方案
大模型·ocr
wuhen_n21 小时前
阿里云百炼平台 API 接入教程(附 Node.js + TypeScript 实战)
前端·人工智能·阿里云·ai编程
Elastic 中国社区官方博客21 小时前
Hacknight Beijing:基于阿里云与 Elastic 构建 AI Agents
大数据·运维·人工智能·elasticsearch·搜索引擎·阿里云·云计算
醇氧21 小时前
【Hermes Agent】使用阿里云百炼 Token Plan(方式一:命令行一键配置)
阿里云·云计算·es·openclaw