华为云文字识别接口

本文档基于华为云的文字识别服务,介绍了如何引入并使用华为云的OCR接口进行文字识别,涉及相关jar包的导入步骤。
摘要由CSDN通过智能技术生成

在华文云提供的文档基础上进行了简单的整理,需要引入华为相关的jar包

import com.oss.oss_demo.util.OcrClientToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.net.URISyntaxException;

@RestController
@RequestMapping("/huaweicloud/ocr")
@Api(tags = "华为云 文字识别")
public class HWOcrController {
    private String Username="";
    private String Password="";
    private String Domainname=""; //if it's not IAM user the Domain_name is the same with username
    private String Regionname="cn-north-1";
    private String HttpEndpoint="ocr.cn-north-1.myhuaweicloud.com";


    @PostMapping(value ="getIdCard")
    @ApiOperation("身份证识别")
    @ApiImplicitParam(name ="imagePath",value ="图片路径",required = true)
    public String getIdCard(String imagePath) throws InterruptedException, IOException, URISyntaxException {
        OcrClientToken ocrClient= new OcrClientToken(Domainname,Username,Password,Regionname,HttpEndpoint);
        HttpResponse response=ocrClient.requestOcrServiceBase64("/v1.0/ocr/id-card", imagePath);
        System.out.println(response);
        String content = IOUtils.toString(response.getEntity().getContent(), "utf-8");
        System.out.println(content);
        return content;
    }

    @PostMapping(value ="getDriverLicense")
    @ApiOperation("驾驶证识别")
    @ApiImplicitParam(name ="imagePath",value ="图片路径",required = true)
    public String getDriverLicense(String imagePath) throws InterruptedException, IOException, URISyntaxException {
        OcrClientToken ocrClient= new OcrClientToken(Domainname,Username,Password,Regionname,HttpEndpoint);
        HttpResponse response=ocrClient.requestOcrServiceBase64("/v1.0/ocr/driver-license", imagePath);
        System.out.println(response);
        String content = IOUtils.toString(response.getEntity().getContent(), "utf-8");
        System.out.println(content);
        return content;
    }

    @PostMapping(value ="getVehicleLicense")
    @ApiOperation("行驶证识别")
    @ApiImplicitParam(name ="imagePath",value ="图片路径",required = true)
    public String getVehicleLicense(String imagePath) throws InterruptedException, IOException, URISyntaxException {
        OcrClientToken ocrClient= new OcrClientToken(Domainname,Username,Password,Regionname,HttpEndpoint);
        HttpResponse response=ocrClient.requestOcrServiceBase64("/v1.0/ocr/vehicle-license", imagePath);
        System.out.println(response);
        String content = IOUtils.toString(response.getEntity().getContent(), "u
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值