public void SendTextFound(TextFound textAreaToReturn)
        {
            NetworkStream   serverStream = Client.GetStream();
            BinaryFormatter bf           = new BinaryFormatter();

            using (MemoryStream ms = new MemoryStream())
            {
                bf.Serialize(ms, textAreaToReturn);
                Byte[] sendData = ms.ToArray();
                serverStream.Write(sendData, 0, sendData.Length);
                serverStream.Flush();
            }
        }
        public static void ReceiveTextFound(TcpClient client)
        {
            NetworkStream serverStream = client.GetStream();

            byte[] inStream = new byte[9999999];
            Int32  bytes    = serverStream.Read(inStream, 0, (int)client.ReceiveBufferSize);

            MemoryStream    memStream = new MemoryStream();
            BinaryFormatter binForm   = new BinaryFormatter();

            memStream.Write(inStream, 0, inStream.Length);
            memStream.Seek(0, SeekOrigin.Begin);
            TextFound obj = (TextFound)binForm.Deserialize(memStream);

            Console.WriteLine("Received");
            Console.WriteLine(obj.SearchText);
            Console.WriteLine(obj.ImageText);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var    ocr        = new OneNoteOCR();
            var    findText   = new ActionNote();
            string imagePath  = String.Empty;
            string textToFind = String.Empty;

            try
            {
                ocr.Verify();
            }
            catch (Exception)
            {
                Console.WriteLine("you do not have OneNote 15 ");
                return;
            }

            if (Debugger.IsAttached)
            {
                imagePath  = @"C:\Users\gastanica\Desktop\serverPASS4.png";
                textToFind = "daily";
            }
            else
            {
                if (args.Length < 2)
                {
                    Console.WriteLine("please add argument = path to the image file");
                    return;
                }
                imagePath  = args[0];
                textToFind = args[1];
            }

            TextFound ocrText = new TextFound(0, 0, 0, 0, "", "");

            ocrText = findText.FindText(imagePath, textToFind);
            Console.WriteLine(imagePath);
            Console.WriteLine(textToFind);

            Console.WriteLine(ocrText.TextArea);
            Console.WriteLine(ocrText.Center());
            Console.WriteLine(ocrText.ImageText);
            Console.WriteLine(ocrText.SearchText);
        }
Exemple #4
0
        private async Task <string> ExtractTextFromMarking(InkCanvas inkCanvas, String filepath)
        {
            var file = await StorageFile.GetFileFromPathAsync(filepath);

            var newImgFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(file.Name + Guid.NewGuid(), CreationCollisionOption.ReplaceExisting);

            var strokes = inkCanvas.InkPresenter.StrokeContainer.GetStrokes();
            var stroke  = strokes[strokes.Count - 1];

            // find the outside bounderies of the last stroke
            double strokeSmallestX = Double.MaxValue;
            double strokeSmallestY = Double.MaxValue;
            double strokeLargestX  = Double.MinValue;
            double strokeLargestY  = Double.MinValue;

            ImageCropper.FindBounderiesOfStroke(stroke, ref strokeSmallestX, ref strokeSmallestY, ref strokeLargestX, ref strokeLargestY);

            // find crop size
            var cropWidth  = (strokeLargestX - strokeSmallestX);
            var cropHeight = (strokeLargestY - strokeSmallestY);

            var cropPointX = strokeSmallestX;
            var cropPointY = strokeSmallestY;
            var cropSize   = new Size(cropWidth, cropHeight);

            if (ShowDebugRectangle)
            {
                DebugHelper.ShowNewDebuggingCanvas(strokeSmallestX, strokeSmallestY, cropHeight, cropWidth, ManipulationGrid, ref _debuggingCanvas);
            }

            // normalize here regarding grid position
            if (inkCanvas.ActualHeight > MyImage.ActualHeight)
            {
                cropPointY = cropPointY - ((ManipulationGrid.ActualHeight / 2) - (MyImage.ActualHeight / 2));
            }

            if (inkCanvas.ActualWidth > MyImage.ActualWidth)
            {
                cropPointX = cropPointX - ((ManipulationGrid.ActualWidth / 2) - (MyImage.ActualWidth / 2));
            }

            var startPoint = new Point(cropPointX, cropPointY);

            Size wis = new Size(MyImage.ActualWidth, MyImage.ActualHeight);

            _croppedFile = await ImageCropper.SaveCroppedBitmapAsync(file, newImgFile, startPoint, cropSize, wis);

            if (DebugCropImage != null)
            {
                BitmapImage bim = new BitmapImage(new Uri(_croppedFile.Path));
                DebugCropImage.Source = bim;
            }


            if (UseOnlineOcr)
            {
                var res = await ProjOxWrapper.PostToOnlineOcrRecoAsync(_croppedFile, SubscriptionKey);

                if (res != string.Empty)
                {
                    if (TextFound != null)
                    {
                        TextFound.Invoke(this, new TextFoundEventArgs(res));
                    }
                }
                Debug.WriteLine("From Online OCR:" + res);
                return(res);
            }
            else
            {
                // extract Text offline
                var result = await OfflineImageTextExtractor.ExtractTextFromImageAsync(_croppedFile, OCREngine);

                if (result != string.Empty)
                {
                    if (TextFound != null)
                    {
                        TextFound.Invoke(this, new TextFoundEventArgs(result));
                    }
                }
                Debug.WriteLine("Offline OCR: " + result);

                return(result);
            }
        }