百度文字识别API

注册成为百度云管理中心会员
创建一个文字识别的新应用(AppID/APIKey/Secret Key)

后台调用api时需要用到这几个参数。

后台调用照片识别api的方法:
public class picToWord {
    //设置APPID/AK/SK
    public static final String APP_ID = "123456789";
    public static final String API_KEY = "gdsjgiodfjgiofioffjgidfj";
    public static final String SECRET_KEY = "fasdfdsfsdfdsfsdfdfdff";
    public static String getBussinessLicenseMsg(String image) {
        // 初始化一个AipOcr
        AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        // 可选:设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 参数为本地路径.businessLicense,使用营业执照的接口
        JSONObject res = client.businessLicense(image, options);

        return res.toString(2);

    }
}
前端HTML:

直接调用拍照接口或从相册取出照片需要调用微信的拍照接口(jssdk),这里不做描述

<input type="button" name="Image" title="请选择图片" id="Image">上传

后台代码:

//识别营业执照返回执照信息
@RequestMapping(value = "getBLiscenseMsg")
@ResponseBody
public String getBLiscenseMsg(HttpServletRequest request) {
    //获取前端传来的图片信息
    String pic = request.getParameter("pic");
    if (!StringUtils.isBlank(pic)) {
        pic = DloadImgUtil.downloadMedias(TokenSchUtil.accessToken_x, pic, "", "");
        pic = pic.split("/")[1];          //解析成.jpg格式
    }
    //调用api得到照片解析后的信息,返回前端ajax
    String picMsg = picToWord.getBussinessLicenseMsg(pic);
    System.out.println("提取营业执照结果:"+picMsg);
    return picMsg;
}

js获取后台返回的信息:

function getPicMsg(){
    var pic = $("#imageUrl").val();      //图片信息
    alert(pic);
    $.ajax({
        url: "getBLiscenseMsg",
        type: "POST",
        data: "pic="+pic,
        dataType: "json",
        success: function (result) {
            //根据返回值的结构提取对应所需的值
            var list = result.words_result;
            var enterpriseName = list["单位名称"].words;
            var chargePerson = list["法人"].words;
            var addr = list["地址"].words;

            //传到前端input文本框
            $('#enterpriseName').val(enterpriseName);  //单位名称
            $('#chargePerson').val(chargePerson);      //法人代表
            $('#managerPerson').val(chargePerson);
            $('#addr').val(addr);                      //地址
        }
    });
}

解析图片返回的内容:

解析图片返回的值:
 {
  "log_id": 1234567899874563214,
  "words_result": {
    "社会信用代码": {
      "words": "1234567899",
      "location": {
        "top": 365,
        "left": 671,
        "width": 187,
        "height": 16
      }
    },
    "成立日期": {
      "words": "2017年02月30日",
      "location": {
        "top": 701,
        "left": 443,
        "width": 155,
        "height": 31
      }
    },
    "法人": {
      "words": "某某某",
      "location": {
        "top": 0,
        "left": 0,
        "width": 0,
        "height": 0
      }
    },
    "注册资本": {
      "words": "1000万元",
      "location": {
        "top": 644,
        "left": 450,
        "width": 37,
        "height": 31
      }
    },
    "证件编号": {
      "words": "无",
      "location": {
        "top": 0,
        "left": 0,
        "width": 0,
        "height": 0
      }
    },
    "地址": {
      "words": "****路110号",
      "location": {
        "top": 549,
        "left": 448,
        "width": 52,
        "height": 16
      }
    },
    "单位名称": {
      "words": "******有限公司",
      "location": {
        "top": 429,
        "left": 452,
        "width": 298,
        "height": 26
      }
    },
    "有效期": {
      "words": "2041年02月16日",
      "location": {
        "top": 767,
        "left": 642,
        "width": 148,
        "height": 24
      }
    }
  },
  "words_result_num": 8,
  "direction": 0
}

原文地址:https://www.cnblogs.com/sanzashu/p/11145816.html

时间: 2024-08-30 05:03:01

百度文字识别API的相关文章

百度OCR文字识别API使用心得===com.baidu.ocr.sdk.exception.SDKError[283604]

异常com.baidu.ocr.sdk.exception.SDKError[283604]App identifier unmatch.错误的packname或bundleId.logId::30309247 本文的案例源码下载地址在这里哦!!!! https://download.csdn.net/download/pyfysf/10406761 最终实现的效果(识别的有些慢,是由于我的网速原因.-_-) ? 最近有个小项目使用到了OCR技术,顺便到网上搜索了一下,大家都在使用百度的API.

C#百度图片识别API调用返回数据包解析

百度图片识别api接口 public static JObject GeneralBasic(string apikey,string secretkey,string path) { var client = new Baidu.Aip.Ocr.Ocr(apikey, secretkey); var image = File.ReadAllBytes(path); // 通用文字识别 var result = client.GeneralBasic(image, null); return r

百度 验证码识别API 使用

先到百度云申请文字识别API ,会给你一个API KEY和一个SECRET KEY,免费,一天最多500次请求. try: temp_url = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=[API KEY]&client_secret=[SECRET KEY]' temp_res = requests.post(temp_url) temp_token = eval(t

Delphi百度文字识别【支持通用文字识别、身份证识别、银行卡识别、驾驶证识别、行驶证识别、车牌识别等功能】

Delphi百度文字识别          百度api文档 [Delphi百度文字识别]支持 通用文字识别.通用文字识别(高精度版).通用文字识别(含位置信息版).通用文字识别(高精度含位置版).手写文字识别.身份证识别.银行卡识别.营业执照识别.护照识别.名片识别.户口本识别.出生医学证明识别.港澳通行证识别.台湾通行证识别.通用票据识别.表格文字识别.通用票据识别.增值税发票识别.火车票识别.出租车票识别.定额发票识别.驾驶证识别.行驶证识别.车牌识别.机动车销售发票识别.车辆合格证识别.V

利用百度文字识别图片中的文字(python版)

import glob from os import path import os from aip import AipOcr from PIL import Image def convertimg(picfile, outdir): '''调整图片大小,对于过大的图片进行压缩 picfile: 图片路径 outdir: 图片输出路径 ''' img = Image.open(picfile) width, height = img.size while(width*height > 400

百度文字识别获取access token

import requests url = "https://aip.baidubce.com/oauth/2.0/token" data = { 'grant_type':'client_credentials', 'client_id':API Key, 'client_secret':Secret Key,} response = requests.post(url=url,data=data)print(response.text) 原文地址:https://www.cnblo

python之图片文字识别

总体思路: 1.借用热键截图,保存到本地 2.用百度的图片文字识别api,识别图中文字 import time import keyboard # 监控键盘事件pip install keyboard from PIL import ImageGrab # 能够去从剪切板当中把图片读取出来pip install pillow from aip import AipOcr #百度文字识别库 pip install baidu-aip # 上面的都是扩展包, 得安装 pip install pill

截图 文字识别

主: import keyboard # 键盘控制 from PIL import ImageGrab # 获取剪切板的文件 import time import sys from baidu import BaiDuAPI # 自己写的 百度文字识别, # 取图 def show_p(): if keyboard.wait('ctrl + alt + a') == None: # 截图 if keyboard.wait('ctrl') == None: # 告知程序截图完了, time.sle

【华为云技术分享】云图说|人工智能新科技—文字识别服务

在日常生产和生活中,我们往往要处理大量的文字.报表和文本.为了减轻人们的劳动,提高工作效率,华为云文字识别服务应用而生.您可以调用服务提供的文字识别API接口,将我们日常中大量的证件.票据.表格识别成可编辑的文本,代替人工录入,提升业务效率. 到底什么是文字识别服务?“云图说”带您了解它的来龙去脉. 点击“了解更多”,华为云文字识别服务等着您! 原文地址:https://www.cnblogs.com/huaweicloud/p/12523501.html