百度OCR+Unity

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Baidu.Aip.Ocr;
using System.IO;
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;


public class TEXTOCR : MonoBehaviour {


    const string APP_ID = "自己去官网注册";
    const string ApiKey = "自己去官网注册";
    const string SecretKey = "自己去官网注册 ";

    Ocr client;


    // Use this for initialization
    void Awake () {
        client = new Ocr(ApiKey, SecretKey);
        client.Timeout = 60000;
	}
    void Start()
    {

        GeneralBasicDemo();
    }
//解决证书问题
    public bool MyRemoteCertificateValidationCallback(System.Object sender,
    X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
        bool isOk = true;
        // If there are errors in the certificate chain,
        // look at each error to determine the cause.
        if (sslPolicyErrors != SslPolicyErrors.None)
        {
            for (int i = 0; i < chain.ChainStatus.Length; i++)
            {
                if (chain.ChainStatus[i].Status == X509ChainStatusFlags.RevocationStatusUnknown)
                {
                    continue;
                }
                chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
                chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
                chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
                chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
                bool chainIsValid = chain.Build((X509Certificate2)certificate);
                if (!chainIsValid)
                {
                    isOk = false;
                    break;
                }
            }
        }
        return isOk;
    }

  
    public void GeneralBasicDemo()
    {
       

        try
        {
            ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
           
             //    result = client.AccurateBasic(image, null);//高精度
                
           
                result = client.GeneralBasic(image, null);//普通精度
                
            
                Debug.Log(result);
            

            

        }
        catch (Exception e)
        {

            Debug.Log(e);
        }
    }
}

c# sdk的导入百度自己找,这里不再复述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值