qrcode

package module
v0.0.0-...-366b953 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2021 License: GPL-3.0 Imports: 16 Imported by: 1

README

QR Code Decoder by Golang

This Project is Developing.

Plan

  1. 动态二值化
  2. 提升图片扫描的速度:OK
  3. 修复标线取值: OK
  4. 容错码纠正数据:OK
  5. 数据编码方式 Numbert alphanumeric    8-bit byte: OK    Kanji
  6. 识别各角度倾斜的二维码

Example

fi, err := os.Open("qrcode.png")
if err != nil{
    logger.Println(err.Error())
    return
}
defer fi.Close()
qrmatrix, err := qrcode.Decode(fi)
if err != nil{
    logger.Println(err.Error())
    return
}
logger.Println(qrmatrix.Content)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	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 = []QRcodeVersion{}/* 160 elements not displayed */

)

Functions

func Bit2Byte

func Bit2Byte(bits []bool) byte

func Bit2Int

func Bit2Int(bits []bool) int

func Bits2Bytes

func Bits2Bytes(dataCode []bool, version int) ([]byte, error)

func Bool2Byte

func Bool2Byte(dataCode []bool) []byte

func Byte2Bool

func Byte2Bool(bl []byte) []bool

func Copy

func Copy(src interface{}) interface{}

Copy creates a deep copy of whatever is passed to it and returns the copy in an interface{}. The returned value will need to be asserted to the correct type.

func ExportGroups

func ExportGroups(size image.Rectangle, hollow []*PosGroup, filename string) error

func GetData

func GetData(unmaskMatrix, dataArea *Matrix) []bool

func GetDataEncoder

func GetDataEncoder(version int) (*dataEncoder, error)

func Hollow

func Hollow(group *PosGroup) bool

func IsPositionDetectionPattern

func IsPositionDetectionPattern(solidGroup, hollowGroup *PosGroup) bool

func IsVertical

func IsVertical(kf, kl *K) (offset float64)

func Line

func Line(start, end *Pos, matrix *Matrix) (line []bool)

func LineWidth

func LineWidth(positionDetectionPatterns [][]*PosGroup) float64

func MaskFunc

func MaskFunc(code int) func(x, y int) bool

func ParseBlock

func ParseBlock(m *Matrix, data []bool) ([]bool, error)

func QRReconstruct

func QRReconstruct(data, ecc []byte) ([]byte, error)

func Radian

func Radian(k *K)

func Rectangle

func Rectangle(group []Pos) (minX, maxX, minY, maxY int)

func SplitGroup

func SplitGroup(poss *[][]bool, centerX, centerY int, around *[]Pos)

func StringBool

func StringBool(dataCode []bool) string

func StringByte

func StringByte(b []byte) string

Types

type Block

type Block struct {
	NumBlocks int

	// Total codewords (NumCodewords == numErrorCodewords+NumDataCodewords).
	NumCodewords int

	// Number of data codewords.
	NumDataCodewords int
}

type FormatInfo

type FormatInfo struct {
	ErrorCorrectionLevel, Mask int
}

type K

type K struct {
	FirstPosGroup *PosGroup
	LastPosGroup  *PosGroup
	K             float64
}

type Matrix

type Matrix struct {
	OrgImage  image.Image
	OrgSize   image.Rectangle
	OrgPoints [][]bool
	Points    [][]bool
	Size      image.Rectangle
	Data      []bool
	Content   string
}

func Decode

func Decode(fi io.Reader) (*Matrix, error)

Decode 二维码识别函数

func DecodeImg

func DecodeImg(img image.Image, batchPath string) (*Matrix, error)

func (*Matrix) AtOrgPoints

func (mx *Matrix) AtOrgPoints(x, y int) bool

func (*Matrix) AtPoints

func (mx *Matrix) AtPoints(x, y int) bool

func (*Matrix) Binarization

func (mx *Matrix) Binarization() uint8

func (*Matrix) CenterList

func (mx *Matrix) CenterList(line []bool, offset int) (li []int)

标线

func (*Matrix) DataArea

func (mx *Matrix) DataArea() *Matrix

func (*Matrix) FormatInfo

func (mx *Matrix) FormatInfo() (*FormatInfo, error)

func (*Matrix) GetBin

func (mx *Matrix) GetBin(poss []Pos) int

func (*Matrix) ReadImage

func (mx *Matrix) ReadImage(batchPath string)

func (*Matrix) SplitGroups

func (mx *Matrix) SplitGroups() [][]Pos

func (*Matrix) Version

func (mx *Matrix) Version() int

type Pos

type Pos struct {
	X int
	Y int
}

func CenterPoint

func CenterPoint(group []Pos) Pos

type PosGroup

type PosGroup struct {
	Group    []Pos
	GroupMap map[Pos]bool
	Min      Pos
	Max      Pos
	Center   Pos
	Hollow   bool
}

func PossListToGroup

func PossListToGroup(groups []*PosGroup) *PosGroup

func PossToGroup

func PossToGroup(group []Pos) *PosGroup

type PositionDetectionPatterns

type PositionDetectionPatterns struct {
	TopLeft *PosGroup
	Right   *PosGroup
	Bottom  *PosGroup
}

func NewPositionDetectionPattern

func NewPositionDetectionPattern(PDPs [][]*PosGroup) (*PositionDetectionPatterns, error)

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
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL