Example #1
0
        /// <summary>
        /// 画像回転
        /// </summary>
        /// <param name="orgImg"></param>
        /// <returns></returns>
        public static Bitmap RotateImage(Bitmap orgImg, int angle)
        {
            IDocumentSDKComponent docSdk = DocumentSDKFactory.GetDocumentSDK();
            Bitmap targetImg             = orgImg.Clone(new Rectangle(0, 0, orgImg.Width, orgImg.Height), orgImg.PixelFormat);

            using (Image chgimg = docSdk.RotateImage(targetImg, angle))
            {
                return((Bitmap)chgimg.Clone());
            }
        }
Example #2
0
        /// <summary>
        /// ノイズ除去
        /// </summary>
        /// <param name="orgImg"></param>
        /// <returns></returns>
        public static Bitmap EraseNoise(Bitmap orgImg)
        {
            IDocumentSDKComponent docSdk = DocumentSDKFactory.GetDocumentSDK();
            Bitmap targetImg             = orgImg.Clone(new Rectangle(0, 0, orgImg.Width, orgImg.Height), System.Drawing.Imaging.PixelFormat.Format1bppIndexed);
            // ノイズ除去処理
            DocumentSDKArea area = new DocumentSDKArea()
            {
                xs = 0,
                ys = 0,
                xe = targetImg.Width - 1,
                ye = targetImg.Height - 1
            };

            using (Image chgimg = docSdk.EraseNoise(targetImg, area, NoiseEnv.ToDocumentSDKEnshParam()))
            {
                return((Bitmap)chgimg.Clone());
            }
        }
Example #3
0
        /// <summary>
        /// 傾き補正処理
        /// </summary>
        /// <param name="orgImg"></param>
        /// <returns></returns>
        private Bitmap ModifyImage(Bitmap orgImg)
        {
            Counter counter = new Counter(SetSubTimeCount);
            IDocumentSDKComponent docSdk = DocumentSDKFactory.GetDocumentSDK();
            Bitmap TargetImg             = CloneIMage(orgImg);
            double?angle = docSdk.GetAngle(TargetImg);

            if (angle.HasValue)
            {
                // SDK用引数の準備
                DocumentSDKInterface.DocumentSDKSkewParam param = new DocumentSDKInterface.DocumentSDKSkewParam()
                {
                    det_max      = DocumentSDKInterface.DocumentSDKDefinition.SKEW_DET_MAX_DEFAULT,
                    det_mode     = DocumentSDKInterface.DocumentSDKDetMode.SKEW_DET_MODE_DEFAULT,
                    correct_mode = DocumentSDKInterface.DocumentSDKCorrectMode.SKEW_COR_MODE_DEFAULT,
                    expand_mode  = DocumentSDKInterface.DocumentSDKExpandMode.SKEW_EXPAND_MODE_DEFAULT,
                };
                counter.Start("傾き角度:" + angle.Value.ToString("#.#"));
                Image resultImg = docSdk.ModifyImage(TargetImg, angle.Value, param);
                counter.End();
                return((Bitmap)resultImg.Clone());
            }
            return(orgImg);
        }
Example #4
0
        /// <summary>
        /// OMR認識処理
        /// </summary>
        /// <param name="itemImage">項目画像</param>
        /// <param name="recogItem">認識対象情報</param>
        /// <returns>OMR認識結果</returns>
        public DocumentSDKOmrResult executeOmr(Image itemImage, DocumentSDKCheckType markType, Rectangle markArea, Image masterImg, Rectangle masterRect)
        {
            IDocumentSDKComponent documentSDK = DocumentSDKFactory.GetDocumentSDK();
            FileStream            stream      = null;
            Image masterImage = null;
            List <DocumentSDKArea> areaList       = new List <DocumentSDKArea>();
            List <DocumentSDKArea> masterAreaList = null;

            try
            {
                // OMRパラメーターの設定
                DocumentSDKOmrParam param = new DocumentSDKOmrParam()
                {
                    check_num    = DocumentSDKDefinition.OMR_CN_UNKNOWN,
                    check_type   = markType,
                    threshold    = SByte.Parse("50"),
                    area_type    = DocumentSDKAreaType.OMR_AT_SOLID,
                    around_area  = DocumentSDKAroundArea.OMR_AA_UNKNOWN,
                    check_size_x = DocumentSDKDefinition.OMR_CS_UNKNOWN,
                    check_size_y = DocumentSDKDefinition.OMR_CS_UNKNOWN,
                };

                // OMR領域を設定(文字領域を抽出され場合、OCRの文字領域を使用する)
                DocumentSDKArea area = new DocumentSDKArea()
                {
                    xs = markArea.Left,
                    ys = markArea.Top,
                    xe = markArea.Left + markArea.Width - 1,
                    ye = markArea.Top + markArea.Height - 1,
                };
                areaList.Add(area);
                if (markType == DocumentSDKCheckType.OMR_CT_UNKNOWN)
                {
                    masterImage    = masterImg;
                    masterAreaList = new List <DocumentSDKArea>();
                    DocumentSDKArea masterArea = new DocumentSDKArea()
                    {
                        xs = masterRect.X,
                        ys = masterRect.Y,
                        xe = masterRect.X + masterRect.Width,
                        ye = masterRect.Y + markArea.Height,
                    };
                    masterAreaList.Add(masterArea);
                }

                // OMR処理の実行
                DocumentSDKOmrResult result = documentSDK.ExecuteOmr(itemImage, areaList, masterImage, masterAreaList, param);

                return(result);
            }
            finally
            {
                // ファイルストリームの破棄
                if (stream != null)
                {
                    stream.Dispose();
                }
                // マスター画像の破棄
                if (masterImage != null)
                {
                    masterImage.Dispose();
                }
            }
        }