Exemple #1
0
        public ResponseMessage addEmployee(string rfid, EmployeePic employee)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Max-Age", "1728000");

            try
            {
                createDirectories(rfid);
                byte[] pict     = Convert.FromBase64String(employee.picture);
                string pictName = employee.employee.rfid;
                string path     = ROOT + "\\" + rfid + "\\" + ColorType.GREEN.ToString() + "\\" + pictName + ".bmp";
                File.WriteAllBytes(path, pict);

                Image <Bgr, byte>  receivedImg   = new Image <Bgr, byte>(path);
                Image <Gray, byte> normalizedImg = receivedImg.Convert <Gray, Byte>();

                Rectangle[] rectangles = classifier.DetectMultiScale(normalizedImg, 1.4, 1, new Size(100, 100), new Size(800, 800));

                foreach (Rectangle r in rectangles)
                {
                    receivedImg.Draw(r, new Bgr(Color.Red), 2);
                }

                if (rectangles.Length <= 0)
                {
                    //put into red folder
                    return(new ResponseMessage(201, "Impossible to insert a new Employee.Face Not found."));
                }

                normalizedImg = receivedImg.Copy(rectangles[0]).Convert <Gray, byte>().Resize(64, 64, Emgu.CV.CvEnum.Inter.Cubic);
                normalizedImg._EqualizeHist();

                Classifier_Train eigenRecog = new Classifier_Train(ROOT + "\\" + rfid + "\\" + ColorType.GREEN.ToString());


                eigenRecog.AddTrainingImage(normalizedImg, rfid, rfid + ".bmp");

                /* Image<Gray, byte> dummyImg = new Image<Gray, byte>("dummy.jpg");
                 * File.Copy("dummy.jpg", ROOT + "\\" + rfid + "\\" + ColorType.GREEN.ToString()+"\\"+"dummy.jpg");
                 * eigenRecog.AddTrainingImage(dummyImg, "Unknown","dummy.jpg");*/

                DBConnect       db   = new DBConnect();
                MySqlConnection conn = db.getConnection();
                MySqlCommand    cmd2 = new MySqlCommand();
                cmd2.Connection  = conn;
                cmd2.CommandText = "INSERT INTO `user`(`rfid`, `name`, `surname`) VALUES (?a,?b,?c);";
                cmd2.Parameters.Add("?a", MySqlDbType.VarChar).Value = employee.employee.rfid;
                cmd2.Parameters.Add("?b", MySqlDbType.VarChar).Value = employee.employee.name;
                cmd2.Parameters.Add("?c", MySqlDbType.VarChar).Value = employee.employee.surname;
                cmd2.ExecuteNonQuery();
                conn.Close();
            }
            catch (Exception e)
            {
                return(new ResponseMessage(201, "Impossible to insert a new Employee."));
            }
            return(new ResponseMessage(200, employee.employee.name + " " + employee.employee.surname + " added correctly."));
        }
Exemple #2
0
        public ResponseMessage addEmployee2(string rfid, EmployeePic employee)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Max-Age", "1728000");

            try{
                createDirectories(rfid);
                byte[] pict     = Convert.FromBase64String(employee.picture);
                string pictName = employee.employee.rfid;
                string path     = ROOT + "\\" + rfid + "\\" + ColorType.GREEN.ToString() + "\\" + pictName + ".bmp";
                File.WriteAllBytes(path, pict);
                DBConnect       db   = new DBConnect();
                MySqlConnection conn = db.getConnection();
                MySqlCommand    cmd2 = new MySqlCommand();
                cmd2.Connection  = conn;
                cmd2.CommandText = "INSERT INTO `user`(`rfid`, `name`, `surname`) VALUES (?a,?b,?c);";
                cmd2.Parameters.Add("?a", MySqlDbType.VarChar).Value = employee.employee.rfid;
                cmd2.Parameters.Add("?b", MySqlDbType.VarChar).Value = employee.employee.name;
                cmd2.Parameters.Add("?c", MySqlDbType.VarChar).Value = employee.employee.surname;
                cmd2.ExecuteNonQuery();
                conn.Close();
            }catch (Exception e) {
                return(new ResponseMessage(201, "Impossible to insert a new Employee."));
            }
            return(new ResponseMessage(200, employee.employee.name + " " + employee.employee.surname + " added correctly."));
        }
Exemple #3
0
        public EmployeePic getInfo(string rfid)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Max-Age", "1728000");

            DBConnect       db         = new DBConnect();
            MySqlConnection conn       = db.getConnection();
            string          query      = "SELECT * FROM user where rfid='" + rfid + "'";
            MySqlCommand    cmd        = new MySqlCommand(query, conn);
            MySqlDataReader dataReader = cmd.ExecuteReader();
            EmployeePic     employee   = new EmployeePic();

            employee.employee = new Employee();
            if (dataReader.Read())
            {
                employee.employee.rfid    = dataReader["rfid"].ToString();
                employee.employee.name    = dataReader["name"].ToString();
                employee.employee.surname = dataReader["surname"].ToString();
                string path          = ROOT + "\\" + rfid + "\\" + "GREEN" + "\\" + rfid + ".bmp";
                string base64picture = Convert.ToBase64String(File.ReadAllBytes(path));
                employee.picture = base64picture;
            }

            conn.Close();
            return(employee);
        }