微信小程序:OCR识别 通用字体

参考链接:微信小程序:OCR识别_weixin_42325507的博客-CSDN博客_微信小程序ocr识别

上面链接js部分里面有好几个错误地方,仔细看下

1、先购买

https://fuwu.weixin.qq.com/service/detail/000ce4cec24ca026d37900ed551415

 

 

 2、 这个比较方便,直接在前端搞定,不需要开发者服务器再进行API访问。一共就两个步骤:购买,加前端

程序

wxml部分:

<camera device-position="back" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>
<view style="flex-direction: row;text-align: center;">
    <button size="mini" type="default" bindtap="photoAlbum">相册</button>
</view>
<view style="text-align: center;">预览</view>
<image mode="widthFix" src="{{src}}"></image>
 
  js部分:
// index.js
Page({
  data: {
    src: '',
    text: '' //要赋的值
  },

  /**
   * OCR 识别
   * @param {*} tempFilePath 
   */
  ocrtt(tempFilePath){
    const invokeRes = wx.serviceMarket.invokeService({
        service: 'wx79ac3de8be320b71', // '固定为服务商OCR的appid,非小程序appid',
        api: 'OcrAllInOne',
        data: {
            // 用 CDN 方法标记要上传并转换成 HTTP URL 的文件
            img_url: new wx.serviceMarket.CDN({
                type: 'filePath',
                filePath: tempFilePath,
            }),
            data_type: 3,
            ocr_type: 8
        },
        success:function(res){
            wx.showModal({
                title: 'success',
                content: JSON.stringify(res),
            })
        }
    })
},
  /**
     * 相册
     */
    photoAlbum() {
      const thas = this;
      wx.chooseImage({
          count: 1,
          sizeType: ['original', 'compressed'],
          sourceType: ['album', 'camera'],
          success(res) {
              // tempFilePath可以作为img标签的src属性显示图片
              const tempFilePath = res.tempFilePaths[0]
              const fileSys = wx.getFileSystemManager();
              const base64 = fileSys.readFileSync(tempFilePath, "base64");
              thas.setData({
                  src: tempFilePath,
                  base64: base64
              })

              thas.ocrtt(tempFilePath);
          }
      })
  },
 /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function (options) {
  },
})



posted @   小小菜鸟04  阅读(743)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示