Tuesday, March 26, 2024

Simplify Barcode and QR Code Reading in Golang with Dynamsoft Barcode Reader


Integrating barcode and QR code reading capabilities into your Golang applications can enhance their functionality and streamline data processing. However, implementing such functionality from scratch can be complex and time-consuming. Enter the Golang Barcode QR Code Reader, a project that provides a Golang wrapper for the Dynamsoft Barcode Reader C++ SDK. With this module, developers can effortlessly read various types of barcodes and symbols, including QR Codes, Data Matrix, PDF417, Aztec Code, and more, from images and PDF files.

Prerequisites:

  • Go
  • Dynamsoft Barcode Reader v9.x trial license

Supported Platforms:

  • Windows
  • Linux
  • macOS

Testing the Module:

To ensure the module works seamlessly, follow these steps for testing on different platforms:

For Windows:

.\run_windows_test.ps1

For Linux:

./run_linux_test.sh

For macOS:

chmod +x run_mac_test.sh

sudo ./run_mac_test.sh


How to Use the Go Module

To incorporate the Golang Barcode QR Code Reader into your project, follow these simple steps:

Download the Go module:

go get github.com/yushulx/goBarcodeQrSDK

Import the package in your Go file:

import (

"github.com/yushulx/goBarcodeQrSDK"

)

Specify the dynamic library path at runtime before running Go apps.

Parameter Configuration:

For detailed parameter configuration, refer to the official documentation.

Quick Start:

Get started quickly with the Golang Barcode QR Code Reader by setting the license key and providing the path to the image file you wish to decode:

package main


import (

"fmt"

"time"


"github.com/yushulx/goBarcodeQrSDK"

)


func main() {

ret, _ := goBarcodeQrSDK.InitLicense("LICENSE-KEY")

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)

}

}

Example:

Explore different usage scenarios with examples including Command-line, Web, and Docker Build.

Docker Build:

Build and run the barcode QR code reader in Docker with ease:

docker build -t golang-barcode-qr-reader .

docker run -it --rm golang-barcode-qr-reader

Docker Usage:

Utilize Docker for seamless integration and deployment:

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

Conclusion

The Golang Barcode QR Code Reader provides a straightforward solution for integrating barcode and QR code reading capabilities into Golang applications. With its easy-to-use interface and support for various barcode types, developers can efficiently process data from images and PDF files across different platforms.

0 comments:

Post a Comment