brunocicom / goBarcodeQrSDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Golang Barcode QR Code Reader

The project is a Golang wrapper for Dynamsoft Barcode Reader C++ SDK. You can use this module to read barcodes, QR Code (including Micro QR Code), Data Matrix, PDF417 (including Micro PDF417), Aztec Code, MaxiCode (mode 2-5), and DotCode from images and PDF files.

Pre-requisites

Test the Module

go test

Parameter Configuration

https://www.dynamsoft.com/barcode-reader/docs/core/parameters/structure-and-interfaces-of-parameters.html?ver=latest

Example

package main

import (
	"fmt"
	"time"

	"github.com/yushulx/goBarcodeQrSDK"
)

func main() {
	ret, _ := goBarcodeQrSDK.InitLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
	if ret != 0 {
		fmt.Printf(`initLicense("") = %d`, ret)
	}
	obj := goBarcodeQrSDK.CreateBarcodeReader()
	obj.SetParameters("{\"ImageParameter\":{\"BarcodeFormatIds\":[\"BF_ONED\",\"BF_PDF417\",\"BF_QR_CODE\",\"BF_DATAMATRIX\"],\"BarcodeFormatIds_2\":null,\"Name\":\"sts\",\"RegionDefinitionNameArray\":[\"region0\"]},\"RegionDefinition\":{\"Bottom\":100,\"Left\":0,\"MeasuredByPercentage\":1,\"Name\":\"region0\",\"Right\":100,\"Top\":0}}")
	startTime := time.Now()
	code, barcodes := obj.DecodeFile("image-file")
	elapsed := time.Since(startTime)
	fmt.Println("DecodeFile() time cost: ", elapsed)

	if code != 0 {
		fmt.Printf(`DecodeFile() = %d`, code)
	}

	for i := 0; i < len(barcodes); i++ {
		barcode := barcodes[i]
		fmt.Println(barcode.Text)
		fmt.Println(barcode.Format)
		fmt.Println(barcode.X1)
		fmt.Println(barcode.Y1)
		fmt.Println(barcode.X2)
		fmt.Println(barcode.Y2)
		fmt.Println(barcode.X3)
		fmt.Println(barcode.Y3)
		fmt.Println(barcode.X4)
		fmt.Println(barcode.Y4)
	}
}

Set the license key in InitLicense() and update the image-file to the path of the image file you want to decode. Then run the example.

go run .

Docker Build

  • Build and run barcode QR code reader in Docker:

    docker build -t golang-barcode-qr-reader .
    docker run -it --rm golang-barcode-qr-reader
  • Read barcode and QR code from a local image file:

    docker run -it --rm -v <image-folder>:/app golang-barcode-qr-reader reader /app/<image-file> <license-key> <template-file>

Docker Usage

https://hub.docker.com/repository/docker/yushulx/golang-barcode-qr-reader

docker run -it --rm -v <image-folder>:/app yushulx/golang-barcode-qr-reader:latest reader /app/<image-file> <license-key> <template-file>

About

License:MIT License


Languages

Language:C 94.7%Language:Go 5.1%Language:Dockerfile 0.2%