提交修改
This commit is contained in:
parent
1197b7d078
commit
ba3fa83588
@ -16,25 +16,25 @@ public class BWebImageLocRequest extends BaiduOfdRequest {
|
||||
* - true:检测朝向;
|
||||
* - false:不检测朝向
|
||||
*/
|
||||
private String detectDirection;
|
||||
private String detectDirection = "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";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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<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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -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<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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -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;
|
||||
|
||||
}
|
||||
@ -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; // 表示定位位置的长方形的高度
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user