コード例 #1
0
 void _is_face_in_image(string filename)
 {
     try
     {
         //assuming that faces are vertical (handlearbitraryrotations=false) to speed up face detection
         FSDK.SetFaceDetectionParameters(false, true, 384);
         FSDK.SetFaceDetectionThreshold((int)(FaceDetectionThreshold));
         fr = new TFaceRecord();
         fr.ImageFileName  = filename;
         fr.FacePosition   = new FSDK.TFacePosition();
         fr.FacialFeatures = new FSDK.TPoint[1];
         fr.Template       = new Byte[FSDK.TemplateSize - 1];
         fr.image          = new FSDK.CImage(filename);
         fr.FacePosition   = fr.image.DetectFace();
         if (fr.FacePosition.w == 0)
         {
             MessageBox.Show("no face found, make sure you face the camera then try capturing image again...");
         }
         else
         {
             fr.faceImage = fr.image.CopyRect((int)(fr.FacePosition.xc - System.Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.yc - System.Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.xc + System.Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.yc + System.Math.Round(fr.FacePosition.w * 0.5)));
             bool eyesDetected = false;
             try
             {
                 fr.FacialFeatures = fr.image.DetectEyesInRegion(ref fr.FacePosition);
                 eyesDetected      = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Error detecting eyes during registration!!!");
             }
             if (eyesDetected)
             {
                 fr.Template = fr.image.GetFaceTemplateInRegion(ref fr.FacePosition);
             }
             //call savemethod here ->SAVE(fr);
             save_records(fr);
             FaceList = new List <TFaceRecord>();
             FaceList.Add(fr);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Can't open image(s) with error: " + ex.Message.ToString());
     }
 }
コード例 #2
0
        void save_records(TFaceRecord tr)
        {
            MySqlConnection sqlconnect = null;

            try
            {
                //lets prepare the face record to save
                Image img      = null;
                Image img_face = null;
                System.IO.MemoryStream strm      = new System.IO.MemoryStream();
                System.IO.MemoryStream strm_face = new System.IO.MemoryStream();
                img      = fr.image.ToCLRImage();
                img_face = fr.faceImage.ToCLRImage();
                img.Save(strm, System.Drawing.Imaging.ImageFormat.Jpeg);
                img_face.Save(strm_face, System.Drawing.Imaging.ImageFormat.Jpeg);
                Byte[] img_array      = new byte[strm.Length - 1];
                Byte[] img_array_face = new byte[strm_face.Length - 1];
                strm.Position = 0;
                strm.Read(img_array, 0, img_array.Length);
                strm_face.Position = 0;
                strm_face.Read(img_array_face, 0, img_array_face.Length);
                //lets connect to ur mysql database and save record
                sqlconnect = new MySqlConnection("server=127.0.0.1;user id=root;password=;database=verification_system");
                sqlconnect.Open();
                MySqlCommand sqlcmd = new MySqlCommand();
                sqlcmd.Connection  = sqlconnect;
                sqlcmd.CommandText = "INSERT INTO records(ImageFileName, FacePositionXc, FacePositionYc, FacePositionW, FacePositionAngle, Eye1X, Eye1Y, Eye2X, Eye2Y, imagetemplate, Image, FaceImage, name, email, phone, gender, marital, address, dob) " + " VALUES(@ImageFileName, @FacePositionXc, @FacePositionYc, @FacePositionW, @FacePositionAngle, @Eye1X, @Eye1Y, @Eye2X, @Eye2Y, @imageTemplate, @Image, @FaceImage, @name, @email, @phone, @gender, @marital, @address, @dob)";
                //
                sqlcmd.Parameters.AddWithValue("@ImageFileName", fr.ImageFileName);
                sqlcmd.Parameters.AddWithValue("@FacePositionXc", fr.FacePosition.xc);
                sqlcmd.Parameters.AddWithValue("@FacePositionYc", fr.FacePosition.yc);
                sqlcmd.Parameters.AddWithValue("@FacePositionW", fr.FacePosition.w);
                sqlcmd.Parameters.AddWithValue("@FacePositionAngle", (Single)(fr.FacePosition.angle));
                sqlcmd.Parameters.AddWithValue("@Eye1X", fr.FacialFeatures[0].x);
                sqlcmd.Parameters.AddWithValue("@Eye1Y", fr.FacialFeatures[0].y);
                sqlcmd.Parameters.AddWithValue("@Eye2X", fr.FacialFeatures[1].x);
                sqlcmd.Parameters.AddWithValue("@Eye2Y", fr.FacialFeatures[1].y);
                sqlcmd.Parameters.AddWithValue("@imageTemplate", fr.Template);
                sqlcmd.Parameters.AddWithValue("@Image", img_array);
                sqlcmd.Parameters.AddWithValue("@FaceImage", img_array_face);
                //sqlcmd.Parameters.AddWithValue("@ID", bio.c);
                sqlcmd.Parameters.AddWithValue("@name", txt_firstname.Text + " " + txt_surname.Text);
                sqlcmd.Parameters.AddWithValue("@email", txt_email.Text);
                sqlcmd.Parameters.AddWithValue("@phone", txt_phone.Text);
                sqlcmd.Parameters.AddWithValue("@gender", cbo_gender.Text);
                sqlcmd.Parameters.AddWithValue("@marital", cbo_marital.Text);
                sqlcmd.Parameters.AddWithValue("@address", txt_address.Text);
                sqlcmd.Parameters.AddWithValue("@dob", dt_staff.Value.ToShortDateString());
                sqlcmd.ExecuteNonQuery();
                logic log = new logic();
                //log action here -> ID card generation in progress
                log.generate_qrcode(txt_firstname.Text + " " + txt_surname.Text, txt_phone.Text, get_staffname());
                log.generate_user_id(Application.StartupPath + "\\images\\" + get_staffname() + ".jpg", txt_firstname.Text + " " + txt_surname.Text, dt_staff.Value.ToShortDateString(), cbo_gender.Text, get_staffname());
                MessageBox.Show("Staff successfully registered", "Registration");
                //clear all input fields
                txt_address.Text    = "";
                txt_email.Text      = "";
                txt_firstname.Text  = "";
                txt_phone.Text      = "";
                txt_surname.Text    = "";
                staff_picture.Image = null;
                img.Dispose();
                img_face.Dispose();
                cbo_gender.SelectedItem  = null;
                cbo_marital.SelectedItem = null;
                dt_staff.Value           = DateTime.Now;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception on saving to database");
                //log error here
            }
            finally
            {
                sqlconnect.Close();
            }
        }