Table of Contents

Class GridSampler

Namespace
ZXing.Common
Assembly
zxing.dll

Implementations of this class can, given locations of finder patterns for a QR code in an image, sample the right points in the image to reconstruct the QR code, accounting for perspective distortion. It is abstracted since it is relatively expensive and should be allowed to take advantage of platform-specific optimized implementations, like Sun's Java Advanced Imaging library, but which may not be available in other environments such as J2ME, and vice versa.

       The implementation used can be controlled by calling {@link #setGridSampler(GridSampler)}
       with an instance of a class which implements this interface.
public abstract class GridSampler
Inheritance
GridSampler
Derived
Inherited Members

Constructors

GridSampler()

protected GridSampler()

Properties

Instance

public static GridSampler Instance { get; }

Property Value

GridSampler

the current implementation of GridSampler

Methods

checkAndNudgePoints(BitMatrix, float[])

Checks a set of points that have been transformed to sample points on an image against the image's dimensions to see if the point are even within the image.

       <p>This method will actually "nudge" the endpoints back onto the image if they are found to be
       barely (less than 1 pixel) off the image. This accounts for imperfect detection of finder
       patterns in an image where the QR Code runs all the way to the image border.</p>

       <p>For efficiency, the method will check points from either end of the line until one is found
       to be within the image. Because the set of points are assumed to be linear, this is valid.</p>
protected static bool checkAndNudgePoints(BitMatrix image, float[] points)

Parameters

image BitMatrix

image into which the points should map

points float[]

actual points in x1,y1,...,xn,yn form

Returns

bool

sampleGrid(BitMatrix, int, int, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)

Samples an image for a square matrix of bits of the given dimension. This is used to extract the black/white modules of a 2D barcode like a QR Code found in an image. Because this barcode may be rotated or perspective-distorted, the caller supplies four points in the source image that define known points in the barcode, so that the image may be sampled appropriately.

The last eight "from" parameters are four X/Y coordinate pairs of locations of points in the image that define some significant points in the image to be sample. For example, these may be the location of finder pattern in a QR Code.

The first eight "to" parameters are four X/Y coordinate pairs measured in the destination BitMatrix, from the top left, where the known points in the image given by the "from" parameters map to.

These 16 parameters define the transformation needed to sample the image.

public abstract BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, float p1ToX, float p1ToY, float p2ToX, float p2ToY, float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX, float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY)

Parameters

image BitMatrix

image to sample

dimensionX int

The dimension X.

dimensionY int

The dimension Y.

p1ToX float

The p1 preimage X.

p1ToY float

The p1 preimage Y.

p2ToX float

The p2 preimage X.

p2ToY float

The p2 preimage Y.

p3ToX float

The p3 preimage X.

p3ToY float

The p3 preimage Y.

p4ToX float

The p4 preimage X.

p4ToY float

The p4 preimage Y.

p1FromX float

The p1 image X.

p1FromY float

The p1 image Y.

p2FromX float

The p2 image X.

p2FromY float

The p2 image Y.

p3FromX float

The p3 image X.

p3FromY float

The p3 image Y.

p4FromX float

The p4 image X.

p4FromY float

The p4 image Y.

Returns

BitMatrix

BitMatrix representing a grid of points sampled from the image within a region defined by the "from" parameters

sampleGrid(BitMatrix, int, int, PerspectiveTransform)

public virtual BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, PerspectiveTransform transform)

Parameters

image BitMatrix
dimensionX int
dimensionY int
transform PerspectiveTransform

Returns

BitMatrix

setGridSampler(GridSampler)

Sets the implementation of GridSampler used by the library. One global instance is stored, which may sound problematic. But, the implementation provided ought to be appropriate for the entire platform, and all uses of this library in the whole lifetime of the JVM. For instance, an Android activity can swap in an implementation that takes advantage of native platform libraries.

public static void setGridSampler(GridSampler newGridSampler)

Parameters

newGridSampler GridSampler

The platform-specific object to install.