public void SaveTrainTestFacesTest() { ExtractFeatures target = new ExtractFeatures(); // TODO: Initialize to an appropriate value target.SaveTrainTestFaces(); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public void CreateVectorsAfterFFTTest() { ExtractFeatures target = new ExtractFeatures(); // TODO: Initialize to an appropriate value target.CreateVectorsAfterFFT(); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public void ExtractFeaturesConstructorTest() { ObservableCollection <FaceImage> trainFaces = null; // TODO: Initialize to an appropriate value ObservableCollection <FaceImage> testFaces = null; // TODO: Initialize to an appropriate value ExtractFeatures target = new ExtractFeatures(trainFaces, testFaces); Assert.Inconclusive("TODO: Implement code to verify target"); }
public void CreateVectorsTest() { ExtractFeatures target = new ExtractFeatures(); // TODO: Initialize to an appropriate value ObservableCollection <FaceImage> trainFaces = null; // TODO: Initialize to an appropriate value ObservableCollection <FaceImage> testFaces = null; // TODO: Initialize to an appropriate value target.CreateVectors(trainFaces, testFaces); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
private void btnTestNetwork_Click(object sender, RoutedEventArgs e) { OCR.ShapeNet SelectedShapeNet; PageComponent PageComponent; List <Example> Examples = new List <Example>(0); bool Result; //Collect the examples SelectedShapeNet = (OCR.ShapeNet)lstNeuralNetworks.SelectedItem; List <String> Filenames = new List <string>(0); Example newExample; //collect all available examples for (int lIndex = 0; lIndex < SelectedShapeNet.ShapeList.Count; lIndex++) { Filenames.Clear(); MakeExampleList(Filenames, SelectedShapeNet.ShapeList[lIndex].SampleFolder); for (int lIndex2 = 0; lIndex2 < Filenames.Count; lIndex2++) { newExample = new Example(); newExample.Filename = Filenames[lIndex2]; newExample.ShapeId = lIndex; Examples.Add(newExample); } } //Test all examples against the network foreach (Example Example in Examples) { PageComponent = new PageComponent(); PageComponent.LoadBitmap(Example.Filename); Result = false; ExtractFeatures.ExecuteExtractFeatures(PageComponent, true); RecogniseComponent.RecogniseWithoutConnectedRepair(SelectedShapeNet, PageComponent); if (PageComponent.RecognitionResults.Count > 0 && Example.ShapeId < SelectedShapeNet.ShapeList.Count) { if (SelectedShapeNet.ShapeList[Example.ShapeId].Shape.ToLower() == PageComponent.RecognitionResults[0].Content.ToLower()) { Result = true; } } if (!Result) { lstFailedExamples.Items.Add(Example.Filename); } } }
public void Execute() { Console.WriteLine("Execute OCR"); OCR.Statistics.Clear(); OCR.Statistics.AddCounter("Processors", System.Environment.ProcessorCount); SISThreshold filter = new SISThreshold(); int Threshold = filter.CalculateThreshold(m_Image.Image, m_Image.Area); OtsuThreshold filterOtsu = new OtsuThreshold(); Threshold = filterOtsu.CalculateThreshold(m_Image.Image, m_Image.Area); PreprocessPage Processor = new PreprocessPage(); Processor.Image = m_Image; Processor.Treshold = m_Image.CalculateOtsuThreshold(); m_Image.Threshold = 170; Processor.Execute(); resultBitmap = PageImage.CreateBitmapFromByteArray(m_Image.BinaryBytes, new Size(m_Image.Width, m_Image.Height)); DetectComponents Step2 = new DetectComponents(); Step2.Image = m_Image; Step2.Execute(); AnalyseComponents Step3 = new AnalyseComponents(); Step3.Image = m_Image; Step3.Execute(); DetectSentences Step4 = new DetectSentences(); Step4.Image = m_Image; Step4.Execute(); ExtractFeatures Step5 = new ExtractFeatures(); Step5.Image = m_Image; Step5.Execute(); RecogniseComponent Step6 = new RecogniseComponent(); Step6.Image = m_Image; Step6.Execute(); ProcessSentences Step7 = new ProcessSentences(); Step7.Image = m_Image; Step7.Execute(); }
public PreprocessingPanelViewModel() { _trainFaces = new ObservableCollection <FaceImage>(); _testFaces = new ObservableCollection <FaceImage>(); _trainImages = new ObservableCollection <FaceImage>(); _testImages = new ObservableCollection <FaceImage>(); _extractFeatures = new ExtractFeatures(); _faceDetectionRepository = new FdFaceDetection(); PreprocessingPanelControl.FaceImagesSavedEvent += new EventHandler(PreprocessingPanelControl_FaceImagesSavedEvent); PreprocessingPanelControl.FacesGotEvent += new EventHandler(PreprocessingPanelControl_FacesGotEvent); }
private static void CreateTrainingData(OCR.ShapeNet ShapeNet, List <Example> Examples) { NeuralNetwork.LearningData oLearningData; OCR.PageComponent PageComponent; sNeuralInput newInput; foreach (Example Example in Examples) { PageComponent = new OCR.PageComponent(); PageComponent.LoadBitmap(Example.Filename); ExtractFeatures.ExecuteExtractFeatures(PageComponent, true); PageComponent.Position.Ascent = ShapeNet.ShapeList[Example.ShapeId].Position.Ascent; PageComponent.Position.Height = ShapeNet.ShapeList[Example.ShapeId].Position.Height; PageComponent.Position.Center = ShapeNet.ShapeList[Example.ShapeId].Position.Center; PageComponent.Position.Base = ShapeNet.ShapeList[Example.ShapeId].Position.Base; PageComponent.Position.Descent = ShapeNet.ShapeList[Example.ShapeId].Position.Descent; //Fill the oLearningData = new NeuralNetwork.LearningData(); oLearningData.oInput.fInputs.Clear(); oLearningData.oOutput.fOutputs.Clear(); newInput = RecogniseComponent.CalculateNetworkInput(PageComponent); oLearningData.oInput = newInput; for (long lIndex2 = 0; lIndex2 < ShapeNet.ShapeList.Count; lIndex2++) { if (Example.ShapeId == lIndex2) { oLearningData.oOutput.fOutputs.Add(1); } else { oLearningData.oOutput.fOutputs.Add(0); } } ShapeNet.NeuralNetwork.AddSituation(oLearningData); } ShapeNet.NeuralNetwork.ComputeInputRatios(); }
private void lstFiles_SelectionChanged(object sender, SelectionChangedEventArgs e) { String Filename; String ResultString; RecognitionResult MostLikelyShape; try { // OCR.ShapeNet Shapenet = new OCR.ShapeNet(); PageComponent Component = new PageComponent(); //Get the selected item Filename = "D:\\OCR\\Images\\" + (String)lstFiles.SelectedItem; if (lstFiles.SelectedItem == null) { return; } //Load the image Component.LoadBitmap(Filename); //Extract features and recognize ExtractFeatures.ExecuteExtractFeatures(Component, true); RecogniseComponent.Recognise((OCR.ShapeNet)lstNeuralNetworks.SelectedItem, Component); //Fill the imgContainer ExtractFeatures.CreateCompareMatrixWithoutPruning(Component, Component.Bytes); imgTrainingDataOriginal.Bytes = Component.CompareMatrix; for (int index = 0; index < 256; index++) { imgTrainingDataOriginal.GridBrushes[index] = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)index, (byte)index, (byte)index)); } imgTrainingDataOriginal.InvalidateVisual(); //Fill the recognition list lstRecognitionResult.Items.Clear(); MostLikelyShape = new RecognitionResult(); MostLikelyShape.Probability = 0; foreach (RecognitionResult Result in Component.RecognitionResults) { if (Result.Probability > MostLikelyShape.Probability) { MostLikelyShape = Result; } } ShapeListEntry Shape = new ShapeListEntry();; //Select the result with the highest probability in the shape list. if (MostLikelyShape.Probability > 0) { ResultString = MostLikelyShape.Content + " (" + MostLikelyShape.Probability + ")"; lstRecognitionResult.Items.Add(ResultString); foreach (Object Item in lstShapes.Items) { Shape = (ShapeListEntry)Item; if (Shape.Shape == MostLikelyShape.Content) { lstShapes.SelectedItem = Item; lstShapes.ScrollIntoView(Item); lstShapes.Focus(); } } } } catch (Exception exp) { Console.WriteLine("Exception caught: " + exp.Message); Console.WriteLine(" In: " + exp.StackTrace); } }
public void DoFillFileList(string Filter, OCR.ShapeNet ShapeNet) { try { if (ShapeFiles == null) { ShapeFiles = new List <ShapeFileList>(0); } if (ShapeFiles.Count == 0) { DirectoryInfo di = new DirectoryInfo("D:\\OCR\\Images\\"); FileInfo[] Files = di.GetFiles("*_org.bmp"); foreach (FileInfo fi in Files) { if (Filter.Length > 0) { String Filename; RecognitionResult MostLikelyShape; // OCR.ShapeNet Shapenet = new OCR.ShapeNet(); PageComponent Component = new PageComponent(); //Get the selected item Filename = fi.Name.ToString(); //Load the image Component.LoadBitmap(fi.FullName.ToString()); //Extract features and recognize ExtractFeatures.ExecuteExtractFeatures(Component, true); RecogniseComponent.Recognise(ShapeNet, Component); //Fill the recognition list MostLikelyShape = new RecognitionResult(); MostLikelyShape.Probability = 0; foreach (RecognitionResult Result in Component.RecognitionResults) { if (Result.Probability > MostLikelyShape.Probability) { MostLikelyShape = Result; } } //Add ShapeFile to cache ShapeFileList ShapeFile; ShapeFile.Shape = MostLikelyShape.Content; ShapeFile.File = fi.Name.ToString(); ShapeFiles.Add(ShapeFile); //Add file to filelist if (MostLikelyShape.Content == Filter) { bwFileList.ReportProgress(0, fi.Name.ToString()); } } else { bwFileList.ReportProgress(0, fi.Name.ToString()); } } } else { foreach (ShapeFileList ShapeFile in ShapeFiles) { if (Filter.Length == 0) { bwFileList.ReportProgress(0, ShapeFile.File); } else { if (Filter == ShapeFile.Shape) { bwFileList.ReportProgress(0, ShapeFile.File); } } } } } catch (Exception e) { Console.WriteLine("Exception caught: " + e.Message); Console.WriteLine(" In: " + e.StackTrace); } }
private void RunThinning_Click(object sender, RoutedEventArgs e) { OCRStubControls.CharacterGrid[] CharacterGrids = new OCRStubControls.CharacterGrid[7]; OCR.PageImage PageImage; OCR.PageComponent PageComponent; //Initialize charactergrids CharacterGrids[0] = ThinningStep1; CharacterGrids[1] = ThinningStep2; CharacterGrids[2] = ThinningStep3; CharacterGrids[3] = ThinningStep4; CharacterGrids[4] = ThinningStep5; CharacterGrids[5] = ThinningStep6; CharacterGrids[6] = ThinningStep7; PageImage = new OCR.PageImage(); PageComponent = new OCR.PageComponent(); PageComponent.LoadBitmap(txtThinningSample.Text); for (int x = 0; x < PageComponent.Width; x++) { for (int y = 0; y < PageComponent.Height; y++) { PageComponent.BinaryBytes[x, y] = PageComponent.Bytes[x, y]; } } ExtractFeatures.CreateCompareMatrixWithoutPruning(PageComponent); for (int x = 0; x < PageComponent.Width; x++) { for (int y = 0; y < PageComponent.Height; y++) { PageComponent.BinaryBytes[x, y] = (PageComponent.Bytes[x, y] == 0xFF ? (Byte)0xFF : (Byte)0x00); } } CharacterGrids[0].Bytes = new byte[32, 32]; for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { CharacterGrids[0].Bytes[x, y] = PageComponent.CompareMatrix[x, y]; } } CharacterGrids[0].InvalidateVisual(); for (int i = 0; i < 6; i++) { CharacterGrids[i + 1].Bytes = new byte[32, 32]; for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { CharacterGrids[i + 1].Bytes[x, y] = PageComponent.CompareMatrix[x, y]; } } switch (ThinningAlgorithm.SelectedIndex) { case 0: //Standard ExtractFeatures.Thinning(CharacterGrids[i + 1].Bytes, 0, 0xFF, i + 1); break; case 1: //Erode ExtractFeatures.ErodeThinning(CharacterGrids[i + 1].Bytes, 0, 0xFF, i + 1); break; case 2: //Middle ExtractFeatures.MiddleThinning(CharacterGrids[i + 1].Bytes, 0, 0xFF); break; case 3: //Condensed PageComponent = new OCR.PageComponent(); PageComponent.LoadBitmap(txtThinningSample.Text); ExtractFeatures.CondensedThinning(PageImage, PageComponent, 0, 0xFF, i + 1); for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { CharacterGrids[i + 1].Bytes[x, y] = PageComponent.CompareMatrix[x, y]; } } break; case 4: //Pruning PageComponent = new OCR.PageComponent(); PageComponent.LoadBitmap(txtThinningSample.Text); for (int x = 0; x < PageComponent.Width; x++) { for (int y = 0; y < PageComponent.Height; y++) { PageComponent.BinaryBytes[x, y] = PageComponent.Bytes[x, y]; } } ExtractFeatures.ThinningPruningOnOriginalImage(PageComponent, PageComponent, 0, i + 1); ExtractFeatures.CreateCompareMatrixWithoutPruning(PageComponent); for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { CharacterGrids[i + 1].Bytes[x, y] = PageComponent.CompareMatrix[x, y]; } } break; case 5: //Pruning original PageComponent = new OCR.PageComponent(); PageComponent.LoadBitmap(txtThinningSample.Text); ExtractFeatures.ThinningPruningOnOriginalImage(PageImage, PageComponent, 2, i + 1); ExtractFeatures.CreateCompareMatrixWithoutPruning(PageComponent); for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { CharacterGrids[i + 1].Bytes[x, y] = PageComponent.CompareMatrix[x, y]; } } break; } CharacterGrids[i + 1].InvalidateVisual(); } }
private void btnTest_Click(object sender, RoutedEventArgs e) { OCR.ShapeNet SelectedShapeNet; OCR.PageComponent PageComponent; SelectedShapeNet = (OCR.ShapeNet)lstNeuralNetworks.SelectedItem; PageComponent.newID = 0; PageComponent = new OCR.PageComponent(); PageComponent.LoadBitmap(txtSample.Text); ExtractFeatures.ExecuteExtractFeatures(PageComponent, PageComponent, true); RecogniseComponent.Recognise(SelectedShapeNet, PageComponent); //Recognise the component lstResults.Items.Clear(); String ResultText = ""; foreach (RecognitionResult Result in PageComponent.RecognitionResults) { ResultText = Result.Content + " (" + Result.Probability + ")"; lstResults.Items.Add(ResultText); } //Build the original image PageComponent Original = new PageComponent(); Original.LoadBitmap(txtSample.Text); ExtractFeatures.CreateCompareMatrixWithoutPruning(Original, Original.Bytes); imgSample.Bytes = Original.CompareMatrix; for (int index = 0; index < 256; index++) { imgSample.GridBrushes[index] = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)index, (byte)index, (byte)index)); } imgSample.InvalidateVisual(); ExtractFeatures.CreateCompareMatrixWithoutPruning(PageComponent); //Build the thinned and stroked image for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { if (PageComponent.StrokeMatrix[x, y] == 0xFF && PageComponent.CompareMatrix[x, y] != 0xFF) { PageComponent.StrokeMatrix[x, y] = 0x04; } if (PageComponent.PixelTypeMatrix[x, y] == ePixelType.End) { PageComponent.StrokeMatrix[x, y] = 0xFE; } if (PageComponent.PixelTypeMatrix[x, y] == ePixelType.Junction) { PageComponent.StrokeMatrix[x, y] = 0xFD; } } } imgProjection.Bytes = PageComponent.StrokeMatrix; imgProjection.GridBrushes[0] = new SolidColorBrush(Colors.Black); imgProjection.GridBrushes[4] = new SolidColorBrush(Colors.LightGray); imgProjection.GridBrushes[11] = new SolidColorBrush(Colors.Brown); imgProjection.GridBrushes[12] = new SolidColorBrush(Colors.Maroon); imgProjection.GridBrushes[13] = new SolidColorBrush(Colors.Magenta); imgProjection.GridBrushes[14] = new SolidColorBrush(Colors.Lime); imgProjection.GridBrushes[15] = new SolidColorBrush(Colors.LightCyan); imgProjection.GridBrushes[16] = new SolidColorBrush(Colors.Purple); imgProjection.GridBrushes[32] = new SolidColorBrush(Colors.Blue); imgProjection.GridBrushes[48] = new SolidColorBrush(Colors.Green); imgProjection.GridBrushes[64] = new SolidColorBrush(Colors.Yellow); imgProjection.GridBrushes[253] = new SolidColorBrush(Colors.Red); imgProjection.GridBrushes[254] = new SolidColorBrush(Colors.Red); imgProjection.InvalidateVisual(); lblStrokes.Content = "#Strokes: " + Convert.ToString(PageComponent.Strokes); //Bitmap StrokeMatrixBitmap = OCR.DebugTrace.DebugTrace.CreateBitmapFromByteArray(PageComponent.StrokeMatrix, new System.Drawing.Size(32, 32)); //StrokeMatrixBitmap.Save("d:\\ocr\\temp.bmp"); //imgProjection.Source = new BitmapImage(new Uri("d:\\ocr\\temp.bmp")); pbHorizontal.Clear(); int ProjectionValue; for (int x = 0; x < 3; x++) { ProjectionValue = 0; for (int y = 0; y < 3; y++) { ProjectionValue += PageComponent.PixelTypeProjectionJunction[x, y]; ProjectionValue += PageComponent.PixelTypeProjectionEndpoint[x, y]; } pbHorizontal.AddValue(ProjectionValue); } pbVertical.Clear(); for (int y = 0; y < 3; y++) { ProjectionValue = 0; for (int x = 0; x < 3; x++) { ProjectionValue += PageComponent.PixelTypeProjectionJunction[x, y]; ProjectionValue += PageComponent.PixelTypeProjectionEndpoint[x, y]; } pbVertical.AddValue(ProjectionValue); } pbStrokeHorizontal.Clear(); foreach (int Value in PageComponent.lStrokeDirectionX) { pbStrokeHorizontal.AddValue(Value); } pbStrokeVertical.Clear(); foreach (int Value in PageComponent.lStrokeDirectionY) { pbStrokeVertical.AddValue(Value); } }
private void lstFailedExamples_SelectionChanged(object sender, SelectionChangedEventArgs e) { PageComponent PageComponent; String item; OCR.ShapeNet SelectedShapeNet; //Load the image item = (String)lstFailedExamples.SelectedItem; PageComponent = new PageComponent(); PageComponent.LoadBitmap(item); //Recognise the image and fill the result list SelectedShapeNet = (OCR.ShapeNet)lstNeuralNetworks.SelectedItem; ExtractFeatures.ExecuteExtractFeatures(PageComponent, true); RecogniseComponent.RecogniseWithoutConnectedRepair(SelectedShapeNet, PageComponent); lstFailedResult.Items.Clear(); String ResultText = ""; foreach (RecognitionResult Result in PageComponent.RecognitionResults) { ResultText = Result.Content + " (" + Result.Probability + ")"; lstFailedResult.Items.Add(ResultText); } //Build the image PageComponent Original = new PageComponent(); Original.LoadBitmap(item); PageComponent OriginalWithPruning = new PageComponent(); OriginalWithPruning.LoadBitmap(item); ExtractFeatures.CreateCompareMatrixWithoutPruning(Original); ExtractFeatures.CreateCompareMatrix(OriginalWithPruning); for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { PageComponent.CompareMatrix[x, y] = Original.CompareMatrix[x, y]; if (Original.CompareMatrix[x, y] != 0xFF && PageComponent.CompareMatrix[x, y] == 0xFF) { PageComponent.CompareMatrix[x, y] = 4; } if (PageComponent.StrokeMatrix[x, y] != 0xFF) { PageComponent.CompareMatrix[x, y] = PageComponent.StrokeMatrix[x, y]; } } } imgFailed.Bytes = PageComponent.CompareMatrix; imgFailed.GridBrushes[0] = new SolidColorBrush(Colors.Gray); imgFailed.GridBrushes[4] = new SolidColorBrush(Colors.LightGray); imgFailed.GridBrushes[11] = new SolidColorBrush(Colors.Brown); imgFailed.GridBrushes[12] = new SolidColorBrush(Colors.Maroon); imgFailed.GridBrushes[13] = new SolidColorBrush(Colors.Magenta); imgFailed.GridBrushes[14] = new SolidColorBrush(Colors.Lime); imgFailed.GridBrushes[15] = new SolidColorBrush(Colors.LightCyan); imgFailed.GridBrushes[16] = new SolidColorBrush(Colors.Purple); imgFailed.GridBrushes[32] = new SolidColorBrush(Colors.Blue); imgFailed.GridBrushes[48] = new SolidColorBrush(Colors.Green); imgFailed.GridBrushes[64] = new SolidColorBrush(Colors.Yellow); imgFailed.GridBrushes[253] = new SolidColorBrush(Colors.Red); imgFailed.GridBrushes[254] = new SolidColorBrush(Colors.Red); imgFailed.GridBrushes[255] = new SolidColorBrush(Colors.White); imgFailed.InvalidateVisual(); //imgFailed.Bytes = PageComponent.StrokeMatrix; //imgFailed.InvalidateVisual(); }
private void imgResult_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { String ResultText; System.Windows.Point Position = e.GetPosition(imgResult); lstResults.Items.Clear(); foreach (PageComponent Component in m_OCR.PageImage.Components) { if (Component.Area.Contains((int)Position.X, (int)Position.Y)) { ExtractFeatures.CreateCompareMatrixWithoutPruning(Component, Component.Bytes); imgOriginal.Bytes = Component.CompareMatrix; for (int index = 0; index < 256; index++) { imgOriginal.GridBrushes[index] = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)index, (byte)index, (byte)index)); } imgOriginal.InvalidateVisual(); //Add thinned and stroked image //Merge strokematrix and pixeltypematrix to show all info in the same image for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { if (Component.PixelTypeMatrix[x, y] == ePixelType.End) { Component.StrokeMatrix[x, y] = 0xFE; } if (Component.PixelTypeMatrix[x, y] == ePixelType.Junction) { Component.StrokeMatrix[x, y] = 0xFD; } if (Component.StrokeMatrix[x, y] == 0xFF) { if (Component.CompareMatrix[x, y] != 0xFF) { Component.StrokeMatrix[x, y] = 0x04; } } } } imgProjection.Bytes = Component.StrokeMatrix; imgProjection.GridBrushes[4] = new SolidColorBrush(Colors.LightGray); imgProjection.GridBrushes[11] = new SolidColorBrush(Colors.Brown); imgProjection.GridBrushes[12] = new SolidColorBrush(Colors.Maroon); imgProjection.GridBrushes[13] = new SolidColorBrush(Colors.Magenta); imgProjection.GridBrushes[14] = new SolidColorBrush(Colors.Lime); imgProjection.GridBrushes[15] = new SolidColorBrush(Colors.LightCyan); imgProjection.GridBrushes[16] = new SolidColorBrush(Colors.Purple); imgProjection.GridBrushes[32] = new SolidColorBrush(Colors.Blue); imgProjection.GridBrushes[48] = new SolidColorBrush(Colors.Green); imgProjection.GridBrushes[64] = new SolidColorBrush(Colors.Yellow); imgProjection.GridBrushes[253] = new SolidColorBrush(Colors.Red); imgProjection.GridBrushes[254] = new SolidColorBrush(Colors.Red); imgProjection.InvalidateVisual(); //Add result if (Component.RecognitionResults.Count > 0) { ResultText = Component.RecognitionResults[0].Content; ResultText += " ("; ResultText += Component.RecognitionResults[0].Probability; ResultText += " )"; lstResults.Items.Add(ResultText); } else { lstResults.Items.Add("No results"); } //Add ID labelID.Content = "ID: " + Component.ID; CurrentComponentId = Component.ID; } } }
/// <summary> /// This functions splits a character in multiple components. Used for splitting connected characters /// </summary> public void Split(ShapeNet ShapeNet) { List <int> SplitLines; //Step 1: Get the position for possible splits SplitLines = SplitDeterminePositions(); if (SplitLines.Count == 0) { return; } RecognitionResults.Clear(); //Step 2: Find the combination of the best (highest scores) recognised components List <PageComponent> Components = new List <PageComponent>(0); PageComponent newComponent; PageComponent prevComponent; Rectangle SplitArea; int start, end; SplitLines.Insert(0, 0); SplitLines.Add(Width - 1); start = 0; end = 1; while (end < SplitLines.Count) { SplitArea = new Rectangle(SplitLines[start] + 1, 0, SplitLines[end] - SplitLines[start] - 2, Height); if (SplitArea.Width > 0 && SplitArea.Height > 0) { while (NumberPixelsOnRow(BinaryBytes, SplitArea, 0, 0) == 0) { SplitArea.Y = SplitArea.Y + 1; SplitArea.Height = SplitArea.Height - 1; } while (NumberPixelsOnRow(BinaryBytes, SplitArea, SplitArea.Height - 1, 0) == 0) { SplitArea.Height = SplitArea.Height - 1; } newComponent = PartialCopy(SplitArea); ExtractFeatures.ExecuteExtractFeatures(newComponent, false); RecogniseComponent.RecogniseWithoutConnectedRepair(ShapeNet, newComponent); if (Components.Count > 0 && end - start > 1) { prevComponent = Components.Last(); if (prevComponent.ContentProbability < newComponent.ContentProbability && newComponent.Content != "connected" && newComponent.Content != "garbage") { Components.Remove(prevComponent); Components.Add(newComponent); } else { start = end - 1; end--; } } else { Components.Add(newComponent); } } end++; } //Add the new recognition result RecognitionResult newResult; newResult = new RecognitionResult(); newResult.Content = ""; newResult.Probability = 0; foreach (PageComponent Component in Components) { newResult.Content += Component.Content; newResult.Probability += Component.ContentProbability; } newResult.Probability = newResult.Probability / Components.Count; RecognitionResults.Add(newResult); //Save a copy of the image to the disc if (DebugTrace.DebugTrace.TraceFeatures) { String ComponentID = "000000" + ID; ComponentID = ComponentID.Substring(ComponentID.Length - 6); foreach (int SplitLine in SplitLines) { int pointer = SplitLine; for (int y = 0; y < Height; y++) { if (BinaryBytes[SplitLine, y] == 0xFF) { BinaryBytes[SplitLine, y] = 0x10; } pointer += Stride; } } Bitmap Bitmap = DebugTrace.DebugTrace.CreateBitmapFromByteArray(BinaryBytes, new Size(Width, Height)); String Filename = DebugTrace.DebugTrace.TraceFeatureFolder + "image_" + ComponentID + "_split.bmp"; Bitmap.Save(Filename); } }
public void ExtractFeaturesConstructorTest1() { ExtractFeatures target = new ExtractFeatures(); Assert.Inconclusive("TODO: Implement code to verify target"); }