Springboot+Vue 调用百度云接口,实现OCR文字识别
@RestController
public class HelloController {
@RequestMapping(value = "/hello",method = RequestMethod.GET)
public String Hello(){
return "hello world";
}
}
代码:
public static String picToWords(MultipartFile file) throws IOException {
// 初始化一个AipOcr
AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
String path = "/Users/31593/Desktop/test.png"; //绝对路径
JSONObject res = client.basicGeneral(file.getBytes(), new HashMap<String, String>());
JSONArray words_result = res.getJSONArray("words_result");
String result="";
for(int i=0;i<words_result.length();i++){
JSONObject jsonObject = words_result.getJSONObject(i);
Object words = jsonObject.get("words");
String s=(String)words;
result+=s+"";
}
System.out.println(result);
return result;
}