Ejemplo n.º 1
0
        private void Convert_dataset_button_Click(object sender, EventArgs e)
        {
            string conversion_algorithm_selected = convert_method_list.Text;

            if (conversion_algorithm_selected == "" || conversion_algorithm_selected == null)
            {
                MessageBox.Show("Select Conversion");
                return;
            }
            Algorithms          conversion_algorithms = new Algorithms((UInt32)eventlatency.Value);
            FolderBrowserDialog folderFileDialog      = new FolderBrowserDialog();

            DialogResult result = folderFileDialog.ShowDialog();

            if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(folderFileDialog.SelectedPath))
            {
                List <string> files = new List <string>(Directory.GetFiles(folderFileDialog.SelectedPath));
                files.RemoveAll(i => i.Contains(".aedat"));
                Dataset_progress_bar.Maximum = files.Count;

                new Thread(() =>
                {
                    Dataset_progress_bar.BeginInvoke(new Action(() => Dataset_progress_bar.Value = 0));

                    foreach (string frame in files)
                    {
                        Image <Bgr, Byte> ImageDataset = new Image <Bgr, Byte>((Bitmap)Bitmap.FromFile(frame)).Resize(128, 128, 0);
                        Image <Gray, Byte> grayImage   = ImageDataset.Convert <Gray, Byte>();
                        Bitmap image2event             = grayImage.Bitmap;

                        float[,] bright_matrix = new float[image2event.Width, image2event.Height];
                        Frame_Utils.Get_pixel_bright(image2event, bright_matrix);
                        BinaryWriter bWriter = new BinaryWriter(File.Create(frame + ".aedat"));

                        this.Invoke((MethodInvoker) delegate
                        {
                            DataSetPictureBox.Image = grayImage.Resize(DataSetPictureBox.Width, DataSetPictureBox.Height, 0).Bitmap;
                            // runs on UI thread
                        });

                        Dataset_progress_bar.BeginInvoke(new Action(() => Dataset_progress_bar.Increment(1)));

                        switch (conversion_algorithm_selected)
                        {
                        case "Scan":
                            conversion_algorithms.Scan_Method(bright_matrix, bWriter, true);
                            break;

                        case "Random":
                            conversion_algorithms.Random_Method(bright_matrix, bWriter, true);
                            break;

                        case "Bitwise":
                            conversion_algorithms.Bitwise_method(bright_matrix, bWriter, true);
                            break;
                        }
                    }
                    System.Windows.Forms.MessageBox.Show("Dataset Converted", "Message");
                }).Start();
            }
        }
Ejemplo n.º 2
0
        //Browse Video and convert it using a selected conversion algorithm
        private void BrowseVideo_Click(object sender, EventArgs e)
        {
            //browse for a video
            Algorithms     conversion_algorithms = new Algorithms((UInt32)eventlatency.Value);
            OpenFileDialog openFileDialog        = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter           = "mp4 (*.mp4)|*.mp4|avi files (*.avi)|*.avi|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //Get frames of the Video
                List <Image <Bgr, Byte> > image_array = new List <Image <Bgr, Byte> >();
                image_array = Frame_Utils.GetVideoFrames((int)Miliseconds_frame.Value, openFileDialog.FileName);

                //Select where output file will be stored
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = "Aedat file|*.aedat";
                saveFileDialog.Title  = "Save an Image File";
                saveFileDialog.ShowDialog();

                // If the file name is not an empty string open it for saving.
                if (saveFileDialog.FileName != "")
                {
                    BinaryWriter bWriter = new BinaryWriter(File.Create(saveFileDialog.FileName));
                    string       method  = convert_method_list.Text;

                    if (method != "")
                    {
                        //Create a new thread to convert the video
                        new Thread(() =>
                        {
                            Thread.CurrentThread.IsBackground = true;

                            for (int frame = 0; frame < image_array.Count; frame++)
                            {
                                //Get current image to be converted and its brightness
                                Bitmap current_image_frame  = image_array[frame].Convert <Gray, Byte>().Sobel(0, 1, 3).AbsDiff(new Gray(0.0)).Resize(128, 128, 0).Bitmap;
                                VideoBox.Image              = image_array[frame].Resize(VideoBox.Width, VideoBox.Height, 0).Bitmap;
                                float[,] pixel_matrix_frame = new float[current_image_frame.Width, current_image_frame.Height];
                                Frame_Utils.Get_pixel_bright(current_image_frame, pixel_matrix_frame);
                                bool oneframe = (frame == 0);
                                //Conver current frame
                                switch (method)
                                {
                                case "Scan":
                                    conversion_algorithms.Scan_Method(pixel_matrix_frame, bWriter, oneframe);
                                    break;

                                case "Random":
                                    conversion_algorithms.Random_Method(pixel_matrix_frame, bWriter, oneframe);
                                    break;

                                case "Bitwise":
                                    conversion_algorithms.Bitwise_method(pixel_matrix_frame, bWriter, oneframe);
                                    break;
                                }
                            }
                            MessageBox.Show("Video Converted");

                            bWriter.Close();
                        }).Start();
                    }
                }
                else
                {
                    MessageBox.Show("Please Select a conversion method");
                }
            }
        }