腾讯云API OCR驾驶证 文字信息识别提取

和身份证识别,大部分代码都是一样的,可参考身份证识别的博文
腾讯云API OCR个人身份证正反面文字信息识别提取-CSDN博客

不一样的地方,如下

复制代码
请求对象类型:
身份证:IDCardOCRRequest
驾驶证:DriverLicenseOCRRequest

响应对象类型:
身份证:IDCardOCRResponse
驾驶证:DriverLicenseOCRResponse

OCR方法调用:
身份证:client.IDCardOCR(req)
驾驶证:client.DriverLicenseOCR(req)

pom.xml,yml配置,属性注入,和身份证识别一模一样,调用的详细代码如下

复制代码
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.ocr.v20181119.OcrClient;
import com.tencentcloudapi.ocr.v20181119.models.DriverLicenseOCRRequest;
import com.tencentcloudapi.ocr.v20181119.models.DriverLicenseOCRResponse;
import com.tencentcloudapi.ocr.v20181119.models.IDCardOCRRequest;
import com.tencentcloudapi.ocr.v20181119.models.IDCardOCRResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.util.Base64;

@RestController
public class Controller_jdriverLicenseOcr {

    @Autowired
    private TencentCloudProperties tencentCloudProperties;

    @RequestMapping("/driverLicenseOcr")
    public Object idCardOcr(@RequestPart("file") MultipartFile file) {
        try {
            // 检查文件是否为空
            if (file.isEmpty()) {
                return "文件不能为空";
            }

            // 图片转换base64格式字符串
            BufferedImage image = ImageIO.read(file.getInputStream());
            // 将图像转换为字节
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write(image, "png", baos);
            byte[] imageBytes = baos.toByteArray();

            // 使用Base64进行编码
            String fileBase64 = "data:image/png;base64," + Base64.getEncoder().encodeToString(imageBytes);

            // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
            Credential cred = new Credential(tencentCloudProperties.getSecretId(),
                    tencentCloudProperties.getSecretKey());
            // 实例化一个http选项,可选的,没有特殊需求可以跳过
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("ocr.tencentcloudapi.com");
            // 实例化一个client选项,可选的,没有特殊需求可以跳过
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            // 实例化要请求产品的client对象,clientProfile是可选的
            OcrClient client = new OcrClient(cred, tencentCloudProperties.getRegion(),
                    clientProfile);
            // 实例化一个请求对象,每个接口都会对应一个request对象
            DriverLicenseOCRRequest req = new DriverLicenseOCRRequest();
            req.setImageBase64(fileBase64);

            // 返回的resp是一个DriverLicenseOCRResponse的实例,与请求对象对应
            DriverLicenseOCRResponse resp = client.DriverLicenseOCR(req);
            System.out.println("resp = " + resp);
            return resp;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }

    }
}
相关推荐
陈西子在网上冲浪19 小时前
SEO关键词布局总踩坑?用腾讯云AI工具从核心词到长尾词一键生成(附青少年英语培训实操案例)
人工智能·云计算·腾讯云
hit56实验室19 小时前
腾讯云的运维笔记——从yum的安装与更新源开始
运维·笔记·腾讯云
腾讯云开发者2 天前
腾讯云 MCP 场景征集计划 | 你的方案,正在定义开发新范式
云计算·腾讯云
杏花春雨江南2 天前
腾讯云 CVM 上的 SpringBoot 应用避免非法访问
spring boot·云计算·腾讯云
AI人工智能+3 天前
竣工验收备案识别技术:通过AI和OCR实现智能化文档处理,提升效率与准确性,推动建筑行业数字化转型。
人工智能·nlp·ocr·竣工验收备案识别
似水流年 光阴已逝3 天前
腾讯云重保流程详解:从预案到复盘的全周期安全防护
安全·云计算·腾讯云
df007df3 天前
【RAGFlow代码详解-10】文本处理和查询处理
人工智能·ocr·embedding·llama
血手人屠喵帕斯4 天前
腾讯云人脸库技术架构深度解析
架构·云计算·腾讯云
似水流年 光阴已逝4 天前
腾讯云DTS数据库迁移底层原理与实战解析
云计算·腾讯云·数据迁移
AI人工智能+9 天前
表格识别技术:通过图像处理与深度学习,将非结构化表格转化为可编辑结构化数据,推动智能化发展
人工智能·深度学习·ocr·表格识别