using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing.Imaging; using AForge.Video; using AForge.Video.DirectShow; using AForge.Vision.Motion; using AForge.Imaging; using System.Collections; using Background_Filter; namespace VideoPlayer { public partial class VideoPlayerForm : Form { private FileVideoSource videoSource; private int frameCount; private Boolean videoPaused = false; private BackgroundFilterBase filter; private Bitmap currentFrame; private Bitmap motionFrame; public VideoPlayerForm() { InitializeComponent(); } private void loadButton_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { loadVideoFromFile(openFileDialog1.FileName); } surpressNoiseCheckbox.Checked = false; } private void loadVideoFromFile(String fileName) { videoSource = new FileVideoSource(fileName); // New frame event handler, which is invoked on each new available video frame videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame); } private void startButton_Click(object sender, EventArgs e) { frameCount = 0; videoSource.Start(); } private void pauseButton_Click(object sender, EventArgs e) { videoPaused = !videoPaused; } // New frame event handler, which is invoked on each new available video frame private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) { // Get new frame currentFrame = (Bitmap)(eventArgs.Frame.Clone()); motionFrame = (Bitmap)(eventArgs.Frame.Clone()); // Display the frame if (!videoPaused) { pictureBox1.Image = currentFrame; // Load frame from background subtraction algorithm if (filter != null) { filter.ProcessFrame(motionFrame); motionFrame = filter.MotionFrame; pictureBox2.Image = motionFrame; } } frameLabel.Text = "Frame: " + frameCount++; } private void stopButton_Click_1(object sender, EventArgs e) { videoSource.Stop(); } private void VideoPlayerForm_FormClosed(object sender, FormClosedEventArgs e) { videoSource.Stop(); } private void twoFrameDifferenceButton_Click(object sender, EventArgs e) { if (currentFrame != null) { Boolean surpressNoise = surpressNoiseCheckbox.Checked; filter = new TwoFrameDifferencingFilter(currentFrame, surpressNoise); } } private void backgroundSubtractionButton_Click(object sender, EventArgs e) { if (currentFrame != null) { Boolean surpressNoise = surpressNoiseCheckbox.Checked; filter = new BackgroundSubtractionFilter(currentFrame, surpressNoise, 0.5); } } private void backgroundSubtractionMedianButton_Click(object sender, EventArgs e) { if (currentFrame != null) { Boolean surpressNoise = surpressNoiseCheckbox.Checked; filter = new BackgroundSubtractionMedianFilter(currentFrame, surpressNoise, 9); } } private void GaussianModelButton_Click(object sender, EventArgs e) { if (currentFrame != null) { Boolean surpressNoise = surpressNoiseCheckbox.Checked; filter = new GaussianModelFilter(currentFrame, surpressNoise, 0.3); } } private void relaxationLabellingButton_Click(object sender, EventArgs e) { if (currentFrame != null) { Boolean surpressNoise = surpressNoiseCheckbox.Checked; filter = new RelaxationLabellingFilter(currentFrame, surpressNoise, 0.1); } } private void surpressNoiseCheckbox_CheckedChanged(object sender, EventArgs e) { if ((surpressNoiseCheckbox.Checked) && (filter != null)) filter.SuppressNoise = true; else if ((!surpressNoiseCheckbox.Checked) && (filter != null)) filter.SuppressNoise = false; } } }