public void LabelingForce(int bin) { var labeler = new SurfaceLabeler(255); var listinf = new List<ImgInfo>(); Task<List<ImgInfo>>.Factory.StartNew( () => { var result = new List<ImgInfo>(); for (int i = 100; i < 200; i += 10) result.Add(labeler.Labeling(Binar(i), _currentImage)); return result; } ).ContinueWith(x => { _info = x.Result.OrderByDescending(y => y.Classes.Values.Count()).First(); _myMap = _info.NewPicture; }, TaskScheduler.FromCurrentSynchronizationContext()); }
public void Labeling(int bin) { var processedPicture = FilterMatrix.GetMatrixBrightness(_currentImage); processedPicture = FilterMatrix.ApplyBinarize(processedPicture, bin); int ni = processedPicture.Length; int nj = processedPicture[0].Length; int[,] processedPictureInt = new int[ni, nj]; for (int i = 0; i < processedPicture.Length; i++) { for (int j = 0; j < nj; j++) { processedPictureInt[i, j] = (int)processedPicture[i][j]; } } var labeler = new SurfaceLabeler(255); Task<ImgInfo>.Factory.StartNew(() => labeler.Labeling(processedPictureInt, _currentImage)).ContinueWith(x => { _info = x.Result; if (_info.OldPicture == _info.NewPicture || (_info.Classes.Values.Any() && _info.Classes.Values.Count < 4)) { if (bin + 5 < 255) Labeling(bin + 5); } else { resultPictureBox.Image = x.Result.NewPicture; } _myMap = x.Result.NewPicture; }, TaskScheduler.FromCurrentSynchronizationContext()); }
private void button2_Click(object sender, EventArgs e) { var processedPicture = FilterMatrix.GetMatrixBrightness(_currentImage); processedPicture = FilterMatrix.ApplyBinarize(processedPicture, 125); int ni = processedPicture.Length; int nj = processedPicture[0].Length; int[,] processedPictureInt = new int[ni, nj]; for (int i = 0; i < processedPicture.Length; i++) { for (int j = 0; j < nj; j++) { processedPictureInt[i, j] = (int)processedPicture[i][j]; } } var labeler = new SurfaceLabeler(); Task<ImgInfo>.Factory.StartNew(() => labeler.Labeling(processedPictureInt, _currentImage)).ContinueWith(x => { _info = x.Result; resultPictureBox.Image = x.Result.NewPicture; _myMap = x.Result.NewPicture; }, TaskScheduler.FromCurrentSynchronizationContext()); }