提交修改

This commit is contained in:
quyixiao 2025-03-23 14:23:34 +08:00
parent 1197b7d078
commit ba3fa83588
6 changed files with 288 additions and 5 deletions

View File

@ -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";
}

View File

@ -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&timestamp=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<SealResp> respList = new ArrayList<>();
ApiR<BSealResp> bR = bSealHandle.handle(request);
if (bR.isSuccess()) {
BSealResp bSealResp = bR.getData();
List<BSealResp.ResultDTO> 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<SealOtherResp> 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();
}
}

View File

@ -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&timestamp=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<WebImageLocLineResp> respList = new ArrayList<>();
ApiR<BWebImageLocResp> 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();
}
}

View File

@ -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;
}

View File

@ -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<SealOtherResp> otherSealList;
}

View File

@ -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; // 表示定位位置的长方形的高度
}
}