导入的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);
}
}
已解决.问题出在单例模式上,与调用无关.