I have neen experimenting with optical character recognition using the microsoft office document imagining library.
I used a sample code from msdn, which I modified a little.
It works great for the images I tested if they are in grayscale, color images aren't as consistent.
So my question is whether anyone knows how I can go about converting an image to grayscale ?
Is there another library I can reference for that purpose ?
Or an API ?
Sub TestLayout()
Dim miDoc As MODI.Document
Dim miLayout As MODI.Layout
Dim strLayoutInfo As String
' Load an existing TIFF file.
Set miDoc = New MODI.Document
' miDoc.Create "C:\ee.tif"
miDoc.Create "C:\www.tif"
' Perform OCR.
miDoc.Images(0).OCR
' MsgBox "Image height = " & miDoc.Images(0).PixelHeight & "px" & _
' vbLf & "Image width = " & miDoc.Images(0).PixelWidth & "px"
' Retrieve and summarize the OCR results.
Set miLayout = miDoc.Images(0).Layout
strLayoutInfo = _
"Language: " & miLayout.Language & vbCrLf & _
"Number of characters: " & miLayout.NumChars & vbCrLf & _
"Number of fonts: " & miLayout.NumFonts & vbCrLf & _
"Number of words: " & miLayout.NumWords & vbCrLf & _
"Beginning of text: " & Left(miLayout.Text, 50) & vbCrLf & _
"First word of text: " & miLayout.Words(0).Text
' MsgBox strLayoutInfo, vbInformation + vbOKOnly, _
"Layout Information"
MsgBox miLayout.Words(34).Text & vbCrLf & _
miLayout.Words(35).Text & vbCrLf & _
miLayout.Words(36).Text & vbCrLf & _
miLayout.Words(37).Text & vbCrLf & _
miLayout.Words(38).Text & vbCrLf & _
miLayout.Words(39).Text & vbCrLf & _
miLayout.Words(41).Text & vbCrLf & _
miLayout.Words(42).Text & vbCrLf & _
miLayout.Words(43).Text & vbCrLf & _
miLayout.Words(44).Text & vbCrLf & _
miLayout.Words(45).Text & vbCrLf & _
miLayout.Words(46).Text & vbCrLf & _
miLayout.Words(47).Text & vbCrLf & _
miLayout.Words(48).Text & vbCrLf
Set miLayout = Nothing
Set miDoc = Nothing
End Sub
Bookmarks