【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>
相关推荐
Serverless社区15 小时前
进阶指南:BrowserUse + Agentrun Sandbox 最佳实践指南
运维·阿里云·云原生·serverless·函数计算
安当加密15 小时前
电力系统如何防“明文传输”?某电网公司用SM2+UKey构建“端到端加密”实战
服务器·数据库·安全·阿里云
游戏开发爱好者816 小时前
了解 Xcode 在 iOS 开发中的作用和功能有哪些
android·ios·小程序·https·uni-app·iphone·webview
翼龙云_cloud20 小时前
阿里云渠道商:云服务计费 按量 包年 预留实例怎么选?
服务器·阿里云·云计算
2501_9151063221 小时前
iOS 抓包工具实战实践指南,围绕代理抓包、数据流抓包和拦截器等常见工具
android·ios·小程序·https·uni-app·iphone·webview
Jyywww12121 小时前
Uniapp+Vue3 移动端顶部安全距离
uni-app
gaize121321 小时前
阿里云ECS云服务器怎么样?值得入手吗?最新测评
服务器·阿里云·云计算
2501_915106321 天前
如何在 iOS 设备上理解和分析 CPU 使用率(windows环境)
android·ios·小程序·https·uni-app·iphone·webview
咕噜企业分发小米1 天前
阿里云与华为云基因测序数据同步的日志内容中,哪些字段对于故障排查最为关键?
数据库·阿里云·华为云
alvinToffler1 天前
kkocr简单好用的ocr文字表格识别工具
ocr·文字识别·表格识别·表格按列选择