From fb788ea0ce97f006bebf468bc5ec024dc22d4870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Mon, 9 Sep 2024 14:19:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=99=BE=E5=BA=A6OCR?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=99=A8=E6=89=80=E9=9C=80=E5=8C=85=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mitmproxy/package.json | 1 + packages/mitmproxy/test/baiduOcrTest.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 packages/mitmproxy/test/baiduOcrTest.js diff --git a/packages/mitmproxy/package.json b/packages/mitmproxy/package.json index 9f5c92401b..67681943e1 100644 --- a/packages/mitmproxy/package.json +++ b/packages/mitmproxy/package.json @@ -13,6 +13,7 @@ "dependencies": { "agentkeepalive": "^2.1.1", "axios": "^0.21.1", + "baidu-aip-sdk": "^4.16.16", "child_process": "^1.0.2", "colors": "^1.1.2", "commander": "^2.9.0", diff --git a/packages/mitmproxy/test/baiduOcrTest.js b/packages/mitmproxy/test/baiduOcrTest.js new file mode 100644 index 0000000000..70a7b7ed01 --- /dev/null +++ b/packages/mitmproxy/test/baiduOcrTest.js @@ -0,0 +1,25 @@ +const AipOcrClient = require('baidu-aip-sdk').ocr + +// 设置APPID/AK/SK +const APP_ID = '101474620' +const API_KEY = 'fqCvIHGisGwpsglzV2wdxZJ5' +const SECRET_KEY = 'RhTOXUA4V6CrGuCTJJvUQ7z6Nl4m0Lij' + +// 新建一个对象,建议只保存一个对象调用服务接口 +const client = new AipOcrClient(APP_ID, API_KEY, SECRET_KEY) + +// 图片:6525 +const imageBase64 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAAAeCAYAAAC7Q5mxAAAac0lEQVRoQ0VaCXScV3m9/+yrZtOMdsm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9jvOAPJsmomm3VERHUXDx9G6ezy2cfpFrk/BCihkKLaCaPvX973+/AovM/2K2ZbKRAsokluNmqNM+bqqgT9As3RljnKed6T9TcTFRtss7DhgB+TgGFbibHu7mQ5/5rEKlnJkUGGHH+eYgMdoUP5Vey/tKNKumTuzkQEkGcbO0sKS7PPewso1NbEs55AlH46oIMo7JJgWIwmA4iLyjjP6xQSYgESxwoJcUpMzdpTVTeaQcEtVwFhWhqGMKY6ICp+jFPKQBOVVzEZk1bMnr168rtEmyJFxYU8PDe45wsgmyaEHOjfFJbCB6Rak93MBaTldWWqUIaUkKK60r+afQgAwKi2x/8ZxSOFFjNYpys9R9JGThad3/A6cC8EsBkFJyAAAAAElFTkSuQmCC' + +const options = {} +options.detect_direction = 'false' +options.paragraph = 'false' +options.probability = 'false' + +// 调用通用文字识别(高精度版)(异步) +client.accurateBasic(imageBase64, options).then(function (result) { + console.log(JSON.stringify(result)) +}).catch(function (err) { + // 如果发生网络错误 + console.log(err) +})