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 Window_Loaded(object sender, RoutedEventArgs e) { //Bitmap test = new Bitmap("balls1.png"); //ct = new ColorClusterCreator(test.Width, test.Height); //Stopwatch w = new Stopwatch(); //w.Start(); //ct.SetColorDistance(14); ////for (int i = 0; i < 1; i++) ////{ // ct.UpdateClusters(test); // ct.BitmapFromClusterMap(); ////} //w.Stop(); //ct.BitmapFromClusterMap().Save("testResult.png"); //MessageBox.Show(w.ElapsedMilliseconds.ToString()); FilterInfoCollection videoSources = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoSources == null) { MessageBox.Show("No webcam found."); return; } //assume for now that the first source is the webcam videoSource = new VideoCaptureDevice(videoSources[0].MonikerString); //if it isn't a webcam, then it can't provide video if (videoSource.VideoCapabilities.Length == 0) { MessageBox.Show("No webcam found."); return; } //select highest resolution with atleast 10 fps. //it's a random balance between resolution and fps. VideoCapabilities videoInput = videoSource.VideoCapabilities.OrderBy(x => x.FrameSize.Height * x.FrameSize.Width) //.Where(x => x.AverageFrameRate >= 10) .Where(x => x.BitCount == 24) .LastOrDefault(); if (videoInput == default(VideoCapabilities)) { MessageBox.Show("Webcam doesn't support the required image format."); return; } videoSource.VideoResolution = videoInput; ct = new ColorClusterCreator(videoSource.VideoResolution.FrameSize.Width, videoSource.VideoResolution.FrameSize.Height); videoSource.NewFrame += new AForge.Video.NewFrameEventHandler(VideoSource_NewFrame); videoSource.Start(); infoWindow.Show(); infoWindow.AllowedDistanceSlider.ValueChanged += (se, ev) => ct.SetColorDistance((float)ev.NewValue / 100.0f); infoWindow.ClusterView.SelectionChanged += (se, ev) => ct.SetClusterViewType((ClusterViewTypes)((ComboBox)se).SelectedIndex); infoWindow.UseNoiseRemoval.Click += (se, ev) => ct.SetUseNoiseRemoval((bool)infoWindow.UseNoiseRemoval.IsChecked); infoWindow.UseGausBlur.Click += (se, ev) => ct.SetUseGaussBlur((bool)infoWindow.UseGausBlur.IsChecked); infoWindow.Closed += (se, ev) => this.Close(); }