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

    }
}
相关推荐
2501_9307992417 分钟前
数据安全新选择:访答本地知识库的隐私守护之道
人工智能·aigc·ocr
咕噜企业分发小米5 小时前
阿里云与华为云在基因测序数据存储上哪个更好?
服务器·阿里云·腾讯云
21996 小时前
中文OCR产品与多模态大模型OCR能力选型报告
ocr
技术小甜甜6 小时前
[Python] 使用 Tesseract 实现 OCR 文字识别全流程指南
开发语言·python·ocr·实用工具
wang6021252186 小时前
OCR服务-本地打包docker+docker下载ssh调试
docker·ssh·ocr
小白狮ww7 小时前
当 OCR 模型开始「理解整页文档」:HunyuanOCR 的端到端之路
人工智能·深度学习·机器学习·ocr·文字识别·文档处理·腾讯混元
2501_941982051 天前
结合 AI 视觉:使用 OCR 识别企业微信聊天记录中的图片信息
人工智能·ocr·企业微信
翼龙云_cloud1 天前
腾讯云渠道商:腾讯云快照和镜像备份区别在哪?
运维·服务器·云计算·腾讯云
AI人工智能+1 天前
承兑汇票识别技术;融合OCR、深度学习和NLP的多模态智能系统,可实现秒级高精度识别
深度学习·ocr·承兑汇票识别
TG:@yunlaoda360 云老大2 天前
腾讯云国际站代理商的QAPM服务能提供哪些专属服务?
人工智能·云计算·腾讯云