腾讯云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());
        }

    }
}
相关推荐
AI人工智能+13 小时前
机动车登记证识别技术通过计算机视觉与深度学习实现证件信息自动化提取,显著提升车辆管理效率
深度学习·计算机视觉·自然语言处理·ocr·机动车登记证识别
AI人工智能+2 天前
银行回单识别系统通过融合计算机视觉、深度学习和自然语言处理技术,实现了财务凭证的智能化处理
人工智能·深度学习·ocr·银行回单识别
我不介意孤独3 天前
面向华为昇腾 NPU 的企业级 PaddleOCR 推理服务,支持多卡多实例动态扩缩容、高召回 OCR 与生产级部署。
服务器·华为·ocr
翼龙云_cloud3 天前
腾讯云代理商:腾讯云如何部署DeepSeek版 Claude Code?
人工智能·云计算·腾讯云·ai智能体·deepseek-tui
eggcode3 天前
腾讯云使用Docker模板的学习记录
学习·docker·腾讯云
合合技术团队4 天前
海外发票智能解析:跨版式、多税制票据的自动化处理方案(附GitHub项目地址)
运维·自动化·github·ocr
OCR_133716212755 天前
证件日期防伪核验技术解析:AI+OCR助力多场景精准验真
人工智能·ocr
AI人工智能+5 天前
一种基于深度学习的表格识别技术,通过融合计算机视觉、图神经网络和Transformer等算法,能精准解析复杂表格结构
深度学习·计算机视觉·ocr·表格识别
HyperAI超神经5 天前
在线教程丨单卡即可爆改,面壁智能等开源MiniCPM-V-4.6,1.3B端侧模型支持图像理解/视频理解/OCR/多轮多模态对话
人工智能·ai·ocr
AI人工智能+5 天前
营业执照识别技术通过计算机视觉与人工智能技术,实现企业证照信息的自动化采集
人工智能·深度学习·ocr·营业执照识别