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

1

while debugging i got the error like this Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

This below error code line works for capture screen and do ocr. But dynamically(Means Multiple time capturing window with certain time limits) changing window capture and do ocr is giving error.

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;
            }
}

//Function to capture and do 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);

            }



        }

Assembly: "Interop.MODI" , Version=12.0.0.0

System.Runtime.InteropServices.COMException: {"The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"}

Source: "Interop.MODI"

Stacktrace:

" at MODI.DocumentClass.OCR(MiLANGUAGES LangId, Boolean OCROrientImage, Boolean OCRStraightenImage)\r\n at OCRConsole.Program.Main(String[] args) in D:\Vishnus\OCRConsole\OCRConsole\Program.cs:line 29\r\n at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()"

May i know whats the issue i made here in those lines

c#
ocr
modi
asked on Stack Overflow Jul 26, 2013 by Vichu • edited Aug 6, 2013 by Vichu

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0