Platforms to show: All Mac Windows Linux Cross-Platform
/OCR/OCR with picture
Feedback.
Function:
You find this example project in your Plugins Download as a Realbasic project file within the examples folder: /OCR/OCR with picture
This example is the version from Sat, 14th Dec 2012.
Notes: Last modified: Sat, 14th Dec 2012
Feedback.
Function:
You find this example project in your Plugins Download as a Realbasic project file within the examples folder: /OCR/OCR with picture
This example is the version from Sat, 14th Dec 2012.
Notes: Last modified: Sat, 14th Dec 2012
Project "OCR with picture.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
Function UnhandledException(error As RuntimeException) As Boolean
MsgBox error.Message+EndOfLine+EndOfLine+Join(error.Stack,EndOfLine)
End
End Class
Class Window1 Inherits Window
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End ControlInstance
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
End ControlInstance
Sub Action()
Refresh
End
End Control
Control CheckBox2 Inherits CheckBox
ControlInstance CheckBox2 Inherits CheckBox
End ControlInstance
Sub Action()
Refresh
End
End Control
Control Out Inherits Canvas
ControlInstance Out Inherits Canvas
End ControlInstance
Sub Paint(g As Graphics)
if pic<>Nil Then
g.DrawPicture pic,0,0
end if
g.ForeColor=&cFF0000
// check result
dim r as TesseractResultIteratorMBS = o.ResultIterator
if r<>Nil and CheckBox2.Value then
do
// query values like confidence
g.ForeColor=&c000000
if CheckBox1.Value then
dim Confidence as Double = r.Confidence(r.kLevelWord)
g.ForeColor=Rgb((100-Confidence)*2.55, Confidence*2.55, 0)
end if
dim rleft, rtop, rright, rbottom as integer
// query bounding box
if r.BoundingBox(r.kLevelWord, rleft, rtop, rright, rbottom) then
dim rwidth as integer = rright - rleft
dim rheight as integer = rbottom - rtop
g.DrawRect rleft, rtop, rwidth, rHeight
end if
// and go to next word
loop until r.NextItem(r.kLevelWord) = false
end if
End
End Control
Sub Open()
// search tessdata folder
dim fo as FolderItem = findfile("tessdata")
if TargetWin32 then
// on Windows the parent folder
fo = fo.Parent
else
// path must be correct to have it find the files and point to folder where tessdata folder is inside
fo = GetFolderItem("")
end if
o = new TesseractMBS(fo, "eng")
dim n as integer = o.NumDawgs
if n = 0 then
MsgBox "No lang data found!"
quit
end if
dim f as FolderItem
// pick a test file
if rnd<0.5 then
f = findfile("eurotext.tif")
else
f = findfile("phototest.tif")
end if
dim p as Picture = f.OpenAsPicture
if o.SetImage(p) then
EditField1.text = o.getText
pic=p
end if
Exception ex as TesseractErrorExceptionMBS
MsgBox "Exception: "+ex.message
End
Function FindFile(name as string) As FolderItem
// we need this function as Real Studio may use a builds folder
dim folder as FolderItem = GetFolderItem("")
dim fo as folderitem = folder.Child(name)
while fo.Exists = false
folder = folder.Parent
fo = folder.Child(name)
wend
Return fo
End
Property o As TesseractMBS
Property pic As Picture
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Module Module1
End Module
End Project
The items on this page are in the following plugins: MBS Real Studio OCR Plugin.
Links
MBS Realbasic Chart Plugins