提交修改
This commit is contained in:
parent
8ddfdb1d7f
commit
ba26de2889
@ -22,5 +22,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
package com.heyu.api.alibaba.request.common.text;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class GeneralBasicOcrRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* 是否必选: 和 url/pdf_file/ofd_file 四选一
|
||||
* 类型: string
|
||||
* 说明:
|
||||
* 图像数据,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过8M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式
|
||||
* 优先级:image > url > pdf_file > ofd_file ,当image字段存在时,url、pdf_file、ofd_file 字段失效
|
||||
*/
|
||||
private String imageBase64;
|
||||
|
||||
/**
|
||||
* 和 image/pdf_file/ofd_file 四选一
|
||||
* 说明 :
|
||||
* 图片完整url,url长度不超过1024字节,url对应的图片base64编码后大小不超过8M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式
|
||||
* 优先级:image > url > pdf_file > ofd_file,当image字段存在时,url字段失效
|
||||
* 请注意关闭URL防盗链
|
||||
*/
|
||||
private String imageUrl;
|
||||
|
||||
/**
|
||||
*
|
||||
* 和 image/url 三选一
|
||||
* PDF文件,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过4M,最短边至少15px,最长边最大4096px
|
||||
* 优先级:image > url > pdf_file,当image、url字段存在时,pdf_file字段失效
|
||||
*/
|
||||
private String pdfFile;
|
||||
|
||||
|
||||
// 需要识别的PDF文件的对应页码,当 pdf_file 参数有效时,识别传入页码的对应页面内容,若不传入,则默认识别第 1 页
|
||||
private String pdfFileNum = "1";
|
||||
|
||||
/**
|
||||
* 和 image/url/pdf_file 四选一
|
||||
* OFD文件,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过8M,最短边至少15px,最长边最大8192px
|
||||
* 优先级:image > url > pdf_file > ofd_file,当image、url、pdf_file字段存在时,ofd_file字段失效
|
||||
*/
|
||||
private String ofdFile;
|
||||
|
||||
/**
|
||||
* ofd_file_num
|
||||
* 需要识别的OFD文件的对应页码,当 ofd_file 参数有效时,识别传入页码的对应页面内容,若不传入,则默认识别第 1 页
|
||||
*/
|
||||
private String ofdFileNum = "1";
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package com.heyu.api.alibaba.request.common.text;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HighPrecisionOcrRequest {
|
||||
|
||||
/**
|
||||
* 是否必选: 和 url/pdf_file/ofd_file 四选一
|
||||
* 类型: string
|
||||
* 说明:
|
||||
* 图像数据,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过8M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式
|
||||
* 优先级:image > url > pdf_file > ofd_file ,当image字段存在时,url、pdf_file、ofd_file 字段失效
|
||||
*/
|
||||
private String imageBase64;
|
||||
|
||||
/**
|
||||
* 和 image/pdf_file/ofd_file 四选一
|
||||
* 说明 :
|
||||
* 图片完整url,url长度不超过1024字节,url对应的图片base64编码后大小不超过8M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式
|
||||
* 优先级:image > url > pdf_file > ofd_file,当image字段存在时,url字段失效
|
||||
* 请注意关闭URL防盗链
|
||||
*/
|
||||
private String imageUrl;
|
||||
|
||||
/**
|
||||
*
|
||||
* 和 image/url 三选一
|
||||
* PDF文件,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过4M,最短边至少15px,最长边最大4096px
|
||||
* 优先级:image > url > pdf_file,当image、url字段存在时,pdf_file字段失效
|
||||
*/
|
||||
private String pdfFile;
|
||||
|
||||
|
||||
// 需要识别的PDF文件的对应页码,当 pdf_file 参数有效时,识别传入页码的对应页面内容,若不传入,则默认识别第 1 页
|
||||
private String pdfFileNum = "1";
|
||||
|
||||
/**
|
||||
* 和 image/url/pdf_file 四选一
|
||||
* OFD文件,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过8M,最短边至少15px,最长边最大8192px
|
||||
* 优先级:image > url > pdf_file > ofd_file,当image、url、pdf_file字段存在时,ofd_file字段失效
|
||||
*/
|
||||
private String ofdFile;
|
||||
|
||||
/**
|
||||
* ofd_file_num
|
||||
* 需要识别的OFD文件的对应页码,当 ofd_file 参数有效时,识别传入页码的对应页面内容,若不传入,则默认识别第 1 页
|
||||
*/
|
||||
private String ofdFileNum = "1";
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.heyu.api.baidu.ocr;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
|
||||
public class HighPrecisionOcrResp {
|
||||
|
||||
/***
|
||||
* 文本
|
||||
*/
|
||||
private String text;
|
||||
|
||||
|
||||
/***
|
||||
* 行置信度
|
||||
*/
|
||||
private LineProbabilityResp lineProbabilityResp;
|
||||
|
||||
|
||||
/***
|
||||
* 这一行的位置
|
||||
*/
|
||||
private WordsLocationResp wordsLocationResp;
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.heyu.api.baidu.ocr;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LineProbabilityResp {
|
||||
|
||||
|
||||
/**
|
||||
* 每个字符 最小置信度
|
||||
*/
|
||||
private Double min;
|
||||
|
||||
|
||||
/**
|
||||
* 平均置信度
|
||||
*/
|
||||
private Double average;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.heyu.api.baidu.ocr;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WordsLocationResp {
|
||||
|
||||
|
||||
|
||||
private Integer left;
|
||||
|
||||
private Integer height;
|
||||
|
||||
private Integer width;
|
||||
|
||||
|
||||
private Integer top;
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
package com.heyu.api.controller.ocr;
|
||||
|
||||
|
||||
import com.heyu.api.alibaba.request.common.text.GeneralBasicOcrRequest;
|
||||
import com.heyu.api.baidu.handle.common.BGeneralBasicHandle;
|
||||
import com.heyu.api.baidu.request.common.BGeneralBasicRequest;
|
||||
import com.heyu.api.baidu.response.common.BGeneralBasicResp;
|
||||
import com.heyu.api.controller.BaseController;
|
||||
import com.heyu.api.data.annotation.EbAuthentication;
|
||||
import com.heyu.api.data.constants.ApiConstants;
|
||||
import com.heyu.api.data.utils.ApiR;
|
||||
import com.heyu.api.data.utils.R;
|
||||
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://market.aliyun.com/apimarket/detail/cmapi00066584#sku=yuncode60584000011
|
||||
*
|
||||
* *
|
||||
* *银行卡二要素核验
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/general/text/orc/")
|
||||
public class GeneralBasicOcrController extends BaseController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private BGeneralBasicHandle bGeneralBasicHandle;
|
||||
|
||||
|
||||
// http://localhost:8888/bank/card/3/verify?bankCard=6214855713516769&realName=瞿贻晓&idCardNumber=430529199209255030
|
||||
@EbAuthentication(tencent = ApiConstants.TENCENT_AUTH)
|
||||
@RequestMapping("/recognize")
|
||||
public R recognize(GeneralBasicOcrRequest generalBasicOcrRequest) {
|
||||
BGeneralBasicRequest bGeneralBasicRequest = new BGeneralBasicRequest();
|
||||
|
||||
bGeneralBasicRequest.setImageBase64(generalBasicOcrRequest.getImageBase64());
|
||||
bGeneralBasicRequest.setImageUrl(generalBasicOcrRequest.getImageUrl());
|
||||
bGeneralBasicRequest.setPdfFile(generalBasicOcrRequest.getPdfFile());
|
||||
bGeneralBasicRequest.setPdfFileNum(generalBasicOcrRequest.getPdfFileNum());
|
||||
bGeneralBasicRequest.setOfd_file(generalBasicOcrRequest.getOfdFile());
|
||||
bGeneralBasicRequest.setOfd_file_num(generalBasicOcrRequest.getOfdFileNum());
|
||||
|
||||
ApiR<BGeneralBasicResp> aR = bGeneralBasicHandle.handle(bGeneralBasicRequest);
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
if(aR.isSuccess()){
|
||||
BGeneralBasicResp bGeneralBasicResp = aR.getData();
|
||||
if(CollectionUtils.isNotEmpty(bGeneralBasicResp.getWordsResult())){
|
||||
for (BGeneralBasicResp.WordsResultDTO wordsResultDTO : bGeneralBasicResp.getWordsResult()) {
|
||||
list.add(wordsResultDTO.getWords());
|
||||
}
|
||||
}
|
||||
}
|
||||
return R.ok();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package com.heyu.api.controller.ocr;
|
||||
|
||||
|
||||
import com.heyu.api.alibaba.request.common.text.HighPrecisionOcrRequest;
|
||||
import com.heyu.api.baidu.handle.common.BDocAnalysisOfficeHandle;
|
||||
import com.heyu.api.baidu.ocr.HighPrecisionOcrResp;
|
||||
import com.heyu.api.baidu.ocr.LineProbabilityResp;
|
||||
import com.heyu.api.baidu.ocr.WordsLocationResp;
|
||||
import com.heyu.api.baidu.request.common.BDocAnalysisOfficeRequest;
|
||||
import com.heyu.api.baidu.response.common.BDocAnalysisOfficeResp;
|
||||
import com.heyu.api.data.annotation.EbAuthentication;
|
||||
import com.heyu.api.data.constants.ApiConstants;
|
||||
import com.heyu.api.data.utils.ApiR;
|
||||
import com.heyu.api.data.utils.R;
|
||||
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;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/high/precision/orc/")
|
||||
public class HighPrecisionOcrController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private BDocAnalysisOfficeHandle bDocAnalysisOfficeHandle;
|
||||
|
||||
|
||||
// http://localhost:8888/bank/card/3/verify?bankCard=6214855713516769&realName=瞿贻晓&idCardNumber=430529199209255030
|
||||
@EbAuthentication(tencent = ApiConstants.TENCENT_AUTH)
|
||||
@RequestMapping("/recognize")
|
||||
public R recognize(HighPrecisionOcrRequest generalBasicOcrRequest) {
|
||||
|
||||
BDocAnalysisOfficeRequest bGeneralBasicRequest = new BDocAnalysisOfficeRequest();
|
||||
bGeneralBasicRequest.setImageBase64(generalBasicOcrRequest.getImageBase64());
|
||||
bGeneralBasicRequest.setImageUrl(generalBasicOcrRequest.getImageUrl());
|
||||
bGeneralBasicRequest.setPdfFile(generalBasicOcrRequest.getPdfFile());
|
||||
bGeneralBasicRequest.setPdfFileNum(generalBasicOcrRequest.getPdfFileNum());
|
||||
bGeneralBasicRequest.setOfd_file(generalBasicOcrRequest.getOfdFile());
|
||||
bGeneralBasicRequest.setOfd_file_num(generalBasicOcrRequest.getOfdFileNum());
|
||||
bGeneralBasicRequest.setLineProbability("true");
|
||||
|
||||
ApiR<BDocAnalysisOfficeResp> aR = bDocAnalysisOfficeHandle.handle(bGeneralBasicRequest);
|
||||
List<HighPrecisionOcrResp> list = new ArrayList<>();
|
||||
if(aR.isSuccess()){
|
||||
BDocAnalysisOfficeResp bGeneralBasicResp = aR.getData();
|
||||
if(CollectionUtils.isNotEmpty(bGeneralBasicResp.getResults())){
|
||||
for (BDocAnalysisOfficeResp.ResultsDTO result : bGeneralBasicResp.getResults()) {
|
||||
BDocAnalysisOfficeResp.ResultsDTO.WordsDTO wordsDTO = result.getWords();
|
||||
if(wordsDTO !=null){
|
||||
HighPrecisionOcrResp highPrecisionOcrResp = new HighPrecisionOcrResp();
|
||||
highPrecisionOcrResp.setText(wordsDTO.getWord());
|
||||
|
||||
BDocAnalysisOfficeResp.ResultsDTO.WordsDTO.LineProbabilityDTO lineProbabilityDTO = wordsDTO.getLineProbability();
|
||||
|
||||
|
||||
LineProbabilityResp lineProbabilityResp = new LineProbabilityResp();
|
||||
lineProbabilityResp.setMin(lineProbabilityDTO.getMin());
|
||||
lineProbabilityResp.setAverage(lineProbabilityDTO.getAverage());
|
||||
|
||||
|
||||
highPrecisionOcrResp.setLineProbabilityResp(lineProbabilityResp);
|
||||
|
||||
BDocAnalysisOfficeResp.ResultsDTO.WordsDTO.WordsLocationDTO wordsLocationDTO = wordsDTO.getWordsLocation();
|
||||
|
||||
|
||||
WordsLocationResp wordsLocationResp = new WordsLocationResp();
|
||||
wordsLocationResp.setHeight(wordsLocationDTO.getHeight());
|
||||
wordsLocationResp.setWidth(wordsLocationDTO.getWidth());
|
||||
wordsLocationResp.setTop(wordsLocationDTO.getTop());
|
||||
wordsLocationResp.setLeft(wordsLocationDTO.getLeft());
|
||||
|
||||
highPrecisionOcrResp.setWordsLocationResp(wordsLocationResp);
|
||||
|
||||
list.add(highPrecisionOcrResp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return R.error("识别错误");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -78,4 +78,25 @@ public class Test1 {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test5(){
|
||||
|
||||
int buyerId1 = 1;
|
||||
int buyerId2 = 2;
|
||||
//int i = 32289328;
|
||||
int i = 322525;
|
||||
|
||||
int a = i* 10000 + buyerId1 % 10000;
|
||||
|
||||
|
||||
a = Math.abs(a ) % 1000% 1024;
|
||||
|
||||
|
||||
System.out.println("a = "+ a);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user