|
@@ -38,8 +38,7 @@ public class BaiduOcrClient extends OcrApiClient {
|
|
|
if (result != null && result.getWordsList() != null) {
|
|
|
if (!result.getWordsList().isEmpty()) {
|
|
|
return mapper.readValue(data, BaiduOcrResult.class).getWordsList().stream().map(BaiduOcrWords::getWords)
|
|
|
- .collect(Collectors.joining("\n"));
|
|
|
- //.replaceAll("☰", "").replaceAll("≡", "");
|
|
|
+ .collect(Collectors.joining("\n")).replaceAll("☰", "").replaceAll("≡", "");
|
|
|
} else {
|
|
|
return StringUtils.EMPTY;
|
|
|
}
|
|
@@ -95,9 +94,9 @@ public class BaiduOcrClient extends OcrApiClient {
|
|
|
private FormBody buildBody(OcrType type, byte[] image) {
|
|
|
FormBody.Builder builder = new FormBody.Builder();
|
|
|
builder.add("image", CodecUtils.toBase64(image));
|
|
|
- //if (type == OcrType.HANDWRITING) {
|
|
|
- //builder.add("detect_alteration", "true");
|
|
|
- //}
|
|
|
+ if (type == OcrType.HANDWRITING) {
|
|
|
+ builder.add("detect_alteration", "false");
|
|
|
+ }
|
|
|
return builder.build();
|
|
|
}
|
|
|
|
|
@@ -113,12 +112,12 @@ public class BaiduOcrClient extends OcrApiClient {
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
OcrApiConfig config = new OcrApiConfig();
|
|
|
config.setUrl("https://aip.baidubce.com/rest/2.0/ocr/v1/");
|
|
|
- config.setKey("90a8e5e586924cb7937526b68e441aeb");
|
|
|
- config.setSecret("a13ced7ae3804b2a84ca4abd005f488f");
|
|
|
+ config.setKey("");
|
|
|
+ config.setSecret("");
|
|
|
config.setQps(10);
|
|
|
BaiduOcrClient client = new BaiduOcrClient(config);
|
|
|
System.out.println(client.forImage(OcrType.HANDWRITING,
|
|
|
- ByteArray.fromFile(new File("/Users/luoshi/Downloads/test2.jpg")).value()));
|
|
|
+ ByteArray.fromFile(new File("/Users/luoshi/Downloads/test.jpg")).value()));
|
|
|
}
|
|
|
|
|
|
}
|