• LeadTools答题卡识别方案


     /// <summary>
            /// 批改操作
            /// </summary>
            public AnswerCard DoCorrect(Stream AnserCardFile)
            {
                AnswerCard anserCard=new AnswerCard();
                try
                {
                    //RasterImage crrentImages;
                    // Create the Auto Forms Engine
                    AutoFormsEngine autoEngine;
                    RasterCodecs formsCodec=new RasterCodecs();
                    //Create a collection of OCR Engines
                    IOcrEngine ocrEngine;
                    //Create the repository of master forms
                    DiskMasterFormsRepository formsRepository;
                    //Create an OCR Engine
                    using (ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false))
                    {
                       
                        ocrEngine.Startup(formsCodec, null,null, null);
    
                       
                        // Load the first page as RasterImage 
                        RasterImage rasterImage = formsCodec.Load(AnserCardFile);
                        //ocrEngine.CreatePage(rasterImage, OcrImageSharingMode.AutoDispose);
                        // Create an OCR page from this image, transform ownership of the RasterImage object 
                        //using (IOcrPage ocrPage = ocrEngine.CreatePage(rasterImage, OcrImageSharingMode.AutoDispose))
                        //{
                        // Auto-preprocess it
                        //ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.All, null);
    
                        // Create an OCR document
                        using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument())
                            {
                            // Add this image to the document
                             IOcrPage ocrPage = ocrDocument.Pages.AddPage(rasterImage, null);
                            BarcodeEngine barcodeEngine = new BarcodeEngine();
                            // Auto-preprocess it
                            ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.All, null);
                            // Point repository to directory with existing master forms 
                            formsRepository = new DiskMasterFormsRepository(formsCodec, masterFormsFolder);
                            autoEngine = new AutoFormsEngine(formsRepository, ocrEngine, null, AutoFormsRecognitionManager.Default | AutoFormsRecognitionManager.Ocr, 30, 80, true);
                            // Recognize (Classify) the form
                            AutoFormsRunResult runResult = autoEngine.Run(ocrPage.GetRasterImage(OcrPageType.Current), null, null, null);
                            //AutoFormsRunResult runResult = autoEngine.Run(rasterImage, null, null, null);
                            //AutoFormsRunResult runResult = autoEngine.Run(AnserCardFile, null);
                            if (runResult != null)
                            {
                                //Recognition was successful
                                anserCard = AnswerHandle(runResult);
                            }
                        }
                        autoEngine.Dispose();
                        formsCodec.Dispose();
                        //rasterImage.Dispose();
                        if (ocrEngine != null && ocrEngine.IsStarted)
                            ocrEngine.Shutdown();
                    }
                    return anserCard;
                }
                catch (Exception ex)
                {
                    return null;
                }
            }

     校正方案可使用

      private void DoDeskew(IOcrEngine ocrEngine, string Filename, string Savename)
            {
                // Load the first page as RasterImage 
                RasterImage image = ocrEngine.RasterCodecsInstance.Load(Filename, 1);
                // 准备命令 
                DeskewCommand command = new DeskewCommand();
                //图像的倾斜校正 
                command.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea;
                command.Run(image);
                // 创建一个RasterCodecs类的新实例
                RasterCodecs codecs = new RasterCodecs();
                codecs.Options.Jpeg2000.Save.UseSopMarker =true;
                // 将图像保存
                codecs.Save(
                   image,
                  Savename,
                RasterImageFormat.TifLzw,
                   1,
                   1,
                   1,
                   1,
                CodecsSavePageMode.Overwrite);
                image.Dispose();
                codecs.Dispose();
            }
    View Code
  • 相关阅读:
    paip.erlang 文本文件读写操作attilax总结
    paip.python错误解决20
    paip.python错误解决8
    paip. sip module implements API v10.0 to v10.1 but the PyQt4.QtCore module requires API v9.2
    解读NoSQL数据库的四大家族
    paip.python错误解决9
    paip.python 执行shell 带空格命令行attilax总结
    paip.python错误解决15
    paip.python错误解决24
    paip.python优缺点attilax总结
  • 原文地址:https://www.cnblogs.com/daxiongblog/p/5316304.html
Copyright © 2020-2023  润新知