Exemplo n.º 1
0
 void loadAccessData()
 {
     try
     {
         AccessToken = AccessJson["access_token"].Value;
         if (AccessJson["refresh_token"] != null)
         {
             RefreshToken = AccessJson["refresh_token"].Value;
         }
     }
     catch {
         throw new Exception("Error loading AccessData from " + AccessJson.ToString());
     }
 }
Exemplo n.º 2
0
        //进入智能分析
        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                //将图片转换成BASE64编码
                Image        bmp = pictureBox1.Image;
                MemoryStream ms  = new MemoryStream();
                bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] arr = new byte[ms.Length];
                ms.Position = 0;
                ms.Read(arr, 0, (int)ms.Length);
                ms.Close();
                String strbaser64 = Convert.ToBase64String(arr);

                //显示数据

                jsontext = AccessJson.Detect(strbaser64);
            }
            catch (Exception ex)
            {
                MessageBox.Show("ImgToBase64String 转换失败\nException:" + ex.Message);
            }

            //解析JSON数据
            RootObject people = JsonConvert.DeserializeObject <RootObject>(jsontext);

            facenum = Convert.ToInt32(people.result.face_num);


            //获取值
            text  = "转换结果:";
            text += people.error_msg + "\r\n";
            //location存着每一个人脸的x,y坐标,长宽四个信息,二维数组
            for (int i = 0; i < facenum; i++)
            {
                location[i] = new int[4] {
                    Convert.ToInt32(Convert.ToSingle(people.result.face_list[i].location.left)),
                    Convert.ToInt32(Convert.ToSingle(people.result.face_list[i].location.top)),
                    Convert.ToInt32(Convert.ToSingle(people.result.face_list[i].location.width)),
                    Convert.ToInt32(Convert.ToSingle(people.result.face_list[i].location.height))
                };
                rect2[i].Location = new Point(location[i][0], location[i][1]);
                rect2[i].Size     = new Size(location[i][2], location[i][3]);
            }



            text += "这是一张人脸的概率:";
            text += people.result.face_list[0].face_probability + "\r\n";

            text += "年龄:";
            text += people.result.face_list[0].age + "\r\n";

            text += "颜值:";
            text += people.result.face_list[0].beauty + "\r\n";

            text += "表情:";
            text += people.result.face_list[0].expression.probability + "概率是";
            string expression_type = people.result.face_list[0].expression.type;

            if (expression_type == "none")
            {
                expression_type = "冷漠脸";
            }
            else if (expression_type == "smile")
            {
                expression_type = "微笑";
            }
            else if (expression_type == "laugh")
            {
                expression_type = "大笑";
            }
            else
            {
                expression_type = "都不知道你什么表情";
            }
            text += expression_type + "\r\n" + "\r\n";

            //square: 正方形 triangle:三角形 oval: 椭圆 heart: 心形 round: 圆形
            text += "脸型:";
            text += people.result.face_list[0].face_shape.probability + "概率是";
            string faceShape = people.result.face_list[0].face_shape.type;

            if (faceShape == "square")
            {
                faceShape = "正方形";
            }
            else if (faceShape == "triangle")
            {
                faceShape = "三角形";
            }
            else if (faceShape == "oval")
            {
                faceShape = "椭圆";
            }
            else if (faceShape == "heart")
            {
                faceShape = "心形";
            }
            else if (faceShape == "round")
            {
                faceShape = "圆形";
            }
            else
            {
                faceShape = "都不知道你什么头";
            }
            text += faceShape + "\r\n" + "\r\n";

            //male:男性 female:女性
            text += "性别:";
            text += people.result.face_list[0].gender.probability + "概率是";
            string sex = people.result.face_list[0].gender.type;

            if (sex == "male")
            {
                sex = "男性";
            }
            else if (sex == "female")
            {
                sex = "女性";
            }
            else
            {
                sex = "都不知道你什么性别";
            }
            text += sex + "\r\n" + "\r\n";

            //none:无眼镜,common:普通眼镜,sun:墨镜
            text += "眼镜类型:";
            text += people.result.face_list[0].glasses.probability + "概率是";
            string glasse = people.result.face_list[0].glasses.type;

            if (glasse == "none")
            {
                glasse = "无眼镜";
            }
            else if (glasse == "common")
            {
                glasse = "普通眼镜";
            }
            else if (glasse == "sun")
            {
                glasse = "墨镜";
            }
            else
            {
                faceShape = "眼呢?";
            }
            text += glasse + "\r\n" + "\r\n";

            //yellow: 黄种人 white: 白种人 black:黑种人 arabs: 阿拉伯人
            text += "种族:";
            text += people.result.face_list[0].race.probability + "概率是";
            string race = people.result.face_list[0].race.type;

            if (race == "yellow")
            {
                race = "黄种人";
            }
            else if (race == "white")
            {
                race = "白种人";
            }
            else if (race == "black")
            {
                race = "黑种人";
            }
            else if (race == "arabs")
            {
                race = "阿拉伯人";
            }
            else
            {
                race = "人呢?";
            }
            text += race + "\r\n" + "\r\n";

            textBox2.Text = "已成功进入智能分析";
        }