private void _twainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e) { if (!_canceled) { try { RasterImage image = e.Image; // Deskew the image DeskewCommand cmd = new DeskewCommand(); cmd.FillColor = Leadtools.Demos.Converters.FromGdiPlusColor(Color.White); cmd.Flags = DeskewCommandFlags.DocumentImage; cmd.Run(image); // Add the page to the OCR engine _document.Pages.AddPage(image, new OcrProgressCallback(OcrProgress)); } catch (Exception ex) { ShowError(ex); e.Cancel = true; } } // Check if we canceled if (_canceled) { e.Cancel = true; } }
private void DeskewDailog_Load(object sender, EventArgs e) { DeskewCommand command = new DeskewCommand(); _initialFillColorLevel = 0; _initialFlags = command.Flags; FillColorLevel = _initialFillColorLevel; Flags = _initialFlags; _rbFill.Checked = (Flags & DeskewCommandFlags.FillExposedArea) == DeskewCommandFlags.FillExposedArea; _rbNoFill.Checked = (Flags & DeskewCommandFlags.DoNotFillExposedArea) == DeskewCommandFlags.DoNotFillExposedArea; _numFillColorLevel.Value = FillColorLevel; FillColor = RasterColor.Black; _pnlRevColor.BackColor = Color.Black; if (_isGray) { _pnlLevel.Visible = true; _pnlColor.Visible = false; } else { _pnlLevel.Visible = false; _pnlColor.Visible = true; } }
public DeskewDialog() { InitializeComponent(); _DeskewCommand = new DeskewCommand(); //Set command default values InitializeUI(); }
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); } }
private static void DeskewImage(RasterImage image, string arguments) { int angleRange = DemoUtils.JsonStringToInteger(arguments, "angleRange"); int angleResolution = DemoUtils.JsonStringToInteger(arguments, "angleResolution"); RasterColor fillColor = DemoUtils.JsonStringToRasterColor(arguments, "fillColor"); int flags = DemoUtils.JsonStringToInteger(arguments, "flags"); DeskewCommand cmd = new DeskewCommand(fillColor, (DeskewCommandFlags)flags); cmd.AngleRange = angleRange; cmd.AngleResolution = angleResolution; cmd.Run(image); }
private void CleanupImage(RasterImage imageToClean, int startIndex, int count) { try { //Deskew if (cleanUpOcrEngine != null && cleanUpOcrEngine.IsStarted) { using (IOcrDocument document = cleanUpOcrEngine.DocumentManager.CreateDocument()) { for (var i = startIndex; i < startIndex + count; i++) { imageToClean.Page = i; document.Pages.AddPage(imageToClean, null); int angle = -document.Pages[0].GetDeskewAngle(); RotateCommand cmd = new RotateCommand(angle * 10, RotateCommandFlags.Bicubic, RasterColor.FromKnownColor(RasterKnownColor.White)); cmd.Run(imageToClean); document.Pages.Clear(); } } } else { for (var i = startIndex; i < startIndex + count; i++) { imageToClean.Page = i; var deskewCommand = new DeskewCommand(); if (imageToClean.Height > 3500) { deskewCommand.Flags = DeskewCommandFlags.DocumentAndPictures | DeskewCommandFlags.DoNotPerformPreProcessing | DeskewCommandFlags.UseNormalDetection | DeskewCommandFlags.DoNotFillExposedArea; } else { deskewCommand.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea; } deskewCommand.Run(imageToClean); } } } catch (Exception ex) { //log.Error(ex); Console.WriteLine("Not recognized"); } }
private void DeskewDialog_Load(object sender, System.EventArgs e) { if (_firstTimer) { _firstTimer = false; DeskewCommand command = new DeskewCommand(); _initialFillColor = command.FillColor; _initialFlags = command.Flags; } FillColor = _initialFillColor; Flags = _initialFlags; _rbFill.Checked = (Flags & DeskewCommandFlags.FillExposedArea) == DeskewCommandFlags.FillExposedArea; _rbNoFill.Checked = (Flags & DeskewCommandFlags.DoNotFillExposedArea) == DeskewCommandFlags.DoNotFillExposedArea; UpdateControls(); }
public void CleanupImage(RasterImage imageToClean) { imageToClean.Page = 1; DeskewCommand deskewCommand = new DeskewCommand(); if (imageToClean.Height > 3500) { deskewCommand.Flags = DeskewCommandFlags.DocumentAndPictures | DeskewCommandFlags.DoNotPerformPreProcessing | DeskewCommandFlags.UseNormalDetection | DeskewCommandFlags.DoNotFillExposedArea; } else { deskewCommand.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea; } deskewCommand.Run(imageToClean); }
private bool CleanupImage(RasterImage imageToClean, int startIndex, int count) { try { if (this.IsStartedOcrEngine()) { using (IOcrDocument document = this.TheOcrEngine.DocumentManager.CreateDocument()) { for (var i = startIndex; i < startIndex + count; i++) { imageToClean.Page = i; document.Pages.AddPage(imageToClean, null); int angle = -document.Pages[0].GetDeskewAngle(); RotateCommand cmd = new RotateCommand(angle * 10, RotateCommandFlags.Bicubic, RasterColor.FromKnownColor(RasterKnownColor.White)); cmd.Run(imageToClean); document.Pages.Clear(); } } } else { for (var i = startIndex; i < startIndex + count; i++) { imageToClean.Page = i; var deskewCommand = new DeskewCommand(); if (imageToClean.Height > 3500) { deskewCommand.Flags = DeskewCommandFlags.DocumentAndPictures | DeskewCommandFlags.DoNotPerformPreProcessing | DeskewCommandFlags.UseNormalDetection | DeskewCommandFlags.DoNotFillExposedArea; } else { deskewCommand.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea; } deskewCommand.Run(imageToClean); } } return(true); } catch (Exception ex) { return(false); } }
private IRecognitionForm RecognizeForm(RasterImage formImage, string id, string name) { IRecognitionForm recognizeForm = MainForm.GetOmrEngine().CreateRecognitionForm(); for (int i = 0; i < formImage.PageCount; i++) { formImage.Page = i + 1; DeskewCommand dskcmd = new DeskewCommand(); dskcmd.FillColor = Leadtools.RasterColor.White; dskcmd.Flags = DeskewCommandFlags.DoNotUseCheckDeskew; dskcmd.Run(formImage); recognizeForm.Pages.AddPage(formImage); } recognizeForm.Recognize(_templateForm); recognizeForm.Id = id; recognizeForm.SaveEmbeddedImage = false; recognizeForm.Name = name; return(recognizeForm); }
///------------------------------------------------------------------------------ /// <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); }
///------------------------------------------------------------------------------ /// <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); }
public DeskewDialog(DeskewCommand DeskewCommand) { InitializeComponent(); _DeskewCommand = DeskewCommand; InitializeUI(); }
public DeskewDialog() { InitializeComponent(); _DeskewCommand = new DeskewCommand(); InitializeUI(); }
///------------------------------------------------------------------------------ /// <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); }
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(); }