zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    ORACLE中dba,user,v$等开头的常用表和视图
    rman restore spfile from backup
    oracle11g设置归档模式和非归档模式
    Oracle数据文件改名
    Linux下rz/sz安装及使用方法
    oracle数据库rman备份计划及恢复
    高级数据查询SQL语法
    关系数据库SQL之基本数据查询:子查询、分组查询、模糊查询
    关系数据库常用SQL语句语法大全
    微服务化的基石——持续集成【转】
  • 原文地址:https://www.cnblogs.com/daxiongblog/p/5316304.html
Copyright © 2011-2022 走看看