barcode

package module
v0.0.0-...-3659f07 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: BSD-2-Clause Imports: 6 Imported by: 0

README

This package provides a simple Go wrapper around zbar for reading
barcodes from image files.  For documentation, see
http://www.godoc.org/github.com/bieber/barcode/

Documentation

Overview

barcode provides a wrapper around zbar for reading barcodes from images. For the time being, it only supports reading from images and not any of zbar's more esoteric features like GUI display and reading directly from barcode scanners or video inputs. I probably won't implement any further features as I don't have any need for them, but feel free to submit a pull request if you need them and want to wrap them yourself.

Because this package uses cgo, it links its dependencies dynamically by default. To compile you'll need the zbar C library and headers installed, and you'll need the library installed to run binaries compiled with this package.

To read codes from an image, simply instantiate an Image (you can create one from any image.Image) and then pass it to an ImageScanner. For example:

import (
	"fmt"
	"gopkg.in/bieber/barcode.v0"
	"image/jpeg"
	"os"
)

func main() {
	fin, _ := os.Open("card.jpg")
	defer fin.Close()
	src, _ := jpeg.Decode(fin)

	img := barcode.NewImage(src)
	scanner := barcode.NewScanner().
		SetEnabledAll(true)

	symbols, _ := scanner.ScanImage(img)
	for _, s := range symbols {
		fmt.Println(s.Type.Name(), s.Data, s.Quality, s.Boundary)
	}
}

Index

Constants

This section is empty.

Variables

View Source
var BusyError = errors.New("zbar: All resources busy")
View Source
var ClosedError = errors.New("zbar: Output window is closed")
View Source
var InternalError = errors.New("zbar: Internal library error")
View Source
var InvalidError = errors.New("zbar: Invalid request")
View Source
var LockingError = errors.New("zbar: Locking error")
View Source
var NoMemoryError = errors.New("zbar: Out of memory")
View Source
var SystemError = errors.New("zbar: System error")
View Source
var UnsupportedError = errors.New("zbar: Unsupported request")
View Source
var WinAPIError = errors.New("zbar: Windows system error")
View Source
var XDisplayError = errors.New("zbar: X11 display error")
View Source
var XProtoError = errors.New("zbar: X11 protocol error")

Functions

func IncreaseVerbosity

func IncreaseVerbosity()

Increases the library debug level.

func SetVerbosity

func SetVerbosity(verbosity int)

SetVerbosity sets the library debug level. Higher values spew more debug information.

func Version

func Version() (major, minor, patch uint)

Version returns the major and minor version numbers of the underlying zbar library.

Types

type Image

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

Image wraps zbar's internal image type, and represents a 2-dimensional image suitable for scanning.

func NewImage

func NewImage(src image.Image) *Image

NewImage creates a new zbar image by copying image data from an image.Image.

type ImageScanner

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

ImageScanner wraps zbar's internal image scanner type. You can set configuration options on an ImageScanner (make sure to enable some or all symbologies first) and then use it to scan an Image for barcodes.

func NewScanner

func NewScanner() *ImageScanner

NewScanner creates a new ImageScanner and returns a pointer to it.

func (*ImageScanner) ScanImage

func (s *ImageScanner) ScanImage(img *Image) ([]*Symbol, error)

ScanImage scans an Image and returns a slice of all Symbols found, or nil and an error if an error is encountered.

func (*ImageScanner) SetASCIIAll

func (s *ImageScanner) SetASCIIAll(enabled bool) *ImageScanner

SetASCIIAll enables or disables the full ASCII character set for all symbologies.

func (*ImageScanner) SetASCIISymbology

func (s *ImageScanner) SetASCIISymbology(
	symbology SymbolType,
	enabled bool,
) *ImageScanner

SetASCIISymbology enables or disables the full ASCII character set for a specific SymbolType.

func (*ImageScanner) SetAddCheckAll

func (s *ImageScanner) SetAddCheckAll(enabled bool) *ImageScanner

SetAddCheckAll enables or disables check digit when optional for all symbologies.

func (*ImageScanner) SetAddCheckSymbology

func (s *ImageScanner) SetAddCheckSymbology(
	symbology SymbolType,
	enabled bool,
) *ImageScanner

SetAddCheckSymbology enables or disables check digit when optional for a specific SymbolType.

func (*ImageScanner) SetEmitCheckAll

func (s *ImageScanner) SetEmitCheckAll(enabled bool) *ImageScanner

SetEmitCheckAll enables or disables return of the check digit when present for all symbologies.

func (*ImageScanner) SetEmitCheckSymbology

func (s *ImageScanner) SetEmitCheckSymbology(
	symbology SymbolType,
	enabled bool,
) *ImageScanner

SetEmitCheckSymbology enables or disables return of the check digit when present for a specific SymbolType.

func (*ImageScanner) SetEnabledAll

func (s *ImageScanner) SetEnabledAll(enabled bool) *ImageScanner

SetEnabledAll turns the ImageScanner on or off for all symbologies.

func (*ImageScanner) SetEnabledSymbology

func (s *ImageScanner) SetEnabledSymbology(
	symbology SymbolType,
	enabled bool,
) *ImageScanner

SetEnabledSymbology turns the ImageScanner on or off for a specific SymbolType.

func (*ImageScanner) SetMaxLengthAll

func (s *ImageScanner) SetMaxLengthAll(length int) *ImageScanner

SetMaxLengthAll sets a maximum data length for all symbologies.

func (*ImageScanner) SetMaxLengthSymbology

func (s *ImageScanner) SetMaxLengthSymbology(
	symbology SymbolType,
	length int,
) *ImageScanner

SetMaxLengthSymbology sets a maximum data length for a specific SymbolType.

func (*ImageScanner) SetMinLengthAll

func (s *ImageScanner) SetMinLengthAll(length int) *ImageScanner

SetMinLengthAll sets a minimum data length for all symbologies.

func (*ImageScanner) SetMinLengthSymbology

func (s *ImageScanner) SetMinLengthSymbology(
	symbology SymbolType,
	length int,
) *ImageScanner

SetMinLengthSymbology sets a minimum data length for a specific SymbolType.

func (*ImageScanner) SetPositionEnabledAll

func (s *ImageScanner) SetPositionEnabledAll(enabled bool) *ImageScanner

SetPositionEnabledAll enables or disables the collection of position data for all symbologies.

func (*ImageScanner) SetPositionEnabledSymbology

func (s *ImageScanner) SetPositionEnabledSymbology(
	symbology SymbolType,
	enabled bool,
) *ImageScanner

SetPositionEnabledSymbology enables or disables the collection of position data for a specific SymbolType.

func (*ImageScanner) SetXDensityAll

func (s *ImageScanner) SetXDensityAll(density int) *ImageScanner

SetXDensityAll sets the scanner's vertical scan density for all symbologies.

func (*ImageScanner) SetXDensitySymbology

func (s *ImageScanner) SetXDensitySymbology(
	symbology SymbolType,
	density int,
) *ImageScanner

SetXDensitySymbology sets the scanner's vertical scan density for a specific SymbolType.

func (*ImageScanner) SetYDensityAll

func (s *ImageScanner) SetYDensityAll(density int) *ImageScanner

SetYDensityAll sets the scanner's horizontal scan density for all symbologies.

func (*ImageScanner) SetYDensitySymbology

func (s *ImageScanner) SetYDensitySymbology(
	symbology SymbolType,
	density int,
) *ImageScanner

SetYDensitySymbology sets the scanner's horizontal scan density for a specific SymbolType.

type Symbol

type Symbol struct {
	Type SymbolType
	Data string

	// Quality is an unscaled, relative quantity which expresses the
	// confidence of the match.  These values are currently meaningful
	// only in relation to each other: a larger value is more
	// confident than a smaller one.
	Quality int

	// Boundary is a set of image.Point which define a polygon
	// containing the scanned symbol in the image.
	Boundary []image.Point
}

Symbol represents a scanned barcode.

type SymbolType

type SymbolType int

func (SymbolType) Name

func (s SymbolType) Name() string

Name returns the name of a given symbol encoding type, or "UNKNOWN" if the encoding is not recognized.

Jump to

Keyboard shortcuts

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