MODI问题`md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH,true,true)'

时间:2013-07-26 13:08:54

标签: c# ocr modi

在调试时我得到了这样的错误试图读取或写入受保护的内存。这通常表明其他内存已损坏。

以下错误代码行适用于捕获屏幕并执行ocr。但是动态地(意味着多次捕获具有特定时间限制的窗口)改变窗口捕获并且做ocr会给出错误。

private void OCRImplementationall()
        {
            MODI.Document md = new MODI.Document();

            Cursor = Cursors.WaitCursor;
            string Name = AppDomain.CurrentDomain.BaseDirectory + @"PT INFO.JPG";
            try
            {
                int fflag = 0;
                CheckForIllegalCrossThreadCalls = false;
                md.Create(Name);
                md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
                string strText = String.Empty;

                MODI.Image image = (MODI.Image)md.Images[0];
                MODI.Layout layout = image.Layout;
                string[] splvalues = layout.Text.Trim().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                //for (int i = 0; i < layout.Words.Count; i++)
                int i = 0;
                foreach (string val in splvalues)
                {}}
  catch (Exception ex)
            {
               //ExceptionHelper exlne = new ExceptionHelper();

                LogFile(ex.Message, "OCRImplementationall", "PT INFO Image Error", ExceptionHelper.LineNumber(ex), this.FindForm().Name);


                //MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
}

//捕获和执行ocr的函数

 public void screenCaptureDOB(bool showCursor)
        {
            try
            {
                Point curPos = new Point(843, 231);

                //Point curPos = new Point(Cursor.Position.X - CurrentTopLeft.X, Cursor.Position.Y - CurrentTopLeft.Y);
                Size curSize = new Size();
                try
                {
                    curSize.Height = Cursor.Current.Size.Height;
                    curSize.Width = Cursor.Current.Size.Width;

                    ScreenPath = AppDomain.CurrentDomain.BaseDirectory + @"DOB.JPG";
                    if (System.IO.File.Exists(ScreenPath))
                    {
                        System.IO.File.Delete(ScreenPath);
                    }
                    //if (!ScreenShot.saveToClipboard)
                    //{

                    //    saveFileDialog1.DefaultExt = "bmp";
                    //    saveFileDialog1.Filter = "bmp files (*.bmp)|*.bmp|jpg files (*.jpg)|*.jpg|gif files (*.gif)|*.gif|tiff files (*.tiff)|*.tiff|png files (*.png)|*.png";
                    //    saveFileDialog1.Title = "Save screenshot to...";
                    //    saveFileDialog1.ShowDialog();
                    //    ScreenPath = saveFileDialog1.FileName;

                    //}

                }
                catch (Exception ex)
                {
                    LogFile(ex.Message, "screenCaptureDOB", "DOB IMAGE ERROR", ExceptionHelper.LineNumber(ex), this.FindForm().Name);

                                       }
                if (ScreenPath != "" || ScreenShot.saveToClipboard)
                {

                    System.Threading.Thread.Sleep(250);
                    //Allow 250 milliseconds for the screen to repaint itself (we don't want to include this form in the capture)
                    Point StartPoint = new Point(80, 194);
                    Rectangle bounds = new Rectangle(80, 194, 1043, 59);

                    //Point StartPoint = new Point(CurrentTopLeft.X, CurrentTopLeft.Y);
                    //Rectangle bounds = new Rectangle(CurrentTopLeft.X, CurrentTopLeft.Y, CurrentBottomRight.X - CurrentTopLeft.X, CurrentBottomRight.Y - CurrentTopLeft.Y);
                    string fi = "";

                    if (ScreenPath != "")
                    {

                        fi = new System.IO.FileInfo(ScreenPath).Extension;

                    }
                    this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
                    this.TopMost = false;
                    // ScreenShot.CaptureImage(showCursor, curSize, curPos, StartPoint, Point.Empty, bounds, ScreenPath, fi);
                    ScreenShot.CaptureImage(showCursor, curSize, curPos, StartPoint, Point.Empty, bounds, ScreenPath, fi);



                    //The screen has been captured and saved to a file so bring this form back into the foreground
                    OCRImplementationDOB();
                    //OCRImplementationall();

                    //if (ScreenShot.saveToClipboard)
                    //{
                    //    LogFile("Screen saved to clipboard", "screenCaptureDOB", "DOB IMAGE", 1, this.FindForm().Name);

                                           //}
                    //else
                    //{
                    //    LogFile("Screen saved to file", "screenCaptureDOB", "DOB IMAGE ERROR", 1, this.FindForm().Name);


                    //}


                }
            }
            catch (Exception EXC)
            {
                LogFile(EXC.Message, "screenCaptureDOB", "DOB IMAGE ERROR", ExceptionHelper.LineNumber(EXC), this.FindForm().Name);

            }



        }

大会: “Interop.MODI”,版本= 12.0.0.0

System.Runtime.InteropServices.COMException: {“服务器引发异常。(HRESULT异常:0x80010105(RPC_E_SERVERFAULT))”}

来源: “Interop.MODI”

堆栈跟踪:

“在MODI.DocumentClass.OCR(MiLANGUAGES LangId,Boolean OCROrientImage,Boolean OCRStraightenImage)\ r \ n,位于D:\ Vishnus \ OCRConsole \ OCRConsole \ Program.cs中的OCRConsole.Program.Main(String [] args):第29行\ r \ n在System.AppDomain._nExecuteAssembly(程序集,String [] args)\ r \ n在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)\ r \ n在Microsoft。在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)的System.Threading.ThreadHelper.ThreadStart_Context(对象状态)\ r \ n中的VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\ r \ n \ r \ n在System.Threading.ThreadHelper.ThreadStart()“

我是否知道我在这些方面所做的问题

0 个答案:

没有答案