master
周文涛 2 years ago
parent f03227bce2
commit 5d500c90d8

@ -32,6 +32,10 @@ public class OcrConstant {
public static String api_test2_identify_url="http://127.0.0.1:7003/semantic";
//public static String api_test2_identify_url="http://127.0.0.1:8000/semantic";
/**
*
*/
public static String FILE_DOWNLOAD_URL_PREFIX="/data/ocr/upFiles";
/**
*
*/

@ -252,8 +252,10 @@ public class ApiController {
@ApiOperation(value = "调试101")
@PostMapping(value = "/test_101")
public Result test101(@RequestBody JSONObject jsonObject){
OcrIdentifyDTO byId = ocrIdentifyService.findById("1692068694831755265");
ocrIdentifyService.updateTaskResultInfo(byId.getId());
//OcrIdentifyDTO byId = ocrIdentifyService.findById("1692068694831755265");
//ocrIdentifyService.updateTaskResultInfo(byId.getId());
JSONObject semanticResponseJson = JSONObject.parseObject("{\"img_path\":\"https://h5.mcnetmart.com/tmp/images/dc_demo1.png\",\"ocr_time\":3.4992809295654297,\"task_id\":\"1697133769514909698_1\",\"message\":\"成功\",\"semantic_result\":{\"ocr_res\":[[[[136.0,98.0],[276.0,70.0],[281.0,93.0],[141.0,121.0]],[\"深圳康瑞医院\",0.9387677311897278]],[[[139.0,120.0],[284.0,92.0],[288.0,109.0],[142.0,136.0]],[\"Shenzhen Kangrui hospual\",0.9168243408203125]],[[[171.0,284.0],[260.0,268.0],[264.0,292.0],[175.0,308.0]],[\"赵思杰\",0.9619879126548767]],[[[191.0,311.0],[247.0,301.0],[251.0,323.0],[195.0,333.0]],[\"妇产科\",0.9429848790168762]],[[[189.0,346.0],[259.0,332.0],[263.0,350.0],[193.0,364.0]],[\"主治医师\",0.8993821144104004]],[[[198.0,375.0],[263.0,364.0],[267.0,381.0],[201.0,393.0]],[\"202015\",0.9382884502410889]]],\"其他\":[{\"area\":[[139.0,120.0],[284.0,92.0],[288.0,109.0],[142.0,136.0]],\"end\":24,\"ocrText\":\"Shenzhen Kangrui hospual\",\"probability\":0.9846151031007864,\"start\":0,\"text\":\"Shenzhen Kangrui hospual\"},{\"area\":[[189.0,346.0],[259.0,332.0],[263.0,350.0],[193.0,364.0]],\"end\":4,\"ocrText\":\"主治医师\",\"probability\":0.9848503723946322,\"start\":0,\"text\":\"主治医师\"},{\"area\":[[198.0,375.0],[263.0,364.0],[267.0,381.0],[201.0,393.0]],\"end\":6,\"ocrText\":\"202015\",\"probability\":0.9731923600763821,\"start\":0,\"text\":\"202015\"}],\"医院名称\":[{\"area\":[[136.0,98.0],[276.0,70.0],[281.0,93.0],[141.0,121.0]],\"end\":6,\"ocrText\":\"深圳康瑞医院\",\"probability\":0.9856892892579268,\"start\":0,\"text\":\"深圳康瑞医院\"}],\"姓名\":[{\"area\":[[171.0,284.0],[260.0,268.0],[264.0,292.0],[175.0,308.0]],\"end\":3,\"ocrText\":\"赵思杰\",\"probability\":0.9996551423001598,\"start\":0,\"text\":\"赵思杰\"}],\"时间\":[],\"科室\":[{\"area\":[[191.0,311.0],[247.0,301.0],[251.0,323.0],[195.0,333.0]],\"end\":3,\"ocrText\":\"妇产科\",\"probability\":0.9983404968615517,\"start\":0,\"text\":\"妇产科\"}]},\"nlu_time\":16.85913324356079,\"identifyId\":\"1697133769514909698\"}");
ocrIdentifyService.getSemanticInfo(semanticResponseJson);
/*OcrRuleCheckVo ocrRuleCheckVo = byId.getOcrRuleCheckVo();
Map<String, String> configRuleMap = ocrRuleCheckVo.getConfigRuleMap();*/
return Result.OK("");

@ -12,6 +12,7 @@ import org.jeecg.modules.ocr.model.TaskModel;
import org.jeecg.modules.ocr.service.IOcrIdentifyService;
import org.jeecg.modules.ocr.service.IOqcApiErrorLogService;
import org.jeecg.modules.ocr.service.impl.TaskService;
import org.jeecg.modules.ocr.utils.FileOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
@ -144,10 +145,15 @@ public class HandleTransInit implements ApplicationRunner {
String masterTaskId = parameters[0];//主任务redis
String task_id = parameters[1];
String image = parameters[2];
//判断是不是网络图片
Boolean onlineFile = FileOUtils.isOnlineFile(image);
if (onlineFile) {
//如果是网络图片,则将图片下载
image = FileOUtils.downLoadFromUrl(image, FileOUtils.getFileName(image), OcrConstant.FILE_DOWNLOAD_URL_PREFIX);
}
JSONObject requestBody = new JSONObject();
requestBody.put("task_id", task_id);
requestBody.put("img_path", image);
//nohup python app.py & tail -f nohup.out &
//更新主任务,正在识别中. conda activate ai
ocrIdentifyService.updateMasterTaskStartTime(task_id.split("_")[0]);
boolean flag=false;
@ -155,6 +161,7 @@ public class HandleTransInit implements ApplicationRunner {
while (!flag){
try {
semanticResponseJson = RestUtil.post(OcrConstant.api_test2_identify_url, requestBody);
//semanticResponseJson = JSONObject.parseObject("{\"img_path\":\"https://h5.mcnetmart.com/tmp/images/dc_demo1.png\",\"ocr_time\":3.4992809295654297,\"task_id\":\"1697133769514909698_1\",\"message\":\"成功\",\"semantic_result\":{\"ocr_res\":[[[[136.0,98.0],[276.0,70.0],[281.0,93.0],[141.0,121.0]],[\"深圳康瑞医院\",0.9387677311897278]],[[[139.0,120.0],[284.0,92.0],[288.0,109.0],[142.0,136.0]],[\"Shenzhen Kangrui hospual\",0.9168243408203125]],[[[171.0,284.0],[260.0,268.0],[264.0,292.0],[175.0,308.0]],[\"赵思杰\",0.9619879126548767]],[[[191.0,311.0],[247.0,301.0],[251.0,323.0],[195.0,333.0]],[\"妇产科\",0.9429848790168762]],[[[189.0,346.0],[259.0,332.0],[263.0,350.0],[193.0,364.0]],[\"主治医师\",0.8993821144104004]],[[[198.0,375.0],[263.0,364.0],[267.0,381.0],[201.0,393.0]],[\"202015\",0.9382884502410889]]],\"其他\":[{\"area\":[[139.0,120.0],[284.0,92.0],[288.0,109.0],[142.0,136.0]],\"end\":24,\"ocrText\":\"Shenzhen Kangrui hospual\",\"probability\":0.9846151031007864,\"start\":0,\"text\":\"Shenzhen Kangrui hospual\"},{\"area\":[[189.0,346.0],[259.0,332.0],[263.0,350.0],[193.0,364.0]],\"end\":4,\"ocrText\":\"主治医师\",\"probability\":0.9848503723946322,\"start\":0,\"text\":\"主治医师\"},{\"area\":[[198.0,375.0],[263.0,364.0],[267.0,381.0],[201.0,393.0]],\"end\":6,\"ocrText\":\"202015\",\"probability\":0.9731923600763821,\"start\":0,\"text\":\"202015\"}],\"医院名称\":[{\"area\":[[136.0,98.0],[276.0,70.0],[281.0,93.0],[141.0,121.0]],\"end\":6,\"ocrText\":\"深圳康瑞医院\",\"probability\":0.9856892892579268,\"start\":0,\"text\":\"深圳康瑞医院\"}],\"姓名\":[{\"area\":[[171.0,284.0],[260.0,268.0],[264.0,292.0],[175.0,308.0]],\"end\":3,\"ocrText\":\"赵思杰\",\"probability\":0.9996551423001598,\"start\":0,\"text\":\"赵思杰\"}],\"时间\":[],\"科室\":[{\"area\":[[191.0,311.0],[247.0,301.0],[251.0,323.0],[195.0,333.0]],\"end\":3,\"ocrText\":\"妇产科\",\"probability\":0.9983404968615517,\"start\":0,\"text\":\"妇产科\"}]},\"nlu_time\":16.85913324356079,\"identifyId\":\"1697133769514909698\"}");
if (semanticResponseJson!=null) {
flag=true;
}

@ -1,14 +1,16 @@
package org.jeecg.modules.ocr.utils;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import org.apache.commons.lang.StringUtils;
import java.io.File;
import java.io.InputStream;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* @Description
* @Author ZhouWenTao
@ -89,6 +91,92 @@ public class FileOUtils {
}
}
/**
* .
* @param fileUrl
* @return true,false:
*/
public static Boolean isOnlineFile(String fileUrl){
//网络目录
try {
URL url = new URL(fileUrl);
// 返回一个 URLConnection 对象,它表示到 URL 所引用的远程对象的连接。
URLConnection uc = url.openConnection();
// 打开的连接读取的输入流。
InputStream in = uc.getInputStream();
return true;
} catch (Exception e) {
//附件不存在
return false;
}
}
public static String getFileName(String fileUrl){
if (StringUtils.isBlank(fileUrl)) {
return null;
}
return fileUrl.substring(fileUrl.lastIndexOf("/") + 1, fileUrl.length());
}
/**
* Url
*
* @param urlStr
* @param fileName
* @param savePath
* @throws IOException
*/
public static String downLoadFromUrl(String urlStr, String fileName, String savePath) {
try {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 设置超时间为3秒
conn.setConnectTimeout(3 * 1000);
// 防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
// 得到输入流
InputStream inputStream = conn.getInputStream();
// 获取字节数组
byte[] getData = readInputStream(inputStream);
// 文件保存位置
File saveDir = new File(savePath);
if (!saveDir.exists()) {
saveDir.mkdir();
}
File file = new File(saveDir + File.separator + fileName);
FileOutputStream fos = new FileOutputStream(file);
fos.write(getData);
fos.close();
inputStream.close();
return saveDir + File.separator + fileName;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
/**
*
*
* @param inputStream
* @return
* @throws IOException
*/
public static byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}
public static void main(String[] args) {
List<String> stringList = fileLists(null,"E:\\workspace_2\\ocr\\images1");
System.out.println(stringList);

Loading…
Cancel
Save