Help with OCR Area

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
Teusck
Newbie
Posts: 4
Joined: Tue Feb 09, 2021 5:53 pm

Help with OCR Area

Post by Teusck » Tue Feb 09, 2021 6:35 pm

Hello everyone, I am doing an automation for my work and I really need your help.

In the program that the company where I work uses, there is a variation in the order of the codes, sometimes they are above or below, so I use OCR for the code to identify and put it in the correct way. placed when the number of hours is less than 0.15, so I need the OCR to be a variable too, to identify the number, that is, if the OCR is not a variable, I will not be able to read that number, and so the command will not identify whether or not to place the code, since if I determine a fixed point, as in InRect, it will read wrong codes and thus I will not have any automation. Here is the example:
www.imgur.com/a/1CkFq0c

The question is:
how do I make the OCR area variable?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Help with OCR Area

Post by Dorian (MJT support) » Tue Feb 09, 2021 8:21 pm

I'm not entirely sure I understand the question, but I think you're asking how to change the coordinates you're using with OCRArea. Can you look at the rows one row at a time, check to see if the value you want is there, and if it isn't, look at the next row?

This could be done in a loop, but hopefully the code below simply demonstrates how to move the rectangle you're looking at. Based on the first row being 1000, and each row being 100 high. It simply looks at 1000-1100, 1100-1200, and so on.

Code: Select all

Let>RowHeight=100
Let>Top=1000
Let>Bottom=Top+RowHeight

OCRArea>100,%Top%,500,%Bottom%,strText
...now check if the value you're looking for is there. if it isn't, look at the next row down..

Let>Top=Top+100
Let>Bottom=Top+RowHeight
OCRArea>100,%Top%,500,%Bottom%,strText

Let>Top=Top+100
Let>Bottom=Top+RowHeight
OCRArea>100,%Top%,500,%Bottom%,strText

Let>Top=Top+100
Let>Bottom=Top+RowHeight
OCRArea>100,%Top%,500,%Bottom%,strText
Yes, we have a Custom Scripting Service. Message me or go here

Teusck
Newbie
Posts: 4
Joined: Tue Feb 09, 2021 5:53 pm

Re: Help with OCR Area

Post by Teusck » Wed Feb 10, 2021 5:51 pm

.
Last edited by Teusck on Wed Feb 10, 2021 8:44 pm, edited 1 time in total.

Teusck
Newbie
Posts: 4
Joined: Tue Feb 09, 2021 5:53 pm

Re: Help with OCR Area

Post by Teusck » Wed Feb 10, 2021 5:52 pm

Thanks for the reply
but that would not be a very long code? and therefore loaded?
I tried it that way, in the same way that the mouse behaves, with the captured image being the starting point for placing the code

Code: Select all

//Find and Move Mouse Middle Right of
FindImagePos>%BMP_DIR%\image_4.bmp,SCREEN,0,2,XArr,YArr,NumFound,EXACT
Let>XArr=x
Let>YArr=y
If>NumFound>0
OCRArea>%x%200,%y%+100,%x%250,%y%100,strText
MessageModal>strText
let>amount=strText
let>value=0,15
  If>amount<value
  Else>amount>value
     MouseMove>{%XArr_0%+20},{%YArr_0%+10}
  LClick
  wait>0.5
  LClick
  SendText>115
  Endif
Endif

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Help with OCR Area

Post by Dorian (MJT support) » Thu Feb 11, 2021 11:32 am

Your usage is a little screwy so I have fixed that. If OCR is the way you need to go it isn't too hard to scan line-by-line. Have you tried the Find Object Wizard on it to see if it can simply get the value without using OCR?

Anyhow, this scans row by row and it isn't slow. But you need a very accurate value for the cell height otherwise it'll creep off. Run this through slowly in the debugger to get it right. It does not have any kind of "end condition" so we have not told it when to stop.

My sample image started at the white first row of data. I tested it using 7 as the value and it clicked the left column of that row successfully every time. I added a mousemove as a visual reference so you can see where it's looking. Hopefully this will get you started.

Code: Select all

//Find and Move Mouse Top Left of 
FindImagePos>%BMP_DIR%\image_4.bmp,SCREEN,0.7,0,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
Endif

Let>left=XArr_0
Let>top=YArr_0

//Carefully edit these values. Cellheight needs to be exact
let>cellheight=41
let>cellwidth=235

//Edit cellstart
let>bottom=top+cellheight
let>cellstart=left+906
let>cellend=cellstart+cellwidth

If>NumFound>0
  label>scannextline
  OCRArea>%cellstart%,%top%,%cellend%,%bottom%,strText
  mousemove>%cellstart%,%top%

  let>amount=strText
  let>value=0,15

  If>amount<value
    Else
    MouseMove>{%XArr_0%+20},{%top%+10}
    LClick
    wait>0.5
    LClick
    SendText>115
  Endif

  Let>top=%top%+%cellheight%
  Let>bottom=%bottom%+%cellheight%
  goto>scannextline
Endif
Yes, we have a Custom Scripting Service. Message me or go here

Teusck
Newbie
Posts: 4
Joined: Tue Feb 09, 2021 5:53 pm

Re: Help with OCR Area

Post by Teusck » Tue Feb 16, 2021 5:59 pm

Thanks for the reply

I tested it on my macro and it’s perfect
it worked very well and I had no problems
the only thing I didn’t understand is that when you decrease CellStart below 500
before decreasing CellWidth it doesn’t count the number, but I managed to solve it by
decreasing the numbers and I had no problem
If I have any more questions I will come back here

Thanks for all

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts