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 ¶
- Variables
- func IncreaseVerbosity()
- func SetVerbosity(verbosity int)
- func Version() (major, minor, patch uint)
- type Image
- type ImageScanner
- func (s *ImageScanner) ScanImage(img *Image) ([]*Symbol, error)
- func (s *ImageScanner) SetASCIIAll(enabled bool) *ImageScanner
- func (s *ImageScanner) SetASCIISymbology(symbology SymbolType, enabled bool) *ImageScanner
- func (s *ImageScanner) SetAddCheckAll(enabled bool) *ImageScanner
- func (s *ImageScanner) SetAddCheckSymbology(symbology SymbolType, enabled bool) *ImageScanner
- func (s *ImageScanner) SetEmitCheckAll(enabled bool) *ImageScanner
- func (s *ImageScanner) SetEmitCheckSymbology(symbology SymbolType, enabled bool) *ImageScanner
- func (s *ImageScanner) SetEnabledAll(enabled bool) *ImageScanner
- func (s *ImageScanner) SetEnabledSymbology(symbology SymbolType, enabled bool) *ImageScanner
- func (s *ImageScanner) SetMaxLengthAll(length int) *ImageScanner
- func (s *ImageScanner) SetMaxLengthSymbology(symbology SymbolType, length int) *ImageScanner
- func (s *ImageScanner) SetMinLengthAll(length int) *ImageScanner
- func (s *ImageScanner) SetMinLengthSymbology(symbology SymbolType, length int) *ImageScanner
- func (s *ImageScanner) SetPositionEnabledAll(enabled bool) *ImageScanner
- func (s *ImageScanner) SetPositionEnabledSymbology(symbology SymbolType, enabled bool) *ImageScanner
- func (s *ImageScanner) SetXDensityAll(density int) *ImageScanner
- func (s *ImageScanner) SetXDensitySymbology(symbology SymbolType, density int) *ImageScanner
- func (s *ImageScanner) SetYDensityAll(density int) *ImageScanner
- func (s *ImageScanner) SetYDensitySymbology(symbology SymbolType, density int) *ImageScanner
- type Symbol
- type SymbolType
Constants ¶
This section is empty.
Variables ¶
var BusyError = errors.New("zbar: All resources busy")
var ClosedError = errors.New("zbar: Output window is closed")
var InternalError = errors.New("zbar: Internal library error")
var InvalidError = errors.New("zbar: Invalid request")
var LockingError = errors.New("zbar: Locking error")
var NoMemoryError = errors.New("zbar: Out of memory")
var SystemError = errors.New("zbar: System error")
var UnsupportedError = errors.New("zbar: Unsupported request")
var WinAPIError = errors.New("zbar: Windows system error")
var XDisplayError = errors.New("zbar: X11 display error")
var XProtoError = errors.New("zbar: X11 protocol error")
Functions ¶
func SetVerbosity ¶
func SetVerbosity(verbosity int)
SetVerbosity sets the library debug level. Higher values spew more debug information.
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.
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
const ( None SymbolType = C.ZBAR_NONE Partial SymbolType = C.ZBAR_PARTIAL EAN8 SymbolType = C.ZBAR_EAN8 UPCE SymbolType = C.ZBAR_UPCE ISBN10 SymbolType = C.ZBAR_ISBN10 UPCA SymbolType = C.ZBAR_UPCA EAN13 SymbolType = C.ZBAR_EAN13 ISBN13 SymbolType = C.ZBAR_ISBN13 I25 SymbolType = C.ZBAR_I25 Code39 SymbolType = C.ZBAR_CODE39 PDF417 SymbolType = C.ZBAR_PDF417 QRCode SymbolType = C.ZBAR_QRCODE Code128 SymbolType = C.ZBAR_CODE128 )
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.