Baidu.Aip.ImageClassify

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//using Baidu.Aip.Ocr;//图片文字识别
using Baidu.Aip.ImageClassify;//图片图像识别
using System.IO;
using Newtonsoft.Json.Linq;
//百度图片图像识别接口调用——非子萧
public class ICTest : MonoBehaviour
{
public Text debugInfo; // 显示debug信息
public Text debugInfo2; // 显示debug信息
public Image image2;
public Sprite mySprite;
public RawImage portrait; // 显示图片
public Texture2D texture; // 用以描绘关键点的图片

//private Ocr client;                              // 用来调用百度AI接口
//private Form form;                              // 用来调用百度AI接口
private ImageClassify client;                              // 用来调用百度AI接口

// private Form form; // 用来调用百度AI接口

private byte[] image;                             // 检测的图像数据
private Dictionary options;       // 返回的数据
private JObject result;                           // 接收返回的结果
private string ApiKey = "Lq8GGt63ruGMGnIByYVvvLpS";//此处填写自己申请的key
private string SecretKey = "0gCFCYn35HobRGquageh4V13NtjpXMIi";//此处填写自己申请的key

private void Awake()
{
    //网页端身份安全验证失败,我们需要在程序运行时手动添加安全证书,在Awake方法中加入
    System.Net.ServicePointManager.ServerCertificateValidationCallback +=
        delegate (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                    System.Security.Cryptography.X509Certificates.X509Chain chain,
                    System.Net.Security.SslPolicyErrors sslPolicyErrors)
        {
            return true;           // always accept
        };
    // 此处填写自己申请的key("Api Key", "Secret Key");
    client = new ImageClassify(ApiKey, SecretKey);
    //client = new Baidu.Aip.ImageClassify.ImageClassify(ApiKey, SecretKey);
    //form = new Baidu.Aip.Ocr.Form(ApiKey, SecretKey);
}
private void Start()
{
}
//// 高精度图片文字识别
//public  void Accurate()
//    {
//    var path = Application.dataPath + "/Images/tw22.jpg";
//    var image = File.ReadAllBytes(path);

//    result = client.Accurate(image);

//    debugInfo.text = result.ToString();
//    Debug.Log("高精度识别");
//}

//菜品识别
public void DishDetectDemo()
{
    var path = Application.dataPath + "/Images2/tt01.jpg";
    var image = File.ReadAllBytes(path);
    var options = new Dictionary{{"top_num", 2 }};
    //参数:top_num=2,返回结果为2条,默认为5;
    result = client.DishDetect(image,options);

    debugInfo.text = result.ToString();

    Debug.Log("菜品识别");
}
//车辆识别
public void CarDetectDemo()
{
    var path = Application.dataPath + "/Images2/tt06.jpg";
    var image = File.ReadAllBytes(path);
    var options = new Dictionary { { "top_num", 2 } };
    //参数:top_num=2,返回结果为2条,默认为5;
    result = client.CarDetect(image, options);

    debugInfo.text = result.ToString();
    Debug.Log("车辆识别");
}
//logo商标识别
public void LogoSearchDemo()
{
    var path = Application.dataPath + "/Images2/tt14png.png";
    var image = File.ReadAllBytes(path);
    var options = new Dictionary { { "custom_lib", true } };
    //参数:true 返回自定义库
    result = client.LogoSearch(image, options);

    debugInfo.text = result.ToString();
    Debug.Log("logo商标识别");
}
//logo商标识别—添加
public void LogoAddDemo()
{
   //// var image = File.ReadAllBytes("图片文件路径");
   //// var brief = "{\"name\": \"宝马\",\"code\":\"666\"}";

   //// // 调用logo入库
   //// var result = client.LogoAdd(image, brief);
   ////// Console.WriteLine(result);
}
//logo商标识别—删除
public void LogoDeleteByImageDemo()
{
   // var image = File.ReadAllBytes("图片文件路径");
   // // 调用删除logo,传入参数为图片
   // var result = client.LogoDeleteByImage(image);
   //// Console.WriteLine(result);
}
//logo商标识别—删除
public void LogoDeleteBySignDemo()
{
    var contSign = "8cnn32frvrr2cd901";

    // 调用删除logo,传入参数为图片签名
    var result = client.LogoDeleteBySign(contSign);
    //Console.WriteLine(result);
}
//动物识别
public void AnimalDetectDemo()
{
    var path = Application.dataPath + "/Images2/tt23.jpg";
    var image = File.ReadAllBytes(path);
    var options = new Dictionary { { "top_num", 2 } };
    //参数:带参数调用动物识别条数
    result = client.AnimalDetect(image, options);

    debugInfo.text = result.ToString();
    Debug.Log("动物识别");
}
//植物识别
public void PlantDetectDemo()
{
    var path = Application.dataPath + "/Images2/tt33.jpg";
    var image = File.ReadAllBytes(path);

    result = client.PlantDetect(image);

    debugInfo.text = result.ToString();
    Debug.Log("植物识别");
}
//图像主体检测
public void ObjectDetectDemo()
{
    var path = Application.dataPath + "/Images/l01.jpg";
    var image = File.ReadAllBytes(path);
    var options = new Dictionary { { "with_face", 1 } };
    //参数:0不带人脸,1,带人脸检测
    result = client.ObjectDetect(image, options);

    debugInfo.text = result.ToString();
    Debug.Log("图像主体检测");
}

}

你可能感兴趣的:(Baidu.Aip.ImageClassify)