Proof of Address OCR Node.js
The Node.js OCR SDK supports the Proof of Address API.
Using the sample below, we are going to illustrate how to extract the data that we want using the OCR SDK.
Quick-Start
const mindee = require("mindee");
// for TS or modules:
// import * as mindee from "mindee";
// Init a new client
const mindeeClient = new mindee.Client({ apiKey: "my-api-key" });
// Load a file from disk
const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext");
// Parse the file
const apiResponse = mindeeClient.parse(
mindee.product.ProofOfAddressV1,
inputSource
);
// Handle the response Promise
apiResponse.then((resp) => {
// print a string summary
console.log(resp.document.toString());
});
Output (RST):
########
Document
########
:Mindee ID: 5d2361e9-405e-4fc1-8531-f92a3aef0c38
:Filename: default_sample.jpg
Inference
#########
:Product: mindee/proof_of_address v1.1
:Rotation applied: Yes
Prediction
==========
:Locale: en; en; USD;
:Issuer Name: PPL ELECTRIC UTILITIES
:Issuer Company Registrations:
:Issuer Address: 2 NORTH 9TH STREET CPC-GENN1 ALLENTOWN.PA 18101-1175
:Recipient Name:
:Recipient Company Registrations:
:Recipient Address: 123 MAIN ST ANYTOWN,PA 18062
:Dates: 2011-07-27
2011-07-06
2011-08-03
2011-07-27
2011-06-01
2011-07-01
2010-07-01
2010-08-01
2011-07-01
2009-08-01
2010-07-01
2011-07-27
:Date of Issue: 2011-07-27
Page Predictions
================
Page 0
------
:Locale: en; en; USD;
:Issuer Name: PPL ELECTRIC UTILITIES
:Issuer Company Registrations:
:Issuer Address: 2 NORTH 9TH STREET CPC-GENN1 ALLENTOWN.PA 18101-1175
:Recipient Name:
:Recipient Company Registrations:
:Recipient Address: 123 MAIN ST ANYTOWN,PA 18062
:Dates: 2011-07-27
2011-07-06
2011-08-03
2011-07-27
2011-06-01
2011-07-01
2010-07-01
2010-08-01
2011-07-01
2009-08-01
2010-07-01
2011-07-27
:Date of Issue: 2011-07-27
Field Types
Standard Fields
These fields are generic and used in several products.
Basic Field
Each prediction object contains a set of fields that inherit from the generic Field
class.
A typical Field
object will have the following attributes:
- value (
number | string
): corresponds to the field value. Can beundefined
if no value was extracted. - confidence (
number
): the confidence score of the field prediction. - boundingBox (
[Point, Point, Point, Point]
): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. - polygon (
Point[]
): contains the relative vertices coordinates (Point
) of a polygon containing the field in the image. - pageId (
number
): the ID of the page, alwaysundefined
when at document-level. - reconstructed (
boolean
): indicates whether an object was reconstructed (not extracted as the API gave it).
Note: A
Point
simply refers to an array of two numbers ([number, number]
).
Aside from the previous attributes, all basic fields have access to a toString()
method that can be used to print their value as a string.
Company Registration Field
Aside from the basic Field
attributes, the company registration field CompanyRegistrationField
also implements the following:
- type (
string
): the type of company.
Date Field
Aside from the basic Field
attributes, the date field DateField
also implements the following:
- dateObject (
Date
): an accessible representation of the value as a JavaScript object.
Locale Field
The locale field LocaleField
only implements the value, confidence and pageId base Field
attributes, but it comes with its own:
- language (
string
): ISO 639-1 language code (e.g.:en
for English). Can beundefined
. - country (
string
): ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3 code for countries (e.g.:GRB
orGB
for "Great Britain"). Can beundefined
. - currency (
string
): ISO 4217 code for currencies (e.g.:USD
for "US Dollars"). Can beundefined
.
String Field
The text field StringField
only has one constraint: its value is a string
(or undefined
).
Attributes
The following fields are extracted for Proof of Address V1:
Date of Issue
date (DateField): The date the document was issued.
console.log(result.document.inference.prediction.date.value);
Dates
dates (DateField[]): List of dates found on the document.
for (const datesElem of result.document.inference.prediction.dates) {
console.log(datesElem.value);
}
Issuer Address
issuerAddress (StringField): The address of the document's issuer.
console.log(result.document.inference.prediction.issuerAddress.value);
Issuer Company Registrations
issuerCompanyRegistration (CompanyRegistrationField[]): List of company registrations found for the issuer.
for (const issuerCompanyRegistrationElem of result.document.inference.prediction.issuerCompanyRegistration) {
console.log(issuerCompanyRegistrationElem.value);
}
Issuer Name
issuerName (StringField): The name of the person or company issuing the document.
console.log(result.document.inference.prediction.issuerName.value);
Locale
locale (LocaleField): The locale detected on the document.
console.log(result.document.inference.prediction.locale.value);
Recipient Address
recipientAddress (StringField): The address of the recipient.
console.log(result.document.inference.prediction.recipientAddress.value);
Recipient Company Registrations
recipientCompanyRegistration (CompanyRegistrationField[]): List of company registrations found for the recipient.
for (const recipientCompanyRegistrationElem of result.document.inference.prediction.recipientCompanyRegistration) {
console.log(recipientCompanyRegistrationElem.value);
}
Recipient Name
recipientName (StringField): The name of the person or company receiving the document.
console.log(result.document.inference.prediction.recipientName.value);
Questions?
Updated 2 months ago