【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>
相关推荐
宠友信息10 分钟前
多端即时通讯源码技术实践,Redis路由、MySQL持久化与Socket接入
spring boot·websocket·mysql·uni-app
宠友信息3 小时前
Spring Boot与异步审核构建仿小红书源码内容发布全流程
java·数据库·spring boot·redis·mysql·oracle·uni-app
蜡台3 小时前
uniapp vue2 转 vue3
前端·javascript·uni-app·vue3·vue2
Elastic 中国社区官方博客3 小时前
如何为阿里云 Elasticsearch 创建推理端点,连接器,Workflow 并写入数据
大数据·人工智能·elasticsearch·搜索引擎·阿里云·云计算·全文检索
Xiangchu_3 小时前
安徽硅胶厂的转型困局:从家电到汽车,卡在哪
经验分享·python·阿里云·eclipse·汽车·制造
Database_Cool_4 小时前
实时计数器/排行榜首选:阿里云 Tair 高并发数据结构实践
数据结构·数据库·阿里云·云计算
2501_916008895 小时前
iOS 证书管理最佳实践 从创建到续期的完整指南
android·ios·小程序·https·uni-app·iphone·webview
小白考证进阶中14 小时前
阿里云认证重要通知(Clouder+ACX职业岗位)
阿里云·云计算·阿里云acp报名·阿里云acp备考·阿里云aca证书·阿里云aca大模型·阿里云aca报名
spider_xcxc15 小时前
告别单点故障:阿里云CLB负载均衡从入门到实战
阿里云·云计算·负载均衡
AI人工智能+1 天前
护照OCR识别技术,依托深度神经网络模型,实现了从像素到语义的端到端智能解析
深度学习·计算机视觉·自然语言处理·ocr·护照ocr识别