gozbar

package module
v0.0.0-...-964bbc0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

README

GoZBar

Fork of https://github.com/PeterCxy/gozbar due to API breaking changes.

ZBar bindings for golang. Only scanner supported.

Read the ZBar documentations for explanations on constants and arguments.

The ZBar library must be installed for this to compile.

Example JPEG Scan.

func TestPhoto(t *testing.T) {
	const expectedStr = "http://www.searchenginestrategies.com/sanfrancisco/share.html"

	f, err := os.Open("./testdata/photo.jpg")
	if err != nil {
		t.Fatal(err)
	}

	i, err := jpeg.Decode(f)
	if err != nil {
		t.Fatal(err)
	}

	img := FromImage(i)

	s := NewScanner()
	err = s.SetConfig(0, CFG_ENABLE, 1)
	if err != nil {
		t.Fatal("error setting config", err)
	}

	err = s.Scan(img)
	if err != nil {
		t.Fatal("error scanning", err)
	}

	defer s.Destroy()

	img.First().Each(func(str string) {
		if str != expectedStr {
			t.Fatalf("expected [%s] got [%s]", expectedStr, str)
		}
	})
}

Documentation

Overview

Package gozbar config bindings for golang. Read the ZBar documents for details

Package gozbar image bindings for golang. Read the ZBar documents for details

Package gozbar scanner bindings for golang. Read the ZBar documents for details

Package gozbar symbol bindings. Read the ZBar documents for details

Index

Constants

View Source
const (
	NONE    = C.ZBAR_NONE
	PARTIAL = C.ZBAR_PARTIAL
	EAN8    = C.ZBAR_EAN8
	UPCE    = C.ZBAR_UPCE
	ISBN10  = C.ZBAR_ISBN10
	UPCA    = C.ZBAR_UPCA
	EAN13   = C.ZBAR_EAN13
	ISBN13  = C.ZBAR_ISBN13
	I25     = C.ZBAR_I25
	CODE39  = C.ZBAR_CODE39
	PDF417  = C.ZBAR_PDF417
	QRCODE  = C.ZBAR_QRCODE
	CODE128 = C.ZBAR_CODE128
	SYMBOL  = C.ZBAR_SYMBOL
	ADDON   = C.ZBAR_ADDON
	ADDON2  = C.ZBAR_ADDON2
	ADDON5  = C.ZBAR_ADDON5
)

Symbol types (Scanner.SetConfig() argument symbology)

View Source
const (
	CFG_ENABLE     = C.ZBAR_CFG_ENABLE
	CFG_ADD_CHECK  = C.ZBAR_CFG_ADD_CHECK
	CFG_EMIT_CHECK = C.ZBAR_CFG_EMIT_CHECK
	CFG_ASCII      = C.ZBAR_CFG_ASCII
	CFG_NUM        = C.ZBAR_CFG_NUM
	CFG_MIN_LEN    = C.ZBAR_CFG_MIN_LEN
	CFG_MAX_LEN    = C.ZBAR_CFG_MAX_LEN
	CFG_POSITION   = C.ZBAR_CFG_POSITION
	CFG_X_DENSITY  = C.ZBAR_CFG_X_DENSITY
	CFG_Y_DENSITY  = C.ZBAR_CFG_Y_DENSITY
)

Configuration keys

Variables

This section is empty.

Functions

This section is empty.

Types

type Image

type Image struct {
	// contains filtered or unexported fields
}

Image contains a zbar image and the grayscale values.

func FromImage

func FromImage(img image.Image) *Image

FromImage will create an ZBar image object from an image.Image. To scan the image, call a Scanner.

func (*Image) Destroy

func (i *Image) Destroy()

Destroy this object

func (*Image) First

func (i *Image) First() *Symbol

First will return the first scanned symbol of this image. To iterate over the symbols, use Symbol.Each() function

func (*Image) GetGray

func (i *Image) GetGray() *image.NRGBA

Destroy this object

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner contains a reference to zbar scanner.

func NewScanner

func NewScanner() *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Destroy

func (s *Scanner) Destroy()

Destroy destroys the scanner.

func (*Scanner) Scan

func (s *Scanner) Scan(img *Image) error

Scan parses the given image and loads the scanner.

func (*Scanner) SetConfig

func (s *Scanner) SetConfig(symbology C.zbar_symbol_type_t, config C.zbar_config_t, value int) error

SetConfig gives the zbar scanner the configuration to run.. Read the ZBar docs for details.

type Symbol

type Symbol struct {
	// contains filtered or unexported fields
}

Symbol is a wrapper around a zbar symbol.

func (*Symbol) Data

func (s *Symbol) Data() string

Data returns the scanned data for this symbol.

func (*Symbol) Each

func (s *Symbol) Each(f func(string))

Each will iterate over all symbols after this symbol. passing them into the provided callback

func (*Symbol) Next

func (s *Symbol) Next() *Symbol

Next returns the next symbol or nil if there is none.

func (*Symbol) Type

func (s *Symbol) Type() C.zbar_symbol_type_t

Type returns the symbol type. Compare it with types in constants to get the accurate symbol type.

Jump to

Keyboard shortcuts

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