瀏覽代碼

修改百度文字识别图片返回的内容

wutt 5 年之前
父節點
當前提交
28b9123e9a

+ 1 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/constant/Constant.java

@@ -18,6 +18,7 @@ public class Constant {
     public static final String SECRET_KEY = "RipT5kfF3Zqp7S2vTXPlNcMiYcA76jfq";//百度文字识别secretKey
     public static final Integer UN_HANDLE = 0;//定时任务未处理的状态码
     public static final String PIC_PATH_PREFIX = "";//定时任务未处理的状态码
+    public static final String COMMON_SOFTWARE_KEYWORDS = "keyWords";//常用软件关键字
     public static final String[] keyWords = new String[]{"Intellij IDEA","Eclipse",
             "Postman","MyEclipse","Visual Studio Code",
             "Navicat","Pycharm","Android Studio",

+ 11 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/task/TimingTask.java

@@ -21,6 +21,7 @@ import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAccessor;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * Author: 吴涛涛
@@ -59,7 +60,16 @@ public class TimingTask {
                 .eq("date_str", DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDateTime.now()))
                 .eq("is_handle", Constant.UN_HANDLE));
         for (Screenshot screenshot : screenshots) {
-            String general = CheckPicUtil.general(path + screenshot.getPicUrl().substring("/upload/".length()), accessToken);
+            List<String> textContents = CheckPicUtil.generalPicTextContent(path + screenshot.getPicUrl().substring("/upload/".length()), accessToken);
+            Set<Object> members = redisUtil.members(Constant.COMMON_SOFTWARE_KEYWORDS);
+            for (String textContent : textContents) {
+                for (Object member : members) {
+                    if(textContent.contains((String)member)){
+                        //包含关键字们可以简单认为是在用常用开发软件
+                        //to do 确定图片是哪个类型的图片
+                    }
+                }
+            }
         }
     }
 }

+ 7 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/CheckPicUtil.java

@@ -6,7 +6,9 @@ import com.alibaba.fastjson.JSONObject;
 import com.baidu.aip.util.Base64Util;
 
 import java.net.URLEncoder;
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -50,9 +52,9 @@ public class CheckPicUtil {
      * 调用百度文字识别api识别图片里的文字
      * @param path 图片路径
      * @param token 调用百度文字识别api的access_token
-     * @return 返回调用api识别出来的内容的set集合
+     * @return 返回调用api识别出来的内容的List集合
      */
-    public static Set<String>  generalPicTextContent (String path,String token) {
+    public static List<String>  generalPicTextContent (String path,String token) {
         // 请求url
         String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general";
         try {
@@ -68,12 +70,13 @@ public class CheckPicUtil {
             String accessToken = token;
 
             String result = HttpUtil.post(url, accessToken, param);
-            Set<String> wordsList = new HashSet<>();
+            List<String> wordsList = new ArrayList<>();
             JSONObject object = JSONArray.parseObject(result);
             JSONArray resultArray = object.getJSONArray("words_result");
             for (int i = 0; i < resultArray.size(); i++) {
                 JSONObject json  = resultArray.getJSONObject(i);
                 String words = (String)json.get("words");
+                System.out.println("words"+i+":"+words);
                 wordsList.add(words);
             }
             System.out.println(wordsList);
@@ -85,6 +88,6 @@ public class CheckPicUtil {
     }
 
     public static void main(String[] args) {
-        CheckPicUtil.generalPicTextContent("D:\\360MoveData\\Users\\Administrator\\Desktop\\idea.jpg",(String)AuthService.getAuth().get("access_token"));
+//        CheckPicUtil.generalPicTextContent("D:\\360MoveData\\Users\\Administrator\\Desktop\\idea.jpg",(String)AuthService.getAuth().get("access_token"));
     }
 }