robsuttonjr
MIS
I had to figure out how to ocr an image cheaply (if you have office 2003 already). Since we already had Office 2003 I could use the OCR engine in office. This code converts base64 to file and ocr's it to text. You can do tiff, jpg, and some others.
DEFINE CLASS imagetools as custom
PROCEDURE img2txt
LPARAMETERS lcBase64String as STRING
lcImage = STRCONV(lcBase64String,14)
IF FILE("tmpimg.jpg",1)
ERASE tmpimg.jpg
ENDIF
STRTOFILE(lcImage,"tmpimg.jpg",0)
miDoc = NEWOBJECT('MODI.Document')
miDoc.Create("tmpimg.jpg")
midoc.Images(0).ocr
mitext = midoc.Images(0).layout
lcText = mitext.Text
midoc.close()
RELEASE miDoc
IF FILE("tmpimg.jpg",1)
ERASE tmpimg.jpg
ENDIF
RETURN lcText
ENDPROC
ENDDEFINE
Regards,
Rob
DEFINE CLASS imagetools as custom
PROCEDURE img2txt
LPARAMETERS lcBase64String as STRING
lcImage = STRCONV(lcBase64String,14)
IF FILE("tmpimg.jpg",1)
ERASE tmpimg.jpg
ENDIF
STRTOFILE(lcImage,"tmpimg.jpg",0)
miDoc = NEWOBJECT('MODI.Document')
miDoc.Create("tmpimg.jpg")
midoc.Images(0).ocr
mitext = midoc.Images(0).layout
lcText = mitext.Text
midoc.close()
RELEASE miDoc
IF FILE("tmpimg.jpg",1)
ERASE tmpimg.jpg
ENDIF
RETURN lcText
ENDPROC
ENDDEFINE
Regards,
Rob