|
@@ -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"));
|
|
|
}
|
|
|
}
|