goqr

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: LGPL-3.0 Imports: 4 Imported by: 0

README

goqr

GoDoc Go Report Card Build Status Coverall License Example

This is a QR Code recognition and decoding library in pure go. It can recognize most of images into QR Code string.

Example

package main

import (
	"bytes"
	"fmt"
	"github.com/jdomzhang/goqr"
	"image"
	_ "image/jpeg"
	_ "image/png"
	"io/ioutil"
)

func recognizeFile(path string) {
	fmt.Printf("recognize file: %v\n", path)
	imgdata, err := ioutil.ReadFile(path)
	if err != nil {
		fmt.Printf("%v\n", err)
		return
	}

	img, _, err := image.Decode(bytes.NewReader(imgdata))
	if err != nil {
		fmt.Printf("image.Decode error: %v\n", err)
		return
	}
	qrCodes, err := goqr.Recognize(img)
	if err != nil {
		fmt.Printf("Recognize failed: %v\n", err)
		return
	}
	for _, qrCode := range qrCodes {
		fmt.Printf("qrCode text: %s\n", qrCode.Payload)
	}
}

func main() {
	recognizeFile("testdata/008.png")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoQRCode        = errors.New("no QR code in image")
	ErrInvalidGridSize = errors.New("invalid grid size")
	ErrInvalidVersion  = errors.New("invalid version")
	ErrFormatEcc       = errors.New("ecc format error")
	ErrDataEcc         = errors.New("ecc data error")
	ErrUnknownDataType = errors.New("unknown data type")
	ErrDataOverflow    = errors.New("data overflow")
	ErrDataUnderflow   = errors.New("data underflow")
)

Error definition

View Source
var (
	ErrOutOfRange = errors.New("out of range")
)

Error definition

Functions

This section is empty.

Types

type QRData

type QRData struct {
	// Various parameters of the QR-code. These can mostly be
	// ignored if you only care about the data.
	Version  int
	EccLevel int
	Mask     int

	// This field is the highest-valued data type found in the QR code.
	DataType int

	// Data Payload. For the Kanji datatype, Payload is encoded as
	// Shift-JIS. For all other datatypes, Payload is ASCII text.
	Payload []uint8

	// ECI assignment number
	Eci uint32
}

QRData holds the decoded QR-code data

func Recognize

func Recognize(img image.Image) ([]*QRData, error)

Recognize recognizes the passed image and returns a slice of QRData.

type Recognizer

type Recognizer interface {
	SetPixel(x, y int, val uint8)
	Begin()
	End()
	Count() int
	Decode(index int) (*QRData, error)
}

Recognizer is a Qr Code recognizer interface

func NewRecognizer

func NewRecognizer(w, h int) Recognizer

NewRecognizer news a recognizer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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