cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to get text from picture using Object Character Recognition

Contributor

Not able to get text from picture using Object Character Recognition

Hi , I am trying to get the text from a field . But I am not sure what type of window object that application has.

 

I checked for all the properties and methods in the object browser of that application and I am not able to find out the text in object browser and not sure how that text is rendered in the desktop application. 

 

So I tried to OCR functionality from testcomplete and it grabbed the picture with text but when I provide OCRObj.GetText(OCROptions) I am not able to fetch the text. Please find the javascript code I used below,

 

Rect = testObj.Picture();
Log.Picture(Rect, "Region with the text to be recognized");

OCRObj = OCR.CreateObject(Rect);
var OCROptions = OCRObj.CreateOptions();
OCROptions.ActiveRecognitionSet = 0;

Log.Message("Found characters:" + OCRObj.GetText(OCROptions));

 

// in logs the text is not printed only  (. `) character is printed. Attached the picture of the text. 

4 REPLIES 4
Contributor

Re: Not able to get text from picture using Object Character Recognition

My first guess is that you need to set the OCROptions.ActiveRecognitionSet value to 1 (since you are only interested in digits).  My second guess is that you need to redefine the testObj.  Hint:  I use the image checkpoint as a cheat to figure out the x/y - height/width coordinates needed to create the picture object (Rect = testObj.Picture(x, y, height, width)) and the namemapping aliases object I need to use.   I use the OCRObj.GetText(OCROptions)) or OCRObj.GetText()) to 'see' what text OCR 'sees'.  If the text I am looking for isn't displayed - it ususally means either there is a special font I need to include in the OCROptions or my picture from Rect = testObj.Picture() is defined wrong.  Hint - it is almost always the Rect = testObj.Picture() is defined wrong.

Contributor

Re: Not able to get text from picture using Object Character Recognition

I forgot to mention you should also disable font smoothing.   instructions:

https://support.smartbear.com/testcomplete/docs/testing-with/advanced/ocr/tips.html

Contributor

Re: Not able to get text from picture using Object Character Recognition

Hi , Thanks for the reply ,

 

I tried the above options, I set OCROptions.ActiveRecognitionSet = 1; and also captured aliases testObj.picture with coordinates and also removed the smooth edges of the screen fonts as mentioned in the link. 

 

Now when I try to run my script it always prints 00. and not the exact number on the picture. I tried with pictures of mutiple combinations of numbers but still it always prints 00.

Contributor

Re: Not able to get text from picture using Object Character Recognition

Before the log was showing .' and now it is showing 00?  This indicates that either the testObj.Picture is defined incorrectly or you need to load additional font options in the OCROPtions.  I assume you tested with OCROptions.ActiveRecognitionSet = 0 and also saw 00 in the log?  You might also consider that OCR cannot read your field.  Are you using OCR for any other fields - if yes - does it work on the other fields?

New Here?
Join us and watch the welcome video:
Join the September Hub-bub to show off, learn and win