百度图片文字识别

2 篇文章 0 订阅

百度图片文字识别
方法名:queryInfo

    @Test
    public void selectAllImg() throws Exception{
    //读取txt中 图片的路径
        File file = new File("28.txt");
        String encoding = "UTF-8";
        InputStreamReader read = new InputStreamReader(
                new FileInputStream(file), encoding);//考虑到编码格式
        BufferedReader bufferedReader = new BufferedReader(read);
        String lineTxt = bufferedReader.readLine();
        List<String> result = Arrays.asList(lineTxt.split(","));
        List<String> strings1 = new ArrayList<>();
        for (int i = 3000; i < 3999; i++) {
            List<String> strings = new ArrayList<>();
            TLicenseVo t = tShopCheckInfoService.queryInfo(result.get(i));
            if (StringUtils.isNotEmpty(t.getCompanyName())) {
                strings.add(t.getCompanyName());
                strings.add(result.get(i));
                String aa = StringUtils.join(strings, "内集合");
                strings1.add(aa);
                System.out.println(strings1.toString().substring(5));
            }
        }
        //将拼接的有效数据写入本地
        writeTxt("3.txt", StringUtils.join(strings1,"外集合"));
    }

//自定义一个对象接收参数 TLicenseVo

public class BaiDuAiUtil {
    public static final String APP_ID = "123";

    public static final String API_KEY = "123";

    public static final String SECRET_KEY = "123";

    private static AipOcr apiOcr;

    private static String filePath = "/Users/";

    static {
        apiOcr = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
    }


    public static TLicenseVo parseLicence(String path) {
//        path = chanPath(path);
        TLicenseVo vo = new TLicenseVo();
        JSONObject res2 = apiOcr.basicGeneral(path, new HashMap<String, String>());
        try {
            JSONArray res = (org.json.JSONArray) res2.get("words_result");
            Map<String,Object> result = new HashMap<>();
//            StringBuffer buffer = new StringBuffer();
            if (res.length() > 0) {
//                buffer.append("开始输出照片");
               String aa =res.toString();
                System.out.print(aa);
                vo.setCompanyName(aa);
//                for (int key = 0; key < res.length(); key++) {
//                    result.put("code","0");
//                    JSONObject object = (JSONObject) res.get(key);
//                    String value = object.getString("words");
//                    buffer.append(object.toString());
//                    if(value.startsWith("法定代表人")){
//                        vo.setName(value.substring(5,value.length()));
//                    }
//                    else if(value.trim().startsWith("公司名称")){
//                        vo.setCompanyName(value.substring(4,value.length()));
//                    }
//                    else if(value.trim().startsWith("名称")){
//                        vo.setCompanyName(value.substring(2,value.length()));
//                    }else if(value.trim().startsWith("称")){
//                        vo.setCompanyName(value.substring(1,value.length()));
//                    }
//                    else if(value.trim().startsWith("地址")){
//                        vo.setAddr(value.substring(2,value.length()));
//                    }
//                    else if(value.trim().startsWith("址")){
//                        vo.setAddr(value.substring(1,value.length()));
//                    }
                    else if(value.startsWith("统一社会")){
                        vo.setCreditCode(value.substring(8,value.length()));
                    }
                    else if(value.startsWith("社会信用代码")){
                        vo.setCreditCode(value.substring(6,value.length()));
                    }
//                    else if(value.startsWith("经营者")){
//                        vo.setManager(value.substring(3,value.length()));
//                    }
//                }
//                System.out.print(buffer.toString());
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

//        File file = new File(path);
//        try {
//            if (file.exists()) {
//                file.delete();
//            }
//        } catch (Exception e) {
//            System.out.println("删除文件"+path+"出错!");
//            e.printStackTrace();
//        }
        return vo;
    }

    private static String chanPath(String path){
        URL url = null;

        String toPatch = filePath + "wx" + path.substring(path.lastIndexOf("/"));
//        String toPatch = "D:/wx"+ path.substring(path.lastIndexOf("/"));

        try {
            url = new URL(path);

            File toPic = new File(toPatch) ;

            Thumbnails.of(url).size(2000,2000).outputQuality(0.25f).toFile(toPic);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return toPatch ;
    }

    //判断上传的是不是营业执照
    public static boolean checkLicence(String path,String company,String name,String credit){
        boolean flag = false;
        TLicenseVo licence = parseLicence(path);
        if(path == null || company == null || name == null || credit == null){
            return  false;
        }
//        if(company.equals(licence.getCompany())&&name.equals(licence.getName())&&credit.equals(licence.getCreditNo())){
//            flag = true;
//        }
        return flag;
    }



    public static void main(String[] args) {
        String path = "/6/image.jpg" ;
       System.out.println(path.substring(path.lastIndexOf("/")));
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值