中软国际智能字符识别API

本API接口具备对手写数字、日期、日文字符的图片数据的快速识别能力, 并返回相应置信度。

使用期限

价格

1
用户评价: 暂无评价

购买人数:12

规格与周期

1.00元/1,000次”,“一年

联系电话

服务保障

精选优质服务商
7*8小时在线客服
专业测试保证品质
退款售后无忧
API文档

TemplateOCR

调用地址:http://service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com/release/

请求方式:POST

返回类型:JSON

API调用: API调用说明(secret_id & secret_key)

去调试

请求参数(Headers)

名称
类型
是否必须
描述
暂无数据

请求参数(Qurey)

名称
类型
是否必须
描述
暂无数据

请求参数(Body)

名称
类型
是否必须
描述
image_base64
string
图片文件的base64字符串。图片大小需要小于300KB。
image_type
string
上传图片的图片类型,支持JPG格式和TIF格式,注意不带(.)
templateSign
string
模板ID

请求示例

import urllib2, ssl, datetime, hmac, base64, hashlib

host = 'service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com'
url = 'http://service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com/release'
path = '/'
source = 'source'
method ='POST'
GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'

#云市场分配的密钥Id
SecretId='xxx'
#云市场分配的密钥Key
SecretKey='xxx'
dateTime = datetime.datetime.utcnow().strftime(GMT_FORMAT)
auth = "hmac id=\"" + SecretId + "\", algorithm=\"hmac-sha1\", headers=\"date source\", signature=\""
signStr = "date: " + dateTime + "\n" + "source: " + source
sign = hmac.new(SecretKey, signStr, hashlib.sha1).digest()
sign = base64.b64encode(sign)
sign = auth + sign + "\""

url = url + path

postData = 'image_base64=&image_type=&templateSign='

request = urllib2.Request(url, postData)

request.add_header('Authorization', sign)
request.add_header('Host', host)
request.add_header('Source', 'source')
request.add_header('Date', dateTime)
request.add_header('Content-Type', 'application/x-www-form-urlencoded')
request.add_header('X-Requested-With', 'XMLHttpRequest')
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urllib2.urlopen(request, context=ctx)
content = response.read()
if (content):
    print(content)
curl -v -X POST http://service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com/release/ -H 'Host:service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com' -H 'Source:source' -H 'Date:Mon, 19 Mar 2018 12:08:40 GMT' -H 'Authorization:hmac id = "AKIDi6qE41WgJ9w8h4h9zq68Vq24d1beIuN0qIwU", algorithm = "hmac-sha1", headers = "date source", signature = yMCxXNytW5nvVGNZ8aBtRxmiLJ4=' -H 'X-Requested-With:XMLHttpRequest' --data '{"image_base64":"","image_type":"","templateSign":"",}'
//请用云市场分配给您的密钥计算签名并放入请求头,Date为当前的GMT时间
<?php
$host = 'service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com';
$url = 'http://service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com/release';
$path = '/';
$method = 'POST';
$source = 'source';

#云市场分配的密钥Id
$SecretId='xxx';
#云市场分配的密钥Key
$SecretKey='xxx';
$dateTime = gmdate('D, d M Y H:i:s T');
$auth = 'hmac id="' . $SecretId . '", algorithm="hmac-sha1", headers="date source", signature="';
$signStr = 'date: ' . $dateTime . "\n" . 'source: ' . $source;
$sign = base64_encode(hash_hmac('sha1', $signStr, $SecretKey, true));
$sign = $auth . $sign . '"';

$url = $url . $path;

$postData = 'image_base64=&image_type=&templateSign=';

$headers = array( 
    "Host: $host",
    'Accept: text/html, */*; q=0.01',
    "Source: $source",
    "Date: $dateTime",
    "Authorization: $sign",
    'X-Requested-With: XMLHttpRequest',
    'Accept-Encoding: gzip, deflate, sdch',
    'Content-Type: application/x-www-form-urlencoded'
);

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

$data = curl_exec($ch); 
if (curl_errno($ch)) { 
    echo "Error: " . curl_error($ch); 
} else { 
    // Show me the result 
    var_dump($data); 
    curl_close($ch); 
}
using System.IO;
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System;

public class CsharpTest
{
    public static String HMACSHA1Text(String EncryptText, String EncryptKey)
    {            
            HMACSHA1 hmacsha1 = new HMACSHA1();
            hmacsha1.Key = System.Text.Encoding.UTF8.GetBytes(EncryptKey);

            byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(EncryptText);
            byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer);
            return Convert.ToBase64String(hashBytes);
    }

    public static void Main(String[] args)
    {
        String url = "http://service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com/release";   
        String host = "service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com";
        String path = "/";
        String method = "POST";
        String source = "source";
        String postData = "image_base64=&image_type=&templateSign=";
        
        //云市场分配的密钥Id
        String  secretId = "xxx";
        //云市场分配的密钥Key       
        String  secretKey = "xxx";

        String dt = DateTime.UtcNow.GetDateTimeFormats('r')[0]; //Mon, 19 Mar 2018 12:00:44 GMT
        url = url + path;    
        
        String signStr = "x-date: " + dt + "\n" + "source: " + source;
        String sign = HMACSHA1Text(signStr, secretKey);
        
        String auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"";        
        auth = auth + sign + "\"";
        Console.WriteLine(auth + "\n");

        HttpWebRequest httpRequest = null;
        HttpWebResponse httpResponse = null;

        if (url.Contains("https://"))
        {
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
        }
        else
        {
            httpRequest = (HttpWebRequest)WebRequest.Create(url);
        }
            
        httpRequest.Method = method;
        httpRequest.ContentLength = requestBodys.Length;
        httpRequest.Headers.Add("Authorization", auth);
        httpRequest.Headers.Add("Source", source);
        httpRequest.Headers.Add("X-date", dt);
        httpRequest.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
        httpRequest.GetRequestStream().Write(postData, 0, postData.Length);

        try
        {
            httpResponse = (HttpWebResponse)httpRequest.GetResponse();
        }
        catch (WebException ex)
        {
            httpResponse = (HttpWebResponse)ex.Response;
        }

        Console.WriteLine(httpResponse.StatusCode);
        Console.WriteLine(httpResponse.Headers);
        Stream st = httpResponse.GetResponseStream();
        StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
        Console.WriteLine(reader.ReadToEnd());
        Console.WriteLine("\n");

    }

    public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
    {
        return true;
    }
}
package main

import (
    "time"
    "fmt"
    "crypto/hmac"
    "crypto/sha1"
    "io"
    "io/ioutil"
    "encoding/base64"
    "net/http"
)


func calcAuthorization(source string, secretId string, secretKey string) (sign string, dateTime string, err error) {
    timeLocation, _ := time.LoadLocation("Etc/GMT")
    dateTime = time.Now().In(timeLocation).Format("Mon, 02 Jan 2006 15:04:05 GMT")
    sign = fmt.Sprintf("x-date: %s\nsource: %s", dateTime, source)
    fmt.Println(sign)

    //hmac-sha1
    h := hmac.New(sha1.New, []byte(secretKey))
    io.WriteString(h, sign)
    sign = fmt.Sprintf("%x", h.Sum(nil))
    sign = string(h.Sum(nil))
    fmt.Println("sign:", fmt.Sprintf("%s", h.Sum(nil)))

    //base64
    sign = base64.StdEncoding.EncodeToString([]byte(sign))
    fmt.Println("sign:", sign)

    auth := fmt.Sprintf("hmac id=\"%s\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"%s\"", 
        secretId, sign)
    fmt.Println("auth:", auth)
        
    return auth, dateTime, nil
}

func main () {

    //云市场分配的密钥Id
    SecretId := "xxx"
    //云市场分配的密钥Key 
    SecretKey := "xxx"
    source := "source"

    sign, dateTime, err := calcAuthorization(source, SecretId, SecretKey)
    if err != nil {
        fmt.Println(err)
        return
    }

    defaultDomain := "service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com"
    path := "/"
    url := "http://service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com/release"
    reqUrl := url + path
    client := &http.Client{
        Timeout: 7 * time.Second,//set timeout
    }

    postData = "image_base64=&image_type=&templateSign=";
    req, err := http.NewRequest("POST", reqUrl, postData) //set body
    if err != nil {
        fmt.Println(err)        
        return 
    }

    req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
    req.Header.Set("Accept", "*/*")
    req.Header.Set("Accept-Charset", "utf-8;")
    req.Header.Set("Host", defaultDomain)
    req.Header.Set("Source", source)
    req.Header.Set("X-Date", dateTime)
    req.Header.Set("Authorization", sign)

    resp, err := client.Do(req)
    if err != nil {
        fmt.Println(err)        
        return 
    }
    defer resp.Body.Close()

    fmt.Println("status code:", resp.StatusCode)
    
    //get resp header
    var headerMsg string
    for key, _ := range resp.Header {
        headerMsg += fmt.Sprintf("\n%s:%s", key, resp.Header.Get(key))
    }
    fmt.Println(headerMsg)

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Println(err)        
        return 
    }

    fmt.Println(string(body))
    
}
import java.io.*;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import sun.misc.BASE64Encoder;

class test 
{
    public static String sign(String secret, String timeStr) 
        throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
        //get signStr
        String signStr = "date: " + timeStr + "\n" + "source: " + "source";
        //get sig
        String sig = null;
        Mac mac1 = Mac.getInstance("HmacSHA1");
        byte[] hash;
        SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes("UTF-8"), mac1.getAlgorithm());
        mac1.init(secretKey);
        hash = mac1.doFinal(signStr.getBytes("UTF-8"));
        sig = new BASE64Encoder().encode(hash);
        System.out.println("signValue--->" + sig);
        return sig;
    }

    public static void main(String[] args) {
        String result = "";
        BufferedReader in = null;

        //get current GMT time
        Calendar cd = Calendar.getInstance(); 
        SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US); 
        sdf.setTimeZone(TimeZone.getTimeZone("GMT")); 
        String timeStr = sdf.format(cd.getTime()); 

        String host = "service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com";  
        String path = "/";
        String url = "http://service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com/release";
        url = url + path;
        String source = "source"; 
        String postData = 'image_base64=&image_type=&templateSign=';

        //云市场分配的密钥Id
        String secretId = "xxx";
        //云市场分配的密钥Key 
        String secretKey = "xxx";

        try {
            String urlNameString = url;
            URL realUrl = new URL(urlNameString);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            HttpURLConnection httpUrlCon = (HttpURLConnection)connection;
            httpUrlCon.setRequestMethod("POST");
            httpUrlCon.setDoOutput(true);
            httpUrlCon.setDoInput(true);
            PrintWriter printWriter = new PrintWriter(httpUrlCon.getOutputStream());
            httpUrlCon.setRequestProperty("Content-Length", postData.length());
            OutputStream outwritestream = httpUrlCon.getOutputStream();
            outwritestream.write(postData);
            outwritestream.flush();
            outwritestream.close();
            
            // 设置通用的请求属性
            httpUrlCon.setRequestProperty("Host", host);
            httpUrlCon.setRequestProperty("Accept", "text/html, */*; q=0.01");
            httpUrlCon.setRequestProperty("Source", source );
            httpUrlCon.setRequestProperty("Date", timeStr);
            String sig = sign(secretKey,timeStr);
            String authen = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"date source\", signature=\"" + sig + "\"";
            System.out.println("authen --->" + authen);
            httpUrlCon.setRequestProperty("Authorization", authen);
            httpUrlCon.setRequestProperty("X-Requested-With", "XMLHttpRequest");
            httpUrlCon.setRequestProperty('Content-Type', 'application/x-www-form-urlencoded');
            httpUrlCon.setRequestProperty("Accept-Encoding", "gzip, deflate, sdch");
            // 建立实际的连接
            httpUrlCon.connect();
            // 获取所有响应头字段
            Map<String, List<String>> map = httpUrlCon.getHeaderFields();
            // 遍历所有的响应头字段
            for (String key : map.keySet()) {
                System.out.println(key + "--->" + map.get(key));
            }
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
            httpUrlCon.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }

            System.out.println(result);

        } catch (Exception e) {
            System.out.println("发送GET请求出现异常!" + e);
            e.printStackTrace();
        }
        // 使用finally块来关闭输入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}
/**
 * npm install crypto-js axios
 */
var CryptoJS = require("crypto-js");
var axios = require('axios');

var nowDate = new Date(); 
var dateTime = nowDate.toGMTString();

var host = "service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com";  
var path = "/";
var url = "http://service-m998s6ue-1253874725.ap-guangzhou.apigateway.myqcloud.com/release";
url = url + path;
var source = "source"; 

var postData = 'image_base64=&image_type=&templateSign=';

//云市场分配的密钥Id
var secretId = "xxx";
//云市场分配的密钥Key 
var secretKey = "xxx";

var auth = "hmac id=\"" + secretId + "\", algorithm=\"hmac-sha1\", headers=\"x-date source\", signature=\"";
var signStr = "x-date: " + dateTime + "\n" + "source: " + source;
var sign = CryptoJS.HmacSHA1(signStr, secretKey)
console.log(sign.toString())
sign = CryptoJS.enc.Base64.stringify(sign)
sign = auth + sign + "\""
console.log(sign)

var instance = axios.create({
    baseURL: url,
    timeout: 5000,
    method: 'post',
    data: postData
    headers: {
                "Source":source,
                "X-date":dateTime,
                "Authorization":sign,
                "Content-Type":"application/x-www-form-urlencoded"
    },
    withCredentials: true
});


instance.get()
.then(function (response) {
        console.log(response);
    })
    .catch(function (error) {
        console.log(error);
    });

正常返回示例

{
"type":"success",
"name":"识别区1",
"Result":"工藤",
"Probability":"93"
}

失败返回示例

{
"type":"error",
"name":"识别区1",
"Result":"outRegion must be inside the coordinate region.",
"Probability":"*"
}

返回码定义

返回码
返回信息
描述
无参数
产品详情

商品文档

名称:中软国际智能字符识别API服务试用指南.pdf 下载

商品详情


业务背景

中软国际基于多年来累积的BPO服务经验,将AI和云技术相结合,致力于协助各外包企业,优化BPO业务流程,提高工作效率。

对于不少企业,日常工作中经常需要处理大量的纸质票据或其图片。将这些资料数字化,转化成可以方便的进行查询、加工的数据,进而形成对运营有价值的信息,而不是任其累积成很难使用的材料,对于客户来说,是非常重要的。票据数字化转化的传统解决方案,高度依赖人的手工操作,通常包括大量数据文字录入、内容审核工作。一般是先将票据图片化,然后将图片单据上的各种手写或打印的数据录入到计算机系统中。特别对于手写字体来说,由于其受各种因素影响很难被传统方式的自动化工具识别,需要大量人力来完成。此类工作,内容简单机械易出错,过程枯燥强度大,遇到业务量高峰期时需要加班加点。

面对这类业务的现状,中软国际有针对性的开发了智能字符识别平台,将当前已经成熟的人工智能ICR技术结合到当前票据数字化业务流程中,显著提升了数字化效率,改善了数据质量,节省了大量人力。此平台支持用户自选识别区,支持位移和偏差的自适应,适用于多种应用场景,具有灵活的拓展性,可以针对客户具体的需求,进行定制化训练,进一步提高识别水平。

解决方案

中软国际智能字符识别服务,具有高度的灵活性,以适配客户多变的应用场景,客户可以使用系统提供的助手工具,方便的定制图像的识别区域模板,不仅提高了准确度,而且节省了算力;该系统还支持位移和偏差的自适应,即使待识别图像与模板有一定差别,识别也能顺畅展开。同时,系统支持对手写体和印刷体的识别,并且可以灵活扩展不同字体的识别。

助手工具:用户使用此工具自定义识别区域模板,形成各种定制化参数。

字符识别API:系统核心功能,接收识别请求并进行识别,返回识别结果。



使用指南

请参考《中软国际智能字符识别API服务试用指南

评价详情
暂无评价
购买记录
联系电话

0755-66867301

联系客服
请提前登录QQ,以获得更好体验

中软腾讯云小助手

服务时间

09:00-19:00

1
立即购买
规格与周期

使用期限

联系方式

联系电话

0755-66867301

服务时间

09:00-19:00

必须同意使用协议才可购买