Commit 98afdbc6 by lilei

删除ocr相关代码

parent 67ee9f81
......@@ -55,13 +55,6 @@
<systemPath>${pom.basedir}/src/main/webapp/WEB-INF/lib/ocr-precision-1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
<scope>system</scope>
<version>5.5.0</version>
<systemPath>${pom.basedir}/src/main/webapp/WEB-INF/lib/jna-5.5.0.jar</systemPath>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
......
package com.founder.controller;
import com.alibaba.fastjson.JSONObject;
import com.founder.service.OcrService;
import com.founder.util.OcrFounder;
import org.apache.ibatis.annotations.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Base64;
import java.util.Date;
import sun.misc.BASE64Encoder;
@RestController
@RequestMapping(value="/ocr",produces = "application/json; charset=utf-8")
public class OcrController {
@Autowired
private OcrService ocrjService;
@Autowired
private OcrFounder ocrFounder;
@ResponseBody
@CrossOrigin
@PostMapping("/InvoiceOcr")
public JSONObject query(HttpServletRequest request, MultipartFile file) {
DateFormat df2 = DateFormat.getDateTimeInstance();//可以精确到时分秒
Date date = new Date();
System.out.println(df2.format(date)+"开始时间");
byte[] fileByte = null;
try {
fileByte = file.getBytes();
} catch (IOException e) {
}
BASE64Encoder encoder = new BASE64Encoder();
String voiceBase64= encoder.encode(fileByte);
JSONObject j = new JSONObject();
j.put("msg",ocrjService.getOcr(voiceBase64));
Date date1 = new Date();
DateFormat df3 = DateFormat.getDateTimeInstance();//可以精确到时分秒
System.out.println(df3.format(date1)+"结束时间");
return j;
}
@ResponseBody
@CrossOrigin
@PostMapping("/OcrFounder")
public JSONObject queryOcrFounder(HttpServletRequest request, MultipartFile file) {
DateFormat df2 = DateFormat.getDateTimeInstance();//可以精确到时分秒
Date date = new Date();
System.out.println(df2.format(date)+"开始时间");
String result="";
byte[] fileByte = null;
try {
fileByte = file.getBytes();
} catch (IOException e) {
}
String ocrRes="";
try {
ocrRes= ocrFounder.getOcrFounder(fileByte);
} catch (Exception e) {
e.printStackTrace();
}
//图片文字与简要案情比对
Float ocrCompJyaq=getSimilarityRatio(ocrRes,"立案");
//图片文字与嫌疑人比对
Float ocrCompZbfzxry=getSimilarityRatio(ocrRes,"王岩");
//图片文字与受害人人比对
Float ocrCompBhr=getSimilarityRatio(ocrRes,"大类");
//图片文字与受害人人比对
Float ocrCompws=getSimilarityRatio(ocrRes,"立案决定书");
if(ocrCompws<0.000001){
}else
if(ocrCompJyaq<0.000001&&ocrCompZbfzxry<0.000001&&ocrCompBhr<0.000001)
{
}
JSONObject j = new JSONObject();
j.put("msg",ocrRes);
Date date1 = new Date();
DateFormat df3 = DateFormat.getDateTimeInstance();//可以精确到时分秒
System.out.println(df3.format(date1)+"结束时间");
return j;
}
@ResponseBody
@CrossOrigin
@PostMapping("/OcrFounderByte")
public JSONObject queryOcrFounderFlws(@RequestBody String fileByte) {
final Base64.Decoder decoder = Base64.getMimeDecoder();
byte[] data=decoder.decode(fileByte);
DateFormat df2 = DateFormat.getDateTimeInstance();//可以精确到时分秒
String result="";
try {
result= ocrFounder.getOcrFounder(data);
} catch (Exception e) {
e.printStackTrace();
}
JSONObject j = new JSONObject();
j.put("msg",result);
Date date1 = new Date();
DateFormat df3 = DateFormat.getDateTimeInstance();//可以精确到时分秒
System.out.println(df3.format(date1)+"结束时间");
return j;
}
public static float getSimilarityRatio(String str, String target) {
int d[][]; // 矩阵
int n = str.length();
int m = target.length();
int i; // 遍历str的
int j; // 遍历target的
char ch1; // str的
char ch2; // target的
int temp; // 记录相同字符,在某个矩阵位置值的增量,不是0就是1
if (n == 0 || m == 0) {
return 0;
}
d = new int[n + 1][m + 1];
for (i = 0; i <= n; i++) { // 初始化第一列
d[i][0] = i;
}
for (j = 0; j <= m; j++) { // 初始化第一行
d[0][j] = j;
}
for (i = 1; i <= n; i++) { // 遍历str
ch1 = str.charAt(i - 1);
// 去匹配target
for (j = 1; j <= m; j++) {
ch2 = target.charAt(j - 1);
if (ch1 == ch2 || ch1 == ch2 + 32 || ch1 + 32 == ch2) {
temp = 0;
} else {
temp = 1;
}
// 左边+1,上边+1, 左上角+temp取最小
d[i][j] = Math.min(Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1), d[i - 1][j - 1] + temp);
}
}
return (1 - (float) d[n][m] / Math.max(str.length(), target.length())) * 100F;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment