home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Archive Magazine 1995
/
ARCHIVE95.iso
/
discs
/
shareware
/
share_40
/
read
/
!Read
/
!Help
< prev
next >
Wrap
Text File
|
1990-09-06
|
12KB
|
230 lines
Read - A character reader for monospaced fonts
VERSION 0.0
INTRODUCTION
Read is an attempt at OCR for the Archimedes. It can load a scan from the
Watford scanner, or load a two-colour sprite file. It then attempts to turn
the image into text.
Read needs to be trained in the particular font used. It only works with
monospaced fonts, i.e. equal spacing between letters, and between lines.
Once a font has been learnt it can be stored for future use.
So far I have attempted to train it in two fonts, Epson MX80 double
emphasised printout and program listings from the Acorn User's "Yellow
Pages".
The first has been fairly successful with < 1% errors, and the second less
so with 5% or more errors.
Read is started from the RISC-OS desktop in the usual way by double clicking
on its sprite. It installs a sprite on the iconbar with the word 'font'
under it, indicating that it needs a font.
Read needs to have seen the !System directory, and to find version 3.5 or
later of the shared C library in !System.Modules.
Read is controlled by two menus, one on the iconbar and one on the main
window.
Menu options are denoted as follows in this file:-
<window->save->sprite> means the sprite option from the save option of
the window menu.
LOADING A SCAN
To load a sprite file drag it to the iconbar icon, or to the main window
if it is open. The sprite file must contain exactly one sprite, and this
must be in a two-colour mode.
If the load is successful the main window appears and displays the
sprite, and a red or green grid. Closing this window deletes the sprite and
frees the memory it uses.
If the sprite has a pallette it is ignored. Read needs the sprite to have
colour 0 as background and colour 1 as writing. In the standard desktop
pallette this will appear as black writing on a white background. Read will
swap the colours if it thinks it is the wrong way round. If it appears
wrongly, invert the sprite using <window->process->invert> (see below).
If you have a Watford hand scanner you can scan directly into read.
Select the desired size of scan and resolution using <iconbar->size> from
the iconbar menu. You can change the units of the scan size by clicking on
the icon displaying the units. The measurements will be rounded to an exact
number of pixels, with the horizontal size a multiple of 32 pixels. The
amount of memory required is updated when you change units or click on
<Check>. The font memory will not be known unless you have loaded a font. If
the free memory goes negative you had better try a smaller scan.
To start the scan click on <iconbar->scan>. If this is shaded you have not
got a Watford scanner, it is not running, or the dpi switch does not agree
with the setting in <iconbar->size> .
The iconbar text should change to "scan". Read now waits for you to finish
scanning. The sprite should now appear as above.
Sprites are displayed at a size that shows each pixel, They are converted
to mode 0 if you are in a 256 line mode or mode 18 if you are in a 512 line
mode.
You can save the scan from the <save->sprite> option of the window menu.
The <process> option of the window menu allows you to invert the sprite
(swap black and white), turn the sprite upside-down (it may be easier to
scan some things upside-down) or shear the sprite.Scans should normally be
done at 400 dpi unless the characters are very large.
<window->process->shear> slides the right hand side up or down while
keeping the left hand side fixed. It may be used to correct slightly slanted
scans. You can shear the whole sprite or all below a given line, If you
select <window->process->Part> the part of the sprite scanned is taken to be
that on and below the top of the grid at this time.
The shear required is entered in the writeable menu icon,positive for
up,negative for down. Selecting this icon performs the shear.A shear factor
of 100 or so may be needed to see any result.
The shear is reversible,except for losses at the top and bottom of the
region, as long as the shear is performed on the whole sprite, or parts are
taken lower down each time. In these cases the shear factor is not
cumulative, so you should enter the total effect you want,rather than the
change required.
LOADING A FONT
Fonts come in two varieties, count fonts which can still be taught new or
improved character shapes, and pixel fonts that are 'frozen', but smaller.
You can load either font by dragging the font file to the window or
iconbar. The iconbar text will change to "box" and the grid to green.
You can save a font from <window->save->counts> or <window->save->pixels>.
STARTING A NEW FONT
To start a new font you must set the sizes of the characters. This is done
by setting the grid over a block of text. The grid spacing can only be
changed when in "new font" mode. This is indicated by a red grid, and the
word "font" on the iconbar. If you have already loaded or started a font you
can get back here by selecting <window->New Font>. Any font in memory will
be lost.
In "new font" mode the top left corner of the grid can be set by clicking
select on the window, and the bottom right by clicking alter. Fine
adjustment can be made using the arrow keys for the top right, and <shift>
arrow keys for the bottom left. The number of characters in your grid must
be set using the <grid> option on the window menu.
It is likely that it will not be possible to ensure that all the
characters fall exactly in the grid rectangles. This does not matter, at
this stage we are only setting the character sizes. Ensure that the number
of rows and columns are correct, line up the top of the top row of boxes
with the top of the first row of characters, and the top of the bottom row
of boxes with the top of the bottom row of characters. Chose characters of
similar height or estimate the height of a fixed character. If there is much
of a slant to the text use the characters at one end, shear till level, or
better scan again. Do the same with the edges.
When you have set your grid correctly select <window->New Box>. The grid
will turn green and the iconbar text turn to "box".
SETTING THE BOX
The box can be set in "New box" mode. The grid is then green and the
iconbar says box. To get to "New box" mode you must load a font or start a
new font. If you have previously set a box you can get back to "New box"
mode by selecting the <window->New Box>. Any text read into memory will be
lost.
The box indicates the part of the sprite to read and the number of
characters and lines to look for. The number of rows and columns can be set
from <window->grid>. The grid is rigid and can be moved by the arrow keys.
<Select> positions the top right corner.
The grid should be set so that the top is as low as possible without
touching the first row of characters, and without the base of the first row
touching the second row of characters. Do not worry about lower rows! Adjust
the grid sideways so that the first row of characters are centered in their
boxes as far as possible.
READING
Reading can be started by selecting one of three options:-
<window->Learn> - Stop at each character.
<window->Read> - Stop when unsure.
<window->Non Stop> - Stop when required number of rows have been read.
The selected menu item will be ticked. You can stop the read by selecting
the ticked option again, or change to another read mode by selecting it.
Obviously if you have just started a new font you should use <Learn>.
The line number reached is displayed on the iconbar. The line and
character are outlined in the scan. When the scan is completed "halt"
appears on the iconbar and the machine beeps. You can now save the text read
from <window->save->text>. In "Non Stop" mode you can save in mid-read.
LEARNING
When learning the machine stops at every non-space character. Blue lines
in the window indicate the current character and line. The text found so far
is displayed including the machines best guess at the character found. You
can enter the correct character below if needed. The buttons then act as
follows.
<Learn> - learn the guess or character entered.
<Set> - set the character in the text but do not learn.
<Read> - change to read mode.
<Fast> - change to non-stop mode.
<Check> - check the scan against another character (see below).
<Halt> - stop. You can restart where you left off by selecting
<window->learn>,<window->Read> or <window->NonStop>. To start from the
beginning select <window->New Box> then one of these.
When the machine stops you can enter more than one character. It will
learn or set these according to the mode, up to the end of the current line.
In read mode the machine stops for instructions only when unsure.
LEARNING FROM FILE
If you have a text file of the text of a scan you can teach the font by
setting the box and then dragging the file onto the window.
This is useful for teaching a printer font. The basic utility TestFile
produces a suitable file. Print this and scan the result, then teach the
font from the file. If you then read the scan you can judge the result using
the compare utility provided.
The third basic utility provided can be used to display a count font on
the screen, this is useful to check you have not made any mistakes teaching
the font.
ADJUSTMENT
Six parameters control the operation of read. These can be
adjusted from <window-adjust>.
"Space threshold" determines the number of black pixels in a character
before read does not assume it is a space. Too large a value will cause full
stops and other small characters to be read as spaces. Too large will slow
read down and produce spurious small characters.
"Query threshold" determines when the machine stops in read mode. Larger
values make it stop more often.
The other 4 determine the weighting given to various factors when read
choses a character, adjusting these can lead to fewer errors. Leave one
unchanged, as scaling them all by the same factor will have no effect.
One way to set them is to use the compare utility and a scan with a
prepared correct text file.
COMMAND LINE ARGUMENTS
Read accepts a number of command line arguments, separated by spaces, of
the form -letternumber, with no spaces between the - letter and number.
letter default
d 4 - scanner dpi 1,2 or 4 for 100,200,400dpi
x 704 - scan width in pixels, this must be a multiple of 32
between 32 and 1664/d
y 3200 - scan height in pixels
w 40 - grid width in characters
h 98 - grid height in lines
f 1638 - filetype of ReadFont files
E.g. If you change the last line in !Run to
Run <Read$Dir>.!RunImage -h60 -f2989 you will get a grid height of 60
lines and the ReadFont filetype will be 2989=BAD hex. You will need to
change the 666 in !Boot to BAD and rename the sprite file_666 to file_BAD in
!Sprites.
DIFFICULTIES
Read does not cope well if lines are slanted or unevenly spaced.
It is quite difficult to scan a magazine page sufficiently accurately. I
resorted to cutting out the pages. Small consistent slants can be coped with
using <window->process->shear>, but unfortunately slants often vary down a
column. This either requires rescanning or using several boxes and combining
the results.
My first attempts at reading a printer font caused problems until I fount
that the spacing of the first line was smaller than the rest. This was
corrected by pulling the printer paper taught before starting to print.
TO DO
1) Improve the line finding routine to cope with slanted lines.
2) Implement 90 degree rotations to allow sideways scanning.
3) Reduce error rate?
4) Read proportionally spaced fonts??
COMMENTS PLEASE
I would welcome bug reports, criticism (constructive or otherwise),
modifications or suggestions for modifications.
Chris Stretch
Archive and Arcade BBS No.62
CBTP13@JANET%UK.AC.ULSTER.UCVAX