示例#1
0
        private void DoOCR(IImage image)
        {
            ClearRenderingData();

            string variable  = "tessedit_pageseg_mode";
            int    storedOSD = 0;

            _ocrProcessor.GetIntVariable(variable, ref storedOSD);
            try
            {
                // Fully automatic page segmentation
                int fully_psm_auto = 3;
                _ocrProcessor.SetVariable(variable, fully_psm_auto.ToString());



                ///// DEMO ONLY
                using (Image bitmap = ToImage(image))
                {
                    ///// DEMO ONLY
                    _ocrProcessor.Clear();
                    _ocrProcessor.ClearAdaptiveClassifier();
                    BlockList blocks = _ocrProcessor.DetectBlocks(bitmap);
                    this.UpdateImageViewer(blocks);


                    ///// DEMO ONLY
                    _ocrProcessor.Clear();
                    _ocrProcessor.ClearAdaptiveClassifier();
                    string      result        = _ocrProcessor.Apply(bitmap);
                    List <Word> detectedWords = _ocrProcessor.RetriveResultDetail();
                    this.UpdateImageViewer(detectedWords);

                    if (!string.IsNullOrEmpty(result))
                    {
                        MessageBox.Show(result);
                    }
                }
            }
            catch
            {
            }
            finally
            {
                _ocrProcessor.SetVariable(variable, storedOSD.ToString());
            }


            //_ocrProcessor.Clear();
            //_ocrProcessor.ClearAdaptiveClassifier();

            //using (Image bitmap = ToImage(image))
            //{
            //    //string result = _ocrProcessor.Apply(_fileName);
            //    string result = _ocrProcessor.Apply(bitmap);

            //    List<Word> detectedWords = _ocrProcessor.RetriveResultDetail();
            //    this.UpdateImageViewer(detectedWords);

            //    if (!string.IsNullOrEmpty(result))
            //        MessageBox.Show(result);
            //}
        }