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;
        }
    }
相关推荐
show4334 小时前
2026视频处理小程序技术选型指南:链接解析+OCR+ASR+AI配音多引擎对比
小程序·ocr·音视频
一个王同学19 小时前
从零到一 | CV转多模态大模型 | week22 | 实战项目-DocuMind-VL:基于 OCR 与 Qwen-VL 的文档多模态问答系统(二)
人工智能·深度学习·机器学习·计算机视觉·ocr
GoCodingInMyWay2 天前
PaddleOCR 开始
pytorch·ai·ocr
Code_流苏2 天前
Pot:免费开源的跨平台划词翻译和 OCR 工具,选中文字就能翻译
开源·ocr·pot·自动翻译·翻译工具·划词翻译
lupai2 天前
行驶证 OCR 识别 API 快速接入与实战指南
网络·数据库·ocr
xfan_me3 天前
行驶证 OCR 识别 API-行驶证识别
网络·数据库·ocr
lupai3 天前
增值税发票 OCR 识别 API 新手接入指南
java·前端·ocr
AI人工智能+3 天前
通用表格识别:实现从非结构化图像到高保真数据的转换,提升业务流程自动化水平
深度学习·自然语言处理·ocr·表格识别
10mAh4 天前
【PaddleOCR】扫描版 PDF 无法复制、RAG 检索为空怎么解决?——OCR 解析与版面还原实战
前端·pdf·ocr
AI人工智能+4 天前
智能文档抽取系统通过“视觉感知+大模型认知“双引擎架构,实现非结构化文档的自动化处理
深度学习·计算机视觉·语言模型·自然语言处理·ocr·文档抽取