From ba3fa835883ecc51b62ce82e07ecada7bccadeb2 Mon Sep 17 00:00:00 2001 From: quyixiao <2621048238@qq.com> Date: Sun, 23 Mar 2025 14:23:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/common/BWebImageLocRequest.java | 10 +-- .../api/controller/common/SealController.java | 85 +++++++++++++++++++ .../common/WebImageLocLineController.java | 85 +++++++++++++++++++ .../heyu/api/resp/common/SealOtherResp.java | 24 ++++++ .../com/heyu/api/resp/common/SealResp.java | 31 +++++++ .../api/resp/common/WebImageLocLineResp.java | 58 +++++++++++++ 6 files changed, 288 insertions(+), 5 deletions(-) create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/controller/common/SealController.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/controller/common/WebImageLocLineController.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/resp/common/SealOtherResp.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/resp/common/SealResp.java create mode 100644 api-web/api-interface/src/main/java/com/heyu/api/resp/common/WebImageLocLineResp.java diff --git a/api-third/src/main/java/com/heyu/api/baidu/request/common/BWebImageLocRequest.java b/api-third/src/main/java/com/heyu/api/baidu/request/common/BWebImageLocRequest.java index ca28969..1122332 100644 --- a/api-third/src/main/java/com/heyu/api/baidu/request/common/BWebImageLocRequest.java +++ b/api-third/src/main/java/com/heyu/api/baidu/request/common/BWebImageLocRequest.java @@ -16,25 +16,25 @@ public class BWebImageLocRequest extends BaiduOfdRequest { * - true:检测朝向; * - false:不检测朝向 */ - private String detectDirection; + private String detectDirection = "false"; /** - * 是否返回每行识别结果的置信度。默认为false + * 是否返回每行识别结果的置信度。默认为 false */ - private String probability; + private String probability = "true"; /** * true/false 是否返回文字所在区域的外接四边形的4个点坐标信息。默认为false */ - private String polyLocation; + private String polyLocation = "false"; /** * string big/small 是否定位单字符位置,big:不定位单字符位置,默认值;small:定位单字符位置 */ - private String recognizeGranularity; + private String recognizeGranularity = "small"; } diff --git a/api-web/api-interface/src/main/java/com/heyu/api/controller/common/SealController.java b/api-web/api-interface/src/main/java/com/heyu/api/controller/common/SealController.java new file mode 100644 index 0000000..584cd6f --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/controller/common/SealController.java @@ -0,0 +1,85 @@ +package com.heyu.api.controller.common; + + +import com.heyu.api.baidu.handle.common.BSealHandle; +import com.heyu.api.baidu.request.common.BSealRequest; +import com.heyu.api.baidu.response.common.BSealResp; +import com.heyu.api.controller.BaseController; +import com.heyu.api.data.annotation.CacheResult; +import com.heyu.api.data.annotation.NotIntercept; +import com.heyu.api.data.utils.ApiR; +import com.heyu.api.data.utils.R; +import com.heyu.api.resp.common.SealOtherResp; +import com.heyu.api.resp.common.SealResp; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +/*** + * https://console.bce.baidu.com/support/?_=1740219852952×tamp=1742702349425#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E9%80%9A%E7%94%A8%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Fseal&method=post + * + * 印章识别 + * + *接口描述 + * 检测并识别合同文件或常用票据中的印章,输出文字内容、印章位置信息以及相关置信度,支持识别印章编码,可覆盖圆形章、椭圆形章、方形章等常见种类的印章。 + * + * + * + */ +@Slf4j +@RestController +@RequestMapping("/seal") +@NotIntercept +public class SealController extends BaseController { + + + @Autowired + private BSealHandle bSealHandle; + + @RequestMapping("/recognize") + @CacheResult + public R recognize(BSealRequest request) { + + List respList = new ArrayList<>(); + + ApiR bR = bSealHandle.handle(request); + if (bR.isSuccess()) { + BSealResp bSealResp = bR.getData(); + + List resultDTOList = bSealResp.getResult(); + if (CollectionUtils.isNotEmpty(resultDTOList)) { + for (BSealResp.ResultDTO resultDTO : resultDTOList) { + SealResp resp = new SealResp(); + resp.setType(resultDTO.getType()); + resp.setMajorWords(resultDTO.getMajor().getWords()); + + if (CollectionUtils.isNotEmpty(resultDTO.getMinor())) { + List sealOtherResps = new ArrayList<>(); + for (BSealResp.ResultDTO.MinorDTO minorDTO : resultDTO.getMinor()) { + + SealOtherResp otherResp = new SealOtherResp(); + + otherResp.setMinorWords(minorDTO.getWords()); + otherResp.setMinorProbability(minorDTO.getProbability() + ""); + + sealOtherResps.add(otherResp); + + } + resp.setOtherSealList(sealOtherResps); + } + respList.add(resp); + } + return R.ok().setData(respList); + } + + } + + return R.error(); + } + +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/controller/common/WebImageLocLineController.java b/api-web/api-interface/src/main/java/com/heyu/api/controller/common/WebImageLocLineController.java new file mode 100644 index 0000000..a573204 --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/controller/common/WebImageLocLineController.java @@ -0,0 +1,85 @@ +package com.heyu.api.controller.common; + + +import com.heyu.api.baidu.handle.common.BWebImageLocHandle; +import com.heyu.api.baidu.request.common.BWebImageLocRequest; +import com.heyu.api.baidu.response.common.BWebImageLocResp; +import com.heyu.api.data.annotation.CacheResult; +import com.heyu.api.data.annotation.NotIntercept; +import com.heyu.api.data.utils.ApiR; +import com.heyu.api.data.utils.R; +import com.heyu.api.resp.common.WebImageLocLineResp; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +/** + * https://console.bce.baidu.com/support/?_=1740219852952×tamp=1740294887952#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E9%80%9A%E7%94%A8%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Fwebimage_loc&method=post + * 网络图片文字识别(含位置版) + * + * + * + */ +@Slf4j +@RestController +@RequestMapping("/image/web/line") +@NotIntercept +public class WebImageLocLineController { + + + @Autowired + private BWebImageLocHandle bWebImageLocHandle; + + + @RequestMapping("/recognize") + @CacheResult + public R recognize(BWebImageLocRequest request) { + + List respList = new ArrayList<>(); + + ApiR bR = bWebImageLocHandle.handle(request); + if(bR.isSuccess()){ + + BWebImageLocResp bWebImageLocResp = bR.getData(); + if(CollectionUtils.isNotEmpty(bWebImageLocResp.getWordsResult())){ + for (BWebImageLocResp.WordsResultDTO wordsResultDTO : bWebImageLocResp.getWordsResult()) { + WebImageLocLineResp resp = new WebImageLocLineResp(); + + resp.setWords(wordsResultDTO.getWords()); + // 当 probability=true 时返回该字段。识别结果中每一行的置信度值,包含 average:行置信度平均值,variance:行置信度方差,min:行置信度最小值 + WebImageLocLineResp.ProbabilityDTO probabilityDTO = new WebImageLocLineResp.ProbabilityDTO(); + + WebImageLocLineResp.LocationDTO locationDTO = new WebImageLocLineResp.LocationDTO(); + + if(wordsResultDTO.getProbability() !=null){ + + probabilityDTO.setMin(wordsResultDTO.getProbability().getMin()); + probabilityDTO.setVariance(wordsResultDTO.getProbability().getVariance()); + probabilityDTO.setAverage(wordsResultDTO.getProbability().getAverage()); + + } + + if(wordsResultDTO.getLocation() !=null){ + locationDTO.setTop(wordsResultDTO.getLocation().getTop()); + locationDTO.setLeft(wordsResultDTO.getLocation().getLeft()); + locationDTO.setWidth(wordsResultDTO.getLocation().getWidth()); + locationDTO.setHeight(wordsResultDTO.getLocation().getHeight()); + } + + resp.setProbability(probabilityDTO); + resp.setLocation(locationDTO); + + + respList.add(resp); + } + } + } + return R.error(); + } + +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/resp/common/SealOtherResp.java b/api-web/api-interface/src/main/java/com/heyu/api/resp/common/SealOtherResp.java new file mode 100644 index 0000000..95ddfc5 --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/resp/common/SealOtherResp.java @@ -0,0 +1,24 @@ +package com.heyu.api.resp.common; + +import com.heyu.api.data.dto.BaseResp; +import lombok.Data; + + +@Data +public class SealOtherResp extends BaseResp { + + + + /*** + * 其他字段内容,即除主字段外的文字识别内容均放置于该参数中返回,数字编码也在该字段返回。若章内不存在其他字段文字,则该参数为空 + */ + private String minorWords; + + /*** + * 其他字段内容置信度 + */ + private String minorProbability; + + + +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/resp/common/SealResp.java b/api-web/api-interface/src/main/java/com/heyu/api/resp/common/SealResp.java new file mode 100644 index 0000000..a31fa41 --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/resp/common/SealResp.java @@ -0,0 +1,31 @@ +package com.heyu.api.resp.common; + +import com.heyu.api.data.dto.BaseResp; +import lombok.Data; + +import java.util.List; + + +@Data +public class SealResp extends BaseResp { + + + /*** + * 主字段内容,即章内上环弯曲文字 + */ + private String majorWords; + /*** + * 主字段内容置信度值 + */ + private String majorProbability; + + + /*** + * 印章的类别,共有circle(圆章),ellipse(椭圆章),rectangle(方章)三种 + */ + private String type; + + + private List otherSealList; + +} diff --git a/api-web/api-interface/src/main/java/com/heyu/api/resp/common/WebImageLocLineResp.java b/api-web/api-interface/src/main/java/com/heyu/api/resp/common/WebImageLocLineResp.java new file mode 100644 index 0000000..de4cd4c --- /dev/null +++ b/api-web/api-interface/src/main/java/com/heyu/api/resp/common/WebImageLocLineResp.java @@ -0,0 +1,58 @@ +package com.heyu.api.resp.common; + + +import com.heyu.api.data.dto.BaseResp; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +public class WebImageLocLineResp extends BaseResp { + + /*** + * 图像方向,当 detect_direction=true 时返回该字段。检测到的图像朝向: + * - - 1:未定义; + * - 0 :正向; + * - 1:逆时针旋转90度; + * - 2:逆时针旋转180度; + * - 3:逆时针旋转270度 + */ + private String direction; + + + /*** + * 文字 + */ + private String words; + + /*** + * 当 probability=true 时返回该字段。识别结果中每一行的置信度值,包含average:行置信度平均值,variance:行置信度方差,min:行置信度最小值 + */ + private ProbabilityDTO probability; + + /*** + * 整行的矩形框坐标。位置数组(坐标0点为左上角) + */ + private LocationDTO location; + + + + // 当 probability=true 时返回该字段。识别结果中每一行的置信度值,包含average:行置信度平均值,variance:行置信度方差,min:行置信度最小值 + @NoArgsConstructor + @Data + public static class ProbabilityDTO { + private Double average; + private Double min; + private Integer variance; + } + + @NoArgsConstructor + @Data + public static class LocationDTO { + private Integer top; // 表示定位位置的长方形左上顶点的垂直坐标 + private Integer left; // 表示定位位置的长方形左上顶点的水平坐标 + private Integer width; // 表示定位位置的长方形的宽度 + private Integer height; // 表示定位位置的长方形的高度 + } + + +}