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的导入百度自己找,这里不再复述
1920

被折叠的 条评论
为什么被折叠?



