VerifyText

Verifies the characters in a text string within an image region. Compares the characters in the text string to character models in a user-trained font and against potentially confusing characters.

Note:
  • The TrainFont, ReadText and VerifyText functions are only available on In-Sight vision systems using In-Sight firmware 4.x.x, and are not available on In-Sight vision systems running In-Sight firmware 5.1.0 and later. For a complete list of models and supported firmware versions, see Firmware Versions.
  • Cognex recommends that the OCRMax function be used instead of the ReadText, TrainFont and VerifyText functions, which are legacy functions. The OCRMax function has enhanced performance capabilities.
Tip:
  • If speed is not needed for your application, enable Scale Tolerance, since minor variations in size can degrade results significantly.
  • If your string is found in the wrong location or not found at all, retry with Confusing Background enabled.
  • If the wrong character is being verified, switch the Reading Mode from Speed to Accuracy. Accuracy is better at distinguishing between characters and gives a more accurate score.If the character is still being mis-verified, open your trained font and investigate the two confusing characters; they may have been trained poorly. For more information, see OCV/OCR Font Training Dialog.

VerifyTextInputs

Syntax: VerifyText(Image,Fixture.Row,Fixture.Column,Fixture.Theta,Region.X,Region.Y,Region.High,Region.Wide,Region.Angle,Region.Curve,Font,String,AcceptThresh,Difference Accept,Tune,Reading Mode,Confusing Background,Scale Tolerance,Timeout,Show)

Parameter Description

Image

This argument must reference a spreadsheet cell that contains a valid Image data structure. By default, the cell referenced is A0, the cell containing the Image data structure returned by AcquireImage. For more information, see AcquireImage.

Fixture

Specifies the image coordinate system in which the input region is defined.

Row

The row offset.

Column

The column offset.

Theta

The orientation.

Region

Specifies the rectangular image region that can be translated and rotated.

X

The x-offset of the origin, in fixture coordinates.

Y

The y-offset of the origin, in fixture coordinates.

High

The dimension along the region's x-axis.

Wide

The dimension along the region's y-axis.

Angle

The orientation, in fixture coordinates.

Curve

The angular deviation between the region's x-axis and the opposing boundary line.

Font

Cell reference to a Font data structure containing a trained font.

String

Characters to verify, up to a maximum of 100 characters.

Note: Note: VerifyText will verify a blank space in a text string if it occupies the same amount of space in the image as a character.

Accept Thresh

Specifies the minimum acceptable match score (0 to 100; default = 90) for each character. VerifyText will fail any character with a match score below the Accept Thresh and fail the string.

Difference Accept

The minimum difference required between the match scores of the highest scoring character and the second highest scoring character (0 to 20; default = 0).

  • To find the second-highest scoring character, use: GetChar(Text,Index, 1)
  • To find the score for the second-highest scoring character, use: GetScore(Text,Index, 1)

Tune

Adjusts the scale of the character models in the referenced Font data structure from 50% to 200% to correspond to the image characters and maximize the match score. Select Tune only when the difference between the size of the character models and the characters to be read exceeds ±5%.

0 = OFF (default)

Does not adjust the scale.

1 = ON

Adjusts the scale of the character models to maximize the match score.

Tip: Tuning is a one-time operation that uses significant processing time. After running the job once with Tune enabled, open the spreadsheet and disable Tuneto save processing time during subsequent job runs.

Reading Mode

Specifies whether an advanced algorithm is used to improve reading accuracy.

Note: Because of background variations, occasionally selecting Speed will produce higher scores than when Accuracy is selected.Base selection on application.
Tip: The Accept Thresh parameter may need to be lowered when Accuracy is selected, due to strict scoring.

0 = Speed (default)

Do not use the advanced algorithm. Using this algorithm may increase the decode speed, but may be less accurate.

1 = Accuracy

Decode using the advanced algorithm. This algorithm is more accurate, but decode speed may decrease.

Confusing Background

Specifies if other features within the image are being confused with the text string. This is especially useful if other features within the image are being mistaken for the beginning of the string.

0 = OFF (default)

No other features within the image are being confused with the text string.

1 = ON

Other features within the image are being confused with the text string.

Scale Tolerance

Specifies a tolerance of ± 10% to compensate for small variations in character size.

0 = OFF (default)

Do not allow for small variations in character scale.

1 = ON

Allow for small variations in character scale.

Timeout

Specifies the amount of time, in milliseconds(0 to 30000), that the function will search for a valid text string before execution is halted and an #ERR is returned. Setting the value to 0 disables the setting and a timeout is not applied.

Show

Specifies the display mode for VerifyText graphics overlays on the image.

0 = hide all (default)

All graphics will be hidden, except when the cell containing the VerifyText function is highlighted in the spreadsheet.

1 = result graphics only

The character segments with their corresponding labels will be displayed at all times.

2 = input and result graphics

The image region and the character segments with their corresponding labels will be displayed at all times.

VerifyText Outputs

Returns

A Text data structure containing the verified character string, or #ERR if any of the input parameters are invalid.

Results

When VerifyText is initially inserted into a cell, a result table is created in the spreadsheet.

VerifyText Vision Data Access Functions

The following Vision Data Access functions are automatically inserted into the spreadsheet to create the result table. For more information, see Text (OCV/OCR).

String

GetString(Text)

Returns the text string in the referenced Text data structure.

StringPass

GetPassed(Text)

Returns the pass/fail status of the entire string in the referenced Text data structure.

Char

GetChar(Text, Index0, [Index1])

Returns the indexed character from the referenced Text data structure. When an optional Index1 parameter is 1, returns the character in the referenced Text data structure most similar to the character specified in the Index0 parameter if the difference in match scores between the two characters is less than 10%.

Score

GetScore(Text, Index0, [Index1])

Returns the match score (0 to 100) of the indexed character in the referenced Text data structure. When an optional Index1 parameter is 1, returns the match score of the character in the referenced Font data structure most similar to the character specified in the Index0 parameter if the difference in match scores between the two characters is less than 10%.

Passed

GetPassed(Text, Index)

Returns the pass/fail status of the indexed character in the referenced Text data structure. If no Index parameter is specified, returns the pass/fail status of the entire string.

Additional data elements can be accessed using the following Text Vision Data Access functions:

Angle

GetAngle(Text)

Returns the angle between the text string in the Text data structure and the horizontal axis of the Image data structure.

Col

GetCol(Text, Index)

Returns the column coordinate (in pixels)of the indexed character in the referenced Text data structure.

Contrast

GetContrast(Text, Index)

Returns the contrast between the foreground and background (in grey levels, 0 to 255) of the indexed character in the referenced Text data structure.

High

GetHigh(Text, Index)

Returns the height (in pixels) of the indexed character in the referenced Text data structure.

Row

GetRow(Text, Index)

Returns the row coordinate (in pixels) of the indexed character in the referenced Text data structure.

Wide

GetWide(Text, Index)

Returns the width (in pixels) of the indexed character in the referenced Text data structure.