Przeglądaj źródła

ocr修改

master
yangpeilai 2 miesięcy temu
rodzic
commit
af2dd849a1

+ 0
- 4
gly-base-core/src/main/java/cn/com/taiji/core/model/comm/protocol/ats/ocr/BusinessLicenseOcrRequest.java Wyświetl plik

@Setter @Setter
public class BusinessLicenseOcrRequest extends AbstractAtsRequest<BusinessLicenseOcrResponse> { public class BusinessLicenseOcrRequest extends AbstractAtsRequest<BusinessLicenseOcrResponse> {


//2-反面、1-正面
@Pattern(regexp = "[1|2]",message = "图片类型输入错误,应为1:正面,2:反面")
@NotBlank
private String imageType;
//图片地址 //图片地址
@NotBlank(message = "图片地址不能为空") @NotBlank(message = "图片地址不能为空")
private String url; private String url;

+ 1
- 1
gly-base-core/src/main/java/cn/com/taiji/core/model/comm/protocol/ats/ocr/OcrServiceCmd.java Wyświetl plik



@Override @Override
public SignServiceType getServiceType() { public SignServiceType getServiceType() {
return AtsServiceType.ANXINSIGN;
return AtsServiceType.OCR;
} }


public static OcrServiceCmd fromIfCode(String ifCode) { public static OcrServiceCmd fromIfCode(String ifCode) {

+ 14
- 22
zhywpt-service-ats/src/main/java/cn/com/taiji/ats/manager/ocr/BusinessLicenseOcrManager.java Wyświetl plik

if(!StringTools.hasText(req.getUrl())){ if(!StringTools.hasText(req.getUrl())){
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请传入图片地址"); throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请传入图片地址");
} }
if(!StringTools.hasText(req.getImageType())){
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请传入图片类型");
}
return doBusiness(req); return doBusiness(req);
} }


public BusinessLicenseOcrResponse doBusiness(BusinessLicenseOcrRequest req) throws ServiceHandleException { public BusinessLicenseOcrResponse doBusiness(BusinessLicenseOcrRequest req) throws ServiceHandleException {
BusinessLicenseOcrResponse res = baiduOcrUsingBase64(req);
logger.info("营业执照识别结果>{}", res);
return res;
try {
URL url = new URL(req.getUrl());
URL downloadUrl = new URL("http", "100.64.2.113", 9000, url.getPath());

String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(downloadUrl.toString());
BusinessLicenseOcrResponse res = baiduOcr(compressedImgBase64);
res.setImageUrl(url == null ? "" : url.toString());
logger.info("营业执照识别结果>{}", res);
return res;
} catch (Exception e) {
logger.error("身份证OCR处理失败", e);
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("很抱歉,我们无法识别您的证件,请按规范上传正副页,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影");
}
} }
public BusinessLicenseOcrResponse baiduOcr(String imgBase64, String imageType) throws ServiceHandleException {
public BusinessLicenseOcrResponse baiduOcr(String imgBase64) throws ServiceHandleException {
try { try {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
BusinessLicenseOcrResponse res = baiduOcrUtil.ocrBusinessLicenseRecognize(imgBase64); BusinessLicenseOcrResponse res = baiduOcrUtil.ocrBusinessLicenseRecognize(imgBase64);
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("用户证件识别失败:" + e.getMessage()); throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("用户证件识别失败:" + e.getMessage());
} }
} }

public BusinessLicenseOcrResponse baiduOcrUsingBase64(BusinessLicenseOcrRequest request) throws ServiceHandleException {
try {
URL url = new URL(request.getUrl());
URL downloadUrl = new URL("http", "100.64.2.113", 9000, url.getPath());

String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(downloadUrl.toString());
BusinessLicenseOcrResponse res = baiduOcr(compressedImgBase64, request.getImageType());
res.setImageUrl(url == null ? "" : url.toString());
return res;
} catch (Exception e) {
logger.error("身份证OCR处理失败", e);
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("很抱歉,我们无法识别您的证件,请按规范上传正副页,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影");
}
}
} }

+ 13
- 18
zhywpt-service-ats/src/main/java/cn/com/taiji/ats/manager/ocr/IdCardOcrManager.java Wyświetl plik

} }


public IdCardOcrResponse doBusiness(IdCardOcrRequest req) throws ServiceHandleException { public IdCardOcrResponse doBusiness(IdCardOcrRequest req) throws ServiceHandleException {
IdCardOcrResponse res = baiduOcrUsingBase64(req);
logger.info("身份证识别结果>{}", res);
return res;
try {
URL url = new URL(req.getUrl());
URL downloadUrl = new URL("http", "100.64.2.113", 9000, url.getPath());

String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(downloadUrl.toString());
IdCardOcrResponse res = baiduOcr(compressedImgBase64, req.getImageType());
res.setImageUrl(url == null ? "" : url.toString());
logger.info("身份证识别结果>{}", res);
return res;
} catch (Exception e) {
logger.error("身份证OCR处理失败", e);
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("很抱歉,我们无法识别您的证件,请按规范上传正副页,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影");
}
} }
public IdCardOcrResponse baiduOcr(String imgBase64, String imageType) throws ServiceHandleException { public IdCardOcrResponse baiduOcr(String imgBase64, String imageType) throws ServiceHandleException {
try { try {
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("用户证件识别失败:" + e.getMessage()); throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("用户证件识别失败:" + e.getMessage());
} }
} }

public IdCardOcrResponse baiduOcrUsingBase64(IdCardOcrRequest request) throws ServiceHandleException {
try {
URL url = new URL(request.getUrl());
URL downloadUrl = new URL("http", "100.64.2.113", 9000, url.getPath());

String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(downloadUrl.toString());
IdCardOcrResponse res = baiduOcr(compressedImgBase64, request.getImageType());
res.setImageUrl(url == null ? "" : url.toString());
return res;
} catch (Exception e) {
logger.error("身份证OCR处理失败", e);
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("很抱歉,我们无法识别您的证件,请按规范上传正副页,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影");
}
}
} }

+ 13
- 18
zhywpt-service-ats/src/main/java/cn/com/taiji/ats/manager/ocr/VehicleLicenseOcrManager.java Wyświetl plik

} }


public VehicleLicenseOcrResponse doBusiness(VehicleLicenseOcrRequest req) throws ServiceHandleException { public VehicleLicenseOcrResponse doBusiness(VehicleLicenseOcrRequest req) throws ServiceHandleException {
VehicleLicenseOcrResponse res = baiduOcrUsingBase64(req);
logger.info("驾驶证识别结果>{}", res);
return res;
try {
URL url = new URL(req.getUrl());
URL downloadUrl = new URL("http", "100.64.2.113", 9000, url.getPath());

String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(downloadUrl.toString());
VehicleLicenseOcrResponse res = baiduOcr(compressedImgBase64, req.getImageType());
res.setImageUrl(url == null ? "" : url.toString());
logger.info("驾驶证识别结果>{}", res);
return res;
} catch (Exception e) {
logger.error("身份证OCR处理失败", e);
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("很抱歉,我们无法识别您的证件,请按规范上传正副页,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影");
}
} }
public VehicleLicenseOcrResponse baiduOcr(String imgBase64, String imageType) throws ServiceHandleException { public VehicleLicenseOcrResponse baiduOcr(String imgBase64, String imageType) throws ServiceHandleException {
try { try {
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("用户证件识别失败:" + e.getMessage()); throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("用户证件识别失败:" + e.getMessage());
} }
} }

public VehicleLicenseOcrResponse baiduOcrUsingBase64(VehicleLicenseOcrRequest request) throws ServiceHandleException {
try {
URL url = new URL(request.getUrl());
URL downloadUrl = new URL("http", "100.64.2.113", 9000, url.getPath());

String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(downloadUrl.toString());
VehicleLicenseOcrResponse res = baiduOcr(compressedImgBase64, request.getImageType());
res.setImageUrl(url == null ? "" : url.toString());
return res;
} catch (Exception e) {
logger.error("身份证OCR处理失败", e);
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("很抱歉,我们无法识别您的证件,请按规范上传正副页,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影");
}
}
} }

Ładowanie…
Anuluj
Zapisz