Example #1
0
        /// <summary>
        /// This Methode decodes the given Image and updates the outputs and presentation.
        /// </summary>
        /// <param name="image"></param>
        public void ProcessImage(byte[] image)
        {
            DecoderItem decoderResult = null;

            //if ocr is selected, use the orcdecoder, else use the codetypeHandler
            decoderResult = settings.DecoderType == VisualDecoderSettings.DecoderTypes.OCR
                ? ORCDecoder.Decode(image, settings)
                : codeTypeHandler[settings.CodeType].Decode(image, settings);


            if (decoderResult != null) //input is valid and has been decoded
            {
                //update Presentation
                presentation.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)(state =>
                {
                    try
                    {
                        presentation.SetImages(decoderResult.BitmapWithMarkedCode);
                        presentation.SetData(decoderResult.CodePayload, decoderResult.CodeType);
                    }
                    catch (Exception e)
                    {
                        GuiLogMessage(e.Message, NotificationLevel.Error);
                    }
                }), null);

                //update output
                OutputData = decoderResult.CodePayload;
                OnPropertyChanged("OutputData");

                //update Progress
                ProgressChanged(1, 1);

                codeFound = true;
            }
            else
            {
                //reset metadata and set image
                presentation.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)(state =>
                {
                    try
                    {
                        presentation.ClearPresentation();
                        presentation.SetImages(PictureInput);
                    }
                    catch (Exception e)
                    {
                        GuiLogMessage(e.Message, NotificationLevel.Error);
                    }
                }), null);
            }
        }
Example #2
0
        public override DecoderItem Decode(byte[] input, VisualDecoderSettings settings)
        {
            var result   = new DecoderItem();
            var language = settings.OCRLanguage.ToString();

            //use eng if the user dont know the language
            if (language.Equals(VisualDecoderSettings.OCRLanguages.unkown.ToString()))
            {
                language = VisualDecoderSettings.OCRLanguages.eng.ToString();
            }

            using (var ocr = new tessnet2.Tesseract()){
                try
                {
                    ocr.Init(TessractData, language, settings.NumericMode);
                    List <tessnet2.Word> r1 = ocr.DoOCR(ByteArrayToImage(input), Rectangle.Empty);

                    //aggregate resultTest
                    string resultText = "";
                    int    lc         = tessnet2.Tesseract.LineCount(r1);
                    for (int i = 0; i < lc; i++)
                    {
                        resultText += tessnet2.Tesseract.GetLineText(r1, i) + "\n";
                    }

                    //fill result
                    result.CodePayload          = resultText;
                    result.CodeType             = "none";
                    result.BitmapWithMarkedCode = input;
                    ocr.Clear();
                }
                catch (Exception) // well, the ocr lib sucks... it sometimes trows memory leaks.
                                  // But it is the best opensource lib available.
                {
                }
            }
            return(result);
        }