When using the MIL String Reader module, the space is not considered a normal character. For example, you can never read a space with String Reader, nor can you set a space as a constraint to which a valid character must adhere, to be read (for more information on character constraints, see the Rules for character placement section later in this chapter).
The space is used to delimit multiple strings in the target image when performing a read operation (MstrRead()). That is, the space size establishes the maximum distance between two adjacent characters before each character is considered part of two separate strings. The space size is calculated using the space width (a font setting) and the maximum number of consecutive spaces (a string model setting). For more information, see the Space size subsection of the Creating and customizing the fonts for a font-based context section earlier in this chapter.
Note that, like the space, the carriage return also signifies a new string. If a character is on another line, it is automatically part of another string.
If the space was treated like a normal character, there would be tricky issues to contend with, such as distinguishing the space from noise. By defining a space as the marker that separates strings, there is less chance for an incorrect read operation. For example, consider an ANPR application that must read the following target image:
Since most license plates do not have any symbol between characters, and the ones that do cannot be ignored, multiple types of spaces might have to be considered for this string to be read correctly. You would not only have to account for the space that occurs between strings, but how this space might vary when noise exists (in this case, the flag). Essentially, it is simpler to decide whether or not the characters exist, rather than deciding whether or not a space exists.
When a space is encountered in the target image, it is marked by String Reader and can be artificially inserted to display formatted results. For more information, see the Formatted and non-formatted results subsection of the Retrieving results and annotation section later in this chapter.
To set the width of the space character in the font, use MstrControl() with M_SPACE_WIDTH. By default, the space width is set to M_MEAN_CHAR_WIDTH, which is equal to the average X-size (width) of the characters in the font. You can also set the space width to M_INFINITE, which is equal to an infinite amount of space. That is, all characters on the same line are always part of the same string. In this case, however, there will never be a space character in the formatted string since the distance can never be large enough to constitute a space character. Other settings for the space width include the maximum X-size or minimum X-size character in the font, and a quarter of the maximum character width in the font. You can also set the space width to a specific value, in pixels.
The space width that you set is relative to the font. Therefore, the space width is considered to be at the size of the font (that is, the point size of the characters in the font), and adjusted according to the scale and aspect ratio of the string.
To set the maximum number of consecutive spaces required for two adjacent characters to be part of two separate strings, use MstrControl() with M_SPACE_MAX_CONSECUTIVE. The default value is 3 consecutive spaces.
Note that M_SPACE_MAX_CONSECUTIVE is a string model setting, while M_SPACE_WIDTH is a font setting. Therefore, each string model can have a maximum number of consecutive spaces, while all string models must adhere to their font's space width.
The notion of consecutive spaces is important, since non-consecutive spaces do not cause a split in the string. Consider the following Quebec license plate.
In this example, the first 3 characters are separated by a single space each, which makes them part of the same string. However, following the letter 'N', there are several consecutive spaces; if you set a maximum of one consecutive space, the '9' would be part of a different string. Based on the maximum number of spaces, this license plate can either be read as two strings, or one string with a large space between 'N' and '9'.