OCR Not detecting numbers

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
psiquetp
Junior Coder
Posts: 25
Joined: Tue Jul 17, 2018 7:56 pm

OCR Not detecting numbers

Post by psiquetp » Tue Jul 24, 2018 2:07 pm

Hi, I'm trying to detect the row where a given number is found

In this image...
https://imgur.com/2gIj3ik

But OCR is only reading the value of 10 as in this output:
The value 30 was not found in the table. ...
| 806,248,863,273 > 10 | 806,281,863,306 > | 806,314,863,339 >
| 806,347,863,372 > 10
| 806,380,863,405 > 10
| 806,413,863,438 > | 806,446,863,471 > | 806,479,863,504 > | 806,512,863,537 >
| 806,545,863,570 > 10
| 806,578,863,603 > | 806,611,863,636 > | 806,644,863,669 > | 806,677,863,702 > | 806,710,863,735 >
This is the code

Code: Select all

//Subroutine to find a text in a given table ------------------------------------------
//Const: BASE_DIRECTORY       .- Directory where the macro has its files.
//Const: IMAGES_SUB_DIRECTORY .- Directory inside the BASE_DIRECTORY where the macro has the images to be searched for.
//Input: IMAGE_NAME           .- Name of the Image with a pic of the header at the top of the column.
//Input: COL_WIDTH            .- Width of the column in pixels.
//Input: ROW_HEIGHT           .- Height of the row in pixels.
//Input: ROW_SKIP_PIXELS      .- Number of Pixels to skip before finding the next row
//Input: FILE_LINE_INDEX      .- See ReadFileVariable
//Outpt: FILE_VAR_TEXT        .- See ReadFileVariable
//Outpt: X_CORD,X2_CORD       .- Horizontal coordinates of the found item
//Outpt: Y_CORD,Y2_CORD       .- Vertical coordinates of the found item
SRT>FindInTable
  //Retrieve text to be found
  Let>FILE_VAR_TEXT=30

  ArrayCount>YArr,NUM_IMGS_FOUND
  Let>ARR_IDX=0
  Let>X_CORD=0
  Let>Y_CORD=0
  Let>VAR_LOG_FIND_IN_TABLE=...

  //Find header
 FindImagePos>%BASE_DIRECTORY%\%IMAGES_SUB_DIRECTORY%\%IMAGE_NAME%,SCREEN,0.7,3,XArr,YArr,NumFound,CCOEFF
  IF>NumFound>0
    While>ARR_IDX<15
      Let>X_CORD=%XArr_0%
      Let>Y_CORD={%ARR_IDX%*%ROW_HEIGHT%}
      Add>Y_CORD,{%ARR_IDX%*%ROW_SKIP_PIXELS%}
      Add>Y_CORD,%YArr_0%
      Let>X2_CORD=%X_CORD%
      Add>X2_CORD,%COL_WIDTH%
      Let>Y2_CORD=%Y_CORD%
      Add>Y2_CORD,%ROW_HEIGHT%
      OCRArea>%X_CORD%,%Y_CORD%,%X2_CORD%,%Y2_CORD%,STR_OCR_RESULT
      Let>VAR_LOG_FIND_IN_TABLE=%VAR_LOG_FIND_IN_TABLE% | %X_CORD%,%Y_CORD%,%X2_CORD%,%Y2_CORD% > %STR_OCR_RESULT%
      Trim>%STR_OCR_RESULT%,STR_OCR_RESULT
      //Message>|%STR_OCR_RESULT%| != |%FILE_VAR_TEXT%|
      IF>STR_OCR_RESULT=FILE_VAR_TEXT
        Goto>ContinueFindInTableNoError
      EndIf
      Let>ARR_IDX={%ARR_IDX%+1}
    EndWhile
  Endif
  Let>ERROR_MESSAGE=The value %FILE_VAR_TEXT% was not found in the table. %VAR_LOG_FIND_IN_TABLE%
  GoSub>ReportError
  Label>ContinueFindInTableNoError
  Let>ROW_SKIP_PIXELS=0
END>FindInTable

//Find the POS
//Outpt: X_CORD,X2_CORD       .- Horizontal coordinates of the found item
//Outpt: Y_CORD,Y2_CORD       .- Vertical coordinates of the found item
Let>IMAGE_NAME=pap_08_oc_pos_right_click.PNG
Let>COL_WIDTH=57
Let>ROW_HEIGHT=25
Let>FILE_LINE_INDEX=9
Let>ROW_SKIP_PIXELS=8
GoSub>FindInTable
Is there something I can change on the OCR to work with numbers? This same code seems to be doing it fine with another table of letters...

Thank you!

psiquetp
Junior Coder
Posts: 25
Joined: Tue Jul 17, 2018 7:56 pm

Re: OCR Not detecting numbers

Post by psiquetp » Fri Jul 27, 2018 3:07 am

Anybody can help?

I tried a different approach... I'm creating little pieces of screen images

Code: Select all

      ScreenCapture>X_CORD,Y_CORD,X2_CORD,Y2_CORD,%NEW_IMAGE_FILE_NAME%
      OCRImage>%NEW_IMAGE_FILE_NAME,STR_OCR_RESULT      
Even though the cut image looks perfect OCR is not finding any text

Check this out...
https://imgur.com/a/syrPbAF

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: OCR Not detecting numbers

Post by Marcus Tettmar » Fri Jul 27, 2018 1:52 pm

Have you tried increasing OCR_SCALEFACTOR. Not sure why it needs it, but this works for me, against your image showing on the imgr website:

Code: Select all

Let>OCR_SCALEFACTOR=10
OCRArea>612,280,665,315,strText
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

psiquetp
Junior Coder
Posts: 25
Joined: Tue Jul 17, 2018 7:56 pm

Re: OCR Not detecting numbers

Post by psiquetp » Sat Jul 28, 2018 6:13 am

It didn't worked but only on some number, nevetheless your other advice for gettext worked after some tweaking.

Thank you!

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