Coder Social home page Coder Social logo

yushulx / gobarcodeqrsdk Goto Github PK

View Code? Open in Web Editor NEW
11.0 7.0 2.0 83.09 MB

Golang barcode detection module based on Dynamsoft C/C++ Barcode SDK

Home Page: https://www.dynamsoft.com/codepool/golang-barcode-qr-code-reader.html

License: MIT License

Go 6.71% C 85.86% Dockerfile 0.14% Shell 1.68% PowerShell 0.91% HTML 0.60% JavaScript 2.59% CSS 1.50%
barcode code39 cpp docker ean13 golang pdf417 qrcode c

gobarcodeqrsdk's Introduction

Golang Barcode QR Code Reader

This project serves as a Golang wrapper for the Dynamsoft Barcode Reader C++ SDK. With this module, you can efficiently read various types of barcodes and symbols, including QR Codes (and Micro QR Codes), Data Matrix, PDF417 (and Micro PDF417), Aztec Code, MaxiCode (modes 2-5), and DotCode from images and PDF files.

Prerequisites

Supported Platforms

  • Windows
  • Linux
  • macOS

Test the Module

# Windows
.\run_windows_test.ps1

# Linux
./run_linux_test.sh

## mac
chmod +x run_mac_test.sh
sudo ./run_mac_test.sh

How to Use the Go Module

  1. Download the Go module:

    go get github.com/yushulx/goBarcodeQrSDK
  2. Import the package in your Go file:

    import (
    	"github.com/yushulx/goBarcodeQrSDK"
    )
  3. Specify the dynamic library path at runtime before running Go apps.

    • Windows

       $originalPath = $env:PATH
      
       # Get the GOPATH
       $GOPATH = $(go env GOPATH)
      
       # Find the path to the shared libraries
       $PACKAGE_PATH = Get-ChildItem -Path "$GOPATH\pkg\mod\github.com\yushulx" -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1 -ExpandProperty FullName
       Write-Host "PACKAGE_PATH set to $PACKAGE_PATH"
       $LIBRARY_PATH = "$PACKAGE_PATH\lib\windows"
      
       Write-Host "LIBRARY_PATH set to $LIBRARY_PATH"
       # Update PATH to include the assembly path
       $env:PATH = "$LIBRARY_PATH;" + $env:PATH
       # Write-Host "PATH set to $($env:PATH)"
      
       # Run your Go application
       go run test.go test.png
      
       $env:PATH = $originalPath
    • Linux

       #!/bin/bash
      
       # Save the original PATH
       originalPath=$LD_LIBRARY_PATH
      
       # Get the GOPATH
       GOPATH=$(go env GOPATH)
      
       # Find the path to the shared libraries
       PACKAGE_PATH=$(find "$GOPATH/pkg/mod/github.com/yushulx" -mindepth 1 -maxdepth 1 -type d | sort -r | head -n 1)
       echo "PACKAGE_PATH set to $PACKAGE_PATH"
       LIBRARY_PATH="$PACKAGE_PATH/lib/linux"
      
       echo "LIBRARY_PATH set to $LIBRARY_PATH"
      
       export LD_LIBRARY_PATH="$LIBRARY_PATH:$originalPath"
      
       # Run your Go application
       go run test.go test.png
      
       # Restore the original PATH
       export LD_LIBRARY_PATH=$originalPath
    • macOS

       #!/bin/bash
      
       # Save the original PATH
       originalPath=$LD_LIBRARY_PATH
      
       # Get the GOPATH
       GOPATH=$(go env GOPATH)
      
       # Find the path to the shared libraries
       PACKAGE_PATH=$(find "$GOPATH/pkg/mod/github.com/yushulx" -mindepth 1 -maxdepth 1 -type d | sort -r | head -n 1)
       echo "PACKAGE_PATH set to $PACKAGE_PATH"
       RPATH="$PACKAGE_PATH/lib/mac"
      
       echo "LIBRARY_PATH set to $LIBRARY_PATH"
      
       TARGET="testapp"
      
       go build -o $TARGET
      
       if ! otool -l $TARGET | grep -q $RPATH; then
       	echo "Adding rpath $RPATH to $TARGET"
       	install_name_tool -add_rpath $RPATH $TARGET
       else
       	echo "RPATH $RPATH already exists in $TARGET"
       fi
      
       ./$TARGET test.png
      
       rm ./$TARGET

Parameter Configuration

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

Quick Start

Set the license key within the InitLicense() function, and replace the image-file with the path of 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

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>

gobarcodeqrsdk's People

Contributors

yushulx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

bxlkm brunocicom

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.