Documentation
¶
Overview ¶
Package qrcode implements a QR code decoder.
Index ¶
- Variables
- func Bit2Byte(bits []bool) byte
- func Bit2Int(bits []bool) int
- func Bits2Bytes(dataCode []bool, version int) ([]byte, error)
- func Bool2Byte(dataCode []bool) []byte
- func Byte2Bool(bl []byte) []bool
- func GetData(unmaskMatrix, dataArea *Matrix) []bool
- func GetDataEncoder(version int) (*dataEncoder, error)
- func Hollow(group *PosGroup) bool
- func IsPositionDetectionPattern(solidGroup, hollowGroup *PosGroup) bool
- func IsVertical(kf, kl *K) (offset float64)
- func MaskFunc(code int) func(x, y int) bool
- func ParseBlock(m *Matrix, data []bool) ([]bool, error)
- func QRReconstruct(data, ecc []byte) ([]byte, error)
- func Radian(k *K)
- func Rectangle(group []Pos) (minX, maxX, minY, maxY int)
- func SplitGroup(poss *[][]bool, centerX, centerY int, around *[]Pos)
- type AlphanumericDecoder
- type Block
- type EightBitDecoder
- type FormatInfo
- type K
- type KanjiDecoder
- type Matrix
- func (mx *Matrix) AtOrgPoints(x, y int) bool
- func (mx *Matrix) AtPoints(x, y int) bool
- func (mx *Matrix) Binarization(pic *image.Gray) uint8
- func (mx *Matrix) DataArea() *Matrix
- func (mx *Matrix) FormatInfo() (*FormatInfo, error)
- func (mx *Matrix) GetBin(poss []Pos) int
- func (mx *Matrix) ReadImage()
- func (mx *Matrix) SplitGroups() [][]Pos
- func (mx *Matrix) Version() int
- type ModeCharDecoder
- type NumericDecoder
- type Pos
- type PosGroup
- type PositionDetectionPatterns
- type QRcodeVersion
- type RecoveryLevel
Constants ¶
This section is empty.
Variables ¶
var ( // AlignmentPatternCenter lists the module coordinates of alignment pattern // centers for each QR version. AlignmentPatternCenter = [][]int{ {}, {}, {6, 18}, {6, 22}, {6, 26}, {6, 30}, {6, 34}, {6, 22, 38}, {6, 24, 42}, {6, 26, 46}, {6, 28, 50}, {6, 30, 54}, {6, 32, 58}, {6, 34, 62}, {6, 26, 46, 66}, {6, 26, 48, 70}, {6, 26, 50, 74}, {6, 30, 54, 78}, {6, 30, 56, 82}, {6, 30, 58, 86}, {6, 34, 62, 90}, {6, 28, 50, 72, 94}, {6, 26, 50, 74, 98}, {6, 30, 54, 78, 102}, {6, 28, 54, 80, 106}, {6, 32, 58, 84, 110}, {6, 30, 58, 86, 114}, {6, 34, 62, 90, 118}, {6, 26, 50, 74, 98, 122}, {6, 30, 54, 78, 102, 126}, {6, 26, 52, 78, 104, 130}, {6, 30, 56, 82, 108, 134}, {6, 34, 60, 86, 112, 138}, {6, 30, 58, 86, 114, 142}, {6, 34, 62, 90, 118, 146}, {6, 30, 54, 78, 102, 126, 150}, {6, 24, 50, 76, 102, 128, 154}, {6, 28, 54, 80, 106, 132, 158}, {6, 32, 58, 84, 110, 136, 162}, {6, 26, 54, 82, 110, 138, 166}, {6, 30, 58, 86, 114, 142, 170}, } // Versions lists every QR code version at every error correction level. Versions = []QRcodeVersion{}/* 160 elements not displayed */ )
var AlphanumericDecoderChar = []string{
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z", "SP", "$", "%", "*",
"+", "-", ".", "/", ":"}
AlphanumericDecoderChar is the QR alphanumeric character set, in value order.
Functions ¶
func Bits2Bytes ¶
Bits2Bytes decodes the data bits (mode + payload) into the final content.
func GetDataEncoder ¶
GetDataEncoder returns the data encoder for the given QR version.
func Hollow ¶
Hollow reports whether a PosGroup contains holes or internal gaps. It compares the total pixel count against the sum of per-row bounding spans: a row whose black pixels are not contiguous makes its span wider than its pixel count, leaving a non-zero remainder. Rows are tracked by their min/max x. For the common case of a compact group we use plain arrays indexed by row offset (no hashing, no allocation churn); very tall groups fall back to a map.
func IsPositionDetectionPattern ¶
IsPositionDetectionPattern reports whether a solid group lies inside a hollow group, forming a QR finder pattern.
func IsVertical ¶
IsVertical returns the angular offset between two edges and a right angle.
func ParseBlock ¶
ParseBlock splits the data bits into blocks, applies Reed-Solomon error correction, and reassembles the corrected data bits.
func QRReconstruct ¶
QRReconstruct corrects errors in data using the Reed-Solomon ecc codewords.
func SplitGroup ¶
SplitGroup performs an 8-neighbor flood fill starting at (centerX, centerY), removing visited points from poss and appending them to around.
Types ¶
type AlphanumericDecoder ¶
type AlphanumericDecoder struct {
// contains filtered or unexported fields
}
AlphanumericDecoder decodes QR alphanumeric mode data.
type EightBitDecoder ¶
type EightBitDecoder struct {
// contains filtered or unexported fields
}
EightBitDecoder decodes QR 8-bit byte mode data.
type FormatInfo ¶
type FormatInfo struct {
ErrorCorrectionLevel, Mask int
}
FormatInfo holds the error correction level and mask of a QR code.
type KanjiDecoder ¶
type KanjiDecoder struct {
// contains filtered or unexported fields
}
KanjiDecoder decodes QR Kanji mode data (Shift JIS encoded).
type Matrix ¶
type Matrix struct {
OrgImage image.Image
OrgSize image.Rectangle
OrgPoints [][]bool
Points [][]bool
Size image.Rectangle
Data []bool
Content string
// contains filtered or unexported fields
}
Matrix is the decoded QR code. It holds the original image, its binarized form, the sampled module grid, and the decoded content.
func DecodeImg ¶
DecodeImg decodes a QR code from an image, returning the sampled matrix with its content populated.
func (*Matrix) AtOrgPoints ¶
func (*Matrix) Binarization ¶
Binarization 使用大津法(Otsu)自动计算全局阈值,避免固定阈值对光照变化敏感。
func (*Matrix) FormatInfo ¶
func (mx *Matrix) FormatInfo() (*FormatInfo, error)
func (*Matrix) SplitGroups ¶
SplitGroups splits the matrix's binary grid into connected components.
type ModeCharDecoder ¶
type NumericDecoder ¶
type NumericDecoder struct {
// contains filtered or unexported fields
}
NumericDecoder decodes QR numeric mode data.
type Pos ¶
Pos is a 2D coordinate.
func CenterPoint ¶
CenterPoint returns the mean coordinate of a point group.
type PosGroup ¶
PosGroup is a connected group of pixels (a connected component) together with its geometric properties.
func PossListToGroup ¶
PossListToGroup merges multiple PosGroups into a single one.
func PossToGroup ¶
PossToGroup builds a PosGroup from a slice of points, computing its center, bounding box, and hollowness.
type PositionDetectionPatterns ¶
PositionDetectionPatterns holds the three finder patterns of a QR code: top-left, top-right, and bottom-left.
func NewPositionDetectionPattern ¶
func NewPositionDetectionPattern(PDPs [][]*PosGroup) (*PositionDetectionPatterns, error)
NewPositionDetectionPattern identifies the three finder patterns from the candidate solid/hollow pairs and determines their roles (top-left, top-right, bottom-left).
type QRcodeVersion ¶
type QRcodeVersion struct {
// Version number (1-40 inclusive).
Version int
// Error recovery Level.
Level RecoveryLevel
DataEncoderType dataEncoderType
// Encoded data can be split into multiple blocks. Each Block contains data
// and error recovery bytes.
//
// Larger QR Codes contain more blocks.
Block []Block
// Number of bits required to pad the combined data & error correction bit
// stream up to the symbol's full capacity.
NumRemainderBits int
}
QRcodeVersion describes the data length and encoding order of a single QR Code Version. There are 40 versions numbers x 4 recovery levels == 160 possible QRcodeVersion structures.
type RecoveryLevel ¶
type RecoveryLevel int
Error detection/recovery capacity.
There are several levels of error detection/recovery capacity. Higher levels of error recovery are able to correct more errors, with the trade-off of increased symbol size.
const ( // Level M: 15% error recovery. Good default choice. 0b00 Medium RecoveryLevel = iota // Level L: 7% error recovery. 0b01 Low // Level H: 30% error recovery.0b10 Highest // Level Q: 25% error recovery.0b11 High )