private void button5_Click(object sender, EventArgs e) { if (filepath1 == null || filepath1 == "") { return; } viewlabel(); var image = File.ReadAllBytes(filepath1); // 如果有可选参数 var options = new Dictionary <string, object> { { "top_num", 3 }, { "baike_num", 5 } }; // 带参数调用动物识别 var result = client.AnimalDetect(image, options); var resultlist = (JArray)(result["result"]); StringBuilder sb = new StringBuilder(""); foreach (var chars in resultlist) //循环获取值 { JObject jo = (JObject)chars; sb.Append("名字:" + Convert.ToString(jo["name"]) + "\n"); sb.Append("置信度:" + Convert.ToString(jo["score"]) + "\n\n\n"); } richTextBox2.Text = sb.ToString(); Status = false; hidelabel(); }
void TestFunc(byte[] imageBytes) { JObject jj = imc.AnimalDetect(imageBytes); foreach (var item in jj) { jsonString = item.Value.ToString(); } List <Result> rrr = new List <Result>(); //有6个结果 第一个相似度 最高 这里只取了第一个 rrr = JsonConvert.DeserializeObject <List <Result> >(jsonString); showRes.text = "识别结果:" + rrr[0].name + " 相似度:" + (Convert.ToSingle(rrr[0].score.ToString()) * 100).ToString() + "%"; }
public static JObject AnimalDetectDemo(byte[] image) { try { // 调用通用物体识别,可能会抛出网络等异常,请使用try/catch捕获 //return _imageClient.AnimalDetect(image); // 如果有可选参数 var options = new Dictionary <string, object> { { "top_num", 3 }, { "baike_num", 5 } }; // 带参数调用动物识别 return(_imageClient.AnimalDetect(image, options)); } catch (AipException exp) { MessageBox.Show(exp.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(null); }