Exemplo n.º 1
0
        private void ApplyDocumentCleanupCommands(RasterImage image)
        {
            try
            {
                if (image.BitsPerPixel != 1)
                {
                    ColorResolutionCommand colorRes = new ColorResolutionCommand();
                    colorRes.BitsPerPixel = 1;

                    colorRes.Order = image.Order;
                    colorRes.Mode  = ColorResolutionCommandMode.InPlace;
                    colorRes.Run(image);
                }

                if (_miDocCleanDeskew.Checked)
                {
                    DeskewCommand cmd = new DeskewCommand();
                    cmd.FillColor = RasterColor.White;
                    cmd.Flags     = DeskewCommandFlags.FillExposedArea;

                    cmd.Run(image);
                }

                if (_miDocCleanDespeckle.Checked)
                {
                    DespeckleCommand cmd = new DespeckleCommand();
                    cmd.Run(image);
                }

                if (_miDocCleanBorderRemove.Checked)
                {
                    BorderRemoveCommand cmd = new BorderRemoveCommand();
                    cmd.Flags = BorderRemoveCommandFlags.AutoRemove;
                    cmd.Run(image);
                }

                if (_miDocCleanHolePunchRemoval.Checked)
                {
                    HolePunchRemoveCommand cmd = new HolePunchRemoveCommand();

                    // try to remove left hole punches
                    cmd.Flags = HolePunchRemoveCommandFlags.UseNormalDetection;
                    cmd.Run(image);

                    // try to remove right hole punches
                    cmd.Flags    = HolePunchRemoveCommandFlags.UseNormalDetection | HolePunchRemoveCommandFlags.UseLocation;
                    cmd.Location = HolePunchRemoveCommandLocation.Right;
                    cmd.Run(image);
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
        }
Exemplo n.º 2
0
        ///------------------------------------------------------------------------------
        /// <summary>
        ///     画像の解像度とサイズを変更する </summary>
        /// <param name="InPath">
        ///     画像ファイル入力パス</param>
        /// <returns>
        ///     true:分割を実施, false:分割ファイルなし</returns>
        ///------------------------------------------------------------------------------
        private bool imageResize(string InPath)
        {
            // 画像を確認
            if (System.IO.Directory.GetFiles(InPath, "*.tif").Count() == 0)
            {
                return(false);
            }

            RasterCodecs.Startup();
            RasterCodecs cs = new RasterCodecs();

            string fnm = string.Empty;

            //コマンドを準備します。(傾き・ノイズ除去・リサイズ)
            DeskewCommand    Dcommand  = new DeskewCommand();
            DespeckleCommand Dkcommand = new DespeckleCommand();
            SizeCommand      Rcommand  = new SizeCommand();

            // オーナーフォームを無効にする
            this.Enabled = false;

            //プログレスバーを表示する
            frmPrg frmP = new frmPrg();

            frmP.Owner = this;
            frmP.Show();

            int cImg = System.IO.Directory.GetFiles(InPath, "*.tif").Count();
            int cCnt = 0;

            foreach (string files in System.IO.Directory.GetFiles(InPath, "*.tif"))
            {
                cCnt++;

                //プログレスバー表示
                frmP.Text          = "OCR変換画像データロード中 " + cCnt.ToString() + "/" + cImg;
                frmP.progressValue = cCnt * 100 / cImg;
                frmP.ProgressStep();

                // 画像読み出す
                RasterImage leadImg = cs.Load(files, 0, CodecsLoadByteOrder.BgrOrGray, 1, -1);

                //画像補正処理 開始 ↓ ****************************
                try
                {
                    //画像の傾きを補正します。
                    Dcommand.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea;
                    Dcommand.Run(leadImg);
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(i + "画像の傾き補正エラー:" + ex.Message);
                }

                //ノイズ除去
                try
                {
                    Dkcommand.Run(leadImg);
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(i + "ノイズ除去エラー:" + ex.Message);
                }

                //解像度調整(200*200dpi)
                leadImg.XResolution = 200;
                leadImg.YResolution = 200;

                //A4縦サイズに変換(ピクセル単位)
                Rcommand.Width  = 1637;
                Rcommand.Height = 2322;
                try
                {
                    Rcommand.Run(leadImg);
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(i + "解像度調整エラー:" + ex.Message);
                }

                //画像補正処理 終了↑ ****************************

                // 画像保存
                cs.Save(leadImg, files, RasterImageFormat.Tif, 0, 1, 1, 1, CodecsSavePageMode.Overwrite);
            }

            //LEADTOOLS入出力ライブラリを終了します。
            RasterCodecs.Shutdown();

            // いったんオーナーをアクティブにする
            this.Activate();

            // 進行状況ダイアログを閉じる
            frmP.Close();

            // オーナーのフォームを有効に戻す
            this.Enabled = true;

            return(true);
        }
Exemplo n.º 3
0
        ///------------------------------------------------------------------------------
        /// <summary>
        ///     マルチフレームの画像ファイルを頁ごとに分割する </summary>
        /// <param name="InPath">
        ///     画像ファイル入力パス</param>
        /// <param name="outPath">
        ///     分割後出力パス</param>
        /// <returns>
        ///     true:分割を実施, false:分割ファイルなし</returns>
        ///------------------------------------------------------------------------------
        private bool MultiTif(string InPath, string outPath, string fName)
        {
            //スキャン出力画像を確認
            if (System.IO.Directory.GetFiles(InPath, "*.tif").Count() == 0)
            {
                return(false);
            }

            // 出力先フォルダがなければ作成する
            if (System.IO.Directory.Exists(outPath) == false)
            {
                System.IO.Directory.CreateDirectory(outPath);
            }

            // 出力先フォルダ内の全てのファイルを削除する(通常ファイルは存在しないが例外処理などで残ってしまった場合に備えて念のため)
            foreach (string files in System.IO.Directory.GetFiles(outPath, "*"))
            {
                System.IO.File.Delete(files);
            }

            RasterCodecs.Startup();
            RasterCodecs cs = new RasterCodecs();

            int    _pageCount = 0;
            string fnm        = string.Empty;

            //コマンドを準備します。(傾き・ノイズ除去・リサイズ)
            DeskewCommand    Dcommand  = new DeskewCommand();
            DespeckleCommand Dkcommand = new DespeckleCommand();
            SizeCommand      Rcommand  = new SizeCommand();

            // マルチTIFを分解して画像ファイルをTRAYフォルダへ保存する
            foreach (string files in System.IO.Directory.GetFiles(InPath, "*.tif"))
            {
                // 画像読み出す
                RasterImage leadImg = cs.Load(files, 0, CodecsLoadByteOrder.BgrOrGray, 1, -1);

                // 頁数を取得
                int _fd_count = leadImg.PageCount;

                // 頁ごとに読み出す
                for (int i = 1; i <= _fd_count; i++)
                {
                    //ページを移動する
                    leadImg.Page = i;

                    // ファイル名設定
                    _pageCount++;
                    fnm = outPath + fName + string.Format("{0:000}", _pageCount) + ".tif";

                    // 2018/06/08 画像補正をしない
                    //画像補正処理 開始 ↓ ****************************
                    //try
                    //{
                    //    //画像の傾きを補正します。
                    //    Dcommand.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea;
                    //    Dcommand.Run(leadImg);
                    //}
                    //catch// (Exception e)
                    //{
                    //}                       //ノイズ除去

                    //try
                    //{
                    //    Dkcommand.Run(leadImg);
                    //}
                    //catch// (Exception e)
                    //{
                    //}

                    ////解像度調整(200*200dpi)
                    //leadImg.XResolution = 200;
                    //leadImg.YResolution = 200;

                    ////A4縦サイズに変換(ピクセル単位)
                    //Rcommand.Width = 1637;
                    //Rcommand.Height = 2322;
                    //try
                    //{
                    //    Rcommand.Run(leadImg);
                    //}
                    //catch// (Exception e)
                    //{
                    //}

                    //画像補正処理 終了↑ ****************************

                    // 画像保存
                    cs.Save(leadImg, fnm, RasterImageFormat.Tif, 0, i, i, 1, CodecsSavePageMode.Insert);
                }
            }

            //LEADTOOLS入出力ライブラリを終了します。
            RasterCodecs.Shutdown();

            // InPathフォルダの全てのtifファイルを削除する
            foreach (var files in System.IO.Directory.GetFiles(InPath, "*.tif"))
            {
                System.IO.File.Delete(files);
            }

            return(true);
        }
Exemplo n.º 4
0
        ///------------------------------------------------------------------------------
        /// <summary>
        ///     マルチフレームの画像ファイルを頁ごとに分割する </summary>
        /// <param name="InPath">
        ///     画像ファイル入力パス</param>
        /// <param name="outPath">
        ///     分割後出力パス</param>
        /// <returns>
        ///     true:分割を実施, false:分割ファイルなし</returns>
        ///------------------------------------------------------------------------------
        private bool MultiTif(string InPath, string outPath, string fName)
        {
            //スキャン出力画像を確認
            if (System.IO.Directory.GetFiles(InPath, "*.tif").Count() == 0)
            {
                return(false);
            }

            // 出力先フォルダがなければ作成する
            if (System.IO.Directory.Exists(outPath) == false)
            {
                System.IO.Directory.CreateDirectory(outPath);
            }

            // 出力先フォルダ内の全てのファイルを削除する(通常ファイルは存在しないが例外処理などで残ってしまった場合に備えて念のため)
            foreach (string files in System.IO.Directory.GetFiles(outPath, "*"))
            {
                System.IO.File.Delete(files);
            }

            RasterCodecs.Startup();
            RasterCodecs cs = new RasterCodecs();

            int    _pageCount = 0;
            string fnm        = string.Empty;

            //コマンドを準備します。(傾き・ノイズ除去・リサイズ)
            DeskewCommand    Dcommand  = new DeskewCommand();
            DespeckleCommand Dkcommand = new DespeckleCommand();
            SizeCommand      Rcommand  = new SizeCommand();

            // オーナーフォームを無効にする
            this.Enabled = false;

            //プログレスバーを表示する
            frmPrg frmP = new frmPrg();

            frmP.Owner = this;
            frmP.Show();

            int cImg = System.IO.Directory.GetFiles(InPath, "*.tif").Count();
            int cCnt = 0;

            // マルチTIFを分解して画像ファイルをTRAYフォルダへ保存する
            foreach (string files in System.IO.Directory.GetFiles(InPath, "*.tif"))
            {
                cCnt++;

                //プログレスバー表示
                frmP.Text          = "OCR変換画像データロード中 " + cCnt.ToString() + "/" + cImg;
                frmP.progressValue = cCnt * 100 / cImg;
                frmP.ProgressStep();

                // 画像読み出す
                RasterImage leadImg = cs.Load(files, 0, CodecsLoadByteOrder.BgrOrGray, 1, -1);

                // 頁数を取得
                int _fd_count = leadImg.PageCount;

                // 頁ごとに読み出す
                for (int i = 1; i <= _fd_count; i++)
                {
                    //ページを移動する
                    leadImg.Page = i;

                    // ファイル名設定
                    _pageCount++;
                    fnm = outPath + fName + string.Format("{0:000}", _pageCount) + ".tif";

                    //画像補正処理 開始 ↓ ****************************
                    try
                    {
                        //画像の傾きを補正します。
                        Dcommand.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea;
                        Dcommand.Run(leadImg);
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(i + "画像の傾き補正エラー:" + ex.Message);
                    }

                    //ノイズ除去
                    try
                    {
                        Dkcommand.Run(leadImg);
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(i + "ノイズ除去エラー:" + ex.Message);
                    }

                    //解像度調整(200*200dpi)
                    leadImg.XResolution = 200;
                    leadImg.YResolution = 200;

                    //A4縦サイズに変換(ピクセル単位)
                    Rcommand.Width  = 1637;
                    Rcommand.Height = 2322;
                    try
                    {
                        Rcommand.Run(leadImg);
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(i + "解像度調整エラー:" + ex.Message);
                    }

                    //画像補正処理 終了↑ ****************************

                    // 画像保存
                    cs.Save(leadImg, fnm, RasterImageFormat.Tif, 0, i, i, 1, CodecsSavePageMode.Insert);
                }
            }

            //LEADTOOLS入出力ライブラリを終了します。
            RasterCodecs.Shutdown();

            // InPathフォルダの全てのtifファイルを削除する
            foreach (var files in System.IO.Directory.GetFiles(InPath, "*.tif"))
            {
                System.IO.File.Delete(files);
            }

            // いったんオーナーをアクティブにする
            this.Activate();

            // 進行状況ダイアログを閉じる
            frmP.Close();

            // オーナーのフォームを有効に戻す
            this.Enabled = true;

            return(true);
        }
Exemplo n.º 5
0
        private void imgResize(string files)
        {
            RasterCodecs.Startup();
            RasterCodecs cs = new RasterCodecs();

            int    _pageCount = 0;
            string fnm        = string.Empty;

            //コマンドを準備します。(傾き・ノイズ除去・リサイズ)
            DeskewCommand    Dcommand  = new DeskewCommand();
            DespeckleCommand Dkcommand = new DespeckleCommand();
            SizeCommand      Rcommand  = new SizeCommand();

            // 画像読み出す
            RasterImage leadImg = cs.Load(files, 0, CodecsLoadByteOrder.BgrOrGray, 1, -1);

            // 頁数を取得
            int _fd_count = leadImg.PageCount;

            //// ファイル名設定
            //_pageCount++;
            //fnm = outPath + fName + string.Format("{0:000}", _pageCount) + ".tif";
            fnm = files;

            //画像補正処理 開始 ↓ ****************************
            try
            {
                //画像の傾きを補正します。
                Dcommand.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea;
                Dcommand.Run(leadImg);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(i + "画像の傾き補正エラー:" + ex.Message);
            }

            //ノイズ除去
            try
            {
                Dkcommand.Run(leadImg);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(i + "ノイズ除去エラー:" + ex.Message);
            }

            //解像度調整(200*200dpi)
            leadImg.XResolution = 200;
            leadImg.YResolution = 200;

            //A4縦サイズに変換(ピクセル単位)
            Rcommand.Width  = 1637;
            Rcommand.Height = 2322;
            try
            {
                Rcommand.Run(leadImg);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(i + "解像度調整エラー:" + ex.Message);
            }

            //画像補正処理 終了↑ ****************************

            // 画像保存
            //cs.Save(leadImg, fnm, RasterImageFormat.Tif, 1, 1, 1, 1, CodecsSavePageMode.Insert);
            cs.Save(leadImg, fnm, RasterImageFormat.Ccitt, 1, 1, 1, 1, CodecsSavePageMode.Insert);

            //LEADTOOLS入出力ライブラリを終了します。
            RasterCodecs.Shutdown();
        }