From 716f57dacce347ba154f3b6a994f4e383e3a97a4 Mon Sep 17 00:00:00 2001
From: liyj <1003249715@qq.com>
Date: Thu, 05 Sep 2024 11:15:38 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 dyh-service/dyh-sys/src/main/java/cn/huge/module/utils/BaiduOcrUtils.java |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/dyh-service/dyh-sys/src/main/java/cn/huge/module/utils/BaiduOcrUtils.java b/dyh-service/dyh-sys/src/main/java/cn/huge/module/utils/BaiduOcrUtils.java
index 93769d6..00d8834 100644
--- a/dyh-service/dyh-sys/src/main/java/cn/huge/module/utils/BaiduOcrUtils.java
+++ b/dyh-service/dyh-sys/src/main/java/cn/huge/module/utils/BaiduOcrUtils.java
@@ -6,9 +6,14 @@
 import cn.huge.module.sys.dto.IdcardOcrResultDTO;
 import com.baidu.aip.ocr.AipOcr;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.json.JSONArray;
 import org.json.JSONObject;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @title: 百度云OCR工具类
@@ -28,6 +33,10 @@
     public static final String APP_ID = "27535980";
     public static final String API_KEY = "6U6tSA75gKf4UMXvHgDpzOC9";
     public static final String SECRET_KEY = "BBjjCDhy2sAVO0jfiaGn8OWIGE470lWU";
+    // 个人账号-18607214221
+    public static final String APP_ID_TEXT = "113806304";
+    public static final String API_KEY_TEXT = "ajKtDuIs8xr0XvjbUZLPGi8C";
+    public static final String SECRET_KEY_TEXT = "vgMrG5BJbUfGwKLda1yPWovTQWuRFWDB";
 
     public static void main(String[] args) {
 
@@ -81,6 +90,35 @@
         }
     }
 
+
+    public static Map<String, Object> ocrText(byte[] images) {
+        AipOcr client = new AipOcr(APP_ID_TEXT, API_KEY_TEXT, SECRET_KEY_TEXT);
+        // 传入可选参数调用接口
+        HashMap<String, String> options = new HashMap<String, String>();
+        options.put("language_type", "CHN_ENG");
+        options.put("detect_direction", "true");
+        options.put("detect_language", "true");
+        options.put("probability", "true");
+
+        Map<String, Object> map = new HashMap<String, Object>();
+        // 参数为本地图片二进制数组
+        JSONObject res = client.basicAccurateGeneral(images, options);
+        map.put("wordsResultNum", res.getInt("words_result_num"));
+        map.put("direction", res.getInt("direction"));
+
+        List<String> wordsResultList = new ArrayList<>();
+        JSONArray jsonArray = res.getJSONArray("words_result");
+        for(int i = 0; i < jsonArray.length(); i++){
+            JSONObject wordResult = jsonArray.getJSONObject(i);
+            String words = wordResult.getString("words");
+            if(StringUtils.isNotBlank(words)){
+                wordsResultList.add(words);
+            }
+        }
+        map.put("wordsResult", wordsResultList);
+        return map;
+    }
+
 }
 /**
  * -------------------_ooOoo_-------------------

--
Gitblit v1.8.0