Forum Discussion

sbkeenan's avatar
sbkeenan
Frequent Contributor
13 years ago

Optical Character Recognition

Hi



Has anyone every had any success with the OCR functionality in TestComplete (I'm running V9.2 Enterprise Edition)?



I am trying to get it to work without switching off the font smoothing feature of Windows.  I know the tips recommend that this feature is switched off, but the text on my screen looks horrible if I do that!!



I thought that if I could tinker with other settings/values such as GrayScaleBinarization, BinarizationThreshold, ExactSearch and SearchAccuracy, I would be able to get consistent results.



What I have found is that when searching for some text that exist, it is found and when searching for some non-existant text, it isn't found.  However, other pieces of existing text are not found, while some non-existent text apparently is found, very strange indeed!!  I can modify the settings such that existing text that wasn't previously found is now found, but this leads to more non-existent text items apparently being found.



One of the tips suggests that the search area be reduced to exclude graphics, etc, but I'm not sure how to go about achieving this.  My image is that of an A4 page within a Developer Xpress View Control.  The object spy can only pick out the page, not any block intems within it, so how do I go about reducing the area to search?



I have included a code snippet below to show what I am currently doing.  Any suggestions would be gratefully received.



Regards

Stephen.





set OCRobject = OCR.createObject(Aliases.Automate_Testing.clsFormControlDX.WinFormsObject("ucXtraReportDisplay").WinFormsObject("prtCtrlReport").WinFormsObject("DocumentViewer"))

set OCRoptions = OCRobject.CreateOptions

set Font = OCROptions.Fonts.Add

Font.Name = "Tahoma" ' Specify the font name

Font.Styles.Add 1 ' Add the Bold style

Font.Styles.Add 2 ' Add the Italic style

Font.Sizes.Add 8 ' Add the 8 pt size

Font.Sizes.Add 9 ' Add the 9 pt size

Font.Sizes.Add 10 ' Add the 10 pt size

Font.Sizes.Add 11 ' Add the 11 pt size

Font.Sizes.Add 12 ' Add the 12 pt size



set Font = OCROptions.Fonts.Add

Font.Name = "Arial" ' Specify the font name

Font.Styles.Add 1 ' Add the Bold style

Font.Styles.Add 2 ' Add the Italic style

Font.Sizes.Add 8 ' Add the 8 pt size

Font.Sizes.Add 9 ' Add the 9 pt size

Font.Sizes.Add 10 ' Add the 10 pt size

Font.Sizes.Add 11 ' Add the 11 pt size

Font.Sizes.Add 12 ' Add the 12 pt size



set Font = OCROptions.Fonts.Add

Font.Name = "Consolas" ' Specify the font name

Font.Styles.Add 1 ' Add the Bold style

Font.Styles.Add 2 ' Add the Italic style

Font.Sizes.Add 8 ' Add the 8 pt size

Font.Sizes.Add 9 ' Add the 9 pt size

Font.Sizes.Add 10 ' Add the 10 pt size

Font.Sizes.Add 11 ' Add the 11 pt size

Font.Sizes.Add 12 ' Add the 12 pt size



OCRoptions.GrayScaleBinarization = True

OCROptions.BinarizationThreshold = 90

OCROptions.ExactSearch = False

OCROptions.SearchAccuracy = 0.8

OCROptions.ActiveRecognitionSet = 0



result = OCRobject.FindRectByText("<my text here>", OCRoptions)

if (result) then' Obtains the coordinates and the size of the found rectangle

  x = OCRobject.FoundLeft

  y = OCRobject.FoundTop

  dx = OCRobject.FoundWidth

  dy = OCRobject.FoundHeight



  set rectResult = Aliases.Automate_Testing.clsFormControlDX.WinFormsObject("ucXtraReportDisplay").WinFormsObject("prtCtrlReport").WinFormsObject("DocumentViewer").Picture(x, y, dx, dy)'Posts the found rectangle to the test log



  call log.picture(RectResult, "Successfully found specified text.")

else

  log.warning("Specified text not found in image.")

end if
No RepliesBe the first to reply