ocr请求接口
parent
d85aa47da4
commit
9039366bd6
@ -1,15 +0,0 @@
|
||||
package com.docus.server.vo.ocr;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@ApiModel(value = "BoxResult", description = "BoxResult")
|
||||
public class BoxResult {
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright 2023 json.cn
|
||||
*/
|
||||
package com.docus.server.vo.ocr;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2023-08-22 11:21:12
|
||||
*
|
||||
* @author json.cn (i@json.cn)
|
||||
* @website http://www.json.cn/java2pojo/
|
||||
*/
|
||||
public class Boxes {
|
||||
|
||||
private int left;
|
||||
private int right;
|
||||
private int top;
|
||||
private int bottom;
|
||||
|
||||
public void setLeft(int left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
public int getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
public void setRight(int right) {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public int getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
public void setTop(int top) {
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
public int getTop() {
|
||||
return top;
|
||||
}
|
||||
|
||||
public void setBottom(int bottom) {
|
||||
this.bottom = bottom;
|
||||
}
|
||||
|
||||
public int getBottom() {
|
||||
return bottom;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright 2023 json.cn
|
||||
*/
|
||||
package com.docus.server.vo.ocr;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2023-08-22 11:21:12
|
||||
*
|
||||
* @author json.cn (i@json.cn)
|
||||
* @website http://www.json.cn/java2pojo/
|
||||
*/
|
||||
public class Data {
|
||||
|
||||
private Boxes boxes;
|
||||
private String text;
|
||||
|
||||
public void setBoxes(Boxes boxes) {
|
||||
this.boxes = boxes;
|
||||
}
|
||||
|
||||
public Boxes getBoxes() {
|
||||
return boxes;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright 2023 json.cn
|
||||
*/
|
||||
package com.docus.server.vo.ocr;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2023-08-22 11:21:12
|
||||
*
|
||||
* @author json.cn (i@json.cn)
|
||||
* @website http://www.json.cn/java2pojo/
|
||||
*/
|
||||
public class Datas {
|
||||
|
||||
private int index;
|
||||
private String file_type;
|
||||
private String angle;
|
||||
private boolean decline;
|
||||
private boolean hand_shadow;
|
||||
private List<List<Sort>> sort;
|
||||
private List<Data> data;
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setFile_type(String file_type) {
|
||||
this.file_type = file_type;
|
||||
}
|
||||
|
||||
public String getFile_type() {
|
||||
return file_type;
|
||||
}
|
||||
|
||||
public void setAngle(String angle) {
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
public String getAngle() {
|
||||
return angle;
|
||||
}
|
||||
|
||||
public void setDecline(boolean decline) {
|
||||
this.decline = decline;
|
||||
}
|
||||
|
||||
public boolean getDecline() {
|
||||
return decline;
|
||||
}
|
||||
|
||||
public void setHand_shadow(boolean hand_shadow) {
|
||||
this.hand_shadow = hand_shadow;
|
||||
}
|
||||
|
||||
public boolean getHand_shadow() {
|
||||
return hand_shadow;
|
||||
}
|
||||
|
||||
public void setSort(List<List<Sort>> sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
public List<List<Sort>> getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void setData(List<Data> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public List<Data> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +1,51 @@
|
||||
package com.docus.server.vo.ocr;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
package com.docus.server.vo.ocr;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@ApiModel(value = "OcrResponse", description = "OcrResponse")
|
||||
/**
|
||||
* Auto-generated: 2023-08-22 11:21:12
|
||||
*
|
||||
* @author json.cn (i@json.cn)
|
||||
* @website http://www.json.cn/java2pojo/
|
||||
*/
|
||||
public class OcrResponse {
|
||||
|
||||
@ApiModelProperty(value = "是否成功")
|
||||
private boolean success;
|
||||
private List<Datas> datas;
|
||||
private double time;
|
||||
private String message;
|
||||
|
||||
@ApiModelProperty(value = "响应结果")
|
||||
private List<OcrVO> datas;
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "响应结果")
|
||||
private Long time;
|
||||
public boolean getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setDatas(List<Datas> datas) {
|
||||
this.datas = datas;
|
||||
}
|
||||
|
||||
public List<Datas> getDatas() {
|
||||
return datas;
|
||||
}
|
||||
|
||||
public void setTime(double time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public double getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "响应消息")
|
||||
private String message;
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package com.docus.server.vo.ocr;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@ApiModel(value = "OcrVO", description = "OcrVO")
|
||||
public class OcrVO {
|
||||
|
||||
@ApiModelProperty(value = "索引")
|
||||
private Long index;
|
||||
|
||||
@ApiModelProperty(value = "文件类型")
|
||||
@JsonProperty(value = "file_type")
|
||||
private String fileType;
|
||||
|
||||
@ApiModelProperty(value = "旋转角度")
|
||||
private String angle;
|
||||
|
||||
@ApiModelProperty(value = "下降")
|
||||
private boolean decline;
|
||||
|
||||
@ApiModelProperty(value = "手动阴影")
|
||||
@JsonProperty(value = "hand_shadow")
|
||||
private boolean handShadow;
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
private List<SortResult> sort;
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright 2023 json.cn
|
||||
*/
|
||||
package com.docus.server.vo.ocr;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2023-08-22 11:21:12
|
||||
*
|
||||
* @author json.cn (i@json.cn)
|
||||
* @website http://www.json.cn/java2pojo/
|
||||
*/
|
||||
public class Sort {
|
||||
|
||||
private Boxes boxes;
|
||||
private String text;
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public void setBoxes(Boxes boxes) {
|
||||
this.boxes = boxes;
|
||||
}
|
||||
|
||||
public Boxes getBoxes() {
|
||||
return boxes;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.docus.server.vo.ocr;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@ApiModel(value = "SortResult", description = "SortResult")
|
||||
public class SortResult {
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
private List<BoxResult> box;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.docus.server.controller;
|
||||
|
||||
import com.docus.server.api.ocr.OcrApi;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ocr API
|
||||
*
|
||||
* @author AutoGenerator
|
||||
* @since 2023-07-15
|
||||
*/
|
||||
@Api(value = "ocr", tags = "ocr")
|
||||
@RestController
|
||||
@RequestMapping("/ocr")
|
||||
public class OcrController {
|
||||
@Resource
|
||||
private OcrApi ocrApi;
|
||||
|
||||
@ApiOperation("ocr")
|
||||
@GetMapping("/ocr")
|
||||
public void ocr() throws Exception {
|
||||
List<String> text = ocrApi.getText("D:\\docus\\cut\\segmentation\\20230822\\c6b03e5767814895a2c155c32f174051\\麻醉.jpg");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.docus.server.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.docus.core.util.Func;
|
||||
import com.docus.server.api.ocr.OcrApi;
|
||||
import com.docus.server.vo.ocr.Datas;
|
||||
import com.docus.server.vo.ocr.OcrResponse;
|
||||
import com.docus.server.vo.ocr.Sort;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class OcrServiceImpl implements OcrApi {
|
||||
|
||||
@Value("${ocr.api-url:http://192.168.16.85:9999/uploadfile}")
|
||||
private String ocrHttpUrl;
|
||||
|
||||
@Override
|
||||
public List<String> getText(String path) {
|
||||
OcrResponse response = ocr(path);
|
||||
|
||||
List<Datas> datas = response.getDatas();
|
||||
|
||||
List<String> texts = new ArrayList<>();
|
||||
|
||||
if (Func.isNotEmpty(datas)) {
|
||||
datas.forEach(p -> {
|
||||
List<List<Sort>> sorts = p.getSort();
|
||||
|
||||
if (Func.isNotEmpty(sorts)) {
|
||||
sorts.forEach(s -> s.forEach(l -> {
|
||||
String text = l.getText();
|
||||
|
||||
texts.add(text);
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return texts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OcrResponse ocr(String path) {
|
||||
File file = new File(path);
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("file", file);
|
||||
data.put("filetype", "jpg");
|
||||
return uploadFile(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OcrResponse uploadFile(Map<String, Object> params) {
|
||||
|
||||
String body = HttpRequest.post(ocrHttpUrl)
|
||||
.form(params)
|
||||
.contentType("multipart/form-data")
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
if (StrUtil.isNotBlank(body)) {
|
||||
return JSON.parseObject(body, OcrResponse.class);
|
||||
}
|
||||
|
||||
return new OcrResponse();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue