예제 #1
0
        private void button2_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 },
                { "filter_threshold", "0.7" },
                { "baike_num", 5 }
            };
            // 带参数调用菜品识别
            JObject       result     = client.DishDetect(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["has_calorie"]) + "\n");
                sb.Append("卡路里:" + Convert.ToString(jo["calorie"]) + "\n");
                sb.Append("置信度:" + Convert.ToString(jo["probability"]) + "\n\n\n");
            }
            richTextBox2.Text = sb.ToString();
            hidelabel();
        }
예제 #2
0
        public static JObject DishDetectDemo(byte[] image)
        {
            try
            {
                // 调用通用物体识别,可能会抛出网络等异常,请使用try/catch捕获
                //return _imageClient.DishDetect(image);
                // 如果有可选参数
                var options = new Dictionary <string, object> {
                    { "top_num", 3 },
                    { "filter_threshold", "0.7" },
                    { "baike_num", 5 }
                };

                // 带参数调用菜品识别
                return(_imageClient.DishDetect(image, options));
            }
            catch (AipException exp)
            {
                MessageBox.Show(exp.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(null);
        }