private void CompateClusterMaps(Bitmap image, int[] expectedClusterMap) { ColorClusterCreator clusterCreator = new ColorClusterCreator(image.Width, image.Height); clusterCreator.SetUseGaussBlur(false); clusterCreator.SetUseNoiseRemoval(false); clusterCreator.UpdateClusters(image); int[] actualClusterMap = clusterCreator.GetClusterMap(); Assert.AreEqual(expectedClusterMap.Length, actualClusterMap.Length); for (int i = 0; i < expectedClusterMap.Length; i++) { Assert.AreEqual(expectedClusterMap[i], actualClusterMap[i], "Maps doesn't match." + Environment.NewLine + "Expected: " + Environment.NewLine + ClusterMapAsString(expectedClusterMap, image.Width, image.Height) + Environment.NewLine + "Actual: " + Environment.NewLine + ClusterMapAsString(actualClusterMap, image.Width, image.Height)); } }
private void VideoSource_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs) { if (SkippedFrames < FRAMES_TO_SKIP) { SkippedFrames++; return; } else { SkippedFrames = 0; } //Cast the frame as Bitmap object and don't forget to use ".Clone()" otherwise Bitmap TempBitmap = (Bitmap)eventArgs.Frame.Clone(); //you'll probably get access violation exceptions watch.Reset(); watch.Start(); TempBitmap.RotateFlip(RotateFlipType.RotateNoneFlipX); try { ct.UpdateClusters(TempBitmap); Bitmap withClusters = ct.BitmapFromClusterMap(); ShowTracker(withClusters); Dispatcher.Invoke(() => infoWindow.ImageViewer.Source = Convert(withClusters)); } catch (Exception e) { Dispatcher.Invoke(() => MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace)); } watch.Stop(); Dispatcher.Invoke(() => infoWindow.ClusterCreationTime.Text = "Time: " + watch.ElapsedMilliseconds); Dispatcher.Invoke(() => infoWindow.ClusterCount.Text = "Cluster Count: " + ct.clusters.Count); }