Skip to content
schulzch edited this page Oct 20, 2014 · 7 revisions

API Reference

This is the API reference of FormVision. It lists all functions that can be called, documents the parameters and provides small code snippets to facilitate learning. Its a good idea to scan text at 300dpi or higher and require DocumentVision along with FormVision:

dv=require('dv');fv=require('fv');

Note: Since the API is far from final, this page is a work in progress.

filters

Functions in fv.filters provide image filters for pre-processing. A filter will not modify its source image. In case those filters do not meet your requirements you should take a look at DocumentVision's Image.

filters#binarize(image)

This filter converts the specified image to black and white using a computed threshold.

filters#darkenInk(image)

This filter select gray-ish pixel blobs of an approximated font size and darkens them. Saturated and large pixels are left unmodified.

filters#deskew(image)

This filter tries to estimate and remove the skew of an image by analyzing the horizontal and vertical projection.

filters#filterBackground(image, fontWidth, fontHeight)

This filter removes gray-ish background while protecting pixel blobs with approximate font size.

filters#removeRed(image)

This filter removes red-ish color (pre-print) from the image while protecting gray-ish pixels.

FormReader

A fv.FormReader object composes text, barcode and checkbox reading.

FormReader#constructor(language = 'eng', image = null)

Initializes a form reader with the specified Tesseract language and image as input.

FormReader#image

Accessor for the input image this barcode reader operates on.

FormReader#tesseract

Accessor for the used dv.Tesseract object. Useful if you want to set tesseract configuration variables.

FormReader#zxing

Accessor for the used dv.ZXing object. Useful if you want to restrict barcode reading.

FormReader#find()

Returns a Form object after raw recognition.

Form

A fv.Form represents raw form data after recognition.

Form#match(schema, cb)

Matches this raw form data to the specified schema, calling cb(err, result) when done. A schema has the following format:

schema={// Bounding Box of the expected page in schema coordinates."page": dv.Box,// Words at specified locations, that may be used for estimation of a projection."words": [{"text": String"box": dv.Box}],// Array of expected form fields."fields": [{// A fully qualified name of the field (e.g. "group1.field1")"path": String,// Type of data (text, barcode, checkbox)"type": String,// Expected relative location on the page."box": dv.Box,// Function used for field validation (e.g. "is this a date?")"fieldValidator": function(value){returnBoolean;},// Function used for field selection, if ambiguous (e.g. "pick 1.1.1900 instead of 111900")"fieldSelector": function(choices){return0;},// Function used for async. form validation (e.g. "auto-complete field A from field B and C or fail otherwise")"formValidator": function(formData,done){done(err);}}]}

Most matching is content- and position-sensitive. Conflict resolution during matching does not exploit inference to prevent cascading errors.

A result has the following format:

result={"group1": {"field1": {// The actual value."value": Any// Confidence between 0..100%."confidence": Number// Location on the page."box": dv.Box// Paths of other fields also claiming ownership on this value."conflicts": [Path]}}}

Form#toObject()

Returns raw form data as object:

{// ZXing Barcode."barcodes": [{"box": dv.Box,// see result of dv.ZXing#findCode()}],// Tesseract Word."text": [{"box": dv.Box,// see result of dv.Tesseract#findWords()}],// Checkbox."checkboxes": ["box": dv.Box,"checked": Boolean,"confidence": Number]}

Form#toImage()

Returns an annotated image for visual debugging.