I have no luck finding a solution, only peers with same problem.
I wish to OCR a simple few JPEGs (i can convert on-fly with iview) and am really frustrated as I get the following error:
Method 'OCR' of object 'IImage' failed
My code isn't perfect yet as I am focussed on getting the darned .ocr method to function. The images are not documents but photos, and contain only a few characters. I could even use a barcode reader, but those are hard to find free. Any ideas?
Public Function OCRtest(strTempImg)
pXname = "ocrTest"
On Error GoTo err_hand
Dim miDoc As Object
Dim miWord As MODI.Word
Dim strWordInfo As String
Set miDoc = CreateObject("MODI.Document")
miDoc.Create strTempImg
' Perform OCR.
miDoc.Images(0).ocr
' Retrieve and display word information.
Set miWord = miDoc.Images(0).Layout.Words(2)
strWordInfo = _
"Id: " & miWord.id & vbCrLf & _
"Line Id: " & miWord.LineId & vbCrLf & _
"Region Id: " & miWord.RegionId & vbCrLf & _
"Font Id: " & miWord.FontId & vbCrLf & _
"Recognition confidence: " & _
miWord.RecognitionConfidence & vbCrLf & _
"Text: " & miWord.Text
Set miWord = Nothing
Set miDoc = Nothing
OCRtest = strWordInfo
Return
Exit Function
err_hand:
Call CStatus(Error, 504, Err.Number, Err.description, strTempImg)
End Function
答案 0 :(得分:1)
如果您使用的是MS Office 2010,则首先需要install MODI。
然后,您需要添加对private List<string> testData=new List<string>();
testData.Add("test");
testData.Add("test1");
private IEnumerable<object[]> ListOfTestData =>
new List<string[]>
{
new[] {testData[0]},
new[] {testData[1]}
};
[DataTestMethod]
[DynamicData (nameof (ListOfTestData))]
public void TestMethod(string test)
{
Assert.AreEqual("test", test);
}
的引用,您将能够使用此代码:
Microsoft Office Document Imaging 1x.0 Type Library
以上代码来自:https://www.mrexcel.com/forum/excel-questions/358499-read-data-tiff-file-using-modi-ocr-vba.html