小程序
小游戏
企业微信
微信支付
扫描小程序码分享
小程序里面如何使用腾讯云的通用文字识别功能?
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
你好!这个可以成功实现图片文字识别吗?会不会偶尔报错?
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
wx.chooseImage({ success: function(res) { let filePath = res.tempFilePaths[0]; const FM = wx.getFileSystemManager(); FM.readFile({ filePath: filePath, encoding: "base64", success: res => { let { data } = res; wx.cloud.callFunction({ name: "ocr", data: { base64: data } }) .then( res => { console.log(res.result); }) } }) }, }) const cloud = require('wx-server-sdk') cloud.init() const tencentcloud = require("tencentcloud-sdk-nodejs"); const OcrClient = tencentcloud.ocr.v20181119.Client; const models = tencentcloud.ocr.v20181119.Models; const Credential = tencentcloud.common.Credential; const ClientProfile = tencentcloud.common.ClientProfile; const HttpProfile = tencentcloud.common.HttpProfile; let cred = new Credential("", ""); let httpProfile = new HttpProfile(); httpProfile.endpoint = "ocr.tencentcloudapi.com"; let clientProfile = new ClientProfile(); clientProfile.httpProfile = httpProfile; let client = new OcrClient(cred, "ap-shanghai", clientProfile); let req = new models.GeneralBasicOCRRequest(); // 云函数入口函数 exports.main = async(event, context) => { const { base64 } = event; let params = `{"ImageBase64":"${base64}"}`; req.from_json_string(params); return new Promise((resolve, reject) => { client.GeneralBasicOCR(req, function (errMsg, response) { if (errMsg) { reject(errMsg); return; } resolve(response.to_json_string()) }); }); }
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
你好!这个可以成功实现图片文字识别吗?会不会偶尔报错?
wx.chooseImage({ success: function(res) { let filePath = res.tempFilePaths[0]; const FM = wx.getFileSystemManager(); FM.readFile({ filePath: filePath, encoding: "base64", success: res => { let { data } = res; wx.cloud.callFunction({ name: "ocr", data: { base64: data } }) .then( res => { console.log(res.result); }) } }) }, }) const cloud = require('wx-server-sdk') cloud.init() const tencentcloud = require("tencentcloud-sdk-nodejs"); const OcrClient = tencentcloud.ocr.v20181119.Client; const models = tencentcloud.ocr.v20181119.Models; const Credential = tencentcloud.common.Credential; const ClientProfile = tencentcloud.common.ClientProfile; const HttpProfile = tencentcloud.common.HttpProfile; let cred = new Credential("", ""); let httpProfile = new HttpProfile(); httpProfile.endpoint = "ocr.tencentcloudapi.com"; let clientProfile = new ClientProfile(); clientProfile.httpProfile = httpProfile; let client = new OcrClient(cred, "ap-shanghai", clientProfile); let req = new models.GeneralBasicOCRRequest(); // 云函数入口函数 exports.main = async(event, context) => { const { base64 } = event; let params = `{"ImageBase64":"${base64}"}`; req.from_json_string(params); return new Promise((resolve, reject) => { client.GeneralBasicOCR(req, function (errMsg, response) { if (errMsg) { reject(errMsg); return; } resolve(response.to_json_string()) }); }); }
2. 只用ocr这个借口,但是却人引入sdk, 导致小程序包很大.
但是有问题,已反馈官方