C# 通过MODI在特定区域而不是整个文档上执行OCR

C# 通过MODI在特定区域而不是整个文档上执行OCR,c#,winforms,image-processing,ocr,modi,C#,Winforms,Image Processing,Ocr,Modi,我试图通过MODI对选定目录中的图像执行批量OCR。这是密码 private void button1_Click(object sender, EventArgs e) { CommonOpenFileDialog dialog = new CommonOpenFileDialog { InitialDirectory = "C:\\Users", IsFolderPicker = true

我试图通过MODI对选定目录中的图像执行批量OCR。这是密码

private void button1_Click(object sender, EventArgs e) {
            CommonOpenFileDialog dialog = new CommonOpenFileDialog {
                InitialDirectory = "C:\\Users",
                IsFolderPicker = true
            };
            if (dialog.ShowDialog() == CommonFileDialogResult.Ok) {
                invoicePath = dialog.FileName;
                CheckFileAndDoOCR(imageDirectory);

            }
        }

public string CheckFileAndDoOCR(string directoryPath) {
            string TheTxt = "";
            IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();

            while (files.MoveNext()) {
                FileInfo foo = new FileInfo(Convert.ToString(files.Current));

                if (foo.Extension == ".jpg" || foo.Extension == ".JPG") {
                    TheTxt = DoOCR(foo.FullName);
                    string txtFileName = foo.DirectoryName + "\\" + foo.Name.Replace(foo.Extension, "") + ".txt";
                    FileStream createFile = new FileStream(txtFileName, FileMode.OpenOrCreate);
                    StreamWriter writeFile = new StreamWriter(createFile);
                    writeFile.Write(TheTxt);
                    writeFile.Close();
                    createFile.Close();
                }
                try {
                    foo.Delete();
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return TheTxt;
        }
public string DoOCR(string FullPath) {
            MODI.Document miDoc;
            MODI.Word miWord;
            MODI.IMiRects miRects;
            MODI.IMiRect miRect;
            string strRectInfo;
            miRect = null;

            string txt;
            string word;
            MODI.Document md = new MODI.Document();
            md.Create(FullPath);
            md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
            MODI.Image image = (MODI.Image)md.Images[0];
            txt = image.Layout.Text;
            word = null;
            image = null;
            md.Close(false);
            md = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            return txt;
        }
例如,如何在特定区域执行OCR

Rectangle Area = new Rectangle() {
                X = 1367,
                Y = 420,
                Height = 57,
                Width = 411
            };

我必须从所有图像中仅从一个区域/矩形提取数据。我该怎么做?我试过IronOCR和Tesseract,效果很好。但我被告知使用莫迪。请帮忙。

为什么你会考虑使用MODE,它一直被应用到Office 2007而不是像RoNoCR这样的最新工具?因为它不是我的决定。当然,但是我在文档、性能和稳定性方面说了。为什么你会考虑使用MODE,它一直被使用到Office2007,而不是像IronOCR这样的最新工具?因为这不是我的决定。当然,但我说过,从文档、性能和稳定性方面来说。