private void btnSelectImage_Click(object sender, EventArgs e) { if (openImage.ShowDialog() == System.Windows.Forms.DialogResult.OK) { sample = new RecognitionSample(TextureRecognition.Instance.Core, openImage.FileName); pbSample.Image = sample.GetSampleImage(); } lbTextureClasses.Items.Clear(); var core = TextureRecognition.Instance.Core; for (int i = 0; i < core.TextureClassCount; ++i) { lbTextureClasses.Items.Add(core.GetTextureClass(i).Name); } lbTextureClasses.SelectedIndex = -1; }
private void btnRefresh_Click(object sender, EventArgs e) { pbSample.Image = sample.GetSampleImage(); }
private void RecognizeThread(object param) { var id = (int)param; RecognitionCore core = null; RecognitionSample currentSample = null; Bitmap currentImage = null; string pref = ""; switch (id) { case 1: pref = " (Полная выборка)"; core = coreF; currentSample = SampleF; currentImage = workImage; break; case 2: pref = " (Компактная выборка)"; core = coreC; currentSample = SampleC; currentImage = workImage; break; case 3: pref = " (Разряженная выборка)"; core = coreD; currentSample = SampleD; currentImage = workImage; break; default: break; } if (core == null) { core = new RecognitionCore(); for (int i = 0; i < recognition.Core.TextureClassCount; ++i) { var their = recognition.Core.GetTextureClass(i); core.AddTextureClass(their.Name, their.RegionColor); } for (int i = 0; i < core.TextureClassCount; ++i) { var currentClass = core.GetTextureClass(i); this.BeginInvoke( new Action(delegate() { lbOutput.Items.Add("Начато обучение классу " + currentClass.Name); lbOutput.SelectedIndex = lbOutput.Items.Count - 1; })); switch (id) { case 1: currentClass.Teach(teachingSamples[i], GetImagesToTeach(teachingSamples[i])); break; case 2: currentClass.TeachCompact(teachingSamples[i], GetImagesToTeach(teachingSamples[i])); break; case 3: currentClass.TeachDischarged(teachingSamples[i], GetImagesToTeach(teachingSamples[i])); break; default: currentClass.Teach(teachingSamples[i], GetImagesToTeach(teachingSamples[i])); break; } while (currentClass.IsTeaching) { Thread.Sleep(200); } var result = this.BeginInvoke( new Action(delegate() { var count = currentClass.KnownSamplesNumber(TextureFeatures.GLCM); var part = count / (float)teachingSamples[i].Count; lbOutput.Items.Add(" После обучения получено образцов GLCM: " + count.ToString() + " (" + part.ToString() + ")"); count = currentClass.KnownSamplesNumber(TextureFeatures.LBP); part = count / (float)teachingSamples[i].Count; lbOutput.Items.Add(" После обучения получено образцов LBP: " + count.ToString() + " (" + part.ToString() + ")"); lbOutput.SelectedIndex = lbOutput.Items.Count - 1; })); while (!result.IsCompleted) { Thread.Sleep(50); } } } switch (id) { case 1: coreF = core; break; case 2: coreC = core; break; case 3: coreD = core; break; default: break; } if (currentSample == null) { this.BeginInvoke( new Action(delegate() { lbOutput.Items.Add("Начато распознавание тестового изображения"); lbOutput.SelectedIndex = lbOutput.Items.Count - 1; })); currentSample = new RecognitionSample(core, sample.Path); currentSample.Recognize(); currentImage = currentSample.GetSampleImage(); switch (id) { case 1: SampleF = currentSample; workImage = currentImage; break; case 2: SampleC = currentSample; workImage = currentImage; break; case 3: SampleD = currentSample; workImage = currentImage; break; default: break; } } var iRes = this.BeginInvoke( new Action(delegate() { lbOutput.Items.Add(currentSample.Path); var result = sample.CompareFeature(currentSample, TextureFeatures.GLCM); lbOutput.Items.Add(pref + " Соответствие GLCM = " + result.ToString()); result = sample.CompareFeature(currentSample, TextureFeatures.LBP); lbOutput.Items.Add(pref + " Соответствие LBP = " + result.ToString()); lbOutput.SelectedIndex = lbOutput.Items.Count - 1; pbWork.Image = currentImage; msMenu.Enabled = true; btnSelectSample.Enabled = true; btnSelectSamples.Enabled = true; cbTextureClass.Enabled = true; btnCompact.Enabled = true; btnDischarged.Enabled = true; btnFull.Enabled = true; })); while (!iRes.IsCompleted) { Thread.Sleep(20); } complete = true; }