Package boofcv.alg.fiducial.qrcode
Class QrCodePolynomialMath
java.lang.Object
boofcv.alg.fiducial.qrcode.QrCodePolynomialMath
Contains all the formulas for encoding and decoding BCH and Reed-Solomon codes. For a more accessible
introduction to this material see [1] and [2].
[1] S. A. Tretter "Introduction to Bose Chaudhuri Hocquenghem codes" Goddard Space Flight Center, September 1967 [2] https://en.wikiversity.org/wiki/Reed–Solomon_codes_for_coders
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
bitPolyModulus
(int data, int generator, int totalBits, int dataBits) Performs division using xcr operators on the encoded polynomials.static boolean
checkFormatBits
(int bitsNoMask) Check the format bits.static boolean
checkVersionBits
(int bits) Encodes the version bits.static int
correctDCH
(int N, int messageNoMask, int generator, int totalBits, int dataBits) Applies a brute force algorithm to find the message which has the smallest hamming distance.static int
correctFormatBits
(int bitsNoMask) Attempts to correct format bit sequence.static int
correctVersionBits
(int bits) Attempts to correct version bit sequence.static void
decodeFormatMessage
(int message, QrCode qr) Assumes that the format message has no errors in it and decodes its data and saves it into the qr codestatic int
encodeFormatBits
(int message5bits) Encodes the 5-bit format bits for QR and Micro QR.static int
encodeFormatBits
(QrCode.ErrorLevel level, int mask) Encodes the format bits.static int
encodeVersionBits
(int version) Encodes the version bits.
-
Field Details
-
FORMAT_GENERATOR
public static final int FORMAT_GENERATOR- See Also:
-
VERSION_GENERATOR
public static final int VERSION_GENERATOR- See Also:
-
-
Constructor Details
-
QrCodePolynomialMath
public QrCodePolynomialMath()
-
-
Method Details
-
encodeVersionBits
public static int encodeVersionBits(int version) Encodes the version bits. BCH(18,6)- Parameters:
version
- QR code version. 7 to 40- Returns:
- encoded bit field
-
checkVersionBits
public static boolean checkVersionBits(int bits) Encodes the version bits. BCH(18,6)- Parameters:
bits
- Read in bits. Should encode 18-bits- Returns:
- encoded bit field
-
correctVersionBits
public static int correctVersionBits(int bits) Attempts to correct version bit sequence.- Parameters:
bits
- Read in bits after removing the mask- Returns:
- If the message could be corrected, th 5-bit format message. -1 if it couldn't
-
encodeFormatBits
Encodes the format bits. BCH(15,5)- Parameters:
level
- Error correction levelmask
- The type of mask that is applied to the qr code- Returns:
- encoded bit field
-
encodeFormatBits
public static int encodeFormatBits(int message5bits) Encodes the 5-bit format bits for QR and Micro QR. BCH(15,5)- Parameters:
message5bits
- 5-bit message- Returns:
- encoded bit field
-
checkFormatBits
public static boolean checkFormatBits(int bitsNoMask) Check the format bits. BCH(15,5) code. -
decodeFormatMessage
Assumes that the format message has no errors in it and decodes its data and saves it into the qr code- Parameters:
message
- format data bits after the mask has been remove and shifted over 10 bitsqr
- Where the results are written to
-
correctFormatBits
public static int correctFormatBits(int bitsNoMask) Attempts to correct format bit sequence.- Parameters:
bitsNoMask
- Read in bits after removing the mask- Returns:
- If the message could be corrected, th 5-bit format message. -1 if it couldn't
-
correctDCH
public static int correctDCH(int N, int messageNoMask, int generator, int totalBits, int dataBits) Applies a brute force algorithm to find the message which has the smallest hamming distance. if two messages have the same distance -1 is returned.- Parameters:
N
- Number of possible messages. 32 or 64messageNoMask
- The observed message with mask removedgenerator
- Generator polynomialtotalBits
- Total number of bits in the message.dataBits
- Total number of data bits in the message- Returns:
- The error corrected message or -1 if it can't be determined.
-
bitPolyModulus
public static int bitPolyModulus(int data, int generator, int totalBits, int dataBits) Performs division using xcr operators on the encoded polynomials. used in BCH encoding/decoding- Parameters:
data
- Data being checkedgenerator
- Generator polynomialtotalBits
- Total number of bits in datadataBits
- Number of data bits. Rest are error correction bits- Returns:
- Remainder after polynomial division
-