Пример #1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter           = "xml files (*.xml)|*.xml";
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK && saveFileDialog1.FileName != string.Empty)
            {
                using (StreamWriter wr = new StreamWriter(saveFileDialog1.FileName))
                {
                    // saving xml
                    ListedFaces listedFaces = new ListedFaces(this.fileName, this.faceList);
                    wr.Write(ListedFaces.SerializeObject(listedFaces));
                    wr.Close();
                }
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            // load button for loading xml onto the face and display in the picture button.
            using (this.loadOpenFileDialog = new OpenFileDialog())
            {
                this.loadOpenFileDialog.InitialDirectory = @"C:\users\";
                this.loadOpenFileDialog.Filter           = "XML files (*.xml)|*.xml";
                this.loadOpenFileDialog.FilterIndex      = 2;
                this.loadOpenFileDialog.RestoreDirectory = true;

                if (loadOpenFileDialog.ShowDialog() == DialogResult.OK)
                {
                    XmlSerializer reader      = new XmlSerializer(typeof(ListedFaces));
                    StreamReader  file        = new StreamReader(this.loadOpenFileDialog.FileName);
                    ListedFaces   listedFaces = (ListedFaces)reader.Deserialize(file);

                    this.fileName = listedFaces.fileName;

                    try
                    {
                        var dst = new Mat(this.fileName, ImreadModes.Color);
                        this.faceList = listedFaces.faces;
                        for (int i = 0; i < listedFaces.faces.Count; i++)
                        {
                            Cv2.Rectangle(dst, listedFaces.faces[i], Scalar.White, 3);
                        }

                        this.image              = BitmapConverter.ToBitmap(dst);
                        mainPictureBox.Image    = (Image)image;
                        mainPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
                    }
                    catch {
                        MessageBox.Show("image File not found");
                    }
                }
            }
        }