ocr-身份证正反面识别

在阿里云官网,申请一个token

[阿里官方]身份证OCR文字识别_API专区_云市场-阿里云 (aliyun.com)

观察一下post请求body部分json字符串,我们根据这个创建一个java对象

先默认是人像面

java 复制代码
public class IdentityBody {
    public String image;

    class configure {
        public String side = "face";
        public boolean quality_info;
    }
}
java 复制代码
@Autowired
    private OkHttpClient okHttpClient;
    
    @Autowired
    private ObjectMapper objectMapper;
    
    private String cardPath = "D:\\image\\card1.jpg";
    
    private String appcode = "c8518f45d5334300b73c638e299820ab";

    public String getIdentityData() throws IOException {
        IdentityBody identityBody = new IdentityBody();
        identityBody.image = ImageToBase64.imageToBase64(cardPath);
        RequestBody requestBody = RequestBody.create(objectMapper.writeValueAsString(identityBody),
                MediaType.get("application/json; charset=utf-8"));
        Request request = new Request.Builder()
                .url("https://cardnumber.market.alicloudapi.com/rest/160601/ocr/ocr_idcard.json")
                .addHeader("Authorization", "APPCODE " + appcode)
                .addHeader("Content-Type", "application/json; charset=UTF-8")
                .post(requestBody)
                .build();

        try (Response response = okHttpClient.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                String errorBody = response.body().string();
                throw new IOException(
                        "API请求失败:\n" +
                                "状态码: " + response.code() + "\n" +
                                "错误信息: " + response.message() + "\n" +
                                "响应体: " + errorBody
                );
            }

            String ret = response.body().string();
            System.out.println("识别结果: " + ret);
            return ret;
        }
    }
相关推荐
小白狮ww28 分钟前
要给 OCR 装个脑子吗?DeepSeek-OCR 2 让文档不再只是扫描
人工智能·深度学习·机器学习·ocr·cpu·gpu·deepseek
智慧地球(AI·Earth)16 小时前
DeepSeek架构新探索!开源OCR 2诞生!
架构·ocr
OpenBayes16 小时前
教程上新|DeepSeek-OCR 2公式/表格解析同步改善,以低视觉token成本实现近4%的性能跃迁
人工智能·深度学习·目标检测·机器学习·大模型·ocr·gpu算力
PPIO派欧云17 小时前
PPIO上线GLM-OCR:0.9B参数SOTA性能,支持一键部署
人工智能·ai·大模型·ocr·智谱
东华果汁哥17 小时前
【大模型 OCR】GLM-OCR 使用教程:从入门到部署
ocr
h7ml1 天前
查券返利机器人的OCR识别集成:Java Tesseract+OpenCV优化图片验证码的自动解析方案
java·机器人·ocr
Funny_AI_LAB1 天前
GLM-OCR发布:性能SOTA,超越PaddleOCR-VL-1.5?
人工智能·计算机视觉·语言模型·ocr
码科智能2 天前
OCR在真实场景“翻车”?面对跨页表格、密集表格、扭曲文档等难题,这个OCR文档解析工具太6了!
ocr
ejinxian2 天前
专业级模型 GLM-OCR
ocr·模型
susu10830189112 天前
本地运行DeepSeek-OCR-2 识别图片文字
ocr