//public static bool IsHuman(this BaiduAnalyzeResult data, List<string> tagIsHumanList = null)
        //{
        //    if (tagIsHumanList == null)
        //    {
        //        tagIsHumanList = new List<string>()
        //        {
        //            "human","person"
        //        };
        //    }
        //    bool res = false;
        //    if (data.Tags != null)
        //    {
        //        res = data.Tags.AsEnumerable().Any(x => tagIsHumanList.Any(l => l == x.Name));
        //    }
        //    if (!res&&data.Description != null)
        //    {
        //        var caption = data.Description.Captions.Where(x => x.Confidence > 0.75).ToList();
        //        //如果结果里边有置信度比较高的结论,以他为准
        //        if (caption.Count() != 0)
        //        {
        //            //res = caption.Any(x =>
        //            //    x.Text.Contains("animal") || x.Text.Contains("bird") || x.Text.Contains("sheep") ||
        //            //    x.Text.Contains("bear") || x.Text.Contains("giraffe"));
        //            res = caption.Any(x => tagIsHumanList.Any(l => x.Text.Contains(l)));
        //        }
        //        else//否则就tags里边查
        //        {
        //            res = data.Description.Tags.AsEnumerable().Any(x => tagIsHumanList.Any(l => l == x));
        //        }
        //    }
        //    return res;
        //}

        public static Score IsWhich(this BaiduAnalyzeResult data)
        {
            Score res = new Score();

            if (data.result != null)
            {
                res = data.result.OrderByDescending(x => x.score).FirstOrDefault();
            }
            return(res);
        }
        public static bool IsAnimal(this BaiduAnalyzeResult data, double minConfidence = 0.4, string likePattern = "")
        {
            var res = false;

            if (data.result != null)
            {
                if (string.IsNullOrWhiteSpace(likePattern))
                {
                    res = data.result.Any(x => x.score >= minConfidence && x.name != "非动物");
                }
                else
                {
                    IEnumerable <Score> liked = data.result.Where(x => x.name != "非动物" && Regex.IsMatch(x.name, likePattern));
                    res = liked.Sum(x => x.score) >= minConfidence;
                }
            }
            return(res);
        }
        private async void BaiduAnalyzeImage(string path)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            BaiduVisionAnalyze ana = new BaiduVisionAnalyze();

            ana.Key  = "vKHUR4T6BMeO3yTVwW3nR1NN";
            ana.SKey = "u8A17o87RD7Q35lU8qQKjxrDs1bguBrD";


            Task <BaiduAnalyzeResult> resTask = ana.UploadAndAnalyzeImage(path);
            BaiduAnalyzeResult        res     = await resTask;

            //watch end
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            //write result
            this.richTextBox1.Text  = $"is animal:{res.IsAnimal()}\n";
            this.richTextBox1.Text += $"run with {imageListView1.SelectedItems[0].FileName}\n";
            this.richTextBox1.Text += $"used {elapsedMs} ms\n";
            this.richTextBox1.Text += VisCommonClass.JsonPrettyPrint(JsonConvert.SerializeObject(res));
            MessageBox.Show($"cost {elapsedMs}ms");
        }