新增了身份证识别,去除了反面114444
This commit is contained in:
parent
3b3c734c8a
commit
7356d6806e
@ -27,4 +27,22 @@ public class Ocr extends Base {
|
|||||||
throw new BusinessException("OCR识别失败: " + e.getMessage());
|
throw new BusinessException("OCR识别失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文字识别
|
||||||
|
*/
|
||||||
|
public JSONObject image(byte[] imageBytes) {
|
||||||
|
try {
|
||||||
|
HashMap<String, String> options = new HashMap<>();
|
||||||
|
options.put("language_type", "CHN_ENG");
|
||||||
|
options.put("detect_direction", "true");
|
||||||
|
options.put("detect_language", "true");
|
||||||
|
options.put("probability", "true");
|
||||||
|
|
||||||
|
return ocrClient.basicGeneral(imageBytes, options);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException("OCR识别失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,28 @@ public class ImageController {
|
|||||||
return ResponseDTO.userErrorParam("参数错误");
|
return ResponseDTO.userErrorParam("参数错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 解码 Base64 字符串为字节数组
|
||||||
|
byte[] frontBytes = Base64.getDecoder().decode(form.getFrontBase64());
|
||||||
|
|
||||||
|
// 调用 Service
|
||||||
|
GetIdCardOcrVo result = ocrService.getIdCardOcr(frontBytes);
|
||||||
|
return ResponseDTO.app_ok(result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseDTO.userErrorParam("识别失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "通用文字识别-ocr")
|
||||||
|
@PostMapping("/ocr/image")
|
||||||
|
public ResponseDTO<GetIdCardOcrVo> getImageOcr(
|
||||||
|
@RequestBody @Valid GetIdCardOcrForm form
|
||||||
|
){
|
||||||
|
if (form.getFrontBase64() == null || form.getFrontBase64().isEmpty()) {
|
||||||
|
return ResponseDTO.userErrorParam("参数错误");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 解码 Base64 字符串为字节数组
|
// 解码 Base64 字符串为字节数组
|
||||||
byte[] frontBytes = Base64.getDecoder().decode(form.getFrontBase64());
|
byte[] frontBytes = Base64.getDecoder().decode(form.getFrontBase64());
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
package net.lab1024.sa.admin.module.app.file.domain.form;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GetIdCardOcrForm {
|
||||||
|
@ApiModelProperty("身份证正面")
|
||||||
|
@NotBlank(message = "身份证正面 不能为空")
|
||||||
|
private String frontBase64;
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package net.lab1024.sa.admin.module.app.file.domain.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GetImageOcrVo {
|
||||||
|
@ApiModelProperty(value = "身份证姓名")
|
||||||
|
private String idCardName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "身份证号")
|
||||||
|
private String idCardNo;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user