Inheritance: System.Windows.Forms.Form
示例#1
0
        /// <summary>
        /// Generate images including face and non-face patch to construct the validation set
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void generateValidToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GenValidForm gen_valid_form = new GenValidForm();

            gen_valid_form.Show();
            gen_valid_form.accept += new EventHandler(gen_valid_form_accept);
        }
示例#2
0
        private void gen_valid_form_accept(object sender, EventArgs e)
        {
            // get information of validation set
            string       valid_image_save_path;
            string       valid_image_list;
            GenValidForm gen_valid_form = (GenValidForm)sender;

            valid_image_save_path = gen_valid_form.image_save_path;
            valid_image_list      = gen_valid_form.list_filename;
            gen_valid_form.Close();

            //
            process data_processing = new process();

            data_processing.Show();
            data_processing.progressBar1.Value   = 0;
            data_processing.progressBar1.Maximum = image_info_list.Count;

            // crop and save images
            double       xtl, ytl, width, height;
            Bitmap       original_image;
            string       list_path = valid_image_save_path + "\\" + valid_image_list + ".txt";
            FileStream   list      = new FileStream(list_path, FileMode.OpenOrCreate);
            StreamWriter sw        = new StreamWriter(list);

            for (int i = 0; i < image_info_list.Count; i++)
            {
                data_processing.progressBar1.Value++;
                if (image_info_list[i].DetectFrList == null)
                {
                    image_info_list[i].DetectFrList = io.getFrList(image_info_list[i].DetectFrPath);
                }
                if (image_info_list[i].GtFrList == null)
                {
                    image_info_list[i].GtFrList = io.getFrList(image_info_list[i].GtFrPath);
                }

                eval.singleImageMatch(image_info_list[i], 0.05);

                original_image = new Bitmap(image_info_list[i].ImgPath);
                string save_path;
                string save_path_name;

                // positive sample
                for (int j = 0; j < image_info_list[i].GtFrList.Count; j++)
                {
                    if (image_info_list[i].GtFrList[j].Length == 5)
                    {
                        double a, b, w;
                        a = image_info_list[i].GtFrList[j][0];
                        b = image_info_list[i].GtFrList[j][1];
                        w = image_info_list[i].GtFrList[j][2];

                        /*
                         * xtl = image_info_list[i].GtFrList[j][3] - image_info_list[i].GtFrList[j][0] * 0.8;
                         * ytl = image_info_list[i].GtFrList[j][4] - image_info_list[i].GtFrList[j][0] * 0.8;
                         * width = image_info_list[i].GtFrList[j][0]  * 2*0.8;
                         * height = image_info_list[i].GtFrList[j][0]  * 2*0.8;*/
                        width  = 2 * Math.Sqrt(Math.Pow(a, 2) + (Math.Pow(b, 2) - Math.Pow(a, 2)) * Math.Pow(Math.Sin(w), 2));
                        height = 2 * Math.Sqrt(Math.Pow(a, 2) + (Math.Pow(b, 2) - Math.Pow(a, 2)) * Math.Pow(Math.Cos(w), 2));
                        xtl    = image_info_list[i].GtFrList[j][3] - 0.5 * width;
                        ytl    = image_info_list[i].GtFrList[j][4] - 0.5 * height;
                    }
                    else
                    {
                        xtl    = image_info_list[i].GtFrList[j][0];
                        ytl    = image_info_list[i].GtFrList[j][1];
                        width  = image_info_list[i].GtFrList[j][2] - xtl + 1;
                        height = image_info_list[i].GtFrList[j][3] - ytl + 1;
                    }
                    Rectangle rect = new Rectangle(Convert.ToInt32(xtl), Convert.ToInt32(ytl), Convert.ToInt32(width), Convert.ToInt32(height));
                    Bitmap    crop = crop_image(original_image, rect);
                    string    line = "pos\\" + image_info_list[i].RelativeImgPath + '_' + j.ToString() + ".jpg";

                    save_path_name = Path.Combine(valid_image_save_path + "\\", line);
                    save_path      = Path.GetDirectoryName(save_path_name).ToString();
                    if (Directory.Exists(save_path) == false)
                    {
                        Directory.CreateDirectory(save_path);
                    }
                    crop.Save(save_path_name, ImageFormat.Jpeg);
                    sw.WriteLine(line.Replace('\\', '/') + " 1");
                }

                // negative samples
                for (int j = 0; j < image_info_list[i].DetectFrList.Count; j++)
                {
                    if (image_info_list[i].Scores[j] < 0.05)
                    {
                        xtl    = image_info_list[i].DetectFrList[j][0];
                        ytl    = image_info_list[i].DetectFrList[j][1];
                        width  = image_info_list[i].DetectFrList[j][2] - xtl + 1;
                        height = image_info_list[i].DetectFrList[j][3] - ytl + 1;

                        Rectangle rect = new Rectangle(Convert.ToInt32(xtl), Convert.ToInt32(ytl), Convert.ToInt32(width), Convert.ToInt32(height));
                        Bitmap    crop = crop_image(original_image, rect);
                        string    line = "neg\\" + image_info_list[i].RelativeImgPath + '_' + j.ToString() + ".jpg";

                        save_path_name = Path.Combine(valid_image_save_path + "\\", line);
                        save_path      = Path.GetDirectoryName(save_path_name).ToString();
                        if (Directory.Exists(save_path) == false)
                        {
                            Directory.CreateDirectory(save_path);
                        }
                        crop.Save(save_path_name, ImageFormat.Jpeg);
                        sw.WriteLine(line.Replace('\\', '/') + " 0");
                    }
                }
                original_image.Dispose();
            }

            data_processing.Close();
            sw.Close();
            list.Close();
        }