Image Font Extractor 1.0

To configure an OCVMax tool you need to specify a font file that defines the layout of each character you want the tool to verify. You can specify any font file for use with an OCVMax tool, which supports all Western-language TrueType ASCII character fonts.

Cognex supplies a library of common fonts suitable for a variety of printing inspections. By default, the installation utility places these fonts in the directory C:\Program Files\Cognex\VisionPro\Fonts. The OCVMax Application Guide, available by choosing Start->Programs->Cognex->VisionPro->OCVMax Application Guide, displays a proof sheet showing all the characters in each font for comparison against your printed strings.

If your character strings use a font not supplied by Cognex, you must acquire the font file separately. In order to locate the correct font file for your vision application, Cognex makes the following suggestions:

  • Contact your print equipment vendor.

    The vendor should be able to provide you with the name of the font the printing equipment uses, and perhaps even the font file itself.

  • If you know the name of the font, search the \WINDOWS\Fonts directory on your PC.

    If your print equipment uses a TrueType font, you can preview all TrueType fonts by using the font dialog box of Microsoft Word.

  • Try the web site http://www.myfonts.com/WhatTheFont, which is online source for finding, trying and buying fonts. The web site boasts 41,680 fonts with search tools that allow you to find and buy the right font to match your printed strings.

  • Use the Image Font Extractor to make your own font file.

    This online document describes how to use the Image Font Extractor.

See the following topics for more information:

  • Image-Based Fonts

  • Extracting Font Characters from an Image

  • Modifying the Font

  • Modifying Individual Characters

  • Creating Font Files for an OCV Tool


Copyright

The software described in this document is furnished under license, and may be used or copied only in accordance with the terms of such license and with the inclusion of the copyright notice shown on this page. Neither the software, this document, nor any copies thereof may be provided to or otherwise made available to anyone other than the licensee. Title to and ownership of this software remains with Cognex Corporation or its licensor.

  • Cognex Corporation

  • FreeType License


Cognex Corporation

Cognex Corporation assumes no responsibility for the use or reliability of its software on equipment that is not supplied by Cognex Corporation. Cognex Corporation makes no warranties, either express or implied, regarding the described software, its merchantability or its fitness for any particular purpose.

The information in this document is subject to change without notice and should not be construed as a commitment by Cognex Corporation. Cognex Corporation is not responsible for any errors that may be present in either this document or the associated software.

Copyright © 2007 Cognex Corporation All Rights Reserved

This document may not be copied in whole or in part, nor transferred to any other media or language, without the written permission of Cognex Corporation.

The hardware and portions of the software described in this document may be covered by one or more of the U.S. patents listed on the Cognex web site http://www.cognex.com/patents.asp. Other U.S. and foreign patents are pending.

The following are registered trademarks of Cognex Corporation:

acuCoder | acuFinder | acuReader | acuWin | BGAII
CheckPoint | Cognex | Cognex, Vision for Industry | CVC-1000 | CVL
DisplayInspect | ID Expert | ID Max | PasteInspect | PatFind
PatInspect | PatMax | PatQuick | PixelProbe | SMD 4
Virtual Checksum | VisionLinx | VisionPro | VisionX |

Other Cognex products, tools, or other trade names may be considered common law trademarks of Cognex Corporation. These trademarks may be marked with a "TM". Other product and company names mentioned herein may be the trademarks of their respective owners.

This product includes code licensed from RSA Security, Inc.

Some portions licensed from IBM are available at http://oss.software.ibm.com/icu4j/.


FreeType License

ProofRead uses the FreeType library. FreeType 2 is a software font engine that is designed to be small, efficient, highly customizable and portable while capable of producing high-quality output (glyph images). It can be used in graphics libraries, display servers, font conversion tools, text image generation tools, and many other products as well.

See http://www.freetype.org/ for more information.


Navigating and Printing the User's Guide

You can view any topic in this help system by clicking on it in the Contents tab. You can also use the following navigation buttons:

  • Takes you to the next help topic, or to the next subtopic of the current topic.

  • Takes you to the previous help topic, or to the topic that contains the current topic.

  • Takes you to the last topic you viewed, so if you follow a hyperlink, you can return to the last topic you viewed.

  • Prints the current topic.

You can also print the current topic and all its subtopics by clicking [image] and selecting Print the heading and all subtopics.

You can print this entire document by selecting the topic Image Font Extractor, and selecting Print the heading and all subtopics in the print dialog box.


Image-Based Fonts

If you cannot locate a font file that defines the layout of the characters in your images, you can use the Image Font Extractor supplied with VisionPro and create your own font file from one or more images that contain examples of the characters that you want an OCVMax tool to verify.

Ultimately, any font file you generate using the Image Font Extractor will contain a collection of character keys, individual characters represented by a set of definitions as shown in the following figure:

In general, any single character that you want to use to generate a character key should exhibit the following traits:

  • A dimension between 10 x 10 and 64 x 64 pixels

  • A stroke width between 3 and 8 pixels

  • A portion of white space around the character equal to the stroke width

  • A model origin that defines its placement along a straight line. The Image Font Extractor automatically locates the model origin in the correct position for most character keys.

As you create an image-based font, you can choose to create a fixed-width font or a proportional font. A fixed-width font keeps the model height and model width the same for each character key. If you allow the model height and model width to vary for different characters, the font you generate will be proportional.

See the following topics for more information on image-based fonts:

  • Space Characters

  • Character key Names

  • Proof Sheets

  • Launching the Image Font Extractor


Space Characters

Many OCVMax tool applications also need to verify one or more blank spaces. The Image Font Extractor allows you to define a space character that does not include any character pixels, but rather is defined by its width, height, name, rotation and origin, as shown in the following figure:

As you configure an OCVMax tool, you specify a <SP> character as you would any other character. The <SP> character is verified like any other character key, as shown in the following figure:

[Note] Note

The character key name for the space character is <SP>, and it cannot be changed.


Character Key Names

The Image Font Extractor assigns a unique name to each character key that it creates. Be aware that the Image Font Extractor enforces a specific naming convention for each character in order for the OCVMax tool to recognize it as valid. Specifically, each character key will have one of the following names:

  • A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  • a b c d e f g h i j k l m n o p q r s t u v w x y z
  • 0 1 2 3 4 5 6 7 8 9
  • <SP> ! " # $ % & ' ) ( * + , - . /


Proof Sheets

To build a font file with the Image Font Extractor, you need images of the characters you want the OCVMax tool to verify. The Image Font Extractor can handle the following qualities for any image you want to use:

  • Continuous or dot-matrix printing

  • Fixed-width or proportional fonts

  • Light on dark or dark on light printing

  • Blank characters

  • Multiple lines of text

    The lines should be parallel to each other and directly beneath each other.

  • Punctuation marks

Cognex recommends you use a proof sheet, a single image of all the characters that might appear in the strings you want to verify. The following image shows an example proof sheet:

A proof sheet should exhibit the following qualities for all characters:

  • The same size and scale as the actual images you will acquire as the application operates

    The characters in the strings you want to verify must not show a change of scale outside the range 0.8 to 1.2 as compared to the characters in the proof sheet.

  • The same rotation, preferrably none

    The Image Font Extractor can compensate for rotated characters as well as characters that exibit shear.

  • Illuminated using the same lighting technique you will use to light the images of character strings you want to verify

    Differences in lighting between the proof sheet and actual character strings typically yield less accurate results

If you cannot obtain or generate a proof sheet, you can use multiple acquired images to generate a font file. The images as a whole, however, should display the same qualities as a single proof sheet. For example, you cannot successfully build and use an image-based font if you do not capture an image of each character you want the OCVMax tool to verify, or if the images you use to generate the font vary greatly in the amount of lighting they contain.

The following images of character strings are examples of images that are not suitable for the Image Font Extractor:


Launching the Image Font Extractor

To launch the Image Font Extractor, choose Start->Cognex->VisionPro->Utilities->Image Font Extractor.

The following figure highlights various components of the Image Font Extractor:


Extracting Font Characters from an Image

In general, extracting character keys for an image-based font is a simple process:

  1. Select an image containing a string or strings with examples of the characters you want to verify with the OCVMax tool:

    See the topic Proof Sheets for information on the types of images Cognex recommends you use.

  2. Use a graphic representing an extraction rectangle to enclose the characters in the image you want to use.

  3. Enter the character string representing those characters surrounded by the extraction rectangle.

  4. Click Extract and verify that the Image Font Extractor creates the character keys you need.

To illustrate, the following figure shows the Image Font Extractor just before the user clicks Extract to generate character keys from the character string enclosed within the extraction rectangle:

The Image Font Extractor supports two modes for creating character keys:

  • Automatic mode

    By default, the Image Font Extractor works in Automatic mode, where character keys can be extracted with very little configuration from the user. Cognex recommends you attempt to generate your image-based font in Automatic mode first.

    In Automatic mode, surrounding the characters with the extraction rectangle is the only step you need to perform before the Image Font Extractor can extract the character keys, as shown in the following figure:

    The topic Using Automatic Mode describes how to use Automatic mode, which also supports a set of advanced parameters for special circumstances, as described in the topic Using Advanced Parameters.

  • Manual mode

    Manual mode is the non-default mode, and often requires more interaction with the user before the Image Font Extractor can successfully extract the character keys from the image. If the Image Font Extractor reports problems creating character keys when you use Automatic mode, try using Manual mode.

    In Manual mode, the extraction rectangle includes vertical lines for separating individual characters from each other, as shown in the following figure:

    If you are creating a font file for a fixed-width font, the vertical lines are fixed with respect to each other, as shown in the previous figure. If, on the other hand, you are creating a proportional font, then the vertical lines can be adjusted individually, as shown in the following figure:

    The topic Using Manual Mode describes how to use Manual mode, which also supports a set of advanced parameters for special circumstances, as described in the topic Using Advanced Parameters.

See the following topics for more information on extracting character keys from an image:

  • Selecting an Image File

  • Placing the Extraction Rectangle

  • Using Automatic Mode

  • Using Manual Mode

  • Using Advanced Parameters


Selecting an Image File

The Image Font Extractor can load images stored as bitmap files, Cognex database (.CDB) files, and image-database (.IDB) files.

Use the Image area of the Image Font Extractor to select the file(s) containing the characters you want to use to generate the font file. The following figure highlights these controls:


Placing the Extraction Rectangle

Regardless of whether you use Automatic or Manual mode, you must place the extraction rectangle around the characters you want to use to create character keys. Keep in mind the following requirements when placing the extraction rectangle in the image:

  • The rectangle supports a set of handles to control its size, the amount of rotation it shows and the amount of shear it exhibits, as highlighted in the following figure:

    In most cases you can use the graphic handles to locate and position the extraction rectangle. Be aware, however, that the extraction rectangle does not have to be modified to precisely match the degree of rotation and shear the characters might currently exhibit. In fact, the extraction rectangle can tolerate approximately 15 degrees of rotation and shear, although you should try to adjust the rectangle so that it more closely matches any rotation and shear in the image. For example, the following image shows three lines of characters where the extraction rectangle has been adjusted to match the shear these characters exhibit:

    In addition, you can use the controls in the Image Font Extractor to provide precise values for the rectangle, as highlighted in the following figure:

    For example, you might choose to set the Rotation value precisely if you are aware that the characters appear at a specific angle in the image.

  • Do not include image information other than the characters themselves.

    For example, the following extraction rectangle inappropriately includes information from a barcode symbol:

  • The enclosing rectangle must include the exact same number of characters you want it to generate:

    For example, the following image contains an extraction rectangle surrounding the character string "0781-8842-01":

    For this character string, you must specify that you want the Image Font Extractor to create character keys for a matching string "0781-8842-01". If you enter a non-matching character string, such as "0781", or the Font Image Extractor will fail to generate the character keys.


Using Automatic Mode

Automatic mode is the default mode for the Image Font Extractor. Try using Automatic mode first to create the character keys for your image-based font.

Perform the following steps to use Automatic mode:

  1. Select the image file containing the characters you want to use to create the image-based font.

    See the topic Selecting an Image File for more information on selecting an image file.

  2. Use the extraction rectangle to surround the characters you want to use, sizing the rectangle appropriately and adjusting for rotation and shear.

    See the topic Placing the Extraction Rectangle for more information on using the extraction rectangle.

  3. Use the Extract tab to enter the characters enclosed within the extraction rectangle, as shown in the following figure:

  4. Click Extract.

If the Image Font Extractor is successful, it displays the new character keys in the character grid, as shown in the following figure:

You can continue to use more images to create other character keys, or save the font for use with an OCVMax tool.

If the character key extraction is not successful, the Image Font Extractor displays the following message:

Try any of the following to correct the problem:

  • Adjust the extraction rectangle to match the size, shape, rotation and shear of the characters in the image.

    See the topic Placing the Extraction Rectangle for more information on using the extraction rectangle.

  • Experiment with advanced parameters such as the threshold value the Image Font Extractor uses to determine which pixels represent characters and which represent the background.

    See the topic Using Advanced Parameters for information on advanced parameters.

  • Try using Manual mode, as described in the topic Using Manual Mode.


Using Manual Mode

Manual mode is the non-default mode for the Image Font Extractor. Try using manual mode if you cannot generate the character keys you need with Automatic mode.

[Note] Note

Be aware that you can only extract a single line of characters when using Manual mode.

Perform the following steps to use Manual mode:

  1. Select the image file containing the characters you want to use to create the image-based font.

    See the topic Selecting an Image File for more information on selecting an image file.

  2. Use the extraction rectangle to surround the single line of characters you want to use, sizing the rectangle appropriately and adjusting for rotation and shear.

    See the topic Placing the Extraction Rectangle for more information on using the extraction rectangle.

    Use the vertical separators within the extraction rectangle to separate the individual characters, as shown in the following figure:

  3. Use the Extract tab to enter the characters enclosed within the extraction rectangle, as shown in the following figure:

  4. Click Extract.

If the Image Font Extractor is successful, it displays the new character keys in the character grid, as shown in the following figure:

If the character key extraction is not successful, the Image Font Extractor displays the following message:

Try either of the following to correct the problem:

  • Adjust the extraction rectangle to match the size, shape, rotation and shear of the characters in the image.

    See the topic Placing the Extraction Rectangle for more information on using the extraction rectangle.

  • Experiment with advanced parameters such as the threshold value the Image Font Extractor uses to determine which pixels represent characters and which represent the background.

    See the topic Using Advanced Parameters for information on advanced parameters.


Using Advanced Parameters

The Extract tab supports a set of advanced parameters that can help you generate the character keys you need if you are not having complete success with Automatic or Manual mode. Using advanced parameters should not be necessary for most image-based fonts. Click Show advanced params to display the advanced parameters, as shown in the following figure:

The following table describes why you might alter the default value of any particular advanced parameter:

Advanced Feature

Use

Specify baseline

By default, the Image Font Extractor determines the proper baseline for all the characters along a single line, but you can enable this advanced parameter and specify how many pixels from the bottom of your enclosing rectangle you want the tool to consider the baseline to be.

You might need to specify a precise baseline value if several characters in your string normally appear well above the baseline, such as quotation marks or an apostrophe, and the Image Font Extractor is having difficulty determining the proper location for the baseline due to the appearance of these characters.

Fix baseline jitter

The jitter setting allows the Image Font Extractor to correctly determine the baseline for characters that use a descender, which is that portion of the character that normally falls below the baseline. For example, the letters "Q" and "g" are normally printed with portions of the character falling below the baseline.

The default value of 10% should work for most fonts, allowing the Image Font Extractor to automatically determine the correct baseline even when one or more characters in the image use a descender. If the characters in your image use large descenders, you may need to increase this value. If none of the characters in your image use a descender, you can set this value to 0.

Keep font single height

By default, the Image Font Extractor expects all the characters along a string to be the same height. You can disable this expectation if some characters in the string are not the same height as other characters.

Allow nonuniform background

If the background to the characters is uniform in appearance, you can disable this parameter.

Auto accept all

The Image Font Extractor will only generate a single character key for any particular character. For character strings with multiple instances of the same character, you can set how the Image Font Extractor will handle which character key to add to the font file:

  • Keep first: Add the first instance of the character in the string to the font, but only if the font does not already contain an instance of this character. If the font already contains that character, it remains unchanged and the new instance is ignored.

  • Keep first new: Add the first instance of the character in the string to the font. If the font already contains this character, it is replaced by the new instance.

  • Keep last: Add the last instance of the character in the string to the font, but only if the font does not already contain an instance of this character. If the font already contains that character, it remains unchanged and the new instance is ignored.

  • Keep last new (default): Add the last instance of the character in the string to the font. If the font already contains this character, it is replaced by the new instance.

Character color

You can precisely specify whether the characters are black or white.

Automatic

The Image Font Extractor supports a set of advanced parameters specific to Automatic mode:

  • Specify threshold: By default the Image Font Extractor considers the grey value 128 as the division between character pixels and background pixels. If the characters in your image do not show a large difference in grey value between character and background, you can enable this parameter and set a specific grey value.

  • Refine baseline angle: By default the extraction rectangle can compensate for small amounts of rotation in the character string, although you should rotate the extraction rectangle to approximately match the rotation the characters in the image display. If the angle that is automatically determined is visibly incorrect, you can disable this parameter.

  • Refine shear: By default the extraction rectangle can compensate for small amounts of shear in the character string, although you should manipulate the extraction rectangle to approximately match any shear the characters in the image display. If the value of shear that is automatically determined is visibly incorrect, you can disable this parameter.

  • Use full vertical extent: By default the Image Font Extractor determines a reasonable height for the characters by including a small amount of vertical padding above and below the character. If you enable this advanced parameter, then the height of each character key matches the height of the extraction rectangle exactly.

Manual

If you are using Manual mode, the Image Font Extractor is configured to extract character keys that are proportional to each other. You can check Fixed-width if the characters in the image are a fixed-width font.


Modifying the Font

Once you have successfully extracted a series of character keys from an image, the current character keys appear in the character grid of the Image Font Extractor, as shown in the following figure:

The character grid uses the following graphics:

  • The red line indicates the Cell min, a distance from the baseline measured in pixels.

  • The blue line represent the baseline as calculated by the Image Font Extractor or specified precisely by you with the advanced parameters.

    For the best performance of an OCVMax tool, all characters should rest on the baseline, except for characters with descenders that fall below the baseline and characters that do not touch the baseline such as an apostrophe.

  • Green markers indicate the character key origin.

    For the best performance of an OCVMax tool, the origin should appear at the lower leading portion of each character, except for characters that do not touch the baseline such as an apostrophe.

  • The green line indicates the Cell max, a distance from the baseline measured in pixels.

  • The currently selected character key appears in a blue box.

    Non-selected character keys appear in a cyan box.

See the following topics for modifying the current font file:

  • Modifying Font Properties

  • Deleting character keys

  • Saving and Loading Font Files


Modifying Font Properties

Select the Font tab to modify parameters relevant to all the character keys in your font. The following image highlights the Font tab:

Use the Font tab in any number of ways:

  • Name the font or alter other characteristics of the font file with the top of the Font tab:

    Be aware that although you can modify properties of the font such as the Cell min and Cell max by entering values into the Font tab, it is easier to use the graphics that appear in the character grid and then click Trim.

  • Alter how the character keys appear in the character grid:

  • Toggle which graphics appear in the character grid:


Deleting character keys

Click Delete chars or Delect all chars to delete one or more character keys from the current font file. If you click Delete chars, the Font tab provides instructions on deleting individual character keys as shown in the following example:


Saving and Loading Font Files

You must save your new image-base font file before you can load it into an OCVMax tool. Click Save on the Font tab to save your font file with the following dialog box:

For best performance of the OCVMax tool, save the font file in the .ocm format.

[Note] Note

The Image Font Extractor supports the older .ocf format for existing font files or if you are creating a font file for use with the OCV tool.

You can also use the Font tab to load an existing font file, which you might need to do in order to add more character keys or alter the properties of the entire font or specific character keys. See the topic Modifying Font Properties for information on modifying the characteristics of a font file, or the topic Modifying Individual Characters for details on modifying a particular character key.


Modifying Individual Characters

The Character tab of the Image Font Extractor allows you to view information specific to each character in your image-based font as well as modify particular settings for any character. The following figure shows an example Character tab:

Selecting any character key in the character grid displays its characteristics in the Character tab, which you can use in any number of ways:

  • View the width, height and color of the character, as shown in this example:

    In addition, you can click Edit image to change the actual grey values for any pixel of the character, as described later in this topic.

  • View the Unicode identifier for the character and give it a description in addition to its Name with the following portion of the tab:

  • Change the position of the model origin or character advance with the following portion of the tab:

If you click Edit image in the Character tab, the Image Font Extractor opens the character within an editor that allows you to modify any portion of the character key, as shown in the following example:

Use the Pen mode controls and your mouse to change the grey values of any pixels in the character, which appears inside the character grid. Use the Pen size controls for determining the size of the pen to use.


Creating Font Files for an OCV Tool

You can use the Image Font Extractor to create a font file for both an OCVMax tool as well as an OCV tool. Like the OCVMax tool, an OCV tool can be used to verify that one or more characters in an image match the expected characters at each position. Being aware of the differences between the tools can help you in choosing the right tool for your vision application:

  • Search reliability

    The OCVMax tool uses Cognex PatMax technology to search for each character string, allowing greater reliability in locating each string as its position varies in successive images.

  • Distortion

    The OCVMax tool can handle far more image-to-image character distortion than the OCV tool.

  • Image-based training

    You can generate a font file for an OCV tool by using the tool directly, without the need to launch the Image Font Extractor. Because of this image-based training ability, an OCV tool can support non-Western fonts.

Finally, if you are using the Image Font Extractor to create a font file for use with an OCV tool, you must save the font file in the .ocf format. An OCV tool does not support the .ocm format.