栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java 使用腾讯云文字识别,识别驾驶证

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java 使用腾讯云文字识别,识别驾驶证

这里只有实现代码,其他实体类等请上腾讯云官网下载SDK :文字识别 驾驶证识别 - 服务端 API 文档 - 文档中心 - 腾讯云

上代码:

import com.ruoyi.app.controller.service.TencentService;
import com.ruoyi.app.controller.tencent.OcrClient;
import com.ruoyi.app.controller.tencent.common.Credential;
import com.ruoyi.app.controller.tencent.common.exception.TencentCloudSDKException;
import com.ruoyi.app.controller.tencent.common.profile.ClientProfile;
import com.ruoyi.app.controller.tencent.common.profile.HttpProfile;
import com.ruoyi.app.controller.tencent.domain.*;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.DriverwalletBankCard;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import sun.misc.base64Encoder;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@Service
public class TencentServiceImpl implements TencentService {
    //腾讯云的密钥Id
    private String secretId = "";
    //腾讯云的密钥Key
    private String secretKey = "";
    private String endpoint = "ocr.tencentcloudapi.com";


    
    @Override
    public DriverLicenseOCRResponse driverLicenseOCR(DriverLicenseOCRRequest req) throws TencentCloudSDKException {
        DriverLicenseOCRResponse resp = new DriverLicenseOCRResponse();
//        try{
            // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
            // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
            Credential cred = new Credential(secretId, secretKey);
            // 实例化一个http选项,可选的,没有特殊需求可以跳过
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint(endpoint);
            // 实例化一个client选项,可选的,没有特殊需求可以跳过
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            // 实例化要请求产品的client对象,clientProfile是可选的
            OcrClient client = new OcrClient(cred, region, clientProfile);
            // 实例化一个请求对象,每个接口都会对应一个request对象
            req.setImageUrl("E:/2021-08-24/license162976861903332ac912dc46b4a5684f89eb9f075bc2e.jpg");
			//驾驶证正面照为:FRONT,反面为:BACK
            req.setCardSide("FRONT");
            // 返回的resp是一个DriverLicenseOCRResponse的实例,与请求对象对应
            //resp = client.DriverLicenseOCR(req);
            // 输出json格式的字符串回包
            log.info("驾驶证(正、副页):{}",DriverLicenseOCRResponse.toJsonString(resp));
//        } catch (TencentCloudSDKException e) {
//            log.error("驾驶证(正、副页)识别异常:{}", e);
//        }
        return resp;
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/571317.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号