コード例 #1
0
        private void btnFilterOnShape_Click(object sender, RoutedEventArgs e)
        {
            if (lstShapes.SelectedIndex != -1)
            {
                ShapeListEntry Shape = (ShapeListEntry)lstShapes.SelectedItem;

                FillFileList(Shape.Shape);
            }
            else
            {
                MessageBox.Show("No shape is selected, filter cannot be applied.", "Error", MessageBoxButton.OK);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        private void CopyShape()
        {
            ShapeListEntry Shape = new ShapeListEntry();;
            String         ImageFile;
            String         DestinationFile;
            int            index;
            bool           Continue;

            //Check if a file and a shape are selected
            if (lstFiles.SelectedIndex == -1 && lstShapes.SelectedIndex == -1)
            {
                MessageBox.Show("A file and a shape must be selected.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            //Get the selected items;
            ImageFile = "D:\\OCR\\Images\\" + lstFiles.SelectedItem;
            Shape     = (ShapeListEntry)lstShapes.SelectedItem;

            //Determine a new file name for the target file
            DirectoryInfo di = new DirectoryInfo(Shape.SampleFolder + "\\");

            FileInfo[] Files = di.GetFiles("*.bmp");

            index = 1;

            do
            {
                Continue         = false;
                DestinationFile  = "00000000" + Convert.ToString(index);
                DestinationFile  = DestinationFile.Substring(DestinationFile.Length - 8);
                DestinationFile += ".bmp";

                foreach (FileInfo File in Files)
                {
                    if (File.Name == DestinationFile)
                    {
                        Continue = true;
                    }
                }

                index++;
            } while (Continue);

            //Copy the file
            DestinationFile = Shape.SampleFolder + "\\" + DestinationFile;
            System.IO.File.Copy(ImageFile, DestinationFile, true);

            //Remove the file from the filelist.
            object SelectedItem;

            SelectedItem = lstFiles.SelectedItem;
            lstFiles.SelectedIndex++;

            lstFiles.Items.Remove(SelectedItem);

            //Delete the original file
            try
            {
                System.IO.File.Delete(ImageFile);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught: " + e.Message);
                Console.WriteLine("  In: " + e.StackTrace);
            }
        }