zbar

package module
v0.0.0-...-a30bdd7 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2017 License: MIT Imports: 3 Imported by: 0

README

go-zbar

Go wrapper around ZBar - C bar code reader library.

Requirements

Original zbar library required. On Ubuntu it can be installed with $ sudo apt install zbar-dev

Installing go-zbar

go get -u github.com/sshikaree/go-zbar

Example

import (
	"fmt"
	"github.com/sshikaree/go-zbar"
)

func main() {
	p := zbar.NewProcessor(1)
	defer p.Destroy()

	p.SetConfig(0, zbar.ZBAR_CFG_ENABLE, 1)
	p.Init("/dev/video0", 1)
	p.SetVisible(1)
	p.SetActive(1)
	if ok := p.ProcessOne(-1); ok < 0 {
		fmt.Println("Error occured. Exiting..")
		return
	} else if ok == 0 {
		fmt.Println("No symbols were found")
	}

	results := p.GetResults()
	if results == nil {
		return
	}
	symbol := results.SetFirstSymbol()
	if symbol == nil {
		return
	}
	fmt.Println("Symbol type:", symbol.GetType())
	fmt.Println("Symbol name:", symbol.GetName())
	fmt.Println("Symbol data:", symbol.GetData())	
}

Example with DataHandler function

import (
	"fmt"
	"github.com/sshikaree/go-zbar"
)

func ImgHandler(img *zbar.Image) {
	s := img.FirstSymbol()
	fmt.Println("Symbol name:", s.GetName())
	fmt.Println("Symbol data:", s.GetData())
}

func main() {
	p := zbar.NewProcessor(1)
	defer p.Destroy()

	p.SetConfig(0, zbar.ZBAR_CFG_ENABLE, 1)
	p.Init("/dev/video0", 1)

	p.SetDataHandler(ImgHandler)

	p.SetVisible(1)
	p.SetActive(1)
	p.UserWait(-1)
}

Documentation

Index

Constants

View Source
const (
	ZBAR_SPACE = iota // light area or space between bars
	ZBAR_BAR          // dark area or colored bar segment
)

"color" of element: bar or space.

View Source
const (
	ZBAR_NONE        = 0   /**< no symbol decoded */
	ZBAR_PARTIAL     = 1   /**< intermediate status */
	ZBAR_EAN2        = 2   /**< GS1 2-digit add-on */
	ZBAR_EAN5        = 5   /**< GS1 5-digit add-on */
	ZBAR_EAN8        = 8   /**< EAN-8 */
	ZBAR_UPCE        = 9   /**< UPC-E */
	ZBAR_ISBN10      = 10  /**< ISBN-10 (from EAN-13). @since 0.4 */
	ZBAR_UPCA        = 12  /**< UPC-A */
	ZBAR_EAN13       = 13  /**< EAN-13 */
	ZBAR_ISBN13      = 14  /**< ISBN-13 (from EAN-13). @since 0.4 */
	ZBAR_COMPOSITE   = 15  /**< EAN/UPC composite */
	ZBAR_I25         = 25  /**< Interleaved 2 of 5. @since 0.4 */
	ZBAR_DATABAR     = 34  /**< GS1 DataBar (RSS). @since 0.11 */
	ZBAR_DATABAR_EXP = 35  /**< GS1 DataBar Expanded. @since 0.11 */
	ZBAR_CODABAR     = 38  /**< Codabar. @since 0.11 */
	ZBAR_CODE39      = 39  /**< Code 39. @since 0.4 */
	ZBAR_PDF417      = 57  /**< PDF417. @since 0.6 */
	ZBAR_QRCODE      = 64  /**< QR Code. @since 0.10 */
	ZBAR_CODE93      = 93  /**< Code 93. @since 0.11 */
	ZBAR_CODE128     = 128 /**< Code 128 */
)

zbar_symbol_type_t decoded symbol type.

View Source
const (
	ZBAR_ORIENT_UNKNOWN = -1 + iota /**< unable to determine orientation */
	ZBAR_ORIENT_UP                  /**< upright, read left to right */
	ZBAR_ORIENT_RIGHT               /**< sideways, read top to bottom */
	ZBAR_ORIENT_DOWN                /**< upside-down, read right to left */
	ZBAR_ORIENT_LEFT                /**< sideways, read bottom to top */
)

ZBar orientation

View Source
const (
	ZBAR_CFG_ENABLE     = iota // enable symbology/feature
	ZBAR_CFG_ADD_CHECK         // enable check digit when optional
	ZBAR_CFG_EMIT_CHECK        // return check digit when present
	ZBAR_CFG_ASCII             // enable full ASCII character set
	ZBAR_CFG_NUM               // number of boolean decoder configs
	ZBAR_CFG_MIN_LEN           // minimum data length for valid decode
	ZBAR_CFG_MAX_LEN           // maximum data length for valid decode
	ZBAR_CFG_POSITION          // enable scanner to collect position data
	ZBAR_CFG_X_DENSITY         // image scanner vertical scan density
	ZBAR_CFG_Y_DENSITY         // image scanner horizontal scan density
)

zbar_config_t decoder configuration options

View Source
const (
	ZBAR_OK              = iota // no error
	ZBAR_ERR_NOMEM              // out of memory
	ZBAR_ERR_INTERNAL           // internal library error
	ZBAR_ERR_UNSUPPORTED        // unsupported request
	ZBAR_ERR_INVALID            // invalid request
	ZBAR_ERR_SYSTEM             // system error
	ZBAR_ERR_LOCKING            // locking error
	ZBAR_ERR_BUSY               // all resources busy
	ZBAR_ERR_XDISPLAY           // X11 display error.
	ZBAR_ERR_XPROTO             // X11 protocol error.
	ZBAR_ERR_CLOSED             // output window is closed
	ZBAR_ERR_WINAPI             // windows system error
	ZBAR_ERR_NUM                // number of error codes
)

error codes

View Source
const (
	ZBAR_MOD_GS1 = iota // barcode tagged as GS1 (EAN.UCC) reserved (eg, FNC1 before first data character).data may be parsed as a sequence of GS1 AIs
	ZBAR_MOD_AIM        // barcode tagged as AIM reserved (eg, FNC1 after first character or digit pair)
	ZBAR_MOD_NUM        // number of modifiers
)

Decoder symbology modifier flags

Variables

This section is empty.

Functions

func ScanSingleSymbol

func ScanSingleSymbol(device string) (result, symbol_type string, err error)

Recognize single code from webcam

Types

type Image

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

func NewImage

func NewImage() *Image

NewImage creates new Image instance

func (*Image) Convert

func (i *Image) Convert(format uint64) *Image

Convert represents image format conversion.

func (*Image) ConvertResize

func (i *Image) ConvertResize(format uint64, width, height uint) *Image

ConvertResize image format conversion with crop/pad.

func (*Image) Destroy

func (i *Image) Destroy()

Destroy is an image destructor

func (*Image) FirstSymbol

func (i *Image) FirstSymbol() *Symbol

Image_scanner decode result iterator.

func (*Image) FreeData

func (i *Image) FreeData()

Built-in cleanup handler.

func (*Image) GetData

func (i *Image) GetData() interface{}

Return the image sample data.

func (*Image) GetDataLength

func (i *Image) GetDataLength() uint64

Return the size of image data.

func (*Image) GetFormat

func (i *Image) GetFormat() uint64

Retrieve the image format.

func (*Image) GetHeight

func (i *Image) GetHeight() uint

Retrieve the height of the image.

func (*Image) GetSequence

func (i *Image) GetSequence() uint

Retrieve a "sequence" (page/frame) number associated with this image.

func (*Image) GetSymbols

func (i *Image) GetSymbols() *SymbolSet

Retrieve the decoded results.

func (*Image) GetWidth

func (i *Image) GetWidth() uint

Retrieve the width of the image.

func (*Image) Ref

func (i *Image) Ref(refs int)

func (*Image) SetFormat

func (i *Image) SetFormat(format uint64)

Specify the fourcc image format code for image sample data.

func (*Image) SetSequence

func (i *Image) SetSequence(sequenceNum uint)

Associate a "sequence" (page/frame) number with this image.

func (*Image) SetSize

func (i *Image) SetSize(width, height uint)

Specify the pixel size of the image.

func (*Image) SetSymbols

func (i *Image) SetSymbols(symbols *SymbolSet)

Associate the specified symbol set with the image, replacing any existing results.

func (*Image) Write

func (i *Image) Write(filebase string) int

Dump raw image data to a file for debug.

type Processor

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

func NewProcessor

func NewProcessor(threaded int) *Processor

NewProcessor creates new Processor instance. If threaded is set and threading is available the processor will spawn threads where appropriate to avoid blocking and improve responsiveness

func (*Processor) Destroy

func (p *Processor) Destroy()

Destroy cleans up all resources associated with the processor

func (*Processor) ErrorString

func (p *Processor) ErrorString(verbosity int) string

Retrieve the detail string for the last processor error

func (*Processor) ForceFormat

func (p *Processor) ForceFormat(inputFormat, outputFormat uint64) int

ForceFormat forces specific input and output formats for debug/testing.

func (*Processor) GetErrorCode

func (p *Processor) GetErrorCode() int

Retrieve the type code for the last processor error.

func (*Processor) GetResults

func (p *Processor) GetResults() *SymbolSet

Retrieve decode results for last scanned image/frame.

func (*Processor) GetUserData

func (p *Processor) GetUserData() unsafe.Pointer

Return user specified data value associated with the processor.

func (*Processor) Init

func (p *Processor) Init(device string, enableDisplay int) int

Init - device (re)initialization. Opens a video input device and/or prepares to display output

func (*Processor) ProcessOne

func (p *Processor) ProcessOne(timeout int) int

Process from the video stream until a result is available, or the timeout (in milliseconds) expires.

func (*Processor) RequestIOMode

func (p *Processor) RequestIOMode(iomode int) int

RequestIOMode requests a preferred video I/O mode for debug/testing.

func (*Processor) RequestInterface

func (p *Processor) RequestInterface(version int) int

RequestInterface requests a preferred video driver interface version for debug/testing.

func (*Processor) RequestSize

func (p *Processor) RequestSize(width, height uint) int

RequestSize requests a preferred size for the video image from the device

func (*Processor) SetActive

func (p *Processor) SetActive(active int) int

Control the processor in free running video mode.

func (*Processor) SetConfig

func (p *Processor) SetConfig(symbology int, config int, value int) int

SetConfig sets config for indicated symbology (0 for all) to specified value. Returns 0 for success, non-0 for failure (config does not apply to specified symbology, or value out of range)

func (*Processor) SetDataHandler

func (p *Processor) SetDataHandler(fn func(img *Image))

Setup result handler callback. The specified function will be called by the processor whenever new results are available from the video stream or a static image.

func (*Processor) SetUserData

func (p *Processor) SetUserData(userdata unsafe.Pointer)

Associate user specified data value with the processor.

func (*Processor) SetVisible

func (p *Processor) SetVisible(visible int) int

Show or hide the display window owned by the library.

func (*Processor) UserWait

func (p *Processor) UserWait(timeout int) int

Wait for input to the display window from the user (via mouse or keyboard).

type Symbol

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

func (*Symbol) FirstComponent

func (s *Symbol) FirstComponent() *Symbol

FirstComponent iterates components of a composite result. Returns:

the first physical component symbol of a composite result
nil if the symbol is already a physical symbol

func (*Symbol) GetAddonName

func (s *Symbol) GetAddonName() string

GetAddonName retrieves string name for addon encoding

func (*Symbol) GetComponents

func (s *Symbol) GetComponents() *SymbolSet

GetComponents retrieves components of a composite result. Returns:

the symbol set containing the components
nil if the symbol is already a physical symbol

func (*Symbol) GetCount

func (s *Symbol) GetCount() int

GetCount retrieves current cache count. When the cache is enabled for the image_scanner this provides inter-frame reliability and redundancy information for video streams. Returns:

< 0 if symbol is still uncertain.
0 if symbol is newly verified.
> 0 for duplicate symbols

func (*Symbol) GetData

func (s *Symbol) GetData() string

GetData retrieves data decoded from symbol.

func (*Symbol) GetDataLength

func (s *Symbol) GetDataLength() uint

GetDataLength retrieves length of binary data.

func (*Symbol) GetLocSize

func (s *Symbol) GetLocSize() uint

Retrieve the number of points in the location polygon. The location polygon defines the image area that the symbol was extracted from. Returns the number of points in the location polygon Note:

this is currently not a polygon, but the scan locations where the symbol was decoded

func (*Symbol) GetLocX

func (s *Symbol) GetLocX(index uint) int

GetLocX retrieves location polygon x-coordinates. Points are specified by 0-based index. Returns:

the x-coordinate for a point in the location polygon.
-1 if index is out of range

func (*Symbol) GetLocY

func (s *Symbol) GetLocY(index uint) int

GetLocY retrieves location polygon y-coordinates. Points are specified by 0-based index. Returns:

the y-coordinate for a point in the location polygon.
-1 if index is out of range

func (*Symbol) GetName

func (s *Symbol) GetName() string

GetName retrieves string name for symbol encoding.

func (*Symbol) GetQuality

func (s *Symbol) GetQuality() int

GetQuality retrieves a symbol confidence metric. Returns an unscaled, relative quantity: larger values are better than smaller values, where "large" and "small" are application dependent. Note:

expect the exact definition of this quantity to change as the metric is refined.
Currently, only the ordered relationship between two values is defined and will remain stable in the future

func (*Symbol) GetType

func (s *Symbol) GetType() int

GetType retrieves type of decoded symbol.

func (*Symbol) Next

func (s *Symbol) Next() *Symbol

Next iterates the set to which this symbol belongs (there can be only one). Returns:

the next symbol in the set, or
nil when no more results are available

func (*Symbol) Ref

func (s *Symbol) Ref(refs int)

Ref is symbol reference count manipulation. Increment the reference count when you store a new reference to the symbol. Decrement when the reference is no longer used. Do not refer to the symbol once the count is decremented and the containing image has been recycled or destroyed. Note:

the containing image holds a reference to the symbol,
so you only need to use this if you keep a symbol after the image has been destroyed or reused.

type SymbolSet

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

func (*SymbolSet) GetSize

func (ss *SymbolSet) GetSize() int

GetSize retrieves set size. Returns number of symbols in the set.

func (*SymbolSet) SetFirstSymbol

func (ss *SymbolSet) SetFirstSymbol() *Symbol

SetFirstSymbol is a set iterator. Returns first decoded symbol result in a set. Nil if the set is empty

Jump to

Keyboard shortcuts

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