Rectification layer

The rectification layer is a dynamic module you can plug/unplug between the detector’s output and the recognizer’s input to rectify a credit card in order to suppress the distortion. A credit card is distorted if it’s slanted or skewed.

When a user tries to scan a credit card using his/her phone then, both the card and the camera are moving. The credit card is an undeformable object. In such situation, every position the card can take could be estimated using a 3x3 matrice. This is the homography matrice.

The goal for the rectification layer is to estimate the homography matrice using linear regression, compute it’s inverse, multiply it with every pixel from the detector’s output and provide the warped pixels to the recognizer’s input.

As you may expect, this process is time consuming and is disabled by default when the SDK is running on ARM devices. You should not worry about its absence as the default code can already handle moderately distorted credit cards.

See the configuration section on how to enable/disable the rectification layer.

The next image shows how the rectification layer transforms an image to remove the skew and slant.

Image transformation using rectification layer

Left: before rectification. Right: After rectification

Polarity

There are two polarities: dark_on_bright and bright_on_dark.

dark_on_bright:

The text on the credit card is darker than the background. Example: Black numbers on white background (e.g. American Express cards).

bright_on_dark:

The text on the credit card is brighter than the background. Example: White numbers on blue background (e.g. UnEmbossed new Visa cards).

Unlike other implementations we don’t use the four corners from the credit card to estimate the homography matrice because such implemention wouldn’t be robust to high distortions or heavy noise. Instead, we use every edge on the credit card to estimate the skew and shear/slant angles. Theses angles are combined with the x/y scales (size normalization) to build a 3x3 rectification matrice (our homography matrice).

The edges directions are very important and this is why we need to know what the polarity. The code contains a polarifier which can estimate the polarity but it’s not immune to errors. To help the polarifier you can define a preferred polarity and even better you can restrict it if your country uses single polarity. See the configuration section for more info.

See the configuration section on how to give a “hint” to the polarifier or define a fixed value.