예제 #1
0
        static List <Face> Get_FaceBasicInformation()
        {
            List <Face>   Person     = new List <Face>();   //Creat a new list called Person
            StringBuilder W_FileJSON = new StringBuilder(); //W_FileJSON is the String be written into the TXT file.

            W_FileJSON.Clear();
            MyValue.Finish = "";
            string[] MyPhotoDicrectory = Directory.GetFiles("PhotoGroup"); //MyPhotoDicrectory can help API upload all the file in the float photo.
            string[] MySampleDicere    = Directory.GetFiles("Sample");
            MyValue.Count    = 0;
            MyValue.T_Sample = "false";
            foreach (string MPD in MyPhotoDicrectory)
            {
                MyValue.T_Timeout = false;
                int time = 0;
                API_Detect(MPD);
                while (MyValue.Finish != "OK")
                {
                    time++;
                    System.Threading.Thread.Sleep(200);
                    if (time == 150)
                    {
                        MyValue.T_Timeout = true;
                        break;
                    }
                }
                MyValue.Finish = "";
                if (MyValue.T_FindFace == true & MyValue.T_Timeout == false)
                {
                    int t_count = 0;
                    foreach (Face T_FaceValue in MyValue.TA_FaceValue)
                    {
                        if (t_count == 0)
                        {
                            Console.WriteLine("You have upload {0} successful.", T_FaceValue.Directory_F);
                        }
                        Person.Add(T_FaceValue);
                        t_count++;
                    }
                    W_FileJSON.Append("|");
                    W_FileJSON.Append(MyValue.TB_FileJSON);
                    MyValue.Count++;
                }
                else
                {
                    if (MyValue.T_Timeout == true)
                    {
                        Console.WriteLine("Time out!!! Fail to upload {0}", MPD);
                        File.Copy(Path.GetFullPath(MPD), "Error\\"
                                  + "TimeOut  "
                                  + MPD.Substring(11), true);
                    }
                    else
                    {
                        Console.WriteLine("We can't find face in file {0}, please recheck this picture. ", MPD.ToString());
                    }
                }
            }
            MyValue.T_Sample = "true";
            foreach (string MSD in MySampleDicere)
            {
                MyValue.T_Timeout = false;
                int time = 0;
                API_Detect(MSD);
                while (MyValue.Finish != "OK")
                {
                    time++;
                    System.Threading.Thread.Sleep(200);
                    if (time == 150)
                    {
                        MyValue.T_Timeout = true;
                        break;
                    }
                }
                MyValue.Finish = "";
                if (MyValue.T_FindFace == true & MyValue.T_Timeout == false)
                {
                    int t_count = 0;
                    foreach (Face T_FaceValue in MyValue.TA_FaceValue)
                    {
                        if (t_count == 0)
                        {
                            Console.WriteLine("You have upload {0} successful.", T_FaceValue.Directory_F);
                        }
                        Person.Add(T_FaceValue);
                        t_count++;
                    }
                    W_FileJSON.Append("|");
                    W_FileJSON.Append(MyValue.TB_FileJSON);
                    MyValue.Count++;
                }
                else
                {
                    if (MyValue.T_Timeout == true)
                    {
                        Console.WriteLine("Time out!!! Fail to upload {0}", MSD);
                        File.Copy(Path.GetFullPath(MSD), "Error\\"
                                  + "TimeOut  "
                                  + MSD.Substring(11), true);
                    }
                    else
                    {
                        Console.WriteLine("We can't find face in file {0}, please recheck this picture. ", MSD.ToString());
                    }
                }
            }
            Console.WriteLine("***********----------------SUCCESS----------------***********");
            foreach (Face people in Person)
            {
                Console.WriteLine("Name:{0} || Gender:{1} || Age:{2} || FaceID:{3}",
                                  people.Name_F,
                                  people.Gender_F,
                                  people.Age_F,
                                  people.ID_F);
            }
            StreamWriter WriteJSON_TXT = new StreamWriter("JSON_Value.txt");

            WriteJSON_TXT.Write(W_FileJSON.ToString());
            WriteJSON_TXT.Close();
            Console.WriteLine("Warning:The FaceID will expire after 24 hour!!!");
            return(Person);
        }