当前位置: 首页 > news >正文

小程序获取OCR识别结果,示例代码

//获取OCR识别结果,示例代码--startwx.chooseMedia({count: 1,mediaType: ['image'],sourceType: ['album', 'camera'],maxDuration: 30,camera: 'back',success: (res) => {if(res.errMsg=="chooseMedia:ok"){let tempImgPath = res.tempFiles[0].tempFilePath;// const imgBase64 = uni.getFileSystemManager().readFileSync(tempImgPath, "base64");wx.serviceMarket.invokeService({service: 'wx79ac3de8be320b71', // '固定为服务商OCR的appid,非小程序appid',api: 'OcrAllInOne',//服务名称data: {img_url: new wx.serviceMarket.CDN({type: 'filePath',filePath: tempImgPath// 使用选择的第一张图片的路径}),data_type: 3,//1:二进制;2:base64字符串;3:图片urlocr_type: 1,//1:身份证;2:银行卡;3:行驶证;4:驾驶证;7:营业执照;8:通用OCR ; 10: 车牌识别},}).then(res => {console.log('invokeService success', res)//res 成功返回正面示例报文:{"errMsg":"invokeService:ok","data":{"idcard_res":{"type":0,"name":{"text":"崔效伟"},"gender":{"text":"男"},"nationality":{"text":"汉"},"birth":{"text":"2000-03-10"},"address":{"text":"山西省忻州市忻府区解原乡东社村029号"},"id":{"text":"142201200003104873"},"card_position":{"pos":{"left_top":{"x":503.8359375,"y":0},"right_top":{"x":503.8359375,"y":776},"right_bottom":{"x":6.0703125,"y":776},"left_bottom":{"x":6.0703125,"y":0}}},"image_width":516,"image_height":777,"card_property":4}},"requestId":"MLzHwxChFkPT-6Yqi_YFXN3exxf6uL9wYiaRFKet9xeqaM6da2lzO3HF4vsI-j8RxbQ"};//  wx.showModal({// title: 'cost',// content: (Date.now() - d) + ''//  })}).catch(err => {console.error('invokeService fail', err)//  wx.showModal({// title: 'fail',// content: err + '',//  })})}else{uni.showToast({title: res.errMsg,icon: "none",position: 'center',duration: 3000});}},fail: (res) => {console.log("选择身份证照片失败:"+res.errMsg);}});//获取OCR识别结果,示例代码--end

   参考地址:https://blog.csdn.net/weixin_36754290/article/details/151318521

http://www.rkmt.cn/news/51325.html

相关文章:

  • Acunetix v25.11 发布,新增功能简介
  • MySQL数据过滤与计算字段实战技术指南
  • 实用指南:【第五章:计算机视觉-项目实战之推荐/广告系统】1.推荐系统基础与召回算法-(6)召回算法之u2i: FM、deepFM、召回双塔原理精讲与实战
  • 实用指南:On-Page SEO完全指南:从关键词策略到内容优化
  • Java位运算符概览
  • 自动化测大样例
  • 2025年当下行业内知名的旧房翻新企业排名与推荐
  • 现今国内口碑好的旧房翻新企业排行
  • 20232422 龙浩然 2025-2026-1 《网络与系统攻防技术》实验五实验报告
  • [AGC030F]Permutation and Minimum
  • 2025年安徽伸缩门公司哪家权威:十大品牌综合评测
  • Spring 中的 @Configuration 注解
  • C# 封装、继承、抽象、接口
  • 智能床垫品牌全面选品指南:2025年11月最新TOP5榜单深度解析
  • 基于Qt实现的窗口半透明流动背景
  • 2025年11月冷媒剂厂家评测榜:从资质到应用全场景解析
  • 分布式计算通信原语的抽象模型
  • 2025/11/16
  • 数据结构——二十四、图(王道408) - 实践
  • C# Avalonia 18- ControlTemplates - ColorPickerUserControlTest
  • Spring AI Alibaba 项目源码学习(九)-其他继承BaseAgent
  • Linux进程状态 - 教程
  • mybatis_generate_demo
  • 换歌换歌
  • GaN 器件第三象限导通特性
  • Why did Hitler become a greater Napoleon?
  • Qt编写28181推流分发服务/统计访问数量/无人观看超时关闭/等待重新点播/复用点播
  • React Native创建AndroidIOS流程完整指南
  • Ducky - BPMN 工作流管理系统
  • 图论建模问题