コード例 #1
0
ファイル: OMRReader.cs プロジェクト: MartinBG/Gva
        public OMRReader(OMRConfiguration config)
        {
            var assembly = Assembly.GetExecutingAssembly();
            using (var rc = assembly.GetManifestResourceStream("OMR.Resources.rc.jpg"))
            {
                this.rightBoundingImg = new Bitmap(rc);
            }

            using (var lc = assembly.GetManifestResourceStream("OMR.Resources.lc.jpg"))
            {
                this.leftBoundingImg = new Bitmap(lc);
            }

            this.ОMRConfig = config;
        }
コード例 #2
0
ファイル: ExamsController.cs プロジェクト: MartinBG/Gva
        public IHttpActionResult GetAnswers(string fileKey, string name)
        {
            GhostscriptVersionInfo lastInstalledVersion = GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL);
            Dictionary<string, List<List<bool>>> answers = new Dictionary<string, List<List<bool>>>();
            byte[] file;

            string[] extentions = { ".pdf", ".jpg", ".bmp", ".jpeg", ".png", ".tiff" };
            if (!extentions.Contains(Path.GetExtension(name)))
            {
                return Ok(new { err = "noPDForIMGFile" });
            }

            using (MemoryStream m1 = new MemoryStream())
            {
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DbContext"].ConnectionString))
                {
                    connection.Open();

                    using (var blobStream = new BlobReadStream(connection, "dbo", "Blobs", "Content", "Key", fileKey))
                    {
                        blobStream.CopyTo(m1);
                    }
                }

                Bitmap bitmapImg;
                if (Path.GetExtension(name) == ".pdf")
                {
                    using (GhostscriptRasterizer rasterizer = new GhostscriptRasterizer())
                    {
                        rasterizer.Open(m1, lastInstalledVersion, true);

                        //Copied, because rasterizer disposes itself
                        bitmapImg = new Bitmap(rasterizer.GetPage(300, 300, 1));
                    }
                }
                else
                {
                    bitmapImg = new Bitmap(m1);
                }

                OMRConfiguration conf = new OMRConfiguration();
                conf.AdjustmentBlock = new OMRAdjustmentBlock(1572, 3075, 425, 106);
                conf.WhiteBlock = new OMRAdjustmentBlock(1997, 3075, 106, 106);
                conf.DarkFactor = 0.90;
                conf.FillFactor = 1.60;
                conf.ImageWidth = 2182;
                conf.ImageHeight = 3210;
                conf.Blocks.Add(new OMRQuestionBlock("commonQuestions1", 387, 1059, 425, 530, 5));
                conf.Blocks.Add(new OMRQuestionBlock("commonQuestions2", 1312, 1059, 425, 530, 5));
                conf.Blocks.Add(new OMRQuestionBlock("specializedQuestions1", 387, 1798, 425, 1060, 10));
                conf.Blocks.Add(new OMRQuestionBlock("specializedQuestions2", 1312, 1798, 425, 1060, 10));

                using (var omr = new OMRReader(conf))
                using (bitmapImg)
                {
                    answers = omr.Read(bitmapImg);

                    using (Bitmap bitmapImgResized = OMRReader.ResizeImage(bitmapImg, 580, 800))
                    {
                        using (MemoryStream m2 = new MemoryStream())
                        {
                            bitmapImgResized.Save(m2, System.Drawing.Imaging.ImageFormat.Jpeg);
                            file = m2.ToArray();
                        }
                    }
                }
            }

            if (answers != null)
            {
                return Ok(new { answ = answers, file = file });
            }
            else
            {
                return Ok(new { err = "failedRecognition" });
            }
        }