Exemplo n.º 1
0
        private void btnOCR_Click(object sender, RoutedEventArgs e)
        {
            if (isImageLoaded == true)
            {
                //If a video stream is currently happening, do the following, else do the last
                if (isStream == true)
                {
                    //Align the video capture image
                    img = AutoAlignment.Align(img);

                    Bitmap bit = img.ToBitmap();

                    //Pass the bitmap image to be displayed
                    outputPage.imgOutput.Source = ImageUtils.ImageSourceFromBitmap(bit);
                }
                else
                {
                    //Read in the desired image
                    img = OCR.ReadInImage();

                    //Convert the image to a bitmap, then to an image source
                    Bitmap bit = img.ToBitmap();
                    outputPage.imgOutput.Source = ImageUtils.ImageSourceFromBitmap(bit);
                }

                //Detect the text from the image
                string detectedText = OCR.RecognizeText(img);

                //Create a new list for the output
                List <string> output = new List <string>();

                //Add the detected string to the list
                output.Add(detectedText);

                //Display the list
                outputPage.lstOutput.ItemsSource = output;
            }
            else
            {
                System.Windows.MessageBox.Show("Please take or import an image");
            }
        }
Exemplo n.º 2
0
        private void btnOCR_Click(object sender, RoutedEventArgs e)
        {
            Mat img = new Mat();

            if (isStream == true)
            {
                stream.Pause();

                var randomTest = stream.QueryFrame().ToImage <Bgr, byte>();
                var capture    = randomTest.ToBitmap();

                stream.Start();

                Image <Bgr, byte> inputImg = capture.ToImage <Bgr, byte>();

                img = AutoAlignment.Align(inputImg.Mat);

                imgOutput.Source = ImageSourceFromBitmap(img.ToBitmap());
            }
            else
            {
                //Read in the desired image
                img = OCR.ReadInImage();

                //Convert the image to a bitmap, then to an image scource
                Bitmap bit = img.ToBitmap();
                imgOutput.Source = ImageSourceFromBitmap(bit);
            }

            //Detect the text from the image
            string detectedText = OCR.RecognizeText(img);

            //Create a new list for the output
            List <string> output = new List <string>();

            //Add the detected string to the list
            output.Add(detectedText);

            //Display the list
            lstOutput.ItemsSource = output;
        }