Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OCR
#1
Function Function1
Code:
Select All      Help
function

str s1
str fBmp="$temp$\qm_modi.bmp"

if(scan("resource:<Image>image:h1B7A5E0B" w 0 16))
,fBmp.expandpath
,CaptureImageOnScreen(655 340 85 35(fBmp))
,typelib MODI {A5EDEDF4-2BBC-45F3-822B-E60C278A1A79} 13.0
,MODI.Document doc._create
,doc.Create(fBmp)
,doc.OCR(MODI.miLANG_ENGLISH -1 0)
,MODI.Image im=doc.Images.Item(0)
,s1=im.Layout.Text

This was my original OCR code. However, I have a 2 minor issues with this code.

1. I want to capture a image based on where the previous image is located. E.g. image:h1B7A5E0B is located at x: 620, y: 320 I want it to capture the location x:620, y: 320+50. What do I change to do this?

2. I've issues with MODI ever since I upgraded my operating system to windows 10. Sharepoint 2007 cannot be installed anymore. I found a open sources OCR https://github.com/tesseract-ocr/tesseract but I need some guide on how to in-cooperate it into the code.
#2
Macro Macro2761
Code:
Select All      Help
str s1
str fBmp="$temp$\qm_modi.bmp"

RECT r
if(scan("resource:<Image>image:h1B7A5E0B" w r 16|128))
,fBmp.expandpath
,OffsetRect &r 0 50
,CaptureImageOnScreen(r.left r.top r.right-r.left r.bottom-r.top fBmp)
,typelib MODI {A5EDEDF4-2BBC-45F3-822B-E60C278A1A79} 13.0
,MODI.Document doc._create
,doc.Create(fBmp)
,doc.OCR(MODI.miLANG_ENGLISH -1 0)
,MODI.Image im=doc.Images.Item(0)
,s1=im.Layout.Text

2. Tesseract does not OCR screen text well. At least when I tested it last time, 1 year ago. It works well only with bigger font text. We can resize captured screen text, but OCR results are still poor. MODI is much better. I have the test macro, can post if you need.

For example, I tried to OCR your post with tesseract.
Results without resizing, time 7.5 s:
Code:
Select All      Help
miswasutyarigitaiocncode.ttmever,tttaveazmiturissrresvdnrnriscode.

I I want [a capture a iuage based on were me previms iuage is located. Lg. iuage:trttt7A5(ott is located at x: 510, y: 310 I want. [a capture the hcatiuu x:610,y:310-ó50.wltaldnldtange
[a do IItis?

1. We issues wilIt wont ever sitce I upgraded my npemt'llg system In witdrms I0. sttarepairt 1007 carmtbe itslaled anymore. I '01-GÇ£ a open Sources ocn Films:llgimubmnmliesseracr
acr/tesseractbut I need some guide on him In 'lirooopemle it itln the code.
Results when resized 3 times, time 0.9 s:
Code:
Select All      Help
This was my original OCR code. However, I have a 2 minor issues with this code.

1 . I want to capture a image based on where the previous image is located. E.g. image:h1B7A5EOB is located at x: 620, y: 320 I want it to capture the location x:620, y: 320460. What do I diange
to do this?

2. I've issues with MODI ever since I upgraded my operating system to windows 10. Sharepoint 2007 cannot be installed anymore. I found a open sources OCR https:llgithub.comltesseract-
ocrltesseract but I need some guide on how to in-cooperate it into the code.
#3
Will be great if you can share the code as well. I'll play around with it. Thanks!
#4
And for the rectangle. Is it possible change the capture size of the rectangle? E.g. It's 300x100 at the start I need to to be 200x80.
#5
Change r.right etc with operator + or -. Or use function InflateRect.
#6
1. Download/install tesseract. I downloaded from here: https://github.com/UB-Mannheim/tesseract/wiki
2. Download/import FreeImage: Image manipulation with FreeImage graphics library

Macro tesseract
Code:
Select All      Help
;Tested 2017-03-15 with the latest tesseract version 3.05-dev.
;Too much OCR errors to be useful when the image is captured from screen, with small font.
;MODI works without errors with same image.

out
;change these values if need
str fTes.expandpath("$Program Files$\Tesseract-OCR\tesseract.exe")
int scale=3 ;;how much to resize. Tesseract is very sensitive to text size. Usually with 2-4 works best. Fastest 2, slightly slower 3, then 4, slowest 1.
int captureNow=1 ;;if 0, will use previously captured file

;---------------------

str language;;="lit" ;;does not work
str fBmp.expandpath("$temp$\qm_tesseract.bmp") ;;this macro captures screen image and saves it in this temporary file
str fBmp2.expandpath("$temp$\qm_tesseract2.bmp") ;;this macro resizes the image, saves in this file, and passes this file to tesseract.exe

;capture screen image and save in file fBmp
if captureNow
,if(!CaptureImageOrColor(0 0 _hwndqm fBmp)) ret
,;if(!CaptureImageOnScreen(610 400 800 45 fBmp)) ret

PerfFirst ;;measure speed
;resize with FreeImage. Also tried GflAx, worse.
#compile "__FreeImage"
if scale>1
,FI_ShowMoreErrorInfo ;;optional
,FiBitmap x
,x.Load(FIMG.FIF_BMP fBmp)
,int newWidth=FIMG.FreeImage_GetWidth(x)*scale
,int newHeight=FIMG.FreeImage_GetHeight(x)*scale
,;FiBitmap x2.Attach(FIMG.FreeImage_Rescale(x newWidth newHeight FIMG.FILTER_BSPLINE)) ;;too much filtering
,;FiBitmap x2.Attach(FIMG.FreeImage_Rescale(x newWidth newHeight 0)) ;;FIMG.FILTER_BOX, bad OCR
,FiBitmap x2.Attach(FIMG.FreeImage_Rescale(x newWidth newHeight FIMG.FILTER_LANCZOS3)) ;;good
,
,FIMG.FreeImage_AdjustContrast(x2 10)
,
,fBmp=fBmp2
,x2.Save(FIMG.FIF_BMP fBmp)
,PerfNext ;;measure speed

;OCR (convert image to text)
str cl.format("''%s'' ''%s'' stdout" fTes fBmp) so
if(language.len) cl+F" -l {language}"
;out cl
if(RunConsole2(cl so "" 0x200)) end so
PerfNext ;;measure speed
PerfOut ;;measure speed
out so ;;show results

ret ;;disable this line if want to see the image passed to tesseract.exe

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 1000 500 "Shows the resized image for 3 seconds"
;3 Static 0x5400000E 0x0 0 0 1158 174 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040308 "*" "" "" ""

str controls = "3"
str sb3
sb3=fBmp
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,int x y w h
,GetWorkArea x y w h
,MoveWindow hDlg x y w h 0
,SetTimer hDlg 1 3000 0
,case WM_TIMER
,clo hDlg
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


Forum Jump:


Users browsing this thread: 1 Guest(s)