标签: modi

如何处理AccessViolationException

我在我的.net应用程序中使用COM对象(MODI).我调用的方法抛出一个System.AccessViolationException,它被Visual Studio拦截.奇怪的是我在try catch中包含了我的调用,它包含AccessViolationException,COMException和其他所有东西的处理程序,但是当Visual Studio(2010)拦截AccessViolationException时,调试器会中断方法调用(doc.OCR),如果我单步执行,它将继续到下一行,而不是进入catch块.另外,如果我在visual studio外部运行,我的应用程序崩溃了.如何处理COM对象中引发的此异常?

MODI.Document doc = new MODI.Document();
try
{
    doc.Create(sFileName);
    try
    {
        doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
        sText = doc.Images[0].Layout.Text;
    }
    catch (System.AccessViolationException ex)
    {
        //MODI seems to get access violations for some reason, but is still able to return the OCR text.
        sText = doc.Images[0].Layout.Text;
    }
    catch (System.Runtime.InteropServices.COMException ex)
    {
        //if no text exists, the engine throws an exception.
        sText = "";
    }
    catch
    {
        sText = "";
    }

    if (sText != null)
    {
        sText = sText.Trim();
    } …
Run Code Online (Sandbox Code Playgroud)

.net c# com modi exception

170
推荐指数
3
解决办法
13万
查看次数

如何让索引服务和MODI在OCR上生成全文?

我已配置索引服务来索引我的文件,其中还包括保存为高分辨率TIFF文件的扫描图像.我还安装了MS Office 2003+并正确配置了MS Office Document Imaging(MODI),因此我可以对我的图像执行OCR,甚至将OCR文本嵌入到TIFF中.

索引服务能够索引和查找那些手动OCR并使用文本数据重新保存的TIFF(使用MS Document Imaging工具).

事实证明,与Windows XP SP2一起部署的数据执行保护(DEP)认为MODI是恶意的,并且拒绝让它发挥其魔力.我已经能够通过完全关闭DEP来使它工作,但我发现这个解决方案不够优雅.

有没有更好的解决方案来实现这项工作,而不会禁用DEP?

ocr modi indexing-service

71
推荐指数
1
解决办法
2053
查看次数

Windows 7 OCR API

我一直在检查Office 2007 MODI OCR的替代品(OneNote的2010解决方案质量/结果比2007年更低:-().我注意到一旦安装了可选的tiff过滤器,Windows 7就包含一个OCR库

OCR组件已安装到

%programfiles%\Common Files\microsoft shared\OCR\7.0\xocr3.psp.dll 
Run Code Online (Sandbox Code Playgroud)

但我没有看到任何API吗?

有没有人看到这可以如何在C#中进行接口?

解答:找到解决方案,一旦安装了可选的tiff ifilter win7功能,我就可以使用http://www.codeproject.com/KB/cs/IFilter.aspx上的代码/ exe获取截图的文本输出.另外,如果为.png和.jpg添加相同的[HKEY_CLASSES_ROOT.tiff\PersistentHandler],那么OCR也适用于jpg和png.

c# ocr modi sdk windows-7

15
推荐指数
1
解决办法
2万
查看次数

如何在ASP.Net Web应用程序中使用MODI?

我在Microsoft Office Document Imaging COM API周围编写了一个OCR包装器库,在本地运行的Console App中,每次测试都可以完美运行.

遗憾的是,当我们尝试将它与在IIS6下作为ASP.Net Web应用程序运行的WCF服务集成时,事情开始变得糟糕.我们在尝试释放MODI COM对象时遇到了问题,网上有很多帮助我们的例子.

但问题仍然存在.如果我重新启动IIS,并重新部署Web应用程序,那么前几次OCR尝试工作得很好.如果我离开它30分钟左右,然后再做另一个请求,我会收到服务器故障错误,如下所示:

服务器抛出异常.(来自HRESULT的异常:0x80010105(RPC_E_SERVERFAULT)):在MODI.DocumentClass.Create(String FileOpen)

从现在开始,每次请求都将无法执行OCR,直到我重置IIS,并且循环再次开始.

我们在自己的应用程序池中运行此应用程序,它以具有本地管理员权限的身份运行.

更新:此问题可以通过在进程外执行OCR操作来解决.似乎MODI库与托管代码不兼容,当涉及到自身清理时,因此为我的情况生成每个OCR请求的新进程运行良好.

以下是执行OCR的功能:

    public class ImageReader : IDisposable
{
    private MODI.Document _document;
    private MODI.Images _images;
    private MODI.Image _image;
    private MODI.Layout _layout;
    private ManualResetEvent _completedOCR = new ManualResetEvent(false);

    // SNIP - Code removed for clarity

    private string PerformMODI(string fileName)
    {
        _document = new MODI.Document();
        _document.OnOCRProgress += new MODI._IDocumentEvents_OnOCRProgressEventHandler(_document_OnOCRProgress);
        _document.Create(fileName);

        _document.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
        _completedOCR.WaitOne(5000);
        _document.Save();
        _images = _document.Images;
        _image = (MODI.Image)_images[0];
        _layout = _image.Layout;
        string text = _layout.Text; …
Run Code Online (Sandbox Code Playgroud)

asp.net ocr modi

10
推荐指数
1
解决办法
4422
查看次数

.NET OCRing图像

我正在尝试使用MODI来OCR窗口的程序.它适用于截图我使用win32 interop以编程方式抓取,如下所示:

public string SaveScreenShotToFile()
{
    RECT rc;
    GetWindowRect(_hWnd, out rc);

    int width = rc.right - rc.left;
    int height = rc.bottom - rc.top;

    Bitmap bmp = new Bitmap(width, height);
    Graphics gfxBmp = Graphics.FromImage(bmp);
    IntPtr hdcBitmap = gfxBmp.GetHdc();

    PrintWindow(_hWnd, hdcBitmap, 0);

    gfxBmp.ReleaseHdc(hdcBitmap);
    gfxBmp.Dispose();

    string fileName = @"c:\temp\screenshots\" + Guid.NewGuid().ToString() + ".bmp";
    bmp.Save(fileName);
    return fileName;
}
Run Code Online (Sandbox Code Playgroud)

然后将此图像保存到文件中并通过MODI运行,如下所示:

    private string GetTextFromImage(string fileName)
    {

        MODI.Document doc = new MODI.DocumentClass();
        doc.Create(fileName);
        doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
        MODI.Image img = (MODI.Image)doc.Images[0];
        MODI.Layout layout = img.Layout;

        StringBuilder sb = …
Run Code Online (Sandbox Code Playgroud)

.net c# ocr modi

8
推荐指数
1
解决办法
1万
查看次数

将MODI 2003与C#一起使用时出现"OCR运行错误"

我一直在努力让MODI在今天正常工作.这是我试图使用的代码(改编自维基百科MODI条目中给出的VB .

private void button1_Click( object sender, EventArgs e )
{
    string inputFile = @"C:\testImage.bmp";
    textBox1.Text = GetTextFromImage( inputFile );
}

private string GetTextFromImage( string fileName )
{
    string output = "";
    var doc1 = new MODI.Document();
    doc1.Create( fileName );
    doc1.OCR( MiLANGUAGES.miLANG_ENGLISH, false, false );

    for ( int i = 0; i < doc1.Images.Count; i++ )
    {
        output += doc1.Images[i].Layout.Text;
    }

    doc1.Close();
    return output;
}
Run Code Online (Sandbox Code Playgroud)

当我执行此操作时,我在OCR()行上出现错误,说明以下内容:

System.Runtime.InteropServices.COMException was unhandledMessage=OCR running error Source="" ErrorCode=-959967087
Run Code Online (Sandbox Code Playgroud)

现在,我查找了该错误代码,发现了另一个stackoverflow 问题,他们发现他们无法在小图像上运行OCR,但问题是1700x …

c# ocr modi bitmap

6
推荐指数
1
解决办法
7859
查看次数

如何在C#中使用MODI(Microsoft Office Document Imaging)进行串行OCR

我将文件作为.jpg图片扫描到一个文件夹中,我想在C#中连续为该文件夹中的每个文件进行OCR.到目前为止我做到了这一点:

public string CheckFilesAndDoOCR(string directoryPath)
{
    directoryPath = Environment.SpecialFolder.MyPictures + "\\OCRTempPictures\\";
    IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();
    string TheTxt = "";

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

        // Get new file name
        string fileName = AlltoJPG(nfo);

        // FileInfo (New File)
        FileInfo foo = new FileInfo(fileName);

        // Check for JPG File Format
        if (foo.Extension == ".jpg" || foo.Extension == ".JPG")
        // or // ImageFormat.Jpeg.ToString()
        {
            try
            {
                // OCR Operations...
                MODI.Document md = new MODI.Document();
                md.Create(foo.FullName);
                md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false); …
Run Code Online (Sandbox Code Playgroud)

c# ocr error-handling modi ms-office

5
推荐指数
1
解决办法
5849
查看次数

PictureBox在Tab键按下时抛出"参数无效"ArgumentException

我有一个表单,用户可以先扫描到位图.扫描完成后,加载位图,我有4个文本框然后启用.在每个文本框旁边,我有一个名为"从图像剪切"的按钮.当用户单击该按钮时,他们可以单击并拖动位图以使用MODI获取所选文本.

除了一个令人讨厌的bug之外,这种方法很完美:当我点击"从图像剪切"按钮并拖动一个正方形时,它会很好地获取文本框中的信息.然后,如果我点击下一个文本框,它会很顺利,但是如果我使用tab键离开该字段,我会得到一个"参数无效" ArgumentException并且它没有显示任何帮助代码中的位置崩溃了.我可以在表单中四处选择,没有任何问题,但是一旦扫描了位图,当我使用tab键时,它会像10次中的9次一样崩溃.

我尝试使用以下方法覆盖tab键(仅用于调试):

Protected Overrides Function ProcessTabKey(ByVal forward As Boolean) As Boolean
    MsgBox("TAB is currently disabled!")
    Return False 'Tried True as well, just in case
End Function
Run Code Online (Sandbox Code Playgroud)

......但它仍然崩溃.

关于什么是错的任何建议?由于我不知道从哪里开始调试,我无法分辨出要显示的代码.

编辑1

这是ArgumentException抛出的堆栈跟踪:

  • 在System.Drawing.Image.get_Width()
  • 在System.Drawing.Image.get_Size()
  • 在System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode模式)
  • 在System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
  • 在System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,Int16 layer)
  • 在System.Windows.Forms.Control.WmPaint(Message&m)
  • 在System.Windows.Forms.Control.WndProc(Message&m)
  • 在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)
  • 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)
  • 在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)
  • 在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&msg)
  • 在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32 reason,Int32 pvLoopData)
  • 在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)
  • 在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context)
  • 在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
  • 在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
  • 在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String [] commandLine)
  • at ORC_Testing.My.MyApplication.Main(String [] Args)in 17d14f5c-a337-4978-8281-53493378c1071.vb:第81行
  • 在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args)
  • 在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] …

vb.net modi bitmap keypress winforms

4
推荐指数
1
解决办法
1万
查看次数