Coder Social home page Coder Social logo

yushulx / nodejs-barcode Goto Github PK

View Code? Open in Web Editor NEW
27.0 2.0 9.0 212.41 MB

Node.js 1D/2D barcode detection SDK built with Dynamsoft Barcode Reader.

Home Page: https://www.npmjs.com/package/barcode4nodejs

License: MIT License

C++ 11.70% Python 1.70% JavaScript 4.14% C 82.45%
barcode-reader nodejs javascript qrcode qrcode-reader barcode barcode-scanner datamatrix pdf417 camera

nodejs-barcode's Introduction

Node.js Barcode & QR Code SDK

The Node.js barcode QR code SDK is implemented by wrapping Dynamsoft Barcode Reader C++ SDK. It helps developers to build Node.js barcode and QR code scanning applications for Windows, Linux, macOS, Raspberry Pi and Jetson Nano.

Dynamsoft Barcode Reader SDK Version

v9.6.40

License Key for SDK

Pre-requisites

  • Platform-specific C/C++ compiler

  • node-gyp

    npm i node-gyp -g
    

Supported Platforms

  • Windows
  • Linux
  • macOS

Supported Barcode Symbologies

  • Linear Barcodes (1D)

    • Code 39 (including Code 39 Extended)
    • Code 93
    • Code 128
    • Codabar
    • Interleaved 2 of 5
    • EAN-8
    • EAN-13
    • UPC-A
    • UPC-E
    • Industrial 2 of 5
  • 2D Barcodes

    • QR Code (including Micro QR Code and Model 1)
    • Data Matrix
    • PDF417 (including Micro PDF417)
    • Aztec Code
    • MaxiCode (mode 2-5)
    • DotCode
  • Patch Code

  • GS1 Composite Code

  • GS1 DataBar

    • Omnidirectional,
    • Truncated, Stacked, Stacked
    • Omnidirectional, Limited,
    • Expanded, Expanded Stacked
  • Postal Codes

    • USPS Intelligent Mail
    • Postnet
    • Planet
    • Australian Post
    • UK Royal Mail

API

  • initLicense(license-key)
  • decodeFileAsync(fileName, barcodeTypes, callback, template) or await decodeFileAsync(fileName, barcodeTypes, template)
  • decodeFileStreamAsync(fileStream, fileSize, barcodeTypes, callback, template) or await decodeFileStreamAsync(fileStream, fileSize, barcodeTypes, template)
  • decodeBase64Async(base64, barcodeTypes, callback, template) or await decodeBase64Async(base64, barcodeTypes, template)
  • decodeYUYVAsync(buffer, width, height, barcodeTypes, callback, template) or await decodeYUYVAsync(buffer, width, height, barcodeTypes, template)
  • decodeBufferAsync(buffer, width, height, stride, barcodeTypes, callback, template, maxBufferLength) or await decodeBufferAsync(buffer, width, height, stride, barcodeTypes, template, maxBufferLength)

Template Usage

  1. Visit the barcode reader online demo.
  2. Customize parameters in advanced settings and then download the template.

For example:

let params = {
  "ImageParameter": {
    "Name": "Custom_143301_827",
    "BarcodeFormatIds": [
      "BF_ALL"
    ],
    "DeblurLevel": 9,
    "ExpectedBarcodesCount": 100,
    "ScaleDownThreshold": 1200000,
    "Timeout": 100000
  },
  "Version": "3.0"
};
template = JSON.stringify(params);

Quick Usage

Replace LICENSE-KEY with your own license key.

const dbr = require('barcode4nodejs');
dbr.initLicense("LICENSE-KEY")
dbr.decodeFileAsync("YOUR IMAGE FILE", dbr.formats.OneD | dbr.formats.PDF417 | dbr.formats.QRCode | dbr.formats.DataMatrix | dbr.formats.Aztec, function(err, msg){
  console.log(msg);
  for (index in msg) {
    result = msg[index];
    console.log('Format: ' + result['format']);
    console.log('Value : ' + result['value']);
    console.log('x1: ' + result['x1']);
    console.log('y1 : ' + result['y1']);
    console.log('x2: ' + result['x2']);
    console.log('y2 : ' + result['y2']);
    console.log('x3: ' + result['x3']);
    console.log('y3: ' + result['y3']);
    console.log('x4: ' + result['x4']);
    console.log('y4: ' + result['y4']);
    console.log('page: ' + result['page']);
    console.log('decoding time: ' + result['time']);
  }
}, "");

// Or
(async function () {
  try {
    var result = await dbr.decodeFileAsync("YOUR IMAGE FILE", dbr.formats.OneD | dbr.formats.PDF417 | dbr.formats.QRCode | dbr.formats.DataMatrix | dbr.formats.Aztec, "");
    console.log(result);
  } catch (error) {
    console.log(error);
  }
})();

How to Customize and Build the Module

  1. Get the source code:

    git clone https://github.com/yushulx/nodejs-barcode.git
    
  2. Download Dynamsoft C++ Barcode SDK. Copy header files to src folder and copy platform-specific shared libraries to platforms folder.

  3. Edit src/dbr.cc and index.js.

  4. Build the Node.js extension:

    node-gyp configure
    node-gyp build
    

    For Visual Studio 2019 Community

    node-gyp configure --msbuild_path="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" --msvs_version=2017
    node-gyp build
    

Examples

  • Command Line

    node test.js -f MultiPage.pdf
    

    image

  • Web

    npm install
    node server.js
    

    Open http://localhost:2018/index.htm in web browsers.

  • Desktop Electron

    cd src
    node-gyp rebuild --target=0.36.7 --arch=x64 --dist-url=https://atom.io/download/atom-shell
    
    cd examples/desktop-electron
    npm install
    npm start
    
  • Linux Camera

    npm install v4l2camera
    node camera_barcode_reader.js
    
  • RESTful Service

    npm install restify
    node server.js
    

    Open https://< ip >:2018 to scan barcodes in web browsers.

  • OpenCV

nodejs-barcode's People

Contributors

dependabot[bot] avatar klapperkopp avatar vincy1993 avatar yushulx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nodejs-barcode's Issues

License releasing / recycling

Hi,

I'm using this lib to scan QR codes in batch in a serverless function in the cloud. I can't find how to properly release / recycle the license once the job is done so the next invocation can run without errors.

So far I always get errors like this:

Detection error: The number of instances used has exceeded the limit.

Any idea on how to do it?

feature request: typescript declaration file

i would like to use the package in a typescript project and have proper typing for its exports. simply adding an index.d.ts to the root would suffice for this. i went ahead and wrote the contents of this as well as i could, but decided not to make a PR because i'm not very confident with the inner workings of the C++ code and there's some question marks left about some typings (see comments)

export const formats: {
  OneD: number
  PDF417: number
  QRCode: number
  DataMatrix: number
  Aztec: number
}

export type BarcodeFormat = (typeof formats)[keyof typeof formats]
export const barcodeTypes: number

export function getVersion(): string
export function initLicense(license: string): void
export function setInstanceType(type: string): void // ?? (list of options)
export function setLicenseCachePath(path: string): void
export function destroyInstance(): void

export type DetectedBarcodeResult = {
  format:
    | 'AZTEC'
    | 'CODABAR'
    | 'CODE_128'
    | 'CODE_128'
    | 'CODE_128'
    | 'CODE_39_EXTENDED'
    | 'CODE_93'
    | 'DATAMATRIX'
    | 'EAN_13'
    | 'EAN_8'
    | 'INDUSTRIAL_25'
    | 'ITF'
    | 'PDF417'
    | 'QR_CODE'
    | 'UPC_A'
    | 'UPC_E'
  value: string
  x1: number
  y1: number
  x2: number
  y2: number
  x3: number
  y3: number
  x4: number
  y4: number
  page: number
  time: number
}

export function decodeFileAsync(
  fileName: string,
  barcodeTypes: number,
  callback: (err: any, msg: DetectedBarcodeResult) => void,
  template?: string
): void
export function decodeFileAsync(
  fileName: string,
  barcodeTypes: number,
  template?: string
): Promise<DetectedBarcodeResult[]>

export function decodeFileStreamAsync(
  fileStream: Buffer, // ??
  fileSize: number,
  barcodeTypes: number,
  callback: (err: any, msg: DetectedBarcodeResult) => void,
  template?: string
): void
export function decodeFileStreamAsync(
  fileStream: Buffer, // ??
  fileSize: number,
  barcodeTypes: number,
  template?: string
): Promise<DetectedBarcodeResult[]>

export function decodeBase64Async(
  base64: string,
  barcodeTypes: number,
  callback: (err: any, msg: DetectedBarcodeResult) => void,
  template?: string
): void
export function decodeBase64Async(
  base64: string,
  barcodeTypes: number,
  template?: string
): Promise<DetectedBarcodeResult[]>

export function decodeYUYVAsync(
  buffer: Buffer,
  width: number,
  height: number,
  barcodeTypes: number,
  callback: (err: any, msg: DetectedBarcodeResult) => void,
  template?: string
): void
export function decodeYUYVAsync(
  buffer: Buffer,
  width: number,
  height: number,
  barcodeTypes: number,
  template?: string
): Promise<DetectedBarcodeResult[]>

export function decodeBufferAsync(
  buffer: Buffer,
  width: number,
  height: number,
  stride: number,
  barcodeTypes: number,
  callback: (err: any, msg: DetectedBarcodeResult) => void,
  template?: string
): void
export function decodeBufferAsync(
  buffer: Buffer,
  width: number,
  height: number,
  stride: number,
  barcodeTypes: number,
  template?: string
): Promise<DetectedBarcodeResult[]>

Doesn't work on Mac

How to reproduce:

  1. npm i node-gyp -g
  2. git clone https://github.com/yushulx/nodejs-barcode.git
  3. cd nodejs-barcode
  4. npm i
  5. cd examples/web
  6. node server.js

Console output:

klapperkopp@mac web % node server.js
macOS
node:internal/modules/cjs/loader:1210
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: dlopen(/Users/klapperkopp/code/nodejs-barcode/build/Release/dbr.node, 0x0001): Library not loaded: @rpath/libDynamsoftBarcodeReader.dylib
  Referenced from: <ADE06653-F4AC-33C5-8260-32721BD5501C> /Users/klapperkopp/code/nodejs-barcode/build/Release/dbr.node
  Reason: no LC_RPATH's found
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1210:18)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/tkuschan/code/nodejs-barcode/index.js:14:11)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12) {
  code: 'ERR_DLOPEN_FAILED'
}

Other info:

  • XCode Command Line Tools are installed.

  • Apple M1 Pro

  • OSX Sonoma 14.2.1 (23C71)

  • Xcode Version 15.1 (15C65)

  • Tried running sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

  • Tried running sudo xcode-select --reset

Using await / promise

I'd like to use decodeFileAsync as promise instead of supplying a callback.

Your decodeFileAsync function does not have "callback" as last argument as expected by util.promisify(), the last argument should be the callback, but here the last argument is "template".

Any plans to implement a decodeFile function which allows "async/await" to get the result? Or how could this be solved in an easy way with the existing implementation?

Licensing not working on linux/unix systems

Hi,

I have a valid licence key. It worked on windows, but I received DBR_InitLicense: H?ɳ? with a random string and Detection error: No license specified. on Intel MacOS and docker container on the cloud provider. How can I fix it?

Thank you.

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.