Ocr问题有错误 [英] Ocr problem with error

查看:194
本文介绍了Ocr问题有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i对此代码有一些问题:从图像中提取文本(C#.net)~BitsByta [ ^ ]



提供的代码转换为vb .net但我只是继续得到这个问题抛出异常:'OCRtest.exe中的'System.Runtime.InteropServices.COMException'



附加信息:对象尚未被删除在这行代码中已初始化且无法使用



Hi all,

i have some problems regarding this code from : Extracting Text From Image (C#.net) ~ BitsByta[^]

the provided code was converted into vb.net but i just keep getting this problem "Exception thrown: 'System.Runtime.InteropServices.COMException' in OCRtest.exe

Additional information: Object hasn't been initialized and can't be used yet"

on this line of code:

doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, True, True)










Public Class frmOCRextract
    Private extractedText As String = String.Empty
    Private getFileName As String
    Dim openFile As New OpenFileDialog
    'Browsing an image
    Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click

        If openFile.ShowDialog = DialogResult.OK Then

            getFileName = openFile.FileName

            Dim targetImage As Image = Image.FromFile(getFileName)
            'Dim targetimage As Image = getFileName

            targetImage = fitInPBox(targetImage)


            pBox.Image = targetImage
        End If
    End Sub
    'This function fit the browsed image in picture box
    Private Function fitInPBox(img As Image) As Image
        Dim ixc As New Bitmap(img, New Size(pBox.Size.Width, pBox.Size.Height))
        Return DirectCast(ixc, Image)
    End Function
    'Extract button working, text is extracted from image
    Private Sub btnExtract_Click(sender As Object, e As EventArgs) Handles btnExtract.Click
        Dim doc As New MODI.Document()
        doc.Create(getFileName)
        doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, True, True)
        Dim img As MODI.Image = DirectCast(doc.Images(0), MODI.Image)
        Dim layout As MODI.Layout = img.Layout

        For i As Integer = 0 To layout.Words.Count - 1
            Dim word As MODI.Word = DirectCast(layout.Words(i), MODI.Word)

            If extractedText.Length > 0 Then
                extractedText += " "
            End If

            extractedText += word.Text
            RichTextBox1.Text = extractedText
        Next


    End Sub
End Class







tnx很多



我尝试过:



i继续获取那些,即使我尝试使用C#。仍然是同一行给我错误




tnx a lot

What I have tried:

i keep on getting those, even if i try to use C#. Still the same line gives me that error

推荐答案

你应该学会尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到有一点它会停止你所期望的。

在Visual Studio 2010中掌握调试 - 初学者指南 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]



在寻求错误帮助时,首先要提供错误消息,但不是唯一的错误消息。说明(源代码中的行号或位置)也很重要。

至少调试器会显示程序失败的位置。我建议在代码中添加注释以帮助发现问题所在。
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

When asking for help on an error, the error message is the first thing to provide, but not the only one. Saying where (line number or position in source code) matters too.
At least the debugger will show you where your program fails. I recommend to put a comment in code to help spot where is the problem.


这篇关于Ocr问题有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆