Unity 使用C#sdk时报错
740029548 发布于2020-05 浏览:2002 回复:1
0
收藏

导入的aip-csharp-sdk-3.6.9\net40下的aipsdk.dll和newtonsoft.json.dll

代码如下:

public class BaiduFaceAI : Singleton
{
// 设置APPID/AK/SK
const string APP_ID = "....";
const string API_KEY = "....";
const string SECRET_KEY = "....";

private Body client;

void Start()
{
client = new Body(API_KEY, SECRET_KEY);
client.Timeout = 60000; // 修改超时时间

Instance.BodyAnalysis((isHuman) => {
if (isHuman)
{Debug.Log("检测到人体");}
});
}

 

public void BodyAnalysis(Action callback)
{
try
{
//加载本地图片
string path = Application.streamingAssetsPath + "/COCO_val2014_000000000474.jpg";
var image = File.ReadAllBytes(path);

//接受图像的bytes
JObject result= client.BodyAnalysis(image);    报错行:Object reference not set to an instance of an object

callback(IsHuman(result));
}
catch (System.Exception e)
{
Debug.Log(e);
}
}

收藏
点赞
0
个赞
共1条回复 最后由740029548回复于2020-05
#2740029548回复于2020-05

已解决.问题出在单例模式上,与调用无关.

 

0
TOP
切换版块