private void processMovie() { if (videoReader.IsOpen) { Bitmap videoFrame; processor.Background = videoReader.ReadVideoFrame(); int i = 0; while ((videoFrame = videoReader.ReadVideoFrame()) != null) { Bitmap preprocess = processor.preprocessImage(videoFrame); this.Dispatcher.Invoke(new Action(() => frameCountLabel.Content = Properties.Resources.FPS_LABEL_BEGIN + (int)(++i / videoReader.FrameRate) + "s")); this.Dispatcher.Invoke(new Action(() => preprocessedImage.Source = VideoProcessor.convertBitmap(preprocess))); Bitmap diff = processor.findDifference(preprocess); preprocess.Dispose(); this.Dispatcher.Invoke(new Action(() => differenceImage.Source = VideoProcessor.convertBitmap(diff))); Bitmap final = processor.showMotion(videoFrame, diff); diff.Dispose(); this.Dispatcher.Invoke(new Action(() => finalImage.Source = VideoProcessor.convertBitmap(final))); final.Dispose(); videoFrame.Dispose(); } i = 0; videoReader.Dispose(); videoReader.Close(); restart(); } }
private void setInitialBitmaps() { Bitmap initial = new Bitmap(320, 240); for (int x = 0; x < initial.Width; x++) { for (int y = 0; y < initial.Height; y++) { System.Drawing.Color pixelColor = initial.GetPixel(x, y); System.Drawing.Color newColor = System.Drawing.Color.FromArgb(pixelColor.R, 0, 0); initial.SetPixel(x, y, newColor); } } preprocessedImage.Source = VideoProcessor.convertBitmap(initial); differenceImage.Source = VideoProcessor.convertBitmap(initial); finalImage.Source = VideoProcessor.convertBitmap(initial); initial.Dispose(); }